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; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 163 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 164 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 165 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 166 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 167 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 168 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 169 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 170 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 171 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 172 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 173 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 183 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 184 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 185 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 186 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 187 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 188 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 189 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 190 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 191 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 192 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 193 | import com.android.services.telephony.TelecomAccountRegistry; |
| 194 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 195 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 196 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 197 | import java.io.FileDescriptor; |
| 198 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 199 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 200 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 201 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 202 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 203 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 204 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 205 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 206 | import java.util.NoSuchElementException; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 207 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 208 | import java.util.Set; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 209 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 210 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 211 | |
| 212 | /** |
| 213 | * Implementation of the ITelephony interface. |
| 214 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 215 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 216 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 217 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 218 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 219 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 220 | |
| 221 | // Message codes used with mMainThreadHandler |
| 222 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 223 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 224 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 225 | private static final int CMD_OPEN_CHANNEL = 9; |
| 226 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 227 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 228 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 229 | private static final int CMD_NV_READ_ITEM = 13; |
| 230 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 231 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 232 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 233 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 234 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 235 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 236 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 237 | private static final int CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK = 21; |
| 238 | private static final int EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE = 22; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 239 | private static final int CMD_SEND_ENVELOPE = 25; |
| 240 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 241 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 242 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 243 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 244 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 245 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 246 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 247 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 248 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 249 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 250 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 251 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 252 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 253 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 254 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 255 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 256 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 257 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 258 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 259 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 260 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 261 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 262 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 263 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 264 | private static final int CMD_SWITCH_SLOTS = 50; |
| 265 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 266 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 267 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 268 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 269 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 270 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 271 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 272 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 273 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 274 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 275 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 276 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 277 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 278 | private static final int CMD_MODEM_REBOOT = 64; |
| 279 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 280 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 281 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 282 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 283 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 284 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 285 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 286 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 287 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 288 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 289 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 290 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 291 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 292 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 293 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 294 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 295 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 296 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 297 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 298 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 299 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 300 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 301 | private static final int CMD_GET_CALL_WAITING = 87; |
| 302 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 303 | private static final int CMD_SET_CALL_WAITING = 89; |
| 304 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 305 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 306 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 307 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 308 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 309 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 310 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 311 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 312 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 313 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 314 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 315 | private static final int CMD_SET_SIM_POWER = 101; |
| 316 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 317 | private static final int CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST = 103; |
| 318 | private static final int EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 104; |
| 319 | private static final int CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST = 105; |
| 320 | private static final int EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE = 106; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 321 | private static final int CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON = 107; |
| 322 | private static final int EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE = 108; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 323 | private static final int CMD_PREPARE_UNATTENDED_REBOOT = 109; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 324 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 325 | // Parameters of select command. |
| 326 | private static final int SELECT_COMMAND = 0xA4; |
| 327 | private static final int SELECT_P1 = 0x04; |
| 328 | private static final int SELECT_P2 = 0; |
| 329 | private static final int SELECT_P3 = 0x10; |
| 330 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 331 | /** The singleton instance. */ |
| 332 | private static PhoneInterfaceManager sInstance; |
| 333 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 334 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 335 | private CallManager mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 336 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 337 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 338 | private AppOpsManager mAppOps; |
| 339 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 340 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 341 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 342 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 343 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 344 | /** User Activity */ |
| 345 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 346 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 347 | |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 348 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 349 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 350 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 351 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 352 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 353 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 354 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 355 | // String to store multi SIM allowed |
| 356 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 357 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 358 | // The AID of ISD-R. |
| 359 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 360 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 361 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 362 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 363 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 364 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 365 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 366 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 367 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 368 | /** |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 369 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 370 | */ |
| 371 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 372 | "reset_network_erase_modem_config_enabled"; |
| 373 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 374 | private static final int SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS = 2000; // 2 seconds |
| 375 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 376 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 377 | * A request object to use for transmitting data to an ICC. |
| 378 | */ |
| 379 | private static final class IccAPDUArgument { |
| 380 | public int channel, cla, command, p1, p2, p3; |
| 381 | public String data; |
| 382 | |
| 383 | public IccAPDUArgument(int channel, int cla, int command, |
| 384 | int p1, int p2, int p3, String data) { |
| 385 | this.channel = channel; |
| 386 | this.cla = cla; |
| 387 | this.command = command; |
| 388 | this.p1 = p1; |
| 389 | this.p2 = p2; |
| 390 | this.p3 = p3; |
| 391 | this.data = data; |
| 392 | } |
| 393 | } |
| 394 | |
| 395 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 396 | * A request object to use for transmitting data to an ICC. |
| 397 | */ |
| 398 | private static final class ManualNetworkSelectionArgument { |
| 399 | public OperatorInfo operatorInfo; |
| 400 | public boolean persistSelection; |
| 401 | |
| 402 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 403 | this.operatorInfo = operatorInfo; |
| 404 | this.persistSelection = persistSelection; |
| 405 | } |
| 406 | } |
| 407 | |
| 408 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 409 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 410 | * request after sending. The main thread will notify the request when it is complete. |
| 411 | */ |
| 412 | private static final class MainThreadRequest { |
| 413 | /** The argument to use for the request */ |
| 414 | public Object argument; |
| 415 | /** The result of the request that is run on the main thread */ |
| 416 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 417 | // The subscriber id that this request applies to. Defaults to |
| 418 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 419 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 420 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 421 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 422 | public Phone phone; |
| 423 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 424 | public WorkSource workSource; |
| 425 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 426 | public MainThreadRequest(Object argument) { |
| 427 | this.argument = argument; |
| 428 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 429 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 430 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 431 | this.argument = argument; |
| 432 | if (phone != null) { |
| 433 | this.phone = phone; |
| 434 | } |
| 435 | this.workSource = workSource; |
| 436 | } |
| 437 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 438 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 439 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 440 | if (subId != null) { |
| 441 | this.subId = subId; |
| 442 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 443 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 444 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 445 | } |
| 446 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 447 | private static final class IncomingThirdPartyCallArgs { |
| 448 | public final ComponentName component; |
| 449 | public final String callId; |
| 450 | public final String callerDisplayName; |
| 451 | |
| 452 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 453 | String callerDisplayName) { |
| 454 | this.component = component; |
| 455 | this.callId = callId; |
| 456 | this.callerDisplayName = callerDisplayName; |
| 457 | } |
| 458 | } |
| 459 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 460 | /** |
| 461 | * A handler that processes messages on the main thread in the phone process. Since many |
| 462 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 463 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 464 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 465 | * on, which will be notified when the operation completes and will contain the result of the |
| 466 | * request. |
| 467 | * |
| 468 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 469 | * note that request.result must be set to something non-null for the calling thread to |
| 470 | * unblock. |
| 471 | */ |
| 472 | private final class MainThreadHandler extends Handler { |
| 473 | @Override |
| 474 | public void handleMessage(Message msg) { |
| 475 | MainThreadRequest request; |
| 476 | Message onCompleted; |
| 477 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 478 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 479 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 480 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 481 | |
| 482 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 483 | case CMD_HANDLE_USSD_REQUEST: { |
| 484 | request = (MainThreadRequest) msg.obj; |
| 485 | final Phone phone = getPhoneFromRequest(request); |
| 486 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 487 | String ussdRequest = ussdObject.first; |
| 488 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 489 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 490 | if (!isUssdApiAllowed(request.subId)) { |
| 491 | // Carrier does not support use of this API, return failure. |
| 492 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 493 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 494 | Bundle returnData = new Bundle(); |
| 495 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 496 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 497 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 498 | request.result = true; |
| 499 | notifyRequester(request); |
| 500 | return; |
| 501 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 502 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 503 | try { |
| 504 | request.result = phone != null |
| 505 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 506 | } catch (CallStateException cse) { |
| 507 | request.result = false; |
| 508 | } |
| 509 | // Wake up the requesting thread |
| 510 | notifyRequester(request); |
| 511 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 512 | } |
| 513 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 514 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 515 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 516 | final Phone phone = getPhoneFromRequest(request); |
| 517 | request.result = phone != null ? |
| 518 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 519 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 520 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 521 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 522 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 523 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 524 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 525 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 526 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 527 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 528 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 529 | if (uiccCard == null) { |
| 530 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 531 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 532 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 533 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 535 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 536 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 537 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 538 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 539 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 540 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 541 | break; |
| 542 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 543 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 544 | ar = (AsyncResult) msg.obj; |
| 545 | request = (MainThreadRequest) ar.userObj; |
| 546 | if (ar.exception == null && ar.result != null) { |
| 547 | request.result = ar.result; |
| 548 | } else { |
| 549 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 550 | if (ar.result == null) { |
| 551 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 552 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 553 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 554 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 555 | } else { |
| 556 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 557 | } |
| 558 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 559 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 560 | break; |
| 561 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 562 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 563 | request = (MainThreadRequest) msg.obj; |
| 564 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 565 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 566 | if (uiccCard == null) { |
| 567 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 568 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 569 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 570 | } else { |
| 571 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 572 | request); |
| 573 | uiccCard.iccTransmitApduBasicChannel( |
| 574 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 575 | iccArgument.p3, iccArgument.data, onCompleted); |
| 576 | } |
| 577 | break; |
| 578 | |
| 579 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 580 | ar = (AsyncResult) msg.obj; |
| 581 | request = (MainThreadRequest) ar.userObj; |
| 582 | if (ar.exception == null && ar.result != null) { |
| 583 | request.result = ar.result; |
| 584 | } else { |
| 585 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 586 | if (ar.result == null) { |
| 587 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 588 | } else if (ar.exception instanceof CommandException) { |
| 589 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 590 | ar.exception); |
| 591 | } else { |
| 592 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 593 | } |
| 594 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 595 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 596 | break; |
| 597 | |
| 598 | case CMD_EXCHANGE_SIM_IO: |
| 599 | request = (MainThreadRequest) msg.obj; |
| 600 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 601 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 602 | if (uiccCard == null) { |
| 603 | loge("iccExchangeSimIO: No UICC"); |
| 604 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 605 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 606 | } else { |
| 607 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 608 | request); |
| 609 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 610 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 611 | iccArgument.data, onCompleted); |
| 612 | } |
| 613 | break; |
| 614 | |
| 615 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 616 | ar = (AsyncResult) msg.obj; |
| 617 | request = (MainThreadRequest) ar.userObj; |
| 618 | if (ar.exception == null && ar.result != null) { |
| 619 | request.result = ar.result; |
| 620 | } else { |
| 621 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 622 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 623 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 624 | break; |
| 625 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 626 | case CMD_SEND_ENVELOPE: |
| 627 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 628 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 629 | if (uiccCard == null) { |
| 630 | loge("sendEnvelopeWithStatus: No UICC"); |
| 631 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 632 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 633 | } else { |
| 634 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 635 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 636 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 637 | break; |
| 638 | |
| 639 | case EVENT_SEND_ENVELOPE_DONE: |
| 640 | ar = (AsyncResult) msg.obj; |
| 641 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 642 | if (ar.exception == null && ar.result != null) { |
| 643 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 644 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 645 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 646 | if (ar.result == null) { |
| 647 | loge("sendEnvelopeWithStatus: Empty response"); |
| 648 | } else if (ar.exception instanceof CommandException) { |
| 649 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 650 | ar.exception); |
| 651 | } else { |
| 652 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 653 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 654 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 655 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 656 | break; |
| 657 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 658 | case CMD_OPEN_CHANNEL: |
| 659 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 660 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 661 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 662 | if (uiccCard == null) { |
| 663 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 664 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 665 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 666 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 667 | } else { |
| 668 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 669 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 670 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 671 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 672 | break; |
| 673 | |
| 674 | case EVENT_OPEN_CHANNEL_DONE: |
| 675 | ar = (AsyncResult) msg.obj; |
| 676 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 677 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 678 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 679 | int[] result = (int[]) ar.result; |
| 680 | int channelId = result[0]; |
| 681 | byte[] selectResponse = null; |
| 682 | if (result.length > 1) { |
| 683 | selectResponse = new byte[result.length - 1]; |
| 684 | for (int i = 1; i < result.length; ++i) { |
| 685 | selectResponse[i - 1] = (byte) result[i]; |
| 686 | } |
| 687 | } |
| 688 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 689 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 691 | if (ar.result == null) { |
| 692 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 693 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 694 | if (ar.exception != null) { |
| 695 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 696 | } |
| 697 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 698 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 699 | if (ar.exception instanceof CommandException) { |
| 700 | CommandException.Error error = |
| 701 | ((CommandException) (ar.exception)).getCommandError(); |
| 702 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 703 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 704 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 705 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 706 | } |
| 707 | } |
| 708 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 709 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 710 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 711 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 712 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 713 | break; |
| 714 | |
| 715 | case CMD_CLOSE_CHANNEL: |
| 716 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 717 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 718 | if (uiccCard == null) { |
| 719 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 720 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 721 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 722 | } else { |
| 723 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 724 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 725 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 726 | break; |
| 727 | |
| 728 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 729 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 730 | break; |
| 731 | |
| 732 | case CMD_NV_READ_ITEM: |
| 733 | request = (MainThreadRequest) msg.obj; |
| 734 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 735 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 736 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 737 | break; |
| 738 | |
| 739 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 740 | ar = (AsyncResult) msg.obj; |
| 741 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 742 | if (ar.exception == null && ar.result != null) { |
| 743 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 744 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 745 | request.result = ""; |
| 746 | if (ar.result == null) { |
| 747 | loge("nvReadItem: Empty response"); |
| 748 | } else if (ar.exception instanceof CommandException) { |
| 749 | loge("nvReadItem: CommandException: " + |
| 750 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 751 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 752 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 753 | } |
| 754 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 755 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 756 | break; |
| 757 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 758 | case CMD_NV_WRITE_ITEM: |
| 759 | request = (MainThreadRequest) msg.obj; |
| 760 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 761 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 762 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 763 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 764 | break; |
| 765 | |
| 766 | case EVENT_NV_WRITE_ITEM_DONE: |
| 767 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 768 | break; |
| 769 | |
| 770 | case CMD_NV_WRITE_CDMA_PRL: |
| 771 | request = (MainThreadRequest) msg.obj; |
| 772 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 773 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 774 | break; |
| 775 | |
| 776 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 777 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 778 | break; |
| 779 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 780 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 781 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 782 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 783 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 784 | break; |
| 785 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 786 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 787 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 788 | break; |
| 789 | |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 790 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 791 | request = (MainThreadRequest) msg.obj; |
| 792 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 793 | request); |
| 794 | Phone phone = getPhoneFromRequest(request); |
| 795 | if (phone != null) { |
| 796 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 797 | } else { |
| 798 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 799 | request.result = false; |
| 800 | notifyRequester(request); |
| 801 | } |
| 802 | break; |
| 803 | } |
| 804 | |
| 805 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 806 | ar = (AsyncResult) msg.obj; |
| 807 | request = (MainThreadRequest) ar.userObj; |
| 808 | if (ar.exception == null && ar.result != null) { |
| 809 | request.result = ar.result; |
| 810 | } else { |
| 811 | // request.result must be set to something non-null |
| 812 | // for the calling thread to unblock |
| 813 | if (request.result != null) { |
| 814 | request.result = ar.result; |
| 815 | } else { |
| 816 | request.result = false; |
| 817 | } |
| 818 | if (ar.result == null) { |
| 819 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 820 | } else if (ar.exception instanceof CommandException) { |
| 821 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 822 | + ar.exception); |
| 823 | } else { |
| 824 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 825 | } |
| 826 | } |
| 827 | notifyRequester(request); |
| 828 | break; |
| 829 | |
| 830 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 831 | request = (MainThreadRequest) msg.obj; |
| 832 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 833 | Phone phone = getPhoneFromRequest(request); |
| 834 | if (phone != null) { |
| 835 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 836 | request.workSource); |
| 837 | } else { |
| 838 | loge("enableNrDualConnectivity: No phone object"); |
| 839 | request.result = |
| 840 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 841 | notifyRequester(request); |
| 842 | } |
| 843 | break; |
| 844 | } |
| 845 | |
| 846 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 847 | ar = (AsyncResult) msg.obj; |
| 848 | request = (MainThreadRequest) ar.userObj; |
| 849 | if (ar.exception == null) { |
| 850 | request.result = |
| 851 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 852 | } else { |
| 853 | request.result = |
| 854 | TelephonyManager |
| 855 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 856 | if (ar.exception instanceof CommandException) { |
| 857 | CommandException.Error error = |
| 858 | ((CommandException) (ar.exception)).getCommandError(); |
| 859 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 860 | request.result = |
| 861 | TelephonyManager |
| 862 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 863 | } |
| 864 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 865 | + ar.exception); |
| 866 | } else { |
| 867 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 868 | } |
| 869 | } |
| 870 | notifyRequester(request); |
| 871 | break; |
| 872 | } |
| 873 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 874 | case CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 875 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 876 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE, |
| 877 | request); |
| 878 | getPhoneFromRequest(request).getAllowedNetworkTypesBitmask(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 879 | break; |
| 880 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 881 | case EVENT_GET_ALLOWED_NETWORK_TYPES_BITMASK_DONE: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 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) { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 891 | loge("getAllowedNetworkTypesBitmask: Empty response"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 892 | } else if (ar.exception instanceof CommandException) { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 893 | loge("getAllowedNetworkTypesBitmask: CommandException: " |
| 894 | + ar.exception); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 895 | } else { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 896 | loge("getAllowedNetworkTypesBitmask: Unknown exception"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 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 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 902 | case CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON: |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 903 | request = (MainThreadRequest) msg.obj; |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 904 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE, |
| 905 | request); |
| 906 | Pair<Integer, Long> reasonWithNetworkTypes = |
| 907 | (Pair<Integer, Long>) request.argument; |
| 908 | getPhoneFromRequest(request).setAllowedNetworkTypes( |
| 909 | reasonWithNetworkTypes.first, |
| 910 | reasonWithNetworkTypes.second, |
| 911 | onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 912 | break; |
| 913 | |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 914 | case EVENT_SET_ALLOWED_NETWORK_TYPES_FOR_REASON_DONE: |
| 915 | handleNullReturnEvent(msg, "setAllowedNetworkTypesForReason"); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 916 | break; |
| 917 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 918 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 919 | request = (MainThreadRequest)msg.obj; |
| 920 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 921 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 922 | break; |
| 923 | |
| 924 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 925 | ar = (AsyncResult)msg.obj; |
| 926 | request = (MainThreadRequest)ar.userObj; |
| 927 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 928 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 929 | break; |
| 930 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 931 | case CMD_SET_VOICEMAIL_NUMBER: |
| 932 | request = (MainThreadRequest) msg.obj; |
| 933 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 934 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 935 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 936 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 937 | break; |
| 938 | |
| 939 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 940 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 941 | break; |
| 942 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 943 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 944 | request = (MainThreadRequest) msg.obj; |
| 945 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 946 | request); |
| 947 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 948 | break; |
| 949 | |
| 950 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 951 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 952 | break; |
| 953 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 954 | case CMD_PERFORM_NETWORK_SCAN: |
| 955 | request = (MainThreadRequest) msg.obj; |
| 956 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 957 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 958 | break; |
| 959 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 960 | case CMD_GET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 961 | request = (MainThreadRequest) msg.obj; |
| 962 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 963 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 964 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 965 | request.argument; |
| 966 | int callForwardingReason = args.first; |
| 967 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 968 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 969 | } |
| 970 | case EVENT_GET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 971 | ar = (AsyncResult) msg.obj; |
| 972 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 973 | TelephonyManager.CallForwardingInfoCallback callback = |
| 974 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 975 | request.argument).second; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 976 | if (ar.exception == null && ar.result != null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 977 | CallForwardingInfo callForwardingInfo = null; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 978 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 979 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 980 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 981 | // any service for voice call. |
| 982 | if ((callForwardInfo.serviceClass |
| 983 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 984 | callForwardingInfo = new CallForwardingInfo(true, |
| 985 | callForwardInfo.reason, |
| 986 | callForwardInfo.number, |
| 987 | callForwardInfo.timeSeconds); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 988 | break; |
| 989 | } |
| 990 | } |
| 991 | // Didn't find a call forward info for voice call. |
| 992 | if (callForwardingInfo == null) { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 993 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 994 | 0 /* reason */, null /* number */, 0 /* timeout */); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 995 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 996 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 997 | } else { |
| 998 | if (ar.result == null) { |
| 999 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 1000 | } |
| 1001 | if (ar.exception != null) { |
| 1002 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 1003 | } |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1004 | int errorCode = TelephonyManager |
| 1005 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1006 | if (ar.exception instanceof CommandException) { |
| 1007 | CommandException.Error error = |
| 1008 | ((CommandException) (ar.exception)).getCommandError(); |
| 1009 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1010 | errorCode = TelephonyManager |
| 1011 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1012 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1013 | errorCode = TelephonyManager |
| 1014 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1015 | } |
| 1016 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1017 | callback.onError(errorCode); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1018 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1019 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1020 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1021 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1022 | case CMD_SET_CALL_FORWARDING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1023 | request = (MainThreadRequest) msg.obj; |
| 1024 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1025 | request = (MainThreadRequest) msg.obj; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1026 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1027 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1028 | request.argument).first; |
| 1029 | request.phone.setCallForwardingOption( |
| 1030 | callForwardingInfoToSet.isEnabled() |
| 1031 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1032 | : CommandsInterface.CF_ACTION_DISABLE, |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1033 | callForwardingInfoToSet.getReason(), |
| 1034 | callForwardingInfoToSet.getNumber(), |
| 1035 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1036 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1037 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1038 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1039 | case EVENT_SET_CALL_FORWARDING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1040 | ar = (AsyncResult) msg.obj; |
| 1041 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1042 | Consumer<Integer> callback = |
| 1043 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1044 | request.argument).second; |
| 1045 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1046 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1047 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1048 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1049 | if (ar.exception instanceof CommandException) { |
| 1050 | CommandException.Error error = |
| 1051 | ((CommandException) (ar.exception)).getCommandError(); |
| 1052 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1053 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1054 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1055 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1056 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1057 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1058 | } |
| 1059 | } |
| 1060 | callback.accept(errorCode); |
| 1061 | } else { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1062 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1063 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1064 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1065 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1066 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1067 | case CMD_GET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1068 | request = (MainThreadRequest) msg.obj; |
| 1069 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1070 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1071 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1072 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1073 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1074 | case EVENT_GET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1075 | ar = (AsyncResult) msg.obj; |
| 1076 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1077 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1078 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1079 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1080 | int[] callForwardResults = (int[]) ar.result; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1081 | // Service Class is a bit mask per 3gpp 27.007. |
| 1082 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1083 | if (callForwardResults.length > 1 |
| 1084 | && ((callForwardResults[1] |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1085 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1086 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1087 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1088 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1089 | } else { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1090 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1091 | } |
| 1092 | } else { |
| 1093 | if (ar.result == null) { |
| 1094 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1095 | } |
| 1096 | if (ar.exception != null) { |
| 1097 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1098 | } |
| 1099 | if (ar.exception instanceof CommandException) { |
| 1100 | CommandException.Error error = |
| 1101 | ((CommandException) (ar.exception)).getCommandError(); |
| 1102 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1103 | callForwardingStatus = |
| 1104 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1105 | } |
| 1106 | } |
| 1107 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1108 | callback.accept(callForwardingStatus); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1109 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1110 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1111 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1112 | case CMD_SET_CALL_WAITING: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1113 | request = (MainThreadRequest) msg.obj; |
| 1114 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1115 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1116 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1117 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1118 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1119 | |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1120 | case EVENT_SET_CALL_WAITING_DONE: { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1121 | ar = (AsyncResult) msg.obj; |
| 1122 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1123 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1124 | Consumer<Integer> callback = |
| 1125 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1126 | if (ar.exception != null) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1127 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1128 | if (ar.exception instanceof CommandException) { |
| 1129 | CommandException.Error error = |
| 1130 | ((CommandException) (ar.exception)).getCommandError(); |
| 1131 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1132 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1133 | } else { |
| 1134 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1135 | } |
| 1136 | } else { |
| 1137 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1138 | } |
| 1139 | } else { |
| 1140 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1141 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1142 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1143 | break; |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1144 | } |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 1145 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1146 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1147 | ar = (AsyncResult) msg.obj; |
| 1148 | request = (MainThreadRequest) ar.userObj; |
| 1149 | CellNetworkScanResult cellScanResult; |
| 1150 | if (ar.exception == null && ar.result != null) { |
| 1151 | cellScanResult = new CellNetworkScanResult( |
| 1152 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1153 | (List<OperatorInfo>) ar.result); |
| 1154 | } else { |
| 1155 | if (ar.result == null) { |
| 1156 | loge("getCellNetworkScanResults: Empty response"); |
| 1157 | } |
| 1158 | if (ar.exception != null) { |
| 1159 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1160 | } |
| 1161 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1162 | if (ar.exception instanceof CommandException) { |
| 1163 | CommandException.Error error = |
| 1164 | ((CommandException) (ar.exception)).getCommandError(); |
| 1165 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1166 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1167 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1168 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1169 | } |
| 1170 | } |
| 1171 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1172 | } |
| 1173 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1174 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1175 | break; |
| 1176 | |
| 1177 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1178 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1179 | ManualNetworkSelectionArgument selArg = |
| 1180 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1181 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1182 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1183 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1184 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1185 | break; |
| 1186 | |
| 1187 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1188 | ar = (AsyncResult) msg.obj; |
| 1189 | request = (MainThreadRequest) ar.userObj; |
| 1190 | if (ar.exception == null) { |
| 1191 | request.result = true; |
| 1192 | } else { |
| 1193 | request.result = false; |
| 1194 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1195 | } |
| 1196 | notifyRequester(request); |
| 1197 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1198 | break; |
| 1199 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1200 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1201 | request = (MainThreadRequest) msg.obj; |
| 1202 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1203 | if (defaultPhone != null) { |
| 1204 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1205 | } else { |
| 1206 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1207 | Bundle bundle = new Bundle(); |
| 1208 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
| 1209 | new ModemActivityInfo(0, 0, 0, new int[0], 0)); |
| 1210 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1211 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1212 | break; |
| 1213 | |
| 1214 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: |
| 1215 | ar = (AsyncResult) msg.obj; |
| 1216 | request = (MainThreadRequest) ar.userObj; |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1217 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1218 | |
| 1219 | ModemActivityInfo ret = new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1220 | if (ar.exception == null && ar.result != null) { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1221 | // Update the last modem activity info and the result of the request. |
| 1222 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1223 | if (isModemActivityInfoValid(info)) { |
| 1224 | int[] mergedTxTimeMs = new int[ModemActivityInfo.TX_POWER_LEVELS]; |
| 1225 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1226 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1227 | .getTransmitTimeMillis(); |
| 1228 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1229 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1230 | } |
| 1231 | mLastModemActivityInfo.setTimestamp(info.getTimestamp()); |
| 1232 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1233 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1234 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1235 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1236 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1237 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1238 | info.getReceiveTimeMillis() |
| 1239 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1240 | } |
| 1241 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestamp(), |
| 1242 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1243 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1244 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1245 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1246 | } else { |
| 1247 | if (ar.result == null) { |
| 1248 | loge("queryModemActivityInfo: Empty response"); |
| 1249 | } else if (ar.exception instanceof CommandException) { |
| 1250 | loge("queryModemActivityInfo: CommandException: " + |
| 1251 | ar.exception); |
| 1252 | } else { |
| 1253 | loge("queryModemActivityInfo: Unknown exception"); |
| 1254 | } |
| 1255 | } |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 1256 | Bundle bundle = new Bundle(); |
| 1257 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1258 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1259 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1260 | break; |
| 1261 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1262 | case CMD_SET_ALLOWED_CARRIERS: |
| 1263 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1264 | CarrierRestrictionRules argument = |
| 1265 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1266 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1267 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1268 | break; |
| 1269 | |
| 1270 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1271 | ar = (AsyncResult) msg.obj; |
| 1272 | request = (MainThreadRequest) ar.userObj; |
| 1273 | if (ar.exception == null && ar.result != null) { |
| 1274 | request.result = ar.result; |
| 1275 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1276 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1277 | if (ar.exception instanceof CommandException) { |
| 1278 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1279 | CommandException.Error error = |
| 1280 | ((CommandException) (ar.exception)).getCommandError(); |
| 1281 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1282 | request.result = |
| 1283 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1284 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1285 | } else { |
| 1286 | loge("setAllowedCarriers: Unknown exception"); |
| 1287 | } |
| 1288 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1289 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1290 | break; |
| 1291 | |
| 1292 | case CMD_GET_ALLOWED_CARRIERS: |
| 1293 | request = (MainThreadRequest) msg.obj; |
| 1294 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1295 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1296 | break; |
| 1297 | |
| 1298 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1299 | ar = (AsyncResult) msg.obj; |
| 1300 | request = (MainThreadRequest) ar.userObj; |
| 1301 | if (ar.exception == null && ar.result != null) { |
| 1302 | request.result = ar.result; |
| 1303 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1304 | request.result = new IllegalStateException( |
| 1305 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1306 | if (ar.result == null) { |
| 1307 | loge("getAllowedCarriers: Empty response"); |
| 1308 | } else if (ar.exception instanceof CommandException) { |
| 1309 | loge("getAllowedCarriers: CommandException: " + |
| 1310 | ar.exception); |
| 1311 | } else { |
| 1312 | loge("getAllowedCarriers: Unknown exception"); |
| 1313 | } |
| 1314 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1315 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1316 | break; |
| 1317 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1318 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1319 | ar = (AsyncResult) msg.obj; |
| 1320 | request = (MainThreadRequest) ar.userObj; |
| 1321 | if (ar.exception == null && ar.result != null) { |
| 1322 | request.result = ar.result; |
| 1323 | } else { |
| 1324 | request.result = new IllegalArgumentException( |
| 1325 | "Failed to retrieve Forbidden Plmns"); |
| 1326 | if (ar.result == null) { |
| 1327 | loge("getForbiddenPlmns: Empty response"); |
| 1328 | } else { |
| 1329 | loge("getForbiddenPlmns: Unknown exception"); |
| 1330 | } |
| 1331 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1332 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1333 | break; |
| 1334 | |
| 1335 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1336 | request = (MainThreadRequest) msg.obj; |
| 1337 | uiccCard = getUiccCardFromRequest(request); |
| 1338 | if (uiccCard == null) { |
| 1339 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1340 | request.result = new IllegalArgumentException( |
| 1341 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1342 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1343 | break; |
| 1344 | } |
| 1345 | Integer appType = (Integer) request.argument; |
| 1346 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1347 | if (uiccApp == null) { |
| 1348 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1349 | + appType); |
| 1350 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1351 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1352 | break; |
| 1353 | } else { |
| 1354 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1355 | + " specified type -- " + appType); |
| 1356 | } |
| 1357 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1358 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1359 | onCompleted); |
| 1360 | break; |
| 1361 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1362 | case CMD_SWITCH_SLOTS: |
| 1363 | request = (MainThreadRequest) msg.obj; |
| 1364 | int[] physicalSlots = (int[]) request.argument; |
| 1365 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1366 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1367 | break; |
| 1368 | |
| 1369 | case EVENT_SWITCH_SLOTS_DONE: |
| 1370 | ar = (AsyncResult) msg.obj; |
| 1371 | request = (MainThreadRequest) ar.userObj; |
| 1372 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1373 | notifyRequester(request); |
| 1374 | break; |
| 1375 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1376 | request = (MainThreadRequest) msg.obj; |
| 1377 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1378 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1379 | break; |
| 1380 | |
| 1381 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1382 | ar = (AsyncResult) msg.obj; |
| 1383 | request = (MainThreadRequest) ar.userObj; |
| 1384 | if (ar.exception != null) { |
| 1385 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1386 | } else { |
| 1387 | int mode = ((int[]) ar.result)[0]; |
| 1388 | if (mode == 0) { |
| 1389 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1390 | } else { |
| 1391 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1392 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1393 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1394 | notifyRequester(request); |
| 1395 | break; |
| 1396 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1397 | request = (MainThreadRequest) msg.obj; |
| 1398 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1399 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1400 | break; |
| 1401 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1402 | ar = (AsyncResult) msg.obj; |
| 1403 | request = (MainThreadRequest) ar.userObj; |
| 1404 | if (ar.exception != null) { |
| 1405 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1406 | } else { |
| 1407 | request.result = ((int[]) ar.result)[0]; |
| 1408 | } |
| 1409 | notifyRequester(request); |
| 1410 | break; |
| 1411 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1412 | request = (MainThreadRequest) msg.obj; |
| 1413 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1414 | int mode = (int) request.argument; |
| 1415 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1416 | break; |
| 1417 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1418 | ar = (AsyncResult) msg.obj; |
| 1419 | request = (MainThreadRequest) ar.userObj; |
| 1420 | request.result = ar.exception == null; |
| 1421 | notifyRequester(request); |
| 1422 | break; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1423 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1424 | request = (MainThreadRequest) msg.obj; |
| 1425 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1426 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1427 | break; |
| 1428 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1429 | ar = (AsyncResult) msg.obj; |
| 1430 | request = (MainThreadRequest) ar.userObj; |
| 1431 | if (ar.exception != null) { |
| 1432 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1433 | } else { |
| 1434 | request.result = ((int[]) ar.result)[0]; |
| 1435 | } |
| 1436 | notifyRequester(request); |
| 1437 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1438 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1439 | request = (MainThreadRequest) msg.obj; |
| 1440 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1441 | int subscriptionMode = (int) request.argument; |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1442 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1443 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1444 | break; |
| 1445 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1446 | ar = (AsyncResult) msg.obj; |
| 1447 | request = (MainThreadRequest) ar.userObj; |
| 1448 | request.result = ar.exception == null; |
| 1449 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1450 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1451 | case CMD_GET_ALL_CELL_INFO: |
| 1452 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1453 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1454 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1455 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1456 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1457 | ar = (AsyncResult) msg.obj; |
| 1458 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1459 | // If a timeout occurs, the response will be null |
| 1460 | request.result = (ar.exception == null && ar.result != null) |
| 1461 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1462 | synchronized (request) { |
| 1463 | request.notifyAll(); |
| 1464 | } |
| 1465 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1466 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1467 | request = (MainThreadRequest) msg.obj; |
| 1468 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1469 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1470 | break; |
| 1471 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1472 | ar = (AsyncResult) msg.obj; |
| 1473 | request = (MainThreadRequest) ar.userObj; |
| 1474 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1475 | try { |
| 1476 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1477 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1478 | cb.onError( |
| 1479 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1480 | ar.exception.getClass().getName(), |
| 1481 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1482 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1483 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | 6c08ecd | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1484 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1485 | } else { |
| 1486 | // use the result as returned |
| 1487 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1488 | } |
| 1489 | } catch (RemoteException re) { |
| 1490 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1491 | } |
| 1492 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1493 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1494 | request = (MainThreadRequest) msg.obj; |
| 1495 | WorkSource ws = (WorkSource) request.argument; |
| 1496 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1497 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1498 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1499 | } |
| 1500 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1501 | ar = (AsyncResult) msg.obj; |
| 1502 | request = (MainThreadRequest) ar.userObj; |
| 1503 | if (ar.exception == null) { |
| 1504 | request.result = ar.result; |
| 1505 | } else { |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1506 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1507 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1508 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1509 | } |
| 1510 | |
| 1511 | synchronized (request) { |
| 1512 | request.notifyAll(); |
| 1513 | } |
| 1514 | break; |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1515 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1516 | case CMD_MODEM_REBOOT: |
| 1517 | request = (MainThreadRequest) msg.obj; |
| 1518 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1519 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1520 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1521 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1522 | handleNullReturnEvent(msg, "rebootModem"); |
| 1523 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1524 | case CMD_REQUEST_ENABLE_MODEM: |
| 1525 | request = (MainThreadRequest) msg.obj; |
| 1526 | boolean enable = (boolean) request.argument; |
| 1527 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1528 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1529 | PhoneConfigurationManager.getInstance() |
| 1530 | .enablePhone(request.phone, enable, onCompleted); |
| 1531 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1532 | case EVENT_ENABLE_MODEM_DONE: { |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1533 | ar = (AsyncResult) msg.obj; |
| 1534 | request = (MainThreadRequest) ar.userObj; |
| 1535 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1536 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1537 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1538 | if ((boolean) request.result) { |
| 1539 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1540 | updateModemStateMetrics(); |
| 1541 | } else { |
| 1542 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1543 | + ar.exception); |
| 1544 | } |
| 1545 | notifyRequester(request); |
| 1546 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1547 | } |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1548 | case CMD_GET_MODEM_STATUS: |
| 1549 | request = (MainThreadRequest) msg.obj; |
| 1550 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1551 | PhoneConfigurationManager.getInstance() |
| 1552 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1553 | break; |
| 1554 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1555 | ar = (AsyncResult) msg.obj; |
| 1556 | request = (MainThreadRequest) ar.userObj; |
| 1557 | int id = request.phone.getPhoneId(); |
| 1558 | if (ar.exception == null && ar.result != null) { |
| 1559 | request.result = ar.result; |
| 1560 | //update the cache as modem status has changed |
| 1561 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1562 | (boolean) request.result); |
| 1563 | } else { |
| 1564 | // Return true if modem status cannot be retrieved. For most cases, |
| 1565 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1566 | // and disable modem are not supported. Modem is always on. |
| 1567 | // TODO: this should be fixed in R to support a third |
| 1568 | // status UNKNOWN b/131631629 |
| 1569 | request.result = true; |
| 1570 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1571 | + ar.exception); |
| 1572 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1573 | notifyRequester(request); |
| 1574 | break; |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1575 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1576 | request = (MainThreadRequest) msg.obj; |
| 1577 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1578 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1579 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1580 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1581 | break; |
| 1582 | } |
| 1583 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1584 | ar = (AsyncResult) msg.obj; |
| 1585 | request = (MainThreadRequest) ar.userObj; |
| 1586 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1587 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1588 | args.second.accept(ar.exception == null); |
| 1589 | notifyRequester(request); |
| 1590 | break; |
| 1591 | } |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1592 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1593 | request = (MainThreadRequest) msg.obj; |
| 1594 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1595 | Phone phone = getPhoneFromRequest(request); |
| 1596 | if (phone != null) { |
| 1597 | phone.getSystemSelectionChannels(onCompleted); |
| 1598 | } else { |
| 1599 | loge("getSystemSelectionChannels: No phone object"); |
| 1600 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1601 | notifyRequester(request); |
| 1602 | } |
| 1603 | break; |
| 1604 | } |
| 1605 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1606 | ar = (AsyncResult) msg.obj; |
| 1607 | request = (MainThreadRequest) ar.userObj; |
| 1608 | if (ar.exception == null && ar.result != null) { |
| 1609 | request.result = ar.result; |
| 1610 | } else { |
| 1611 | request.result = new IllegalArgumentException( |
| 1612 | "Failed to retrieve system selection channels"); |
| 1613 | if (ar.result == null) { |
| 1614 | loge("getSystemSelectionChannels: Empty response"); |
| 1615 | } else { |
| 1616 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1617 | } |
| 1618 | } |
| 1619 | notifyRequester(request); |
| 1620 | break; |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1621 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1622 | ar = (AsyncResult) msg.obj; |
| 1623 | request = (MainThreadRequest) ar.userObj; |
| 1624 | if (ar.exception == null && ar.result != null) { |
| 1625 | request.result = ar.result; |
| 1626 | } else { |
| 1627 | request.result = -1; |
| 1628 | loge("Failed to set Forbidden Plmns"); |
| 1629 | if (ar.result == null) { |
| 1630 | loge("setForbidenPlmns: Empty response"); |
| 1631 | } else if (ar.exception != null) { |
| 1632 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1633 | request.result = -1; |
| 1634 | } else { |
| 1635 | loge("setForbiddenPlmns: Unknown exception"); |
| 1636 | } |
| 1637 | } |
| 1638 | notifyRequester(request); |
| 1639 | break; |
| 1640 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1641 | request = (MainThreadRequest) msg.obj; |
| 1642 | uiccCard = getUiccCardFromRequest(request); |
| 1643 | if (uiccCard == null) { |
| 1644 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1645 | request.result = -1; |
| 1646 | notifyRequester(request); |
| 1647 | break; |
| 1648 | } |
| 1649 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1650 | (Pair<Integer, List<String>>) request.argument; |
| 1651 | appType = setFplmnsArgs.first; |
| 1652 | List<String> fplmns = setFplmnsArgs.second; |
| 1653 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1654 | if (uiccApp == null) { |
| 1655 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1656 | request.result = -1; |
| 1657 | loge("Failed to get UICC App"); |
| 1658 | notifyRequester(request); |
| 1659 | } else { |
| 1660 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1661 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1662 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1663 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1664 | break; |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1665 | case CMD_ERASE_MODEM_CONFIG: |
| 1666 | request = (MainThreadRequest) msg.obj; |
| 1667 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1668 | defaultPhone.eraseModemConfig(onCompleted); |
| 1669 | break; |
| 1670 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1671 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1672 | break; |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1673 | |
| 1674 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1675 | request = (MainThreadRequest) msg.obj; |
| 1676 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1677 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1678 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1679 | changed.first, changed.second, onCompleted); |
| 1680 | break; |
| 1681 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1682 | ar = (AsyncResult) msg.obj; |
| 1683 | request = (MainThreadRequest) ar.userObj; |
| 1684 | if (ar.exception == null) { |
| 1685 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1686 | // If the operation is successful, update the PIN storage |
| 1687 | Pair<String, String> passwords = (Pair<String, String>) request.argument; |
| 1688 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1689 | UiccController.getInstance().getPinStorage() |
| 1690 | .storePin(passwords.second, phoneId); |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1691 | } else { |
| 1692 | request.result = msg.arg1; |
| 1693 | } |
| 1694 | notifyRequester(request); |
| 1695 | break; |
| 1696 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1697 | case CMD_SET_ICC_LOCK_ENABLED: { |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1698 | request = (MainThreadRequest) msg.obj; |
| 1699 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1700 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1701 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1702 | enabled.first, enabled.second, onCompleted); |
| 1703 | break; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1704 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1705 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1706 | ar = (AsyncResult) msg.obj; |
| 1707 | request = (MainThreadRequest) ar.userObj; |
| 1708 | if (ar.exception == null) { |
| 1709 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1710 | // If the operation is successful, update the PIN storage |
| 1711 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1712 | int phoneId = getPhoneFromRequest(request).getPhoneId(); |
| 1713 | if (enabled.first) { |
| 1714 | UiccController.getInstance().getPinStorage() |
| 1715 | .storePin(enabled.second, phoneId); |
| 1716 | } else { |
| 1717 | UiccController.getInstance().getPinStorage().clearPin(phoneId); |
| 1718 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1719 | } else { |
| 1720 | request.result = msg.arg1; |
| 1721 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1722 | |
| 1723 | |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1724 | notifyRequester(request); |
| 1725 | break; |
| 1726 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1727 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1728 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1729 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1730 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1731 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1732 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1733 | break; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 1734 | |
| 1735 | case CMD_SET_DATA_THROTTLING: { |
| 1736 | request = (MainThreadRequest) msg.obj; |
| 1737 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1738 | DataThrottlingRequest dataThrottlingRequest = |
| 1739 | (DataThrottlingRequest) request.argument; |
| 1740 | Phone phone = getPhoneFromRequest(request); |
| 1741 | if (phone != null) { |
| 1742 | phone.setDataThrottling(onCompleted, |
| 1743 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1744 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1745 | } else { |
| 1746 | loge("setDataThrottling: No phone object"); |
| 1747 | request.result = |
| 1748 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1749 | notifyRequester(request); |
| 1750 | } |
| 1751 | |
| 1752 | break; |
| 1753 | } |
| 1754 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1755 | ar = (AsyncResult) msg.obj; |
| 1756 | request = (MainThreadRequest) ar.userObj; |
| 1757 | |
| 1758 | if (ar.exception == null) { |
| 1759 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1760 | } else if (ar.exception instanceof CommandException) { |
| 1761 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1762 | CommandException.Error error = |
| 1763 | ((CommandException) (ar.exception)).getCommandError(); |
| 1764 | |
| 1765 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1766 | request.result = TelephonyManager |
| 1767 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1768 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1769 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1770 | } else { |
| 1771 | request.result = |
| 1772 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1773 | } |
| 1774 | } else { |
| 1775 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1776 | } |
| 1777 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1778 | notifyRequester(request); |
| 1779 | break; |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1780 | |
| 1781 | case CMD_SET_SIM_POWER: { |
| 1782 | request = (MainThreadRequest) msg.obj; |
| 1783 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1784 | request = (MainThreadRequest) msg.obj; |
| 1785 | int stateToSet = |
| 1786 | ((Pair<Integer, IIntegerConsumer>) |
| 1787 | request.argument).first; |
| 1788 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1789 | break; |
| 1790 | } |
| 1791 | case EVENT_SET_SIM_POWER_DONE: { |
| 1792 | ar = (AsyncResult) msg.obj; |
| 1793 | request = (MainThreadRequest) ar.userObj; |
| 1794 | IIntegerConsumer callback = |
| 1795 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1796 | if (ar.exception != null) { |
| 1797 | loge("setSimPower exception: " + ar.exception); |
| 1798 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1799 | .RESULT_ERROR_UNKNOWN; |
| 1800 | if (ar.exception instanceof CommandException) { |
| 1801 | CommandException.Error error = |
| 1802 | ((CommandException) (ar.exception)).getCommandError(); |
| 1803 | if (error == CommandException.Error.SIM_ERR) { |
| 1804 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1805 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1806 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1807 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1808 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1809 | } else { |
| 1810 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1811 | } |
| 1812 | } |
| 1813 | try { |
| 1814 | callback.accept(errorCode); |
| 1815 | } catch (RemoteException e) { |
| 1816 | // Ignore if the remote process is no longer available to call back. |
| 1817 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1818 | } |
| 1819 | } else { |
| 1820 | try { |
| 1821 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1822 | } catch (RemoteException e) { |
| 1823 | // Ignore if the remote process is no longer available to call back. |
| 1824 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1825 | } |
| 1826 | } |
| 1827 | break; |
| 1828 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 1829 | case CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1830 | request = (MainThreadRequest) msg.obj; |
| 1831 | |
| 1832 | final Phone phone = getPhoneFromRequest(request); |
| 1833 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1834 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1835 | notifyRequester(request); |
| 1836 | break; |
| 1837 | } |
| 1838 | |
| 1839 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1840 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1841 | onCompleted = obtainMessage(EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1842 | request); |
| 1843 | phone.getServiceStateTracker().setSignalStrengthUpdateRequest( |
| 1844 | request.subId, pair.first /*callingUid*/, |
| 1845 | pair.second /*request*/, onCompleted); |
| 1846 | break; |
| 1847 | } |
| 1848 | case EVENT_SET_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1849 | ar = (AsyncResult) msg.obj; |
| 1850 | request = (MainThreadRequest) ar.userObj; |
| 1851 | // request.result will be the exception of ar if present, true otherwise. |
| 1852 | // Be cautious not to leave result null which will wait() forever |
| 1853 | request.result = ar.exception != null ? ar.exception : true; |
| 1854 | notifyRequester(request); |
| 1855 | break; |
| 1856 | } |
| 1857 | case CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST: { |
| 1858 | request = (MainThreadRequest) msg.obj; |
| 1859 | |
| 1860 | Phone phone = getPhoneFromRequest(request); |
| 1861 | if (phone == null || phone.getServiceStateTracker() == null) { |
| 1862 | request.result = new IllegalStateException("Phone or SST is null"); |
| 1863 | notifyRequester(request); |
| 1864 | break; |
| 1865 | } |
| 1866 | |
| 1867 | Pair<Integer, SignalStrengthUpdateRequest> pair = |
| 1868 | (Pair<Integer, SignalStrengthUpdateRequest>) request.argument; |
| 1869 | onCompleted = obtainMessage(EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE, |
| 1870 | request); |
| 1871 | phone.getServiceStateTracker().clearSignalStrengthUpdateRequest( |
| 1872 | request.subId, pair.first /*callingUid*/, |
| 1873 | pair.second /*request*/, onCompleted); |
| 1874 | break; |
| 1875 | } |
| 1876 | case EVENT_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST_DONE: { |
| 1877 | ar = (AsyncResult) msg.obj; |
| 1878 | request = (MainThreadRequest) ar.userObj; |
| 1879 | request.result = ar.exception != null ? ar.exception : true; |
| 1880 | notifyRequester(request); |
| 1881 | break; |
| 1882 | } |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1883 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 1884 | case CMD_PREPARE_UNATTENDED_REBOOT: |
| 1885 | request = (MainThreadRequest) msg.obj; |
| 1886 | request.result = |
| 1887 | UiccController.getInstance().getPinStorage().prepareUnattendedReboot(); |
| 1888 | notifyRequester(request); |
| 1889 | break; |
| 1890 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1891 | default: |
| 1892 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1893 | break; |
| 1894 | } |
| 1895 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1896 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1897 | private void notifyRequester(MainThreadRequest request) { |
| 1898 | synchronized (request) { |
| 1899 | request.notifyAll(); |
| 1900 | } |
| 1901 | } |
| 1902 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1903 | private void handleNullReturnEvent(Message msg, String command) { |
| 1904 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1905 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1906 | if (ar.exception == null) { |
| 1907 | request.result = true; |
| 1908 | } else { |
| 1909 | request.result = false; |
| 1910 | if (ar.exception instanceof CommandException) { |
| 1911 | loge(command + ": CommandException: " + ar.exception); |
| 1912 | } else { |
| 1913 | loge(command + ": Unknown exception"); |
| 1914 | } |
| 1915 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1916 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1917 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1918 | } |
| 1919 | |
| 1920 | /** |
| 1921 | * Posts the specified command to be executed on the main thread, |
| 1922 | * waits for the request to complete, and returns the result. |
| 1923 | * @see #sendRequestAsync |
| 1924 | */ |
| 1925 | private Object sendRequest(int command, Object argument) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1926 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, |
| 1927 | null, -1 /*timeoutInMs*/); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1928 | } |
| 1929 | |
| 1930 | /** |
| 1931 | * Posts the specified command to be executed on the main thread, |
| 1932 | * waits for the request to complete, and returns the result. |
| 1933 | * @see #sendRequestAsync |
| 1934 | */ |
| 1935 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1936 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1937 | null, workSource, -1 /*timeoutInMs*/); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | /** |
| 1941 | * Posts the specified command to be executed on the main thread, |
| 1942 | * waits for the request to complete, and returns the result. |
| 1943 | * @see #sendRequestAsync |
| 1944 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1945 | private Object sendRequest(int command, Object argument, Integer subId) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1946 | return sendRequest(command, argument, subId, null, null, -1 /*timeoutInMs*/); |
| 1947 | } |
| 1948 | |
| 1949 | /** |
| 1950 | * Posts the specified command to be executed on the main thread, |
| 1951 | * waits for the request to complete for at most {@code timeoutInMs}, and returns the result |
| 1952 | * if not timeout or null otherwise. |
| 1953 | * @see #sendRequestAsync |
| 1954 | */ |
| 1955 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, |
| 1956 | long timeoutInMs) { |
| 1957 | return sendRequest(command, argument, subId, null, null, timeoutInMs); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1958 | } |
| 1959 | |
| 1960 | /** |
| 1961 | * Posts the specified command to be executed on the main thread, |
| 1962 | * waits for the request to complete, and returns the result. |
| 1963 | * @see #sendRequestAsync |
| 1964 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1965 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1966 | return sendRequest(command, argument, subId, null, workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1967 | } |
| 1968 | |
| 1969 | /** |
| 1970 | * Posts the specified command to be executed on the main thread, |
| 1971 | * waits for the request to complete, and returns the result. |
| 1972 | * @see #sendRequestAsync |
| 1973 | */ |
| 1974 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1975 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, |
| 1976 | workSource, -1 /*timeoutInMs*/); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
| 1979 | /** |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1980 | * Posts the specified command to be executed on the main thread. If {@code timeoutInMs} is |
| 1981 | * negative, waits for the request to complete, and returns the result. Otherwise, wait for |
| 1982 | * maximum of {@code timeoutInMs} milliseconds, interrupt and return null. |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1983 | * @see #sendRequestAsync |
| 1984 | */ |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 1985 | private @Nullable Object sendRequest(int command, Object argument, Integer subId, Phone phone, |
| 1986 | WorkSource workSource, long timeoutInMs) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1987 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1988 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1989 | } |
| 1990 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1991 | MainThreadRequest request = null; |
| 1992 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1993 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1994 | } else if (phone != null) { |
| 1995 | request = new MainThreadRequest(argument, phone, workSource); |
| 1996 | } else { |
| 1997 | request = new MainThreadRequest(argument, subId, workSource); |
| 1998 | } |
| 1999 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2000 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2001 | msg.sendToTarget(); |
| 2002 | |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2003 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2004 | synchronized (request) { |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2005 | if (timeoutInMs >= 0) { |
| 2006 | // Wait for at least timeoutInMs before returning null request result |
| 2007 | long now = SystemClock.elapsedRealtime(); |
| 2008 | long deadline = now + timeoutInMs; |
| 2009 | while (request == null && now < deadline) { |
| 2010 | try { |
| 2011 | request.wait(deadline - now); |
| 2012 | } catch (InterruptedException e) { |
| 2013 | // Do nothing, go back and check if request is completed or timeout |
| 2014 | } finally { |
| 2015 | now = SystemClock.elapsedRealtime(); |
| 2016 | } |
| 2017 | } |
| 2018 | } else { |
| 2019 | // Wait for the request to complete |
| 2020 | while (request.result == null) { |
| 2021 | try { |
| 2022 | request.wait(); |
| 2023 | } catch (InterruptedException e) { |
| 2024 | // Do nothing, go back and wait until the request is complete |
| 2025 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2026 | } |
| 2027 | } |
| 2028 | } |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 2029 | if (request.result == null) { |
| 2030 | Log.wtf(LOG_TAG, |
| 2031 | "sendRequest: Blocking command timed out. Something has gone terribly wrong."); |
| 2032 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2033 | return request.result; |
| 2034 | } |
| 2035 | |
| 2036 | /** |
| 2037 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 2038 | * Posts the specified command to be executed on the main thread, and |
| 2039 | * returns immediately. |
| 2040 | * @see #sendRequest |
| 2041 | */ |
| 2042 | private void sendRequestAsync(int command) { |
| 2043 | mMainThreadHandler.sendEmptyMessage(command); |
| 2044 | } |
| 2045 | |
| 2046 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2047 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2048 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2049 | */ |
| 2050 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2051 | sendRequestAsync(command, argument, null, null); |
| 2052 | } |
| 2053 | |
| 2054 | /** |
| 2055 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 2056 | * @see {@link #sendRequest(int,Object)} |
| 2057 | */ |
| 2058 | private void sendRequestAsync( |
| 2059 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 2060 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2061 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 2062 | msg.sendToTarget(); |
| 2063 | } |
| 2064 | |
| 2065 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2066 | * Initialize the singleton PhoneInterfaceManager instance. |
| 2067 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 2068 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2069 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2070 | synchronized (PhoneInterfaceManager.class) { |
| 2071 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2072 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2073 | } else { |
| 2074 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 2075 | } |
| 2076 | return sInstance; |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 2081 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2082 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2083 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 2084 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 2085 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2086 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 2087 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 2088 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2089 | mTelephonySharedPreferences = |
| 2090 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 2091 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 2092 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 2093 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2094 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | publish(); |
| 2096 | } |
| 2097 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2098 | private Phone getDefaultPhone() { |
| 2099 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 2100 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 2101 | } |
| 2102 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2103 | private void publish() { |
| 2104 | if (DBG) log("publish: " + this); |
| 2105 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 2106 | TelephonyFrameworkInitializer |
| 2107 | .getTelephonyServiceManager() |
| 2108 | .getTelephonyServiceRegisterer() |
| 2109 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2110 | } |
| 2111 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2112 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2113 | if (request.phone != null) { |
| 2114 | return request.phone; |
| 2115 | } else { |
| 2116 | return getPhoneFromSubId(request.subId); |
| 2117 | } |
| 2118 | } |
| 2119 | |
| 2120 | private Phone getPhoneFromSubId(int subId) { |
| 2121 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2122 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2123 | } |
| 2124 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2125 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2126 | Phone phone = getPhoneFromRequest(request); |
| 2127 | return phone == null ? null : |
| 2128 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2129 | } |
| 2130 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2131 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2132 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2133 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2134 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2135 | |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2136 | private void sendEraseModemConfig(Phone phone) { |
| 2137 | if (phone != null) { |
| 2138 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2139 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2140 | final long identity = Binder.clearCallingIdentity(); |
| 2141 | try { |
| 2142 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2143 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2144 | } finally { |
| 2145 | Binder.restoreCallingIdentity(identity); |
| 2146 | } |
| 2147 | } |
| 2148 | } |
| 2149 | |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2150 | private boolean isImsAvailableOnDevice() { |
| 2151 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2152 | if (pm == null) { |
| 2153 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2154 | // so do not throw error and allow. |
| 2155 | return true; |
| 2156 | } |
| 2157 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2158 | } |
| 2159 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2160 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2161 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2162 | } |
| 2163 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2164 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2165 | if (DBG) log("dial: " + number); |
| 2166 | // No permission check needed here: This is just a wrapper around the |
| 2167 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2168 | // the UI before it does anything. |
| 2169 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2170 | final long identity = Binder.clearCallingIdentity(); |
| 2171 | try { |
| 2172 | String url = createTelUrl(number); |
| 2173 | if (url == null) { |
| 2174 | return; |
| 2175 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2176 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2177 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2178 | PhoneConstants.State state = mCM.getState(subId); |
| 2179 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2180 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2181 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2182 | mApp.startActivity(intent); |
| 2183 | } |
| 2184 | } finally { |
| 2185 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2186 | } |
| 2187 | } |
| 2188 | |
| 2189 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2190 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2193 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2194 | if (DBG) log("call: " + number); |
| 2195 | |
| 2196 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2197 | // need to do a permission check since we're calling startActivity() |
| 2198 | // from the context of the phone app. |
| 2199 | enforceCallPermission(); |
| 2200 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2201 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2202 | != AppOpsManager.MODE_ALLOWED) { |
| 2203 | return; |
| 2204 | } |
| 2205 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2206 | final long identity = Binder.clearCallingIdentity(); |
| 2207 | try { |
| 2208 | String url = createTelUrl(number); |
| 2209 | if (url == null) { |
| 2210 | return; |
| 2211 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2212 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2213 | boolean isValid = false; |
| 2214 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2215 | if (slist != null) { |
| 2216 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2217 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2218 | isValid = true; |
| 2219 | break; |
| 2220 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2221 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2222 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2223 | if (!isValid) { |
| 2224 | return; |
| 2225 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2226 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2227 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2228 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2229 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2230 | mApp.startActivity(intent); |
| 2231 | } finally { |
| 2232 | Binder.restoreCallingIdentity(identity); |
| 2233 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2234 | } |
| 2235 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2236 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2237 | int [] resultArray = supplyPinReportResultForSubscriber(subId, 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 boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2242 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2243 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2244 | } |
| 2245 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2246 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2247 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2248 | |
| 2249 | final long identity = Binder.clearCallingIdentity(); |
| 2250 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2251 | Phone phone = getPhone(subId); |
| 2252 | final UnlockSim checkSimPin = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2253 | checkSimPin.start(); |
| 2254 | return checkSimPin.unlockSim(null, pin); |
| 2255 | } finally { |
| 2256 | Binder.restoreCallingIdentity(identity); |
| 2257 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2258 | } |
| 2259 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2260 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2261 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2262 | |
| 2263 | final long identity = Binder.clearCallingIdentity(); |
| 2264 | try { |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2265 | Phone phone = getPhone(subId); |
| 2266 | final UnlockSim checkSimPuk = new UnlockSim(phone.getPhoneId(), phone.getIccCard()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2267 | checkSimPuk.start(); |
| 2268 | return checkSimPuk.unlockSim(puk, pin); |
| 2269 | } finally { |
| 2270 | Binder.restoreCallingIdentity(identity); |
| 2271 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
| 2274 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2275 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2276 | * a synchronous one. |
| 2277 | */ |
| 2278 | private static class UnlockSim extends Thread { |
| 2279 | |
| 2280 | private final IccCard mSimCard; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2281 | private final int mPhoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2282 | |
| 2283 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2284 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2285 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2286 | |
| 2287 | // For replies from SimCard interface |
| 2288 | private Handler mHandler; |
| 2289 | |
| 2290 | // For async handler to identify request type |
| 2291 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2292 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2293 | UnlockSim(int phoneId, IccCard simCard) { |
| 2294 | mPhoneId = phoneId; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2295 | mSimCard = simCard; |
| 2296 | } |
| 2297 | |
| 2298 | @Override |
| 2299 | public void run() { |
| 2300 | Looper.prepare(); |
| 2301 | synchronized (UnlockSim.this) { |
| 2302 | mHandler = new Handler() { |
| 2303 | @Override |
| 2304 | public void handleMessage(Message msg) { |
| 2305 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2306 | switch (msg.what) { |
| 2307 | case SUPPLY_PIN_COMPLETE: |
| 2308 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2309 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2310 | mRetryCount = msg.arg1; |
| 2311 | if (ar.exception != null) { |
| 2312 | if (ar.exception instanceof CommandException && |
| 2313 | ((CommandException)(ar.exception)).getCommandError() |
| 2314 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2315 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2316 | } //When UiccCardApp dispose,handle message and return exception |
| 2317 | else if (ar.exception instanceof CommandException && |
| 2318 | ((CommandException) (ar.exception)).getCommandError() |
| 2319 | == CommandException.Error.ABORTED) { |
| 2320 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2321 | } else { |
| 2322 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2323 | } |
| 2324 | } else { |
| 2325 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2326 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2327 | mDone = true; |
| 2328 | UnlockSim.this.notifyAll(); |
| 2329 | } |
| 2330 | break; |
| 2331 | } |
| 2332 | } |
| 2333 | }; |
| 2334 | UnlockSim.this.notifyAll(); |
| 2335 | } |
| 2336 | Looper.loop(); |
| 2337 | } |
| 2338 | |
| 2339 | /* |
| 2340 | * Use PIN or PUK to unlock SIM card |
| 2341 | * |
| 2342 | * If PUK is null, unlock SIM card with PIN |
| 2343 | * |
| 2344 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2345 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2346 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2347 | |
| 2348 | while (mHandler == null) { |
| 2349 | try { |
| 2350 | wait(); |
| 2351 | } catch (InterruptedException e) { |
| 2352 | Thread.currentThread().interrupt(); |
| 2353 | } |
| 2354 | } |
| 2355 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2356 | |
| 2357 | if (puk == null) { |
| 2358 | mSimCard.supplyPin(pin, callback); |
| 2359 | } else { |
| 2360 | mSimCard.supplyPuk(puk, pin, callback); |
| 2361 | } |
| 2362 | |
| 2363 | while (!mDone) { |
| 2364 | try { |
| 2365 | Log.d(LOG_TAG, "wait for done"); |
| 2366 | wait(); |
| 2367 | } catch (InterruptedException e) { |
| 2368 | // Restore the interrupted status |
| 2369 | Thread.currentThread().interrupt(); |
| 2370 | } |
| 2371 | } |
| 2372 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2373 | int[] resultArray = new int[2]; |
| 2374 | resultArray[0] = mResult; |
| 2375 | resultArray[1] = mRetryCount; |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 2376 | |
| 2377 | if (mResult == PhoneConstants.PIN_RESULT_SUCCESS && pin.length() > 0) { |
| 2378 | UiccController.getInstance().getPinStorage().storePin(pin, mPhoneId); |
| 2379 | } |
| 2380 | |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2381 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2382 | } |
| 2383 | } |
| 2384 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2385 | /** |
| 2386 | * This method has been removed due to privacy and stability concerns. |
| 2387 | */ |
| 2388 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2389 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2390 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2391 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2392 | } |
| 2393 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2394 | @Override |
| 2395 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2396 | mApp.getSystemService(AppOpsManager.class) |
| 2397 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2398 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2399 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2400 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2401 | // Callers targeting S have no business invoking this method. |
| 2402 | return; |
| 2403 | } |
| 2404 | |
| 2405 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2406 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2407 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2408 | .setCallingPackage(callingPackage) |
| 2409 | .setCallingFeatureId(null) |
| 2410 | .setCallingPid(Binder.getCallingPid()) |
| 2411 | .setCallingUid(Binder.getCallingUid()) |
| 2412 | .setMethod("updateServiceLocation") |
| 2413 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2414 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2415 | .build()); |
| 2416 | // Apps that lack location permission have no business calling this method; |
| 2417 | // however, because no permission was declared in the public API, denials must |
| 2418 | // all be "soft". |
| 2419 | switch (locationResult) { |
| 2420 | case DENIED_HARD: /* fall through */ |
| 2421 | case DENIED_SOFT: |
| 2422 | return; |
| 2423 | } |
| 2424 | |
| 2425 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2426 | final long identity = Binder.clearCallingIdentity(); |
| 2427 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2428 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2429 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2430 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2431 | } |
| 2432 | } finally { |
| 2433 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2434 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2435 | } |
| 2436 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2437 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2438 | @Override |
| 2439 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2440 | return isRadioOnWithFeature(callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2441 | } |
| 2442 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2443 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2444 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2445 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2446 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2447 | callingFeatureId); |
| 2448 | } |
| 2449 | |
| 2450 | @Deprecated |
| 2451 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2452 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2453 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
| 2454 | } |
| 2455 | |
| 2456 | @Override |
| 2457 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2458 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2459 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2460 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2461 | return false; |
| 2462 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2463 | |
| 2464 | final long identity = Binder.clearCallingIdentity(); |
| 2465 | try { |
| 2466 | return isRadioOnForSubscriber(subId); |
| 2467 | } finally { |
| 2468 | Binder.restoreCallingIdentity(identity); |
| 2469 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2470 | } |
| 2471 | |
| 2472 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2473 | final long identity = Binder.clearCallingIdentity(); |
| 2474 | try { |
| 2475 | final Phone phone = getPhone(subId); |
| 2476 | if (phone != null) { |
| 2477 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2478 | } else { |
| 2479 | return false; |
| 2480 | } |
| 2481 | } finally { |
| 2482 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
| 2486 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2487 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2488 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2489 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2490 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2491 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2492 | |
| 2493 | final long identity = Binder.clearCallingIdentity(); |
| 2494 | try { |
| 2495 | final Phone phone = getPhone(subId); |
| 2496 | if (phone != null) { |
| 2497 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2498 | } |
| 2499 | } finally { |
| 2500 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2501 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2502 | } |
| 2503 | |
| 2504 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2505 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2506 | } |
| 2507 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2508 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2509 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2510 | |
| 2511 | final long identity = Binder.clearCallingIdentity(); |
| 2512 | try { |
| 2513 | final Phone phone = getPhone(subId); |
| 2514 | if (phone == null) { |
| 2515 | return false; |
| 2516 | } |
| 2517 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2518 | toggleRadioOnOffForSubscriber(subId); |
| 2519 | } |
| 2520 | return true; |
| 2521 | } finally { |
| 2522 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2523 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2524 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2525 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2526 | public boolean needMobileRadioShutdown() { |
Shuo Qian | afeaf7d | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2527 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2528 | /* |
| 2529 | * If any of the Radios are available, it will need to be |
| 2530 | * shutdown. So return true if any Radio is available. |
| 2531 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2532 | final long identity = Binder.clearCallingIdentity(); |
| 2533 | try { |
| 2534 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2535 | Phone phone = PhoneFactory.getPhone(i); |
| 2536 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2537 | } |
| 2538 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2539 | return false; |
| 2540 | } finally { |
| 2541 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2542 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2543 | } |
| 2544 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2545 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2546 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2547 | enforceModifyPermission(); |
| 2548 | |
| 2549 | final long identity = Binder.clearCallingIdentity(); |
| 2550 | try { |
| 2551 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2552 | logv("Shutting down Phone " + i); |
| 2553 | shutdownRadioUsingPhoneId(i); |
| 2554 | } |
| 2555 | } finally { |
| 2556 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2557 | } |
| 2558 | } |
| 2559 | |
| 2560 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2561 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2562 | if (phone != null && phone.isRadioAvailable()) { |
| 2563 | phone.shutdownRadio(); |
| 2564 | } |
| 2565 | } |
| 2566 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2567 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2568 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2569 | |
| 2570 | final long identity = Binder.clearCallingIdentity(); |
| 2571 | try { |
| 2572 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2573 | if (defaultPhone != null) { |
| 2574 | defaultPhone.setRadioPower(turnOn); |
| 2575 | return true; |
| 2576 | } else { |
| 2577 | loge("There's no default phone."); |
| 2578 | return false; |
| 2579 | } |
| 2580 | } finally { |
| 2581 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2582 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2583 | } |
| 2584 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2585 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2586 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2587 | |
| 2588 | final long identity = Binder.clearCallingIdentity(); |
| 2589 | try { |
| 2590 | final Phone phone = getPhone(subId); |
| 2591 | if (phone != null) { |
| 2592 | phone.setRadioPower(turnOn); |
| 2593 | return true; |
| 2594 | } else { |
| 2595 | return false; |
| 2596 | } |
| 2597 | } finally { |
| 2598 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2599 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2600 | } |
| 2601 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2602 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2603 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2604 | public boolean enableDataConnectivity() { |
| 2605 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2606 | |
| 2607 | final long identity = Binder.clearCallingIdentity(); |
| 2608 | try { |
| 2609 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2610 | final Phone phone = getPhone(subId); |
| 2611 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2612 | phone.getDataEnabledSettings().setDataEnabled( |
| 2613 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2614 | return true; |
| 2615 | } else { |
| 2616 | return false; |
| 2617 | } |
| 2618 | } finally { |
| 2619 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2620 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2621 | } |
| 2622 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2623 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2624 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2625 | public boolean disableDataConnectivity() { |
| 2626 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2627 | |
| 2628 | final long identity = Binder.clearCallingIdentity(); |
| 2629 | try { |
| 2630 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2631 | final Phone phone = getPhone(subId); |
| 2632 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 2633 | phone.getDataEnabledSettings().setDataEnabled( |
| 2634 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2635 | return true; |
| 2636 | } else { |
| 2637 | return false; |
| 2638 | } |
| 2639 | } finally { |
| 2640 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2641 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2642 | } |
| 2643 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2644 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2645 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2646 | final long identity = Binder.clearCallingIdentity(); |
| 2647 | try { |
| 2648 | final Phone phone = getPhone(subId); |
| 2649 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2650 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2651 | } else { |
| 2652 | return false; |
| 2653 | } |
| 2654 | } finally { |
| 2655 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2656 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2657 | } |
| 2658 | |
| 2659 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2660 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2661 | } |
| 2662 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2663 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2664 | enforceCallPermission(); |
| 2665 | |
| 2666 | final long identity = Binder.clearCallingIdentity(); |
| 2667 | try { |
| 2668 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2669 | return; |
| 2670 | } |
| 2671 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2672 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2673 | } finally { |
| 2674 | Binder.restoreCallingIdentity(identity); |
| 2675 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2676 | }; |
| 2677 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2678 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2679 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2680 | |
| 2681 | final long identity = Binder.clearCallingIdentity(); |
| 2682 | try { |
| 2683 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2684 | return false; |
| 2685 | } |
| 2686 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2687 | } finally { |
| 2688 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2689 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2692 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2693 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2694 | } |
| 2695 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2696 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2697 | final long identity = Binder.clearCallingIdentity(); |
| 2698 | try { |
| 2699 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2700 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2701 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2702 | } finally { |
| 2703 | Binder.restoreCallingIdentity(identity); |
| 2704 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2705 | } |
| 2706 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2707 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2708 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2709 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2710 | } |
| 2711 | |
| 2712 | @Override |
| 2713 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2714 | final long identity = Binder.clearCallingIdentity(); |
| 2715 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2716 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2717 | if (phone != null) { |
| 2718 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2719 | } else { |
| 2720 | return PhoneConstantConversions.convertDataState( |
| 2721 | PhoneConstants.DataState.DISCONNECTED); |
| 2722 | } |
| 2723 | } finally { |
| 2724 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2725 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2726 | } |
| 2727 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2728 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2729 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2730 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2731 | } |
| 2732 | |
| 2733 | @Override |
| 2734 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2735 | final long identity = Binder.clearCallingIdentity(); |
| 2736 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2737 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2738 | if (phone != null) { |
| 2739 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2740 | } else { |
| 2741 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2742 | } |
| 2743 | } finally { |
| 2744 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2745 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2746 | } |
| 2747 | |
| 2748 | @Override |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2749 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2750 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2751 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2752 | |
| 2753 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2754 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2755 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2756 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2757 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2758 | .setCallingPid(Binder.getCallingPid()) |
| 2759 | .setCallingUid(Binder.getCallingUid()) |
| 2760 | .setMethod("getCellLocation") |
Hall Liu | c3f8eb6 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2761 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2762 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2763 | .build()); |
| 2764 | switch (locationResult) { |
| 2765 | case DENIED_HARD: |
| 2766 | throw new SecurityException("Not allowed to access cell location"); |
| 2767 | case DENIED_SOFT: |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2768 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2769 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2770 | } |
| 2771 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2772 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2773 | final long identity = Binder.clearCallingIdentity(); |
| 2774 | try { |
| 2775 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2776 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | d64acad | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2777 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2778 | } finally { |
| 2779 | Binder.restoreCallingIdentity(identity); |
| 2780 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2781 | } |
| 2782 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2783 | @Override |
Jack Yu | 0142503 | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2784 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2785 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2786 | // registered cell info, so return a NULL country instead. |
| 2787 | final long identity = Binder.clearCallingIdentity(); |
| 2788 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2789 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2790 | // Get default phone in this case. |
| 2791 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2792 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2793 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2794 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | cf38ed9 | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2795 | if (phone == null) return ""; |
| 2796 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2797 | if (sst == null) return ""; |
| 2798 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2799 | if (lt == null) return ""; |
| 2800 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2801 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2802 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2803 | } finally { |
| 2804 | Binder.restoreCallingIdentity(identity); |
| 2805 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2806 | } |
| 2807 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2808 | /** |
| 2809 | * This method was removed due to potential issues caused by performing partial |
| 2810 | * updates of service state, and lack of a credible use case. |
| 2811 | * |
| 2812 | * This has the ability to break the telephony implementation by disabling notification of |
| 2813 | * changes in device connectivity. DO NOT USE THIS! |
| 2814 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2815 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2816 | public void enableLocationUpdates() { |
| 2817 | mApp.enforceCallingOrSelfPermission( |
| 2818 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2819 | } |
| 2820 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2821 | /** |
| 2822 | * This method was removed due to potential issues caused by performing partial |
| 2823 | * updates of service state, and lack of a credible use case. |
| 2824 | * |
| 2825 | * This has the ability to break the telephony implementation by disabling notification of |
| 2826 | * changes in device connectivity. DO NOT USE THIS! |
| 2827 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2828 | @Override |
| 2829 | public void disableLocationUpdates() { |
| 2830 | mApp.enforceCallingOrSelfPermission( |
| 2831 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2832 | } |
| 2833 | |
| 2834 | @Override |
| 2835 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2836 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2837 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2838 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2839 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2840 | throw new SecurityException( |
| 2841 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2842 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2843 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2844 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2845 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2846 | return null; |
| 2847 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2848 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2849 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2850 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2851 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2852 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2853 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2854 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2855 | for (CellInfo ci : info) { |
| 2856 | if (ci instanceof CellInfoGsm) { |
| 2857 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2858 | } else if (ci instanceof CellInfoWcdma) { |
| 2859 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2860 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2861 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2862 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2863 | } |
| 2864 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2865 | private List<CellInfo> getCachedCellInfo() { |
| 2866 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2867 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2868 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2869 | if (info != null) cellInfos.addAll(info); |
| 2870 | } |
| 2871 | return cellInfos; |
| 2872 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2873 | |
| 2874 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2875 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2876 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2877 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2878 | |
| 2879 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2880 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2881 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2882 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2883 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2884 | .setCallingPid(Binder.getCallingPid()) |
| 2885 | .setCallingUid(Binder.getCallingUid()) |
| 2886 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2887 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2888 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2889 | .build()); |
| 2890 | switch (locationResult) { |
| 2891 | case DENIED_HARD: |
| 2892 | throw new SecurityException("Not allowed to access cell info"); |
| 2893 | case DENIED_SOFT: |
| 2894 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2895 | } |
| 2896 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2897 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2898 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2899 | return getCachedCellInfo(); |
| 2900 | } |
| 2901 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2902 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2903 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2904 | final long identity = Binder.clearCallingIdentity(); |
| 2905 | try { |
| 2906 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2907 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2908 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2909 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2910 | if (info != null) cellInfos.addAll(info); |
| 2911 | } |
| 2912 | return cellInfos; |
| 2913 | } finally { |
| 2914 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2915 | } |
| 2916 | } |
| 2917 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2918 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2919 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2920 | String callingFeatureId) { |
| 2921 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2922 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2923 | } |
| 2924 | |
| 2925 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2926 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2927 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2928 | enforceModifyPermission(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2929 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2930 | } |
| 2931 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2932 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2933 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2934 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2935 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2936 | |
| 2937 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2938 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2939 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2940 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2941 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2942 | .setCallingPid(Binder.getCallingPid()) |
| 2943 | .setCallingUid(Binder.getCallingUid()) |
| 2944 | .setMethod("requestCellInfoUpdate") |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2945 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2946 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2947 | .build()); |
| 2948 | switch (locationResult) { |
| 2949 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2950 | if (TelephonyPermissions |
| 2951 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2952 | // Safetynet logging for b/154934934 |
| 2953 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2954 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2955 | throw new SecurityException("Not allowed to access cell info"); |
| 2956 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2957 | if (TelephonyPermissions |
| 2958 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | aa4283b | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2959 | // Safetynet logging for b/154934934 |
| 2960 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2961 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2962 | try { |
| 2963 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2964 | } catch (RemoteException re) { |
| 2965 | // Drop without consequences |
| 2966 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2967 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2968 | } |
| 2969 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2970 | |
| 2971 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2972 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2973 | |
| 2974 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2975 | } |
| 2976 | |
| 2977 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2978 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2979 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2980 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2981 | |
| 2982 | final long identity = Binder.clearCallingIdentity(); |
| 2983 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2984 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2985 | } finally { |
| 2986 | Binder.restoreCallingIdentity(identity); |
| 2987 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2988 | } |
| 2989 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2990 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2991 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2992 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2993 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2994 | return null; |
| 2995 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2996 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2997 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 2998 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2999 | return null; |
| 3000 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3001 | |
| 3002 | final long identity = Binder.clearCallingIdentity(); |
| 3003 | try { |
| 3004 | return phone.getImei(); |
| 3005 | } finally { |
| 3006 | Binder.restoreCallingIdentity(identity); |
| 3007 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3008 | } |
| 3009 | |
| 3010 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3011 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 3012 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3013 | String tac = null; |
| 3014 | if (phone != null) { |
| 3015 | String imei = phone.getImei(); |
| 3016 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 3017 | } |
| 3018 | return tac; |
| 3019 | } |
| 3020 | |
| 3021 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3022 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3023 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3024 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3025 | return null; |
| 3026 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3027 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3028 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 3029 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3030 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3031 | return null; |
| 3032 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3033 | |
| 3034 | final long identity = Binder.clearCallingIdentity(); |
| 3035 | try { |
| 3036 | return phone.getMeid(); |
| 3037 | } finally { |
| 3038 | Binder.restoreCallingIdentity(identity); |
| 3039 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 3040 | } |
| 3041 | |
| 3042 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 3043 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 3044 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3045 | String manufacturerCode = null; |
| 3046 | if (phone != null) { |
| 3047 | String meid = phone.getMeid(); |
| 3048 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 3049 | } |
| 3050 | return manufacturerCode; |
| 3051 | } |
| 3052 | |
| 3053 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3054 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 3055 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3056 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3057 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3058 | return null; |
| 3059 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3060 | int subId = phone.getSubId(); |
| 3061 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3062 | mApp, subId, callingPackage, callingFeatureId, |
| 3063 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 3064 | return null; |
| 3065 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3066 | |
| 3067 | final long identity = Binder.clearCallingIdentity(); |
| 3068 | try { |
| 3069 | return phone.getDeviceSvn(); |
| 3070 | } finally { |
| 3071 | Binder.restoreCallingIdentity(identity); |
| 3072 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3073 | } |
| 3074 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3075 | @Override |
| 3076 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3077 | final long identity = Binder.clearCallingIdentity(); |
| 3078 | try { |
| 3079 | final Phone phone = getPhone(subId); |
| 3080 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 3081 | } finally { |
| 3082 | Binder.restoreCallingIdentity(identity); |
| 3083 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | @Override |
| 3087 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3088 | final long identity = Binder.clearCallingIdentity(); |
| 3089 | try { |
| 3090 | final Phone phone = getPhone(subId); |
| 3091 | return phone == null ? null : phone.getCarrierName(); |
| 3092 | } finally { |
| 3093 | Binder.restoreCallingIdentity(identity); |
| 3094 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 3095 | } |
| 3096 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 3097 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3098 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3099 | final long identity = Binder.clearCallingIdentity(); |
| 3100 | try { |
| 3101 | final Phone phone = getPhone(subId); |
| 3102 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3103 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3104 | } finally { |
| 3105 | Binder.restoreCallingIdentity(identity); |
| 3106 | } |
| 3107 | } |
| 3108 | |
| 3109 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3110 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3111 | final long identity = Binder.clearCallingIdentity(); |
| 3112 | try { |
| 3113 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 3114 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 3115 | } finally { |
| 3116 | Binder.restoreCallingIdentity(identity); |
| 3117 | } |
| 3118 | } |
| 3119 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3120 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3121 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3122 | if (!isSubscriptionMccMnc) { |
| 3123 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3124 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3125 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3126 | if (phone == null) { |
| 3127 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3128 | } |
| 3129 | final long identity = Binder.clearCallingIdentity(); |
| 3130 | try { |
| 3131 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3132 | } finally { |
| 3133 | Binder.restoreCallingIdentity(identity); |
| 3134 | } |
| 3135 | } |
| 3136 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3137 | // |
| 3138 | // Internal helper methods. |
| 3139 | // |
| 3140 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3141 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3142 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3143 | * |
| 3144 | * @throws SecurityException if the caller does not have the required permission |
| 3145 | */ |
| 3146 | private void enforceModifyPermission() { |
| 3147 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3148 | } |
| 3149 | |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3150 | /** |
| 3151 | * Make sure the caller is system. |
| 3152 | * |
| 3153 | * @throws SecurityException if the caller is not system. |
| 3154 | */ |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 3155 | private static void enforceSystemCaller() { |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3156 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3157 | throw new SecurityException("Caller must be system"); |
| 3158 | } |
| 3159 | } |
| 3160 | |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3161 | private void enforceActiveEmergencySessionPermission() { |
| 3162 | mApp.enforceCallingOrSelfPermission( |
| 3163 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3164 | } |
| 3165 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3166 | /** |
| 3167 | * Make sure the caller has the CALL_PHONE permission. |
| 3168 | * |
| 3169 | * @throws SecurityException if the caller does not have the required permission |
| 3170 | */ |
| 3171 | private void enforceCallPermission() { |
| 3172 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3173 | } |
| 3174 | |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3175 | private void enforceSettingsPermission() { |
| 3176 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3177 | } |
| 3178 | |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 3179 | private void enforceRebootPermission() { |
| 3180 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.REBOOT, null); |
| 3181 | } |
| 3182 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3183 | private String createTelUrl(String number) { |
| 3184 | if (TextUtils.isEmpty(number)) { |
| 3185 | return null; |
| 3186 | } |
| 3187 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3188 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3189 | } |
| 3190 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3191 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3192 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3193 | } |
| 3194 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3195 | private static void logv(String msg) { |
| 3196 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3197 | } |
| 3198 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3199 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3200 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3201 | } |
| 3202 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3203 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3204 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3205 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3206 | } |
| 3207 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3208 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3209 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3210 | final long identity = Binder.clearCallingIdentity(); |
| 3211 | try { |
| 3212 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3213 | if (phone == null) { |
| 3214 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3215 | } else { |
| 3216 | return phone.getPhoneType(); |
| 3217 | } |
| 3218 | } finally { |
| 3219 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3220 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3221 | } |
| 3222 | |
| 3223 | /** |
| 3224 | * Returns the CDMA ERI icon index to display |
| 3225 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3226 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3227 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3228 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3229 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3230 | } |
| 3231 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3232 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3233 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3234 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3235 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3236 | mApp, subId, callingPackage, callingFeatureId, |
| 3237 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3238 | return -1; |
| 3239 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3240 | |
| 3241 | final long identity = Binder.clearCallingIdentity(); |
| 3242 | try { |
| 3243 | final Phone phone = getPhone(subId); |
| 3244 | if (phone != null) { |
| 3245 | return phone.getCdmaEriIconIndex(); |
| 3246 | } else { |
| 3247 | return -1; |
| 3248 | } |
| 3249 | } finally { |
| 3250 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3251 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3252 | } |
| 3253 | |
| 3254 | /** |
| 3255 | * Returns the CDMA ERI icon mode, |
| 3256 | * 0 - ON |
| 3257 | * 1 - FLASHING |
| 3258 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3259 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3260 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3261 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3262 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3263 | } |
| 3264 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3265 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3266 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3267 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3268 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3269 | mApp, subId, callingPackage, callingFeatureId, |
| 3270 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3271 | return -1; |
| 3272 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3273 | |
| 3274 | final long identity = Binder.clearCallingIdentity(); |
| 3275 | try { |
| 3276 | final Phone phone = getPhone(subId); |
| 3277 | if (phone != null) { |
| 3278 | return phone.getCdmaEriIconMode(); |
| 3279 | } else { |
| 3280 | return -1; |
| 3281 | } |
| 3282 | } finally { |
| 3283 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3284 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3285 | } |
| 3286 | |
| 3287 | /** |
| 3288 | * Returns the CDMA ERI text, |
| 3289 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3290 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3291 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3292 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3293 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3294 | } |
| 3295 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3296 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3297 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3298 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3299 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3300 | mApp, subId, callingPackage, callingFeatureId, |
| 3301 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3302 | return null; |
| 3303 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3304 | |
| 3305 | final long identity = Binder.clearCallingIdentity(); |
| 3306 | try { |
| 3307 | final Phone phone = getPhone(subId); |
| 3308 | if (phone != null) { |
| 3309 | return phone.getCdmaEriText(); |
| 3310 | } else { |
| 3311 | return null; |
| 3312 | } |
| 3313 | } finally { |
| 3314 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3315 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3316 | } |
| 3317 | |
| 3318 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3319 | * Returns the CDMA MDN. |
| 3320 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3321 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3322 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3323 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3324 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3325 | |
| 3326 | final long identity = Binder.clearCallingIdentity(); |
| 3327 | try { |
| 3328 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3329 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3330 | return phone.getLine1Number(); |
| 3331 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3332 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3333 | return null; |
| 3334 | } |
| 3335 | } finally { |
| 3336 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3337 | } |
| 3338 | } |
| 3339 | |
| 3340 | /** |
| 3341 | * Returns the CDMA MIN. |
| 3342 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3343 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3344 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3345 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3346 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3347 | |
| 3348 | final long identity = Binder.clearCallingIdentity(); |
| 3349 | try { |
| 3350 | final Phone phone = getPhone(subId); |
| 3351 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3352 | return phone.getCdmaMin(); |
| 3353 | } else { |
| 3354 | return null; |
| 3355 | } |
| 3356 | } finally { |
| 3357 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3358 | } |
| 3359 | } |
| 3360 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3361 | @Override |
| 3362 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3363 | INumberVerificationCallback callback, String callingPackage) { |
| 3364 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3365 | != PERMISSION_GRANTED) { |
| 3366 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3367 | } |
| 3368 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3369 | |
| 3370 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3371 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
Hall Liu | b9d8feb | 2021-01-13 10:28:04 -0800 | [diff] [blame] | 3372 | throw new SecurityException("Calling package must be configured in the device config: " |
| 3373 | + "calling package: " + callingPackage |
| 3374 | + ", configured package: " + authorizedPackage); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3375 | } |
| 3376 | |
| 3377 | if (range == null) { |
| 3378 | throw new NullPointerException("Range must be non-null"); |
| 3379 | } |
| 3380 | |
| 3381 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3382 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3383 | |
| 3384 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3385 | } |
| 3386 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3387 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3388 | * Returns true if CDMA provisioning needs to run. |
| 3389 | */ |
| 3390 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3391 | final long identity = Binder.clearCallingIdentity(); |
| 3392 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3393 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3394 | } finally { |
| 3395 | Binder.restoreCallingIdentity(identity); |
| 3396 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3397 | } |
| 3398 | |
| 3399 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3400 | * Sets the voice mail number of a given subId. |
| 3401 | */ |
| 3402 | @Override |
| 3403 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3404 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3405 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3406 | |
| 3407 | final long identity = Binder.clearCallingIdentity(); |
| 3408 | try { |
| 3409 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3410 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3411 | return success; |
| 3412 | } finally { |
| 3413 | Binder.restoreCallingIdentity(identity); |
| 3414 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3415 | } |
| 3416 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3417 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3418 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3419 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3420 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3421 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3422 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3423 | throw new SecurityException("caller must be system dialer"); |
| 3424 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3425 | |
| 3426 | final long identity = Binder.clearCallingIdentity(); |
| 3427 | try { |
| 3428 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3429 | if (phoneAccountHandle == null) { |
| 3430 | return null; |
| 3431 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3432 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3433 | } finally { |
| 3434 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3435 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3436 | } |
| 3437 | |
| 3438 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3439 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3440 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3441 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3442 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3443 | mApp, subId, callingPackage, callingFeatureId, |
| 3444 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3445 | return null; |
| 3446 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3447 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3448 | final long identity = Binder.clearCallingIdentity(); |
| 3449 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3450 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3451 | } finally { |
| 3452 | Binder.restoreCallingIdentity(identity); |
| 3453 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3454 | } |
| 3455 | |
| 3456 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3457 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3458 | VisualVoicemailSmsFilterSettings settings) { |
| 3459 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3460 | |
| 3461 | final long identity = Binder.clearCallingIdentity(); |
| 3462 | try { |
| 3463 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3464 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3465 | } finally { |
| 3466 | Binder.restoreCallingIdentity(identity); |
| 3467 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3468 | } |
| 3469 | |
| 3470 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3471 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3472 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3473 | |
| 3474 | final long identity = Binder.clearCallingIdentity(); |
| 3475 | try { |
| 3476 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3477 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3478 | } finally { |
| 3479 | Binder.restoreCallingIdentity(identity); |
| 3480 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3481 | } |
| 3482 | |
| 3483 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3484 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3485 | String callingPackage, int subId) { |
| 3486 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3487 | |
| 3488 | final long identity = Binder.clearCallingIdentity(); |
| 3489 | try { |
| 3490 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3491 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3492 | } finally { |
| 3493 | Binder.restoreCallingIdentity(identity); |
| 3494 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3495 | } |
| 3496 | |
| 3497 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3498 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3499 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3500 | |
| 3501 | final long identity = Binder.clearCallingIdentity(); |
| 3502 | try { |
| 3503 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3504 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3505 | } finally { |
| 3506 | Binder.restoreCallingIdentity(identity); |
| 3507 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3508 | } |
| 3509 | |
| 3510 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3511 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3512 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3513 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3514 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3515 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3516 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3517 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3518 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3519 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3520 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3521 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3522 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3523 | * Sets the voice activation state of a given subId. |
| 3524 | */ |
| 3525 | @Override |
| 3526 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3527 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3528 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3529 | |
| 3530 | final long identity = Binder.clearCallingIdentity(); |
| 3531 | try { |
| 3532 | final Phone phone = getPhone(subId); |
| 3533 | if (phone != null) { |
| 3534 | phone.setVoiceActivationState(activationState); |
| 3535 | } else { |
| 3536 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3537 | } |
| 3538 | } finally { |
| 3539 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3540 | } |
| 3541 | } |
| 3542 | |
| 3543 | /** |
| 3544 | * Sets the data activation state of a given subId. |
| 3545 | */ |
| 3546 | @Override |
| 3547 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3548 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3549 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3550 | |
| 3551 | final long identity = Binder.clearCallingIdentity(); |
| 3552 | try { |
| 3553 | final Phone phone = getPhone(subId); |
| 3554 | if (phone != null) { |
| 3555 | phone.setDataActivationState(activationState); |
| 3556 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3557 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3558 | } |
| 3559 | } finally { |
| 3560 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | /** |
| 3565 | * Returns the voice activation state of a given subId. |
| 3566 | */ |
| 3567 | @Override |
| 3568 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3569 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3570 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3571 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3572 | final long identity = Binder.clearCallingIdentity(); |
| 3573 | try { |
| 3574 | if (phone != null) { |
| 3575 | return phone.getVoiceActivationState(); |
| 3576 | } else { |
| 3577 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3578 | } |
| 3579 | } finally { |
| 3580 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3581 | } |
| 3582 | } |
| 3583 | |
| 3584 | /** |
| 3585 | * Returns the data activation state of a given subId. |
| 3586 | */ |
| 3587 | @Override |
| 3588 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3589 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3590 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3591 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3592 | final long identity = Binder.clearCallingIdentity(); |
| 3593 | try { |
| 3594 | if (phone != null) { |
| 3595 | return phone.getDataActivationState(); |
| 3596 | } else { |
| 3597 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3598 | } |
| 3599 | } finally { |
| 3600 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3601 | } |
| 3602 | } |
| 3603 | |
| 3604 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3605 | * Returns the unread count of voicemails for a subId |
| 3606 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3607 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3608 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3609 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3610 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 3611 | mApp, subId, callingPackage, callingFeatureId, |
| 3612 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3613 | return 0; |
| 3614 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3615 | final long identity = Binder.clearCallingIdentity(); |
| 3616 | try { |
| 3617 | final Phone phone = getPhone(subId); |
| 3618 | if (phone != null) { |
| 3619 | return phone.getVoiceMessageCount(); |
| 3620 | } else { |
| 3621 | return 0; |
| 3622 | } |
| 3623 | } finally { |
| 3624 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3625 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3626 | } |
| 3627 | |
| 3628 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3629 | * returns true, if the device is in a state where both voice and data |
| 3630 | * are supported simultaneously. This can change based on location or network condition. |
| 3631 | */ |
| 3632 | @Override |
| 3633 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3634 | final long identity = Binder.clearCallingIdentity(); |
| 3635 | try { |
| 3636 | final Phone phone = getPhone(subId); |
| 3637 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3638 | } finally { |
| 3639 | Binder.restoreCallingIdentity(identity); |
| 3640 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3641 | } |
| 3642 | |
| 3643 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3644 | * Send the dialer code if called from the current default dialer or the caller has |
| 3645 | * carrier privilege. |
| 3646 | * @param inputCode The dialer code to send |
| 3647 | */ |
| 3648 | @Override |
| 3649 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3650 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3651 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3652 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3653 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3654 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3655 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3656 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3657 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3658 | |
| 3659 | final long identity = Binder.clearCallingIdentity(); |
| 3660 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3661 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3662 | } finally { |
| 3663 | Binder.restoreCallingIdentity(identity); |
| 3664 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3665 | } |
| 3666 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3667 | @Override |
| 3668 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3669 | TelephonyPermissions |
| 3670 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3671 | mApp, subId, "getNetworkSelectionMode"); |
| 3672 | final long identity = Binder.clearCallingIdentity(); |
| 3673 | try { |
| 3674 | if (!isActiveSubscription(subId)) { |
| 3675 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3676 | } |
| 3677 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3678 | } finally { |
| 3679 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3680 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3681 | } |
| 3682 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3683 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3684 | public boolean isInEmergencySmsMode() { |
| 3685 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3686 | final long identity = Binder.clearCallingIdentity(); |
| 3687 | try { |
| 3688 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3689 | if (phone.isInEmergencySmsMode()) { |
| 3690 | return true; |
| 3691 | } |
| 3692 | } |
| 3693 | } finally { |
| 3694 | Binder.restoreCallingIdentity(identity); |
| 3695 | } |
| 3696 | return false; |
| 3697 | } |
| 3698 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3699 | /** |
| 3700 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3701 | * @param subId The subscription to use to check the configuration. |
| 3702 | * @param c The callback that will be used to send the result. |
| 3703 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3704 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3705 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3706 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3707 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3708 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3709 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3710 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3711 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3712 | "IMS not available on device."); |
| 3713 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3714 | final long token = Binder.clearCallingIdentity(); |
| 3715 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3716 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3717 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3718 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3719 | } catch (ImsException e) { |
| 3720 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3721 | } finally { |
| 3722 | Binder.restoreCallingIdentity(token); |
| 3723 | } |
| 3724 | } |
| 3725 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3726 | /** |
| 3727 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3728 | * @param subId The subscription to use to check the configuration. |
| 3729 | * @param c The callback that will be used to send the result. |
| 3730 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3731 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3732 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3733 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3734 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3735 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3736 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3737 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3738 | final long token = Binder.clearCallingIdentity(); |
| 3739 | try { |
| 3740 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3741 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3742 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3743 | } catch (ImsException e) { |
| 3744 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3745 | + "is inactive, ignoring unregister."); |
| 3746 | // If the subscription is no longer active, just return, since the callback |
| 3747 | // will already have been removed internally. |
| 3748 | } finally { |
| 3749 | Binder.restoreCallingIdentity(token); |
| 3750 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3751 | } |
| 3752 | |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3753 | /** |
| 3754 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3755 | */ |
| 3756 | @Override |
| 3757 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3758 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3759 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3760 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3761 | "IMS not available on device."); |
| 3762 | } |
| 3763 | final long token = Binder.clearCallingIdentity(); |
| 3764 | try { |
| 3765 | Phone phone = getPhone(subId); |
| 3766 | if (phone == null) { |
| 3767 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3768 | + subId + "'"); |
| 3769 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3770 | } |
| 3771 | phone.getImsRegistrationState(regState -> { |
| 3772 | try { |
| 3773 | consumer.accept((regState == null) |
| 3774 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3775 | } catch (RemoteException e) { |
| 3776 | // Ignore if the remote process is no longer available to call back. |
| 3777 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3778 | } |
| 3779 | }); |
| 3780 | } finally { |
| 3781 | Binder.restoreCallingIdentity(token); |
| 3782 | } |
| 3783 | } |
| 3784 | |
| 3785 | /** |
| 3786 | * Get the transport type for the IMS service registration state. |
| 3787 | */ |
| 3788 | @Override |
| 3789 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3790 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3791 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | 774ba36 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3792 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3793 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3794 | "IMS not available on device."); |
| 3795 | } |
| 3796 | final long token = Binder.clearCallingIdentity(); |
| 3797 | try { |
| 3798 | Phone phone = getPhone(subId); |
| 3799 | if (phone == null) { |
| 3800 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3801 | + subId + "'"); |
| 3802 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3803 | } |
| 3804 | phone.getImsRegistrationTech(regTech -> { |
| 3805 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3806 | int regTechConverted = (regTech == null) |
| 3807 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3808 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3809 | regTechConverted); |
| 3810 | try { |
| 3811 | consumer.accept(regTechConverted); |
| 3812 | } catch (RemoteException e) { |
| 3813 | // Ignore if the remote process is no longer available to call back. |
| 3814 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3815 | } |
| 3816 | }); |
| 3817 | } finally { |
| 3818 | Binder.restoreCallingIdentity(token); |
| 3819 | } |
| 3820 | } |
| 3821 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3822 | /** |
| 3823 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3824 | * @param subId The subscription to use to check the configuration. |
| 3825 | * @param c The callback that will be used to send the result. |
| 3826 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3827 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3828 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3829 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3830 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3831 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3832 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3833 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3834 | "IMS not available on device."); |
| 3835 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3836 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3837 | final long token = Binder.clearCallingIdentity(); |
| 3838 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3839 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3840 | .addCapabilitiesCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3841 | } catch (ImsException e) { |
| 3842 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3843 | } finally { |
| 3844 | Binder.restoreCallingIdentity(token); |
| 3845 | } |
| 3846 | } |
| 3847 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3848 | /** |
| 3849 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3850 | * @param subId The subscription to use to check the configuration. |
| 3851 | * @param c The callback that will be used to send the result. |
| 3852 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3853 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3854 | public void unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3855 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3856 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3857 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3858 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3859 | } |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3860 | |
| 3861 | final long token = Binder.clearCallingIdentity(); |
| 3862 | try { |
| 3863 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone. |
| 3864 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3865 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | d20ad6b | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3866 | } catch (ImsException e) { |
| 3867 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3868 | + "is inactive, ignoring unregister."); |
| 3869 | // If the subscription is no longer active, just return, since the callback |
| 3870 | // will already have been removed internally. |
| 3871 | } finally { |
| 3872 | Binder.restoreCallingIdentity(token); |
| 3873 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3874 | } |
| 3875 | |
| 3876 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3877 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3878 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3879 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3880 | final long token = Binder.clearCallingIdentity(); |
| 3881 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3882 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3883 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3884 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3885 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3886 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3887 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3888 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3889 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3890 | } finally { |
| 3891 | Binder.restoreCallingIdentity(token); |
| 3892 | } |
| 3893 | } |
| 3894 | |
| 3895 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3896 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3897 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3898 | final long token = Binder.clearCallingIdentity(); |
| 3899 | try { |
| 3900 | Phone phone = getPhone(subId); |
| 3901 | if (phone == null) return false; |
| 3902 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 32706d9 | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3903 | } catch (com.android.ims.ImsException e) { |
| 3904 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3905 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3906 | } finally { |
| 3907 | Binder.restoreCallingIdentity(token); |
| 3908 | } |
| 3909 | } |
| 3910 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3911 | /** |
| 3912 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3913 | * subscription. |
| 3914 | * @param subId The subscription to use to check the configuration. |
| 3915 | * @param callback The callback that will be used to send the result. |
| 3916 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3917 | * @param transportType The transport type of the MmTelFeature capability. |
| 3918 | */ |
| 3919 | @Override |
| 3920 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3921 | int transportType) { |
| 3922 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3923 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3924 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3925 | "IMS not available on device."); |
| 3926 | } |
| 3927 | final long token = Binder.clearCallingIdentity(); |
| 3928 | try { |
| 3929 | int slotId = getSlotIndex(subId); |
| 3930 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3931 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3932 | + subId + "'"); |
| 3933 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3934 | } |
| 3935 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3936 | transportType, aBoolean -> { |
| 3937 | try { |
| 3938 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3939 | } catch (RemoteException e) { |
| 3940 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3941 | + "running. Ignore"); |
| 3942 | } |
| 3943 | }); |
| 3944 | } finally { |
| 3945 | Binder.restoreCallingIdentity(token); |
| 3946 | } |
| 3947 | } |
| 3948 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3949 | /** |
| 3950 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3951 | * @param subId The subscription to use to check the configuration. |
| 3952 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3953 | @Override |
| 3954 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3955 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3956 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3957 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3958 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3959 | final long token = Binder.clearCallingIdentity(); |
| 3960 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3961 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3962 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3963 | } catch (ImsException e) { |
| 3964 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3965 | } finally { |
| 3966 | Binder.restoreCallingIdentity(token); |
| 3967 | } |
| 3968 | } |
| 3969 | |
| 3970 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3971 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3972 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3973 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3974 | final long identity = Binder.clearCallingIdentity(); |
| 3975 | try { |
| 3976 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3977 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3978 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3979 | } catch (ImsException e) { |
| 3980 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3981 | } finally { |
| 3982 | Binder.restoreCallingIdentity(identity); |
| 3983 | } |
| 3984 | } |
| 3985 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3986 | /** |
| 3987 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3988 | * @param subId The subscription to use to check the configuration. |
| 3989 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3990 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3991 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3992 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3993 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3994 | final long identity = Binder.clearCallingIdentity(); |
| 3995 | try { |
| 3996 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3997 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3998 | } catch (ImsException e) { |
| 3999 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4000 | } finally { |
| 4001 | Binder.restoreCallingIdentity(identity); |
| 4002 | } |
| 4003 | } |
| 4004 | |
| 4005 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4006 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4007 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4008 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4009 | final long identity = Binder.clearCallingIdentity(); |
| 4010 | try { |
| 4011 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4012 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4013 | } catch (ImsException e) { |
| 4014 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4015 | } finally { |
| 4016 | Binder.restoreCallingIdentity(identity); |
| 4017 | } |
| 4018 | } |
| 4019 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4020 | /** |
| 4021 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4022 | * @param subId The subscription to use to check the configuration. |
| 4023 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4024 | @Override |
| 4025 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4026 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4027 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4028 | final long identity = Binder.clearCallingIdentity(); |
| 4029 | try { |
| 4030 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4031 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4032 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4033 | } catch (ImsException e) { |
| 4034 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4035 | } finally { |
| 4036 | Binder.restoreCallingIdentity(identity); |
| 4037 | } |
| 4038 | } |
| 4039 | |
| 4040 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4041 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4042 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4043 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4044 | final long identity = Binder.clearCallingIdentity(); |
| 4045 | try { |
| 4046 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4047 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4048 | } catch (ImsException e) { |
| 4049 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4050 | } finally { |
| 4051 | Binder.restoreCallingIdentity(identity); |
| 4052 | } |
| 4053 | } |
| 4054 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4055 | /** |
| 4056 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4057 | * @param subId The subscription to use to check the configuration. |
| 4058 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4059 | @Override |
| 4060 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4061 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4062 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4063 | final long identity = Binder.clearCallingIdentity(); |
| 4064 | try { |
| 4065 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4066 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4067 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4068 | } catch (ImsException e) { |
| 4069 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4070 | } finally { |
| 4071 | Binder.restoreCallingIdentity(identity); |
| 4072 | } |
| 4073 | } |
| 4074 | |
| 4075 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4076 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4077 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 4078 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4079 | final long identity = Binder.clearCallingIdentity(); |
| 4080 | try { |
| 4081 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4082 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4083 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4084 | } catch (ImsException e) { |
| 4085 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4086 | } finally { |
| 4087 | Binder.restoreCallingIdentity(identity); |
| 4088 | } |
| 4089 | } |
| 4090 | |
| 4091 | @Override |
| 4092 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 4093 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4094 | "setVoWiFiNonPersistent"); |
| 4095 | final long identity = Binder.clearCallingIdentity(); |
| 4096 | try { |
| 4097 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4098 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 4099 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4100 | } catch (ImsException e) { |
| 4101 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4102 | } finally { |
| 4103 | Binder.restoreCallingIdentity(identity); |
| 4104 | } |
| 4105 | } |
| 4106 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4107 | /** |
| 4108 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4109 | * @param subId The subscription to use to check the configuration. |
| 4110 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4111 | @Override |
| 4112 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4113 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4114 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4115 | final long identity = Binder.clearCallingIdentity(); |
| 4116 | try { |
| 4117 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4118 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4119 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4120 | } catch (ImsException e) { |
| 4121 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4122 | } finally { |
| 4123 | Binder.restoreCallingIdentity(identity); |
| 4124 | } |
| 4125 | } |
| 4126 | |
| 4127 | @Override |
| 4128 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4130 | "setVoWiFiModeSetting"); |
| 4131 | final long identity = Binder.clearCallingIdentity(); |
| 4132 | try { |
| 4133 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4134 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4135 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4136 | } catch (ImsException e) { |
| 4137 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4138 | } finally { |
| 4139 | Binder.restoreCallingIdentity(identity); |
| 4140 | } |
| 4141 | } |
| 4142 | |
| 4143 | @Override |
| 4144 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4145 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4146 | final long identity = Binder.clearCallingIdentity(); |
| 4147 | try { |
| 4148 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4149 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4150 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4151 | } catch (ImsException e) { |
| 4152 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4153 | } finally { |
| 4154 | Binder.restoreCallingIdentity(identity); |
| 4155 | } |
| 4156 | } |
| 4157 | |
| 4158 | @Override |
| 4159 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4160 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4161 | "setVoWiFiRoamingModeSetting"); |
| 4162 | final long identity = Binder.clearCallingIdentity(); |
| 4163 | try { |
| 4164 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4165 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4166 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4167 | } catch (ImsException e) { |
| 4168 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4169 | } finally { |
| 4170 | Binder.restoreCallingIdentity(identity); |
| 4171 | } |
| 4172 | } |
| 4173 | |
| 4174 | @Override |
| 4175 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4176 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4177 | "setRttCapabilityEnabled"); |
| 4178 | final long identity = Binder.clearCallingIdentity(); |
| 4179 | try { |
| 4180 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4181 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4182 | } catch (ImsException e) { |
| 4183 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4184 | } finally { |
| 4185 | Binder.restoreCallingIdentity(identity); |
| 4186 | } |
| 4187 | } |
| 4188 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4189 | /** |
| 4190 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4191 | * @param subId The subscription to use to check the configuration. |
| 4192 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4193 | @Override |
| 4194 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4195 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4196 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4197 | final long identity = Binder.clearCallingIdentity(); |
| 4198 | try { |
| 4199 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4200 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4201 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4202 | } catch (ImsException e) { |
| 4203 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4204 | } finally { |
| 4205 | Binder.restoreCallingIdentity(identity); |
| 4206 | } |
| 4207 | } |
| 4208 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4209 | @Override |
| 4210 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4211 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4212 | final long identity = Binder.clearCallingIdentity(); |
| 4213 | try { |
Brad Ebinger | 6cf0f65 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4214 | if (!isImsAvailableOnDevice()) { |
| 4215 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4216 | "IMS not available on device."); |
Peter Wang | 050bb05 | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4217 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4218 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4219 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4220 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4221 | } catch (ImsException e) { |
| 4222 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4223 | } finally { |
| 4224 | Binder.restoreCallingIdentity(identity); |
| 4225 | } |
| 4226 | } |
| 4227 | |
| 4228 | @Override |
| 4229 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4230 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4231 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4232 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4233 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4234 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4235 | try { |
| 4236 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4237 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4238 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4239 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4240 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4241 | + "is inactive, ignoring unregister."); |
| 4242 | // If the subscription is no longer active, just return, since the callback will already |
| 4243 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4244 | } finally { |
| 4245 | Binder.restoreCallingIdentity(identity); |
| 4246 | } |
| 4247 | } |
| 4248 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4249 | |
| 4250 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4251 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4252 | message); |
| 4253 | } |
| 4254 | |
| 4255 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4256 | boolean isMmtelCapability) { |
| 4257 | Phone phone = getPhone(subId); |
| 4258 | if (phone == null) { |
| 4259 | loge("phone instance null for subid " + subId); |
| 4260 | return false; |
| 4261 | } |
| 4262 | if (isMmtelCapability) { |
| 4263 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4264 | return false; |
| 4265 | } |
| 4266 | } else { |
| 4267 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4268 | return false; |
| 4269 | } |
| 4270 | } |
| 4271 | return true; |
| 4272 | } |
| 4273 | |
| 4274 | @Override |
| 4275 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4276 | boolean isProvisioned) { |
| 4277 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4278 | |
| 4279 | final long identity = Binder.clearCallingIdentity(); |
| 4280 | try { |
| 4281 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4282 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4283 | return; |
| 4284 | } |
| 4285 | |
| 4286 | // this capability requires provisioning, route to the correct API. |
| 4287 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4288 | switch (capability) { |
| 4289 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4290 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4291 | ims.setEabProvisioned(isProvisioned); |
| 4292 | break; |
| 4293 | default: { |
| 4294 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4295 | + "rcs capability '" + capability + "', which does not require " |
| 4296 | + "provisioning."); |
| 4297 | } |
| 4298 | } |
| 4299 | } finally { |
| 4300 | Binder.restoreCallingIdentity(identity); |
| 4301 | } |
| 4302 | |
| 4303 | } |
| 4304 | |
| 4305 | |
| 4306 | @Override |
| 4307 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4308 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4309 | final long identity = Binder.clearCallingIdentity(); |
| 4310 | try { |
| 4311 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4312 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4313 | return true; |
| 4314 | } |
| 4315 | |
| 4316 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4317 | switch (capability) { |
| 4318 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4319 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4320 | return ims.isEabProvisionedOnDevice(); |
| 4321 | |
| 4322 | default: { |
| 4323 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4324 | + "capability '" + capability + "', which does not require " |
| 4325 | + "provisioning."); |
| 4326 | } |
| 4327 | } |
| 4328 | |
| 4329 | } finally { |
| 4330 | Binder.restoreCallingIdentity(identity); |
| 4331 | } |
| 4332 | } |
| 4333 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4334 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4335 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4336 | boolean isProvisioned) { |
| 4337 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4338 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4339 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4340 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4341 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4342 | final long identity = Binder.clearCallingIdentity(); |
| 4343 | try { |
| 4344 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4345 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4346 | return; |
| 4347 | } |
| 4348 | |
| 4349 | // this capability requires provisioning, route to the correct API. |
| 4350 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4351 | switch (capability) { |
| 4352 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4353 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4354 | ims.setVolteProvisioned(isProvisioned); |
| 4355 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4356 | ims.setWfcProvisioned(isProvisioned); |
| 4357 | } |
| 4358 | break; |
| 4359 | } |
| 4360 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4361 | // There is currently no difference in VT provisioning type. |
| 4362 | ims.setVtProvisioned(isProvisioned); |
| 4363 | break; |
| 4364 | } |
| 4365 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4366 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4367 | // change the capability of the feature instead if needed. |
| 4368 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4369 | == isProvisioned) { |
| 4370 | // No change in provisioning. |
| 4371 | return; |
| 4372 | } |
| 4373 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4374 | try { |
| 4375 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4376 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4377 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4378 | + ", Exception" + e.getMessage()); |
| 4379 | } |
| 4380 | break; |
| 4381 | } |
| 4382 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4383 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4384 | + "MmTel capability '" + capability + "', which does not require " |
| 4385 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4386 | } |
| 4387 | } |
| 4388 | |
| 4389 | } finally { |
| 4390 | Binder.restoreCallingIdentity(identity); |
| 4391 | } |
| 4392 | } |
| 4393 | |
| 4394 | @Override |
| 4395 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4396 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4397 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4398 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4399 | } |
| 4400 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4401 | final long identity = Binder.clearCallingIdentity(); |
| 4402 | try { |
| 4403 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4404 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4405 | return true; |
| 4406 | } |
| 4407 | |
| 4408 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4409 | switch (capability) { |
| 4410 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4411 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4412 | return ims.isVolteProvisionedOnDevice(); |
| 4413 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4414 | return ims.isWfcProvisionedOnDevice(); |
| 4415 | } |
| 4416 | // This should never happen, since we are checking tech above to make sure it |
| 4417 | // is either LTE or IWLAN. |
| 4418 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4419 | + "capability."); |
| 4420 | } |
| 4421 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4422 | // There is currently no difference in VT provisioning type. |
| 4423 | return ims.isVtProvisionedOnDevice(); |
| 4424 | } |
| 4425 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4426 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4427 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4428 | } |
| 4429 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4430 | throw new IllegalArgumentException( |
| 4431 | "Tried to get provisioning for MmTel capability '" + capability |
| 4432 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4433 | } |
| 4434 | } |
| 4435 | |
| 4436 | } finally { |
| 4437 | Binder.restoreCallingIdentity(identity); |
| 4438 | } |
| 4439 | } |
| 4440 | |
| 4441 | @Override |
| 4442 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4443 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4444 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4445 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4446 | } |
| 4447 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4448 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4449 | return (provisionedBits & capability) > 0; |
| 4450 | } |
| 4451 | |
| 4452 | @Override |
| 4453 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4454 | boolean isProvisioned) { |
| 4455 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4456 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4457 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4458 | } |
| 4459 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4460 | "setProvisioningStatusForCapability"); |
| 4461 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4462 | // If the current provisioning status for capability already matches isProvisioned, |
| 4463 | // do nothing. |
| 4464 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4465 | return; |
| 4466 | } |
| 4467 | if (isProvisioned) { |
| 4468 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4469 | } else { |
| 4470 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4471 | } |
| 4472 | } |
| 4473 | |
| 4474 | /** |
| 4475 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4476 | * technology. The bitfield should mirror the bitfield defined by |
| 4477 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4478 | */ |
| 4479 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4480 | String key = getMmTelProvisioningKey(subId, tech); |
| 4481 | // Default is no capabilities are provisioned. |
| 4482 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4483 | } |
| 4484 | |
| 4485 | /** |
| 4486 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4487 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4488 | * technology specified. |
| 4489 | * |
| 4490 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4491 | */ |
| 4492 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4493 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4494 | String key = getMmTelProvisioningKey(subId, tech); |
| 4495 | editor.putInt(key, newField); |
| 4496 | editor.commit(); |
| 4497 | } |
| 4498 | |
| 4499 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4500 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4501 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4502 | } |
| 4503 | |
| 4504 | /** |
| 4505 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4506 | * carrier associated with the subscription id. |
| 4507 | */ |
| 4508 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4509 | int capability) { |
| 4510 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4511 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4512 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4513 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4514 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4515 | false); |
| 4516 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4517 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4518 | |
| 4519 | // First check to make sure that the capability requires provisioning. |
| 4520 | switch (capability) { |
| 4521 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4522 | // intentional fallthrough |
| 4523 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4524 | if (requireVoiceVtProvisioning) { |
| 4525 | // Voice and Video requires provisioning |
| 4526 | return true; |
| 4527 | } |
| 4528 | break; |
| 4529 | } |
| 4530 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4531 | if (requireUtProvisioning) { |
| 4532 | // UT requires provisioning |
| 4533 | return true; |
| 4534 | } |
| 4535 | break; |
| 4536 | } |
| 4537 | } |
| 4538 | return false; |
| 4539 | } |
| 4540 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4541 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4542 | int capability) { |
| 4543 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4544 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4545 | |
| 4546 | boolean requireRcsProvisioning = c.getBoolean( |
| 4547 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4548 | |
| 4549 | // First check to make sure that the capability requires provisioning. |
| 4550 | switch (capability) { |
| 4551 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4552 | // intentional fallthrough |
| 4553 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4554 | if (requireRcsProvisioning) { |
| 4555 | // OPTION or PRESENCE requires provisioning |
| 4556 | return true; |
| 4557 | } |
| 4558 | break; |
| 4559 | } |
| 4560 | } |
| 4561 | return false; |
| 4562 | } |
| 4563 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4564 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4565 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4566 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4567 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4568 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4569 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4570 | final long identity = Binder.clearCallingIdentity(); |
| 4571 | try { |
| 4572 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4573 | int slotId = getSlotIndex(subId); |
| 4574 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4575 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4576 | + subId + "' for key:" + key); |
| 4577 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4578 | } |
| 4579 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4580 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4581 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4582 | + subId + "' for key:" + key); |
| 4583 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4584 | } finally { |
| 4585 | Binder.restoreCallingIdentity(identity); |
| 4586 | } |
| 4587 | } |
| 4588 | |
| 4589 | @Override |
| 4590 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4591 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4592 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4593 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4594 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4595 | final long identity = Binder.clearCallingIdentity(); |
| 4596 | try { |
| 4597 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4598 | int slotId = getSlotIndex(subId); |
| 4599 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4600 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4601 | + subId + "' for key:" + key); |
| 4602 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4603 | } |
| 4604 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4605 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4606 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4607 | + subId + "' for key:" + key); |
| 4608 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4609 | } finally { |
| 4610 | Binder.restoreCallingIdentity(identity); |
| 4611 | } |
| 4612 | } |
| 4613 | |
| 4614 | @Override |
| 4615 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4616 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4617 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4618 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4619 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4620 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4621 | final long identity = Binder.clearCallingIdentity(); |
| 4622 | try { |
| 4623 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4624 | int slotId = getSlotIndex(subId); |
| 4625 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4626 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4627 | + subId + "' for key:" + key); |
| 4628 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4629 | } |
| 4630 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4631 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4632 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4633 | + "' for key:" + key); |
| 4634 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4635 | } finally { |
| 4636 | Binder.restoreCallingIdentity(identity); |
| 4637 | } |
| 4638 | } |
| 4639 | |
| 4640 | @Override |
| 4641 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4642 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4643 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4644 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4645 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4646 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4647 | final long identity = Binder.clearCallingIdentity(); |
| 4648 | try { |
| 4649 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4650 | int slotId = getSlotIndex(subId); |
| 4651 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4652 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4653 | + subId + "' for key:" + key); |
| 4654 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4655 | } |
| 4656 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4657 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4658 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4659 | + "' for key:" + key); |
| 4660 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4661 | } finally { |
| 4662 | Binder.restoreCallingIdentity(identity); |
| 4663 | } |
| 4664 | } |
| 4665 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4666 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4667 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4668 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4669 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4670 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4671 | } |
| 4672 | return slotId; |
| 4673 | } |
| 4674 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4675 | private int getSlotIndex(int subId) { |
| 4676 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4677 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4678 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4679 | } |
| 4680 | return slotId; |
| 4681 | } |
| 4682 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4683 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4684 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4685 | */ |
| 4686 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4687 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4688 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4689 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4690 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4691 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4692 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4693 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4694 | mApp, subId, callingPackage, callingFeatureId, |
| 4695 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4696 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4697 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4698 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4699 | final long identity = Binder.clearCallingIdentity(); |
| 4700 | try { |
| 4701 | final Phone phone = getPhone(subId); |
| 4702 | if (phone != null) { |
| 4703 | return phone.getServiceState().getDataNetworkType(); |
| 4704 | } else { |
| 4705 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4706 | } |
| 4707 | } finally { |
| 4708 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4709 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4710 | } |
| 4711 | |
| 4712 | /** |
| 4713 | * Returns the data network type |
| 4714 | */ |
| 4715 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4716 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4717 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4718 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4719 | } |
| 4720 | |
| 4721 | /** |
| 4722 | * Returns the data network type for a subId |
| 4723 | */ |
| 4724 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4725 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4726 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4727 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4728 | mApp, subId, callingPackage, callingFeatureId, |
| 4729 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4730 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4731 | } |
| 4732 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4733 | final long identity = Binder.clearCallingIdentity(); |
| 4734 | try { |
| 4735 | final Phone phone = getPhone(subId); |
| 4736 | if (phone != null) { |
| 4737 | return phone.getServiceState().getDataNetworkType(); |
| 4738 | } else { |
| 4739 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4740 | } |
| 4741 | } finally { |
| 4742 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4743 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4744 | } |
| 4745 | |
| 4746 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4747 | * Returns the Voice network type for a subId |
| 4748 | */ |
| 4749 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4750 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4751 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4752 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4753 | mApp, subId, callingPackage, callingFeatureId, |
| 4754 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4755 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4756 | } |
| 4757 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4758 | final long identity = Binder.clearCallingIdentity(); |
| 4759 | try { |
| 4760 | final Phone phone = getPhone(subId); |
| 4761 | if (phone != null) { |
| 4762 | return phone.getServiceState().getVoiceNetworkType(); |
| 4763 | } else { |
| 4764 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4765 | } |
| 4766 | } finally { |
| 4767 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4768 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | /** |
| 4772 | * @return true if a ICC card is present |
| 4773 | */ |
| 4774 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4775 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4776 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4777 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4778 | } |
| 4779 | |
| 4780 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4781 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4782 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4783 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4784 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4785 | final long identity = Binder.clearCallingIdentity(); |
| 4786 | try { |
| 4787 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4788 | if (phone != null) { |
| 4789 | return phone.getIccCard().hasIccCard(); |
| 4790 | } else { |
| 4791 | return false; |
| 4792 | } |
| 4793 | } finally { |
| 4794 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4795 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4796 | } |
| 4797 | |
| 4798 | /** |
| 4799 | * Return if the current radio is LTE on CDMA. This |
| 4800 | * is a tri-state return value as for a period of time |
| 4801 | * the mode may be unknown. |
| 4802 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4803 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4804 | * @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] | 4805 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4806 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4807 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4808 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4809 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4810 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4811 | } |
| 4812 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4813 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 4814 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4815 | String callingFeatureId) { |
Sarah Chin | f6656a6 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4816 | try { |
| 4817 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4818 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4819 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4820 | } |
| 4821 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4822 | final long identity = Binder.clearCallingIdentity(); |
| 4823 | try { |
| 4824 | final Phone phone = getPhone(subId); |
| 4825 | if (phone == null) { |
| 4826 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4827 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4828 | return TelephonyProperties.lte_on_cdma_device() |
| 4829 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4830 | } |
| 4831 | } finally { |
| 4832 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4833 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4834 | } |
| 4835 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4836 | /** |
| 4837 | * {@hide} |
| 4838 | * Returns Default subId, 0 in the case of single standby. |
| 4839 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4840 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4841 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4842 | } |
| 4843 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4844 | private int getSlotForDefaultSubscription() { |
| 4845 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4846 | } |
| 4847 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4848 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4849 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4850 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4851 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4852 | private boolean isActiveSubscription(int subId) { |
| 4853 | return mSubscriptionController.isActiveSubId(subId); |
| 4854 | } |
| 4855 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4856 | /** |
| 4857 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4858 | */ |
| 4859 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4860 | final long identity = Binder.clearCallingIdentity(); |
| 4861 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4862 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4863 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4864 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4865 | } finally { |
| 4866 | Binder.restoreCallingIdentity(identity); |
| 4867 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4868 | } |
| 4869 | |
| 4870 | /** |
| 4871 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4872 | */ |
| 4873 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4874 | final long identity = Binder.clearCallingIdentity(); |
| 4875 | try { |
| 4876 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4877 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4878 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4879 | } finally { |
| 4880 | Binder.restoreCallingIdentity(identity); |
| 4881 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4882 | } |
| 4883 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4884 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4885 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4886 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4887 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4888 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4889 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4890 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4891 | if (phoneId == -1) { |
| 4892 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4893 | + " does not correspond to an active phone"); |
| 4894 | } |
| 4895 | return PhoneFactory.getPhone(phoneId); |
| 4896 | } |
| 4897 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4898 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4899 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4900 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4901 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4902 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4903 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4904 | if (DBG) { |
| 4905 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4906 | } |
| 4907 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4908 | p2); |
| 4909 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4910 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4911 | |
| 4912 | @Override |
| 4913 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4914 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4915 | enforceModifyPermission(); |
| 4916 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4917 | if (DBG) { |
| 4918 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4919 | } |
| 4920 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4921 | callingPackage, aid, p2); |
| 4922 | } |
| 4923 | |
| 4924 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4925 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4926 | final long identity = Binder.clearCallingIdentity(); |
| 4927 | try { |
| 4928 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4929 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4930 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4931 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4932 | if (bestComponent == null |
| 4933 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4934 | loge("The calling package is not allowed to access ISD-R."); |
| 4935 | throw new SecurityException( |
| 4936 | "The calling package is not allowed to access ISD-R."); |
| 4937 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4938 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4939 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4940 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4941 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4942 | null /* workSource */); |
| 4943 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4944 | return response; |
| 4945 | } finally { |
| 4946 | Binder.restoreCallingIdentity(identity); |
| 4947 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4948 | } |
| 4949 | |
| 4950 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4951 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4952 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4953 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4954 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4955 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4956 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4957 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4958 | @Override |
| 4959 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4960 | enforceModifyPermission(); |
| 4961 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4962 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4963 | channel); |
| 4964 | } |
| 4965 | |
| 4966 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4967 | final long identity = Binder.clearCallingIdentity(); |
| 4968 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4969 | if (channel < 0) { |
| 4970 | return false; |
| 4971 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4972 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4973 | null /* workSource */); |
| 4974 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4975 | return success; |
| 4976 | } finally { |
| 4977 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4978 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4982 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4983 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4984 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4985 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4986 | if (DBG) { |
| 4987 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4988 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4989 | + p3 + " data=" + data); |
| 4990 | } |
| 4991 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4992 | command, p1, p2, p3, data); |
| 4993 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4994 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4995 | @Override |
| 4996 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4997 | int command, int p1, int p2, int p3, String data) { |
| 4998 | enforceModifyPermission(); |
| 4999 | if (DBG) { |
| 5000 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 5001 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 5002 | + p3 + " data=" + data); |
| 5003 | } |
| 5004 | return iccTransmitApduLogicalChannelWithPermission( |
| 5005 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 5006 | data); |
| 5007 | } |
| 5008 | |
| 5009 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 5010 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5011 | final long identity = Binder.clearCallingIdentity(); |
| 5012 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 5013 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5014 | return ""; |
| 5015 | } |
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 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5018 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 5019 | null /* workSource */); |
| 5020 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5021 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5022 | // Append the returned status code to the end of the response payload. |
| 5023 | String s = Integer.toHexString( |
| 5024 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5025 | if (response.payload != null) { |
| 5026 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5027 | } |
| 5028 | return s; |
| 5029 | } finally { |
| 5030 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5031 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 5032 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5033 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5034 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5035 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 5036 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5037 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5038 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5039 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5040 | if (DBG) { |
| 5041 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 5042 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 5043 | } |
| 5044 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 5045 | cla, command, p1, p2, p3, data); |
| 5046 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5047 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5048 | @Override |
| 5049 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 5050 | int command, int p1, int p2, int p3, String data) { |
| 5051 | enforceModifyPermission(); |
| 5052 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 5053 | if (DBG) { |
| 5054 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 5055 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 5056 | + " data=" + data); |
| 5057 | } |
| 5058 | |
| 5059 | return iccTransmitApduBasicChannelWithPermission( |
| 5060 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 5061 | p2, p3, data); |
| 5062 | } |
| 5063 | |
| 5064 | // open APDU basic channel assuming the caller has sufficient permissions |
| 5065 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 5066 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5067 | final long identity = Binder.clearCallingIdentity(); |
| 5068 | try { |
| 5069 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 5070 | && TextUtils.equals(ISDR_AID, data)) { |
| 5071 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5072 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 5073 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5074 | if (bestComponent == null |
| 5075 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 5076 | loge("The calling package is not allowed to select ISD-R."); |
| 5077 | throw new SecurityException( |
| 5078 | "The calling package is not allowed to select ISD-R."); |
| 5079 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5080 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 5081 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5082 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 5083 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 5084 | null /* workSource */); |
| 5085 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5086 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5087 | // Append the returned status code to the end of the response payload. |
| 5088 | String s = Integer.toHexString( |
| 5089 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5090 | if (response.payload != null) { |
| 5091 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5092 | } |
| 5093 | return s; |
| 5094 | } finally { |
| 5095 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 5096 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5100 | 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] | 5101 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5102 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5103 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5104 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5105 | final long identity = Binder.clearCallingIdentity(); |
| 5106 | try { |
| 5107 | if (DBG) { |
| 5108 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 5109 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 5110 | } |
| 5111 | |
| 5112 | IccIoResult response = |
| 5113 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 5114 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 5115 | subId); |
| 5116 | |
| 5117 | if (DBG) { |
| 5118 | log("Exchange SIM_IO [R]" + response); |
| 5119 | } |
| 5120 | |
| 5121 | byte[] result = null; |
| 5122 | int length = 2; |
| 5123 | if (response.payload != null) { |
| 5124 | length = 2 + response.payload.length; |
| 5125 | result = new byte[length]; |
| 5126 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5127 | } else { |
| 5128 | result = new byte[length]; |
| 5129 | } |
| 5130 | |
| 5131 | result[length - 1] = (byte) response.sw2; |
| 5132 | result[length - 2] = (byte) response.sw1; |
| 5133 | return result; |
| 5134 | } finally { |
| 5135 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5136 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5137 | } |
| 5138 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5139 | /** |
| 5140 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5141 | * on a particular subscription |
| 5142 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5143 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5144 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5145 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5146 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5147 | return null; |
| 5148 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5149 | |
| 5150 | final long identity = Binder.clearCallingIdentity(); |
| 5151 | try { |
| 5152 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5153 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5154 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5155 | return null; |
| 5156 | } |
| 5157 | Object response = sendRequest( |
| 5158 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5159 | if (response instanceof String[]) { |
| 5160 | return (String[]) response; |
| 5161 | } |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5162 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5163 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5164 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5165 | } finally { |
| 5166 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5167 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5168 | } |
| 5169 | |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5170 | /** |
| 5171 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5172 | * subscription. |
| 5173 | * |
| 5174 | * @param subId the id of the subscription. |
| 5175 | * @param appType the uicc app type, must be USIM or SIM. |
| 5176 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5177 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5178 | * @param callingFeatureId the feature in the package. |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5179 | * @return number of fplmns that is successfully written to the SIM. |
| 5180 | */ |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5181 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5182 | String callingFeatureId) { |
| 5183 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5184 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | d698b84 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5185 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5186 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5187 | } |
| 5188 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5189 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5190 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5191 | } |
| 5192 | if (fplmns == null) { |
| 5193 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5194 | } |
| 5195 | for (String fplmn : fplmns) { |
| 5196 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5197 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5198 | } |
| 5199 | } |
| 5200 | final long identity = Binder.clearCallingIdentity(); |
| 5201 | try { |
| 5202 | Object response = sendRequest( |
| 5203 | CMD_SET_FORBIDDEN_PLMNS, |
| 5204 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5205 | subId); |
| 5206 | return (int) response; |
| 5207 | } finally { |
| 5208 | Binder.restoreCallingIdentity(identity); |
| 5209 | } |
| 5210 | } |
| 5211 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5212 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5213 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5214 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5215 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5216 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5217 | final long identity = Binder.clearCallingIdentity(); |
| 5218 | try { |
| 5219 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5220 | if (response.payload == null) { |
| 5221 | return ""; |
| 5222 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5223 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5224 | // Append the returned status code to the end of the response payload. |
| 5225 | String s = Integer.toHexString( |
| 5226 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5227 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5228 | return s; |
| 5229 | } finally { |
| 5230 | Binder.restoreCallingIdentity(identity); |
| 5231 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5232 | } |
| 5233 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5234 | /** |
| 5235 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5236 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5237 | * |
| 5238 | * @param itemID the ID of the item to read |
| 5239 | * @return the NV item as a String, or null on error. |
| 5240 | */ |
| 5241 | @Override |
| 5242 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5243 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5244 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5245 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5246 | |
| 5247 | final long identity = Binder.clearCallingIdentity(); |
| 5248 | try { |
| 5249 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5250 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5251 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5252 | return value; |
| 5253 | } finally { |
| 5254 | Binder.restoreCallingIdentity(identity); |
| 5255 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5256 | } |
| 5257 | |
| 5258 | /** |
| 5259 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5260 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5261 | * |
| 5262 | * @param itemID the ID of the item to read |
| 5263 | * @param itemValue the value to write, as a String |
| 5264 | * @return true on success; false on any failure |
| 5265 | */ |
| 5266 | @Override |
| 5267 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5268 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5269 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5270 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5271 | |
| 5272 | final long identity = Binder.clearCallingIdentity(); |
| 5273 | try { |
| 5274 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5275 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5276 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5277 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5278 | return success; |
| 5279 | } finally { |
| 5280 | Binder.restoreCallingIdentity(identity); |
| 5281 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5282 | } |
| 5283 | |
| 5284 | /** |
| 5285 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5286 | * Used for device configuration by some CDMA operators. |
| 5287 | * |
| 5288 | * @param preferredRoamingList byte array containing the new PRL |
| 5289 | * @return true on success; false on any failure |
| 5290 | */ |
| 5291 | @Override |
| 5292 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5293 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5294 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5295 | |
| 5296 | final long identity = Binder.clearCallingIdentity(); |
| 5297 | try { |
| 5298 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5299 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5300 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5301 | return success; |
| 5302 | } finally { |
| 5303 | Binder.restoreCallingIdentity(identity); |
| 5304 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5305 | } |
| 5306 | |
| 5307 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5308 | * 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] | 5309 | * Used for device configuration by some CDMA operators. |
| 5310 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5311 | * @param slotIndex - device slot. |
| 5312 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5313 | * @return true on success; false on any failure |
| 5314 | */ |
| 5315 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5316 | public boolean resetModemConfig(int slotIndex) { |
| 5317 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5318 | if (phone != null) { |
| 5319 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5320 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5321 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5322 | final long identity = Binder.clearCallingIdentity(); |
| 5323 | try { |
| 5324 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5325 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5326 | return success; |
| 5327 | } finally { |
| 5328 | Binder.restoreCallingIdentity(identity); |
| 5329 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5330 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5331 | return false; |
| 5332 | } |
| 5333 | |
| 5334 | /** |
| 5335 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5336 | * |
| 5337 | * @param slotIndex - device slot. |
| 5338 | * |
| 5339 | * @return true on success; false on any failure |
| 5340 | */ |
| 5341 | @Override |
| 5342 | public boolean rebootModem(int slotIndex) { |
| 5343 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5344 | if (phone != null) { |
| 5345 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5346 | mApp, phone.getSubId(), "rebootModem"); |
| 5347 | |
| 5348 | final long identity = Binder.clearCallingIdentity(); |
| 5349 | try { |
| 5350 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5351 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5352 | return success; |
| 5353 | } finally { |
| 5354 | Binder.restoreCallingIdentity(identity); |
| 5355 | } |
| 5356 | } |
| 5357 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5358 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5359 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5360 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5361 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5362 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5363 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5364 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5365 | return new String[0]; |
| 5366 | } |
| 5367 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5368 | final long identity = Binder.clearCallingIdentity(); |
| 5369 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5370 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5371 | } finally { |
| 5372 | Binder.restoreCallingIdentity(identity); |
| 5373 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5374 | } |
| 5375 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5376 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5377 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5378 | * {@link #disableIms(int)}. |
| 5379 | * @param slotIndex device slot. |
| 5380 | */ |
| 5381 | public void resetIms(int slotIndex) { |
| 5382 | enforceModifyPermission(); |
| 5383 | |
| 5384 | final long identity = Binder.clearCallingIdentity(); |
| 5385 | try { |
| 5386 | if (mImsResolver == null) { |
| 5387 | // may happen if the does not support IMS. |
| 5388 | return; |
| 5389 | } |
| 5390 | mImsResolver.disableIms(slotIndex); |
| 5391 | mImsResolver.enableIms(slotIndex); |
| 5392 | } finally { |
| 5393 | Binder.restoreCallingIdentity(identity); |
| 5394 | } |
| 5395 | } |
| 5396 | |
| 5397 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5398 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5399 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5400 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5401 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5402 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5403 | |
| 5404 | final long identity = Binder.clearCallingIdentity(); |
| 5405 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5406 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5407 | // may happen if the device does not support IMS. |
| 5408 | return; |
| 5409 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5410 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5411 | } finally { |
| 5412 | Binder.restoreCallingIdentity(identity); |
| 5413 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5417 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5418 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5419 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5420 | public void disableIms(int slotId) { |
| 5421 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5422 | |
| 5423 | final long identity = Binder.clearCallingIdentity(); |
| 5424 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5425 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5426 | // may happen if the device does not support IMS. |
| 5427 | return; |
| 5428 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5429 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5430 | } finally { |
| 5431 | Binder.restoreCallingIdentity(identity); |
| 5432 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5433 | } |
| 5434 | |
| 5435 | /** |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5436 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5437 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5438 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5439 | @Override |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5440 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5441 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5442 | |
| 5443 | final long identity = Binder.clearCallingIdentity(); |
| 5444 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5445 | if (mImsResolver == null) { |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5446 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5447 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5448 | } |
Brad Ebinger | 6366ce9 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5449 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5450 | } finally { |
| 5451 | Binder.restoreCallingIdentity(identity); |
| 5452 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5453 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5454 | /** |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5455 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5456 | */ |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5457 | @Override |
| 5458 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5459 | enforceModifyPermission(); |
| 5460 | |
| 5461 | final long identity = Binder.clearCallingIdentity(); |
| 5462 | try { |
| 5463 | if (mImsResolver == null) return; |
Brad Ebinger | e3ae65a | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5464 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | ab47dd4 | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5465 | } finally { |
| 5466 | Binder.restoreCallingIdentity(identity); |
| 5467 | } |
| 5468 | } |
| 5469 | |
| 5470 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5471 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5472 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5473 | */ |
| 5474 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5475 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5476 | |
| 5477 | final long identity = Binder.clearCallingIdentity(); |
| 5478 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5479 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5480 | // may happen if the device does not support IMS. |
| 5481 | return null; |
| 5482 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5483 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5484 | } finally { |
| 5485 | Binder.restoreCallingIdentity(identity); |
| 5486 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5487 | } |
| 5488 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5489 | /** |
| 5490 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5491 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5492 | */ |
| 5493 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5494 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5495 | |
| 5496 | final long identity = Binder.clearCallingIdentity(); |
| 5497 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5498 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5499 | // may happen if the device does not support IMS. |
| 5500 | return null; |
| 5501 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5502 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5503 | } finally { |
| 5504 | Binder.restoreCallingIdentity(identity); |
| 5505 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5506 | } |
| 5507 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5508 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5509 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5510 | * |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5511 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5512 | * @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] | 5513 | * ImsService is the device default ImsService. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5514 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5515 | * @param packageName The name of the package that the current configuration will be replaced |
| 5516 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5517 | * @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] | 5518 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5519 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5520 | int[] featureTypes, String packageName) { |
| 5521 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5522 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5524 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5525 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5526 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5527 | final long identity = Binder.clearCallingIdentity(); |
| 5528 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5529 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5530 | // may happen if the device does not support IMS. |
| 5531 | return false; |
| 5532 | } |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5533 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5534 | for (int featureType : featureTypes) { |
| 5535 | featureConfig.put(featureType, packageName); |
| 5536 | } |
| 5537 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5538 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5539 | } finally { |
| 5540 | Binder.restoreCallingIdentity(identity); |
| 5541 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5542 | } |
| 5543 | |
| 5544 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5545 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5546 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5547 | * |
| 5548 | * This should only be used for testing. |
| 5549 | * |
| 5550 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5551 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5552 | */ |
| 5553 | @Override |
| 5554 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5555 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5556 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5557 | "clearCarrierImsServiceOverride"); |
| 5558 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5559 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5560 | "clearCarrierImsServiceOverride"); |
| 5561 | |
| 5562 | final long identity = Binder.clearCallingIdentity(); |
| 5563 | try { |
| 5564 | if (mImsResolver == null) { |
| 5565 | // may happen if the device does not support IMS. |
| 5566 | return false; |
| 5567 | } |
| 5568 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5569 | } finally { |
| 5570 | Binder.restoreCallingIdentity(identity); |
| 5571 | } |
| 5572 | } |
| 5573 | |
| 5574 | /** |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5575 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5576 | * |
| 5577 | * @param slotId The slot that the ImsService is associated with. |
| 5578 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5579 | * the device default. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5580 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5581 | * @return the package name of the ImsService configuration. |
| 5582 | */ |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5583 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5584 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5585 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5586 | TelephonyPermissions |
| 5587 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5588 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5589 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5590 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5591 | final long identity = Binder.clearCallingIdentity(); |
| 5592 | try { |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5593 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5594 | // may happen if the device does not support IMS. |
| 5595 | return ""; |
| 5596 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5597 | // TODO: change API to query RCS separately. |
Brad Ebinger | 05f52c2 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5598 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5599 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5600 | } finally { |
| 5601 | Binder.restoreCallingIdentity(identity); |
| 5602 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5603 | } |
| 5604 | |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5605 | /** |
| 5606 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5607 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5608 | * @param callback A callback with an integer containing the |
| 5609 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5610 | */ |
| 5611 | @Override |
| 5612 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5613 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5614 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5615 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5616 | "IMS not available on device."); |
| 5617 | } |
| 5618 | final long token = Binder.clearCallingIdentity(); |
| 5619 | try { |
| 5620 | int slotId = getSlotIndex(subId); |
| 5621 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5622 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5623 | + subId + "'"); |
| 5624 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5625 | } |
| 5626 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5627 | try { |
| 5628 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5629 | } catch (RemoteException e) { |
| 5630 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5631 | + "Ignore"); |
| 5632 | } |
| 5633 | }); |
| 5634 | } finally { |
| 5635 | Binder.restoreCallingIdentity(token); |
| 5636 | } |
| 5637 | } |
| 5638 | |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5639 | /** |
| 5640 | * Sets the ims registration state on all valid {@link Phone}s. |
| 5641 | */ |
| 5642 | public void setImsRegistrationState(final boolean registered) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5643 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5644 | |
| 5645 | final long identity = Binder.clearCallingIdentity(); |
| 5646 | try { |
Daniel Bright | bb5840b | 2021-01-12 15:48:18 -0800 | [diff] [blame] | 5647 | // NOTE: Before S, this method only set the default phone. |
| 5648 | for (final Phone phone : PhoneFactory.getPhones()) { |
| 5649 | if (SubscriptionManager.isValidSubscriptionId(phone.getSubId())) { |
| 5650 | phone.setImsRegistrationState(registered); |
| 5651 | } |
| 5652 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5653 | } finally { |
| 5654 | Binder.restoreCallingIdentity(identity); |
| 5655 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5656 | } |
| 5657 | |
| 5658 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5659 | * Set the network selection mode to automatic. |
| 5660 | * |
| 5661 | */ |
| 5662 | @Override |
| 5663 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5664 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5665 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5666 | |
| 5667 | final long identity = Binder.clearCallingIdentity(); |
| 5668 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5669 | if (!isActiveSubscription(subId)) { |
| 5670 | return; |
| 5671 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5672 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
Rambo Wang | 0f050d8 | 2021-02-12 11:43:36 -0800 | [diff] [blame] | 5673 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId, |
| 5674 | SET_NETWORK_SELECTION_MODE_AUTOMATIC_TIMEOUT_MS); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5675 | } finally { |
| 5676 | Binder.restoreCallingIdentity(identity); |
| 5677 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5678 | } |
| 5679 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5680 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5681 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5682 | * |
| 5683 | * @param subId the id of the subscription. |
| 5684 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5685 | * the operator to attach to. |
| 5686 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5687 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5688 | * normal network selection next time. |
| 5689 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5690 | */ |
| 5691 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5692 | public boolean setNetworkSelectionModeManual( |
| 5693 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5694 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5695 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5696 | |
| 5697 | if (!isActiveSubscription(subId)) { |
| 5698 | return false; |
| 5699 | } |
| 5700 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5701 | final long identity = Binder.clearCallingIdentity(); |
| 5702 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5703 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5704 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5705 | if (DBG) { |
| 5706 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5707 | + " operator: " + operatorInfo); |
| 5708 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5709 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5710 | } finally { |
| 5711 | Binder.restoreCallingIdentity(identity); |
| 5712 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5713 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5714 | /** |
| 5715 | * Get the manual network selection |
| 5716 | * |
| 5717 | * @param subId the id of the subscription. |
| 5718 | * |
| 5719 | * @return the previously saved user selected PLMN |
| 5720 | */ |
| 5721 | @Override |
| 5722 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5723 | TelephonyPermissions |
| 5724 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5725 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5726 | |
| 5727 | final long identity = Binder.clearCallingIdentity(); |
| 5728 | try { |
| 5729 | if (!isActiveSubscription(subId)) { |
| 5730 | return ""; |
| 5731 | } |
| 5732 | |
| 5733 | final Phone phone = getPhone(subId); |
| 5734 | if (phone == null) { |
| 5735 | return ""; |
| 5736 | } |
| 5737 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5738 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5739 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5740 | } finally { |
| 5741 | Binder.restoreCallingIdentity(identity); |
| 5742 | } |
| 5743 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5744 | |
| 5745 | /** |
| 5746 | * Scans for available networks. |
| 5747 | */ |
| 5748 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5749 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5750 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5751 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5752 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5753 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5754 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5755 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5756 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5757 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5758 | .setCallingPid(Binder.getCallingPid()) |
| 5759 | .setCallingUid(Binder.getCallingUid()) |
| 5760 | .setMethod("getCellNetworkScanResults") |
| 5761 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5762 | .build()); |
| 5763 | switch (locationResult) { |
| 5764 | case DENIED_HARD: |
| 5765 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5766 | case DENIED_SOFT: |
| 5767 | return null; |
| 5768 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5769 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5770 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5771 | try { |
| 5772 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5773 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5774 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5775 | } finally { |
| 5776 | Binder.restoreCallingIdentity(identity); |
| 5777 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5778 | } |
| 5779 | |
| 5780 | /** |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5781 | * Get the call forwarding info, given the call forwarding reason. |
| 5782 | */ |
| 5783 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5784 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5785 | ICallForwardingInfoCallback callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5786 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5787 | long identity = Binder.clearCallingIdentity(); |
| 5788 | try { |
| 5789 | if (DBG) { |
| 5790 | log("getCallForwarding: subId " + subId |
| 5791 | + " callForwardingReason" + callForwardingReason); |
| 5792 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5793 | |
| 5794 | Phone phone = getPhone(subId); |
| 5795 | if (phone == null) { |
| 5796 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5797 | callback.onError( |
| 5798 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5799 | } catch (RemoteException e) { |
| 5800 | // ignore |
| 5801 | } |
| 5802 | return; |
| 5803 | } |
| 5804 | |
| 5805 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5806 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5807 | @Override |
| 5808 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5809 | try { |
| 5810 | callback.onCallForwardingInfoAvailable(info); |
| 5811 | } catch (RemoteException e) { |
| 5812 | // ignore |
| 5813 | } |
| 5814 | } |
| 5815 | |
| 5816 | @Override |
| 5817 | public void onError(int error) { |
| 5818 | try { |
| 5819 | callback.onError(error); |
| 5820 | } catch (RemoteException e) { |
| 5821 | // ignore |
| 5822 | } |
| 5823 | } |
| 5824 | }); |
| 5825 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5826 | } finally { |
| 5827 | Binder.restoreCallingIdentity(identity); |
| 5828 | } |
| 5829 | } |
| 5830 | |
| 5831 | /** |
| 5832 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5833 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5834 | */ |
| 5835 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5836 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5837 | IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5838 | enforceModifyPermission(); |
| 5839 | long identity = Binder.clearCallingIdentity(); |
| 5840 | try { |
| 5841 | if (DBG) { |
| 5842 | log("setCallForwarding: subId " + subId |
| 5843 | + " callForwardingInfo" + callForwardingInfo); |
| 5844 | } |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5845 | |
| 5846 | Phone phone = getPhone(subId); |
| 5847 | if (phone == null) { |
| 5848 | try { |
Hall Liu | ae527aa | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5849 | callback.accept( |
| 5850 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5851 | } catch (RemoteException e) { |
| 5852 | // ignore |
| 5853 | } |
| 5854 | return; |
| 5855 | } |
| 5856 | |
| 5857 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5858 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5859 | |
| 5860 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5861 | } finally { |
| 5862 | Binder.restoreCallingIdentity(identity); |
| 5863 | } |
| 5864 | } |
| 5865 | |
| 5866 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5867 | * Get the call waiting status for a subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5868 | */ |
| 5869 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5870 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5871 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5872 | long identity = Binder.clearCallingIdentity(); |
| 5873 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5874 | |
| 5875 | Phone phone = getPhone(subId); |
| 5876 | if (phone == null) { |
| 5877 | try { |
| 5878 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5879 | } catch (RemoteException e) { |
| 5880 | // ignore |
| 5881 | } |
| 5882 | return; |
| 5883 | } |
| 5884 | |
| 5885 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5886 | |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5887 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5888 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5889 | } finally { |
| 5890 | Binder.restoreCallingIdentity(identity); |
| 5891 | } |
| 5892 | } |
| 5893 | |
| 5894 | /** |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5895 | * Sets whether call waiting is enabled for a given subId. |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5896 | */ |
| 5897 | @Override |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5898 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5899 | enforceModifyPermission(); |
| 5900 | long identity = Binder.clearCallingIdentity(); |
| 5901 | try { |
Hall Liu | a1acea2 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5902 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5903 | |
| 5904 | Phone phone = getPhone(subId); |
| 5905 | if (phone == null) { |
| 5906 | try { |
| 5907 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5908 | } catch (RemoteException e) { |
| 5909 | // ignore |
| 5910 | } |
| 5911 | return; |
| 5912 | } |
| 5913 | |
| 5914 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5915 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5916 | |
| 5917 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
sqian | 8037072 | 2020-01-29 15:02:51 -0800 | [diff] [blame] | 5918 | } finally { |
| 5919 | Binder.restoreCallingIdentity(identity); |
| 5920 | } |
| 5921 | } |
| 5922 | |
| 5923 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5924 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5925 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5926 | * @param subId id of the subscription |
| 5927 | * @param request contains the radio access networks with bands/channels to scan |
| 5928 | * @param messenger callback messenger for scan results or errors |
| 5929 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5930 | * @return the id of the requested scan which can be used to stop the scan. |
| 5931 | */ |
| 5932 | @Override |
| 5933 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5934 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5935 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5936 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5937 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5938 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5939 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5940 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 5941 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5942 | .setCallingPid(Binder.getCallingPid()) |
| 5943 | .setCallingUid(Binder.getCallingUid()) |
| 5944 | .setMethod("requestNetworkScan") |
| 5945 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 5946 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5947 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5948 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5949 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5950 | if (e != null) { |
| 5951 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5952 | throw e; |
| 5953 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5954 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5955 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5956 | } |
| 5957 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5959 | int callingUid = Binder.getCallingUid(); |
| 5960 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5961 | final long identity = Binder.clearCallingIdentity(); |
| 5962 | try { |
| 5963 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5964 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5965 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5966 | } finally { |
| 5967 | Binder.restoreCallingIdentity(identity); |
| 5968 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5969 | } |
| 5970 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5971 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 284aa04 | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5972 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5973 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5974 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5975 | boolean hasNetworkScanPermission = |
| 5976 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5977 | == PERMISSION_GRANTED; |
| 5978 | |
| 5979 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5980 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5981 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5982 | } |
| 5983 | |
| 5984 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5985 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5986 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5987 | return new SecurityException("Specific channels must not be" |
| 5988 | + " scanned without location access."); |
| 5989 | } |
| 5990 | } |
| 5991 | } |
| 5992 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5993 | return null; |
| 5994 | } |
| 5995 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5996 | /** |
| 5997 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5998 | * |
| 5999 | * @param subId id of the subscription |
| 6000 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6001 | */ |
| 6002 | @Override |
| 6003 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6004 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6005 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6006 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6007 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6008 | final long identity = Binder.clearCallingIdentity(); |
| 6009 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 6010 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6011 | } finally { |
| 6012 | Binder.restoreCallingIdentity(identity); |
| 6013 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 6014 | } |
| 6015 | |
| 6016 | /** |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 6017 | * Get the allowed network types bitmask. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6018 | * |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 6019 | * @return the allowed network types bitmask, defined in RILConstants.java. |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 6020 | */ |
| 6021 | @Override |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 6022 | public int getAllowedNetworkTypesBitmask(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 6023 | TelephonyPermissions |
| 6024 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 6025 | mApp, subId, "getAllowedNetworkTypesBitmask"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6026 | |
| 6027 | final long identity = Binder.clearCallingIdentity(); |
| 6028 | try { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 6029 | if (DBG) log("getAllowedNetworkTypesBitmask"); |
| 6030 | int[] result = (int[]) sendRequest(CMD_GET_ALLOWED_NETWORK_TYPES_BITMASK, null, subId); |
| 6031 | int networkTypesBitmask = (result != null ? result[0] : -1); |
| 6032 | if (DBG) log("getAllowedNetworkTypesBitmask: " + networkTypesBitmask); |
| 6033 | return networkTypesBitmask; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6034 | } finally { |
| 6035 | Binder.restoreCallingIdentity(identity); |
| 6036 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 6037 | } |
| 6038 | |
| 6039 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6040 | * Get the allowed network types for certain reason. |
| 6041 | * |
| 6042 | * @param subId the id of the subscription. |
| 6043 | * @param reason the reason the allowed network type change is taking place |
| 6044 | * @return the allowed network types. |
| 6045 | */ |
| 6046 | @Override |
| 6047 | public long getAllowedNetworkTypesForReason(int subId, |
| 6048 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6049 | TelephonyPermissions |
| 6050 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6051 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6052 | final long identity = Binder.clearCallingIdentity(); |
| 6053 | try { |
| 6054 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6055 | } finally { |
| 6056 | Binder.restoreCallingIdentity(identity); |
| 6057 | } |
| 6058 | } |
| 6059 | |
| 6060 | /** |
Sooraj Sasindran | b4a9960 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6061 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6062 | * @param subId subscription id of the sim card |
| 6063 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6064 | * This can be passed following states |
| 6065 | * <ol> |
| 6066 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6067 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6068 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6069 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6070 | * </ol> |
| 6071 | * @return operation result. |
| 6072 | */ |
| 6073 | @Override |
| 6074 | public int setNrDualConnectivityState(int subId, |
| 6075 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6076 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6077 | mApp, subId, "enableNRDualConnectivity"); |
| 6078 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6079 | final long identity = Binder.clearCallingIdentity(); |
| 6080 | try { |
| 6081 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6082 | nrDualConnectivityState, subId, |
| 6083 | workSource); |
| 6084 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6085 | return result; |
| 6086 | } finally { |
| 6087 | Binder.restoreCallingIdentity(identity); |
| 6088 | } |
| 6089 | } |
| 6090 | |
| 6091 | /** |
| 6092 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6093 | * @return true if dual connectivity is enabled else false |
| 6094 | */ |
| 6095 | @Override |
| 6096 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6097 | TelephonyPermissions |
| 6098 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6099 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6100 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6101 | final long identity = Binder.clearCallingIdentity(); |
| 6102 | try { |
| 6103 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6104 | null, subId, workSource); |
| 6105 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6106 | return isEnabled; |
| 6107 | } finally { |
| 6108 | Binder.restoreCallingIdentity(identity); |
| 6109 | } |
| 6110 | } |
| 6111 | |
| 6112 | /** |
Sooraj Sasindran | 1f812e0 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6113 | * get carrier bandwidth per primary and secondary carrier |
| 6114 | * @param subId subscription id of the sim card |
| 6115 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6116 | */ |
| 6117 | @Override |
| 6118 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6119 | TelephonyPermissions |
| 6120 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6121 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6122 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6123 | final long identity = Binder.clearCallingIdentity(); |
| 6124 | try { |
| 6125 | CarrierBandwidth carrierBandwidth = |
| 6126 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6127 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6128 | return carrierBandwidth; |
| 6129 | } finally { |
| 6130 | Binder.restoreCallingIdentity(identity); |
| 6131 | } |
| 6132 | } |
| 6133 | |
| 6134 | /** |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6135 | * Set the allowed network types of the device and |
| 6136 | * provide the reason triggering the allowed network change. |
| 6137 | * |
| 6138 | * @param subId the id of the subscription. |
| 6139 | * @param reason the reason the allowed network type change is taking place |
| 6140 | * @param allowedNetworkTypes the allowed network types. |
| 6141 | * @return true on success; false on any failure. |
| 6142 | */ |
| 6143 | @Override |
| 6144 | public boolean setAllowedNetworkTypesForReason(int subId, |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 6145 | @TelephonyManager.AllowedNetworkTypesReason int reason, |
| 6146 | @TelephonyManager.NetworkTypeBitMask long allowedNetworkTypes) { |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6147 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6148 | mApp, subId, "setAllowedNetworkTypesForReason"); |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 6149 | if (!TelephonyManager.isValidAllowedNetworkTypesReason(reason)) { |
| 6150 | Rlog.e(LOG_TAG, "Invalid allowed network type reason: " + reason); |
| 6151 | return false; |
| 6152 | } |
| 6153 | |
| 6154 | if (DBG) { |
| 6155 | log("setAllowedNetworkTypesForReason: " + reason |
| 6156 | + " value: " + allowedNetworkTypes); |
| 6157 | } |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6158 | final long identity = Binder.clearCallingIdentity(); |
| 6159 | try { |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 6160 | Boolean success = (Boolean) sendRequest( |
| 6161 | CMD_SET_ALLOWED_NETWORK_TYPES_FOR_REASON, |
| 6162 | new Pair<Integer, Long>(reason, allowedNetworkTypes), subId); |
| 6163 | |
| 6164 | if (DBG) log("setAllowedNetworkTypesForReason: " + (success ? "ok" : "fail")); |
| 6165 | return success; |
Sooraj Sasindran | 9e2be4e | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6166 | } finally { |
| 6167 | Binder.restoreCallingIdentity(identity); |
| 6168 | } |
| 6169 | } |
| 6170 | |
| 6171 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6172 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6173 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6174 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6175 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6176 | * @hide |
| 6177 | */ |
| 6178 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6179 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6180 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6181 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6182 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6183 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6184 | if (phone != null) { |
| 6185 | return phone.hasMatchedTetherApnSetting(); |
| 6186 | } else { |
| 6187 | return false; |
| 6188 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6189 | } finally { |
| 6190 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6191 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6192 | } |
| 6193 | |
| 6194 | /** |
Shuo Qian | 5bac1ee | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6195 | * Enable or disable always reporting signal strength changes from radio. |
| 6196 | * |
| 6197 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6198 | */ |
| 6199 | @Override |
| 6200 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6201 | enforceModifyPermission(); |
| 6202 | enforceSystemCaller(); |
| 6203 | |
| 6204 | final long identity = Binder.clearCallingIdentity(); |
| 6205 | final Phone phone = getPhone(subId); |
| 6206 | try { |
| 6207 | if (phone != null) { |
| 6208 | if (DBG) { |
| 6209 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6210 | + " isEnable=" + isEnable); |
| 6211 | } |
| 6212 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6213 | } else { |
| 6214 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6215 | + subId); |
| 6216 | } |
| 6217 | } finally { |
| 6218 | Binder.restoreCallingIdentity(identity); |
| 6219 | } |
| 6220 | } |
| 6221 | |
| 6222 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6223 | * Get the user enabled state of Mobile Data. |
| 6224 | * |
| 6225 | * TODO: remove and use isUserDataEnabled. |
| 6226 | * This can't be removed now because some vendor codes |
| 6227 | * calls through ITelephony directly while they should |
| 6228 | * use TelephonyManager. |
| 6229 | * |
| 6230 | * @return true on enabled |
| 6231 | */ |
| 6232 | @Override |
| 6233 | public boolean getDataEnabled(int subId) { |
| 6234 | return isUserDataEnabled(subId); |
| 6235 | } |
| 6236 | |
| 6237 | /** |
| 6238 | * Get whether mobile data is enabled per user setting. |
| 6239 | * |
| 6240 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6241 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6242 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6243 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6244 | * |
| 6245 | * @return {@code true} if data is enabled else {@code false} |
| 6246 | */ |
| 6247 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6248 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6249 | try { |
| 6250 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6251 | null); |
| 6252 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6253 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6254 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6255 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6256 | |
| 6257 | final long identity = Binder.clearCallingIdentity(); |
| 6258 | try { |
| 6259 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6260 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6261 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6262 | if (phone != null) { |
| 6263 | boolean retVal = phone.isUserDataEnabled(); |
| 6264 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6265 | return retVal; |
| 6266 | } else { |
| 6267 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6268 | return false; |
| 6269 | } |
| 6270 | } finally { |
| 6271 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6272 | } |
| 6273 | } |
| 6274 | |
| 6275 | /** |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6276 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6277 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6278 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6279 | * |
Shuo Qian | 985d123 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6280 | * @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] | 6281 | */ |
| 6282 | @Override |
| 6283 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6284 | try { |
| 6285 | try { |
| 6286 | mApp.enforceCallingOrSelfPermission( |
| 6287 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6288 | null); |
| 6289 | } catch (Exception e) { |
| 6290 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6291 | "isDataEnabled"); |
| 6292 | } |
| 6293 | } catch (Exception e) { |
| 6294 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6295 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6296 | |
| 6297 | final long identity = Binder.clearCallingIdentity(); |
| 6298 | try { |
| 6299 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6300 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6301 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6302 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6303 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6304 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6305 | return retVal; |
| 6306 | } else { |
| 6307 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6308 | return false; |
| 6309 | } |
| 6310 | } finally { |
| 6311 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6312 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6313 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6314 | |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6315 | /** |
| 6316 | * Check if data is enabled for a specific reason |
| 6317 | * @param subId Subscription index |
| 6318 | * @param reason the reason the data enable change is taking place |
| 6319 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6320 | */ |
| 6321 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6322 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6323 | @TelephonyManager.DataEnabledReason int reason) { |
| 6324 | try { |
| 6325 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6326 | null); |
| 6327 | } catch (Exception e) { |
| 6328 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6329 | "isDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6330 | } |
| 6331 | |
| 6332 | |
| 6333 | final long identity = Binder.clearCallingIdentity(); |
| 6334 | try { |
| 6335 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6336 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6337 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6338 | + " reason=" + reason); |
| 6339 | } |
| 6340 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6341 | if (phone != null) { |
| 6342 | boolean retVal; |
| 6343 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6344 | retVal = phone.isUserDataEnabled(); |
| 6345 | } else { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6346 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6347 | } |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6348 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6349 | return retVal; |
| 6350 | } else { |
| 6351 | if (DBG) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6352 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 6353 | + subId + " retVal=false"); |
| 6354 | } |
| 6355 | return false; |
| 6356 | } |
| 6357 | } finally { |
| 6358 | Binder.restoreCallingIdentity(identity); |
| 6359 | } |
| 6360 | } |
| 6361 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6362 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6363 | Phone phone) { |
Hall Liu | ce478d2 | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6364 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6365 | // Skip the check if it's one of these special uids |
| 6366 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6367 | } |
| 6368 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6369 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6370 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6371 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6372 | || subController == null) return privilegeFromSim; |
| 6373 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6374 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6375 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6376 | |
| 6377 | final long identity = Binder.clearCallingIdentity(); |
| 6378 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6379 | int subId = phone.getSubId(); |
| 6380 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6381 | // A test override is in place for the privileges for this subId, so don't try to |
| 6382 | // read the subscription privileges. |
| 6383 | return privilegeFromSim; |
| 6384 | } |
| 6385 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6386 | SubscriptionManager subManager = (SubscriptionManager) |
| 6387 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6388 | for (String pkg : packages) { |
| 6389 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6390 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6391 | } |
| 6392 | } |
| 6393 | return privilegeFromSim; |
| 6394 | } finally { |
| 6395 | Binder.restoreCallingIdentity(identity); |
| 6396 | } |
| 6397 | } |
| 6398 | |
| 6399 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6400 | String pkgName) { |
| 6401 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6402 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6403 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6404 | || subController == null) return privilegeFromSim; |
| 6405 | |
| 6406 | final long identity = Binder.clearCallingIdentity(); |
| 6407 | try { |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6408 | int subId = phone.getSubId(); |
| 6409 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6410 | // A test override is in place for the privileges for this subId, so don't try to |
| 6411 | // read the subscription privileges. |
| 6412 | return privilegeFromSim; |
| 6413 | } |
| 6414 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6415 | SubscriptionManager subManager = (SubscriptionManager) |
| 6416 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6417 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6418 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6419 | } finally { |
| 6420 | Binder.restoreCallingIdentity(identity); |
| 6421 | } |
| 6422 | } |
| 6423 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6424 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6425 | public int getCarrierPrivilegeStatus(int subId) { |
| 6426 | final Phone phone = getPhone(subId); |
| 6427 | if (phone == null) { |
| 6428 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6429 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6430 | } |
| 6431 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6432 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6433 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6434 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6435 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6436 | |
| 6437 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6438 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6439 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6440 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6441 | |
| 6442 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6443 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6444 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6445 | final Phone phone = getPhone(subId); |
| 6446 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6447 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6448 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6449 | } |
| 6450 | UiccProfile profile = |
| 6451 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6452 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6453 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6454 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6455 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6456 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6457 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6458 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6459 | } |
| 6460 | |
| 6461 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6462 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6463 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6464 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6465 | } |
| 6466 | |
| 6467 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6468 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6469 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6470 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6471 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6472 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6473 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6474 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6475 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6476 | } |
| 6477 | |
| 6478 | @Override |
| 6479 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6480 | if (TextUtils.isEmpty(pkgName)) |
| 6481 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6482 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6483 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6484 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6485 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6486 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6487 | continue; |
| 6488 | } |
| 6489 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6490 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6491 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6492 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6493 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6494 | break; |
| 6495 | } |
| 6496 | } |
| 6497 | |
| 6498 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6499 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6500 | |
| 6501 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6502 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6503 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6504 | loge("phoneId " + phoneId + " is not valid."); |
| 6505 | return null; |
| 6506 | } |
| 6507 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6508 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6509 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6510 | return null ; |
| 6511 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6512 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6513 | } |
| 6514 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6515 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6516 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6517 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6518 | List<String> privilegedPackages = new ArrayList<>(); |
| 6519 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6520 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6521 | // has UICC in that slot. |
| 6522 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6523 | if (card.hasCarrierPrivilegeRules()) { |
| 6524 | if (packages == null) { |
| 6525 | // Only check packages in user 0 for now |
| 6526 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6527 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6528 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6529 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6530 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6531 | } |
| 6532 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6533 | PackageInfo pkgInfo = packages.get(p); |
| 6534 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6535 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6536 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6537 | privilegedPackages.add(pkgInfo.packageName); |
| 6538 | } |
| 6539 | } |
| 6540 | } |
| 6541 | } |
| 6542 | return privilegedPackages; |
| 6543 | } |
| 6544 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6545 | @Override |
| 6546 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6547 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6548 | |
| 6549 | final long identity = Binder.clearCallingIdentity(); |
| 6550 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6551 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | d54f9f3 | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6552 | try { |
| 6553 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6554 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6555 | } |
| 6556 | } finally { |
| 6557 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6558 | } |
| 6559 | return privilegedPackages; |
| 6560 | } |
| 6561 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6562 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6563 | final Phone phone = getPhone(subId); |
| 6564 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6565 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6566 | return null; |
| 6567 | } |
| 6568 | String iccId = card.getIccId(); |
| 6569 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6570 | return null; |
| 6571 | } |
| 6572 | return iccId; |
| 6573 | } |
| 6574 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6575 | @Override |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6576 | public void setCallComposerStatus(int subId, int status) { |
| 6577 | enforceModifyPermission(); |
| 6578 | |
| 6579 | final long identity = Binder.clearCallingIdentity(); |
| 6580 | try { |
| 6581 | Phone phone = getPhone(subId); |
| 6582 | if (phone != null) { |
| 6583 | Phone defaultPhone = phone.getImsPhone(); |
| 6584 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6585 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6586 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6587 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6588 | .updateImsServiceConfig(); |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6589 | } |
| 6590 | } |
Shuo Qian | d878246 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6591 | } catch (ImsException e) { |
| 6592 | throw new ServiceSpecificException(e.getCode()); |
| 6593 | } finally { |
Shuo Qian | 8aa1132 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6594 | Binder.restoreCallingIdentity(identity); |
| 6595 | } |
| 6596 | } |
| 6597 | |
| 6598 | @Override |
| 6599 | public int getCallComposerStatus(int subId) { |
| 6600 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 6601 | |
| 6602 | final long identity = Binder.clearCallingIdentity(); |
| 6603 | try { |
| 6604 | Phone phone = getPhone(subId); |
| 6605 | if (phone != null) { |
| 6606 | Phone defaultPhone = phone.getImsPhone(); |
| 6607 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6608 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6609 | return imsPhone.getCallComposerStatus(); |
| 6610 | } |
| 6611 | } |
| 6612 | } finally { |
| 6613 | Binder.restoreCallingIdentity(identity); |
| 6614 | } |
| 6615 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6616 | } |
| 6617 | |
| 6618 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6619 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6620 | String number) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6621 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6622 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6623 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6624 | final long identity = Binder.clearCallingIdentity(); |
| 6625 | try { |
| 6626 | final String iccId = getIccId(subId); |
| 6627 | final Phone phone = getPhone(subId); |
| 6628 | if (phone == null) { |
| 6629 | return false; |
| 6630 | } |
| 6631 | final String subscriberId = phone.getSubscriberId(); |
| 6632 | |
| 6633 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6634 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6635 | + subscriberId + " to " + number); |
| 6636 | } |
| 6637 | |
| 6638 | if (TextUtils.isEmpty(iccId)) { |
| 6639 | return false; |
| 6640 | } |
| 6641 | |
| 6642 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6643 | |
| 6644 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6645 | if (alphaTag == null) { |
| 6646 | editor.remove(alphaTagPrefKey); |
| 6647 | } else { |
| 6648 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6649 | } |
| 6650 | |
| 6651 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6652 | // track all merged IMSIs based on line number |
| 6653 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6654 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6655 | if (number == null) { |
| 6656 | editor.remove(numberPrefKey); |
| 6657 | editor.remove(subscriberPrefKey); |
| 6658 | } else { |
| 6659 | editor.putString(numberPrefKey, number); |
| 6660 | editor.putString(subscriberPrefKey, subscriberId); |
| 6661 | } |
| 6662 | |
| 6663 | editor.commit(); |
| 6664 | return true; |
| 6665 | } finally { |
| 6666 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6667 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6668 | } |
| 6669 | |
| 6670 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6671 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6672 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6673 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6674 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6675 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6676 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6677 | return null; |
| 6678 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6679 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6680 | final long identity = Binder.clearCallingIdentity(); |
| 6681 | try { |
| 6682 | String iccId = getIccId(subId); |
| 6683 | if (iccId != null) { |
| 6684 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6685 | if (DBG_MERGE) { |
| 6686 | log("getLine1NumberForDisplay returning " |
| 6687 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6688 | } |
| 6689 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6690 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6691 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6692 | return null; |
| 6693 | } finally { |
| 6694 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6695 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6696 | } |
| 6697 | |
| 6698 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6699 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6700 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6701 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6702 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6703 | return null; |
| 6704 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6705 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6706 | final long identity = Binder.clearCallingIdentity(); |
| 6707 | try { |
| 6708 | String iccId = getIccId(subId); |
| 6709 | if (iccId != null) { |
| 6710 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6711 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6712 | } |
| 6713 | return null; |
| 6714 | } finally { |
| 6715 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6716 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6717 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6718 | |
| 6719 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6720 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6721 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6722 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6723 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6724 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6725 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6726 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6727 | return null; |
| 6728 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6729 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6730 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6731 | // the process, where TelephonyManager was instantiated. |
| 6732 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6733 | final long identity = Binder.clearCallingIdentity(); |
| 6734 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6735 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6736 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6737 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6738 | |
| 6739 | // Figure out what subscribers are currently active |
| 6740 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6741 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6742 | // Only consider subs which match the current subId |
| 6743 | // This logic can be simplified. See b/131189269 for progress. |
| 6744 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6745 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6746 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6747 | |
| 6748 | // First pass, find a number override for an active subscriber |
| 6749 | String mergeNumber = null; |
| 6750 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6751 | for (String key : prefs.keySet()) { |
| 6752 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6753 | final String subscriberId = (String) prefs.get(key); |
| 6754 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6755 | final String iccId = key.substring( |
| 6756 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6757 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6758 | mergeNumber = (String) prefs.get(numberKey); |
| 6759 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6760 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6761 | + " for active subscriber " + subscriberId); |
| 6762 | } |
| 6763 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6764 | break; |
| 6765 | } |
| 6766 | } |
| 6767 | } |
| 6768 | } |
| 6769 | |
| 6770 | // Shortcut when no active merged subscribers |
| 6771 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6772 | return null; |
| 6773 | } |
| 6774 | |
| 6775 | // Second pass, find all subscribers under that line override |
| 6776 | final ArraySet<String> result = new ArraySet<>(); |
| 6777 | for (String key : prefs.keySet()) { |
| 6778 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6779 | final String number = (String) prefs.get(key); |
| 6780 | if (mergeNumber.equals(number)) { |
| 6781 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6782 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6783 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6784 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6785 | result.add(subscriberId); |
| 6786 | } |
| 6787 | } |
| 6788 | } |
| 6789 | } |
| 6790 | |
| 6791 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6792 | Arrays.sort(resultArray); |
| 6793 | if (DBG_MERGE) { |
Amit Mahajan | 98bbd6e | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6794 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6795 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6796 | } |
| 6797 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6798 | } finally { |
| 6799 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6800 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6801 | } |
| 6802 | |
| 6803 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6804 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6805 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6806 | |
| 6807 | final long identity = Binder.clearCallingIdentity(); |
| 6808 | try { |
| 6809 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6810 | TelephonyManager.class); |
| 6811 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6812 | if (subscriberId == null) { |
| 6813 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6814 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6815 | + subId); |
| 6816 | } |
| 6817 | return null; |
| 6818 | } |
| 6819 | |
| 6820 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6821 | .getSubscriptionInfo(subId); |
| 6822 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6823 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6824 | if (groupUuid == null) { |
| 6825 | return new String[]{subscriberId}; |
| 6826 | } |
| 6827 | |
| 6828 | // Get all subscriberIds from the group. |
| 6829 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6830 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6831 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6832 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6833 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6834 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6835 | if (subscriberId != null) { |
| 6836 | mergedSubscriberIds.add(subscriberId); |
| 6837 | } |
| 6838 | } |
| 6839 | |
| 6840 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6841 | } finally { |
| 6842 | Binder.restoreCallingIdentity(identity); |
| 6843 | |
| 6844 | } |
| 6845 | } |
| 6846 | |
| 6847 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6848 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6849 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6850 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6851 | |
| 6852 | final long identity = Binder.clearCallingIdentity(); |
| 6853 | try { |
| 6854 | final Phone phone = getPhone(subId); |
| 6855 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6856 | } finally { |
| 6857 | Binder.restoreCallingIdentity(identity); |
| 6858 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6859 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6860 | |
| 6861 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6862 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6863 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6864 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 6d92745 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6865 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6866 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6867 | |
| 6868 | final long identity = Binder.clearCallingIdentity(); |
| 6869 | try { |
| 6870 | final Phone phone = getPhone(subId); |
| 6871 | if (phone == null) { |
| 6872 | return false; |
| 6873 | } |
| 6874 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6875 | cdmaNonRoamingList); |
| 6876 | } finally { |
| 6877 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6878 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6879 | } |
| 6880 | |
| 6881 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6882 | @Deprecated |
| 6883 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6884 | enforceModifyPermission(); |
| 6885 | |
| 6886 | int returnValue = 0; |
| 6887 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6888 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6889 | if(result.exception == null) { |
| 6890 | if (result.result != null) { |
| 6891 | byte[] responseData = (byte[])(result.result); |
| 6892 | if(responseData.length > oemResp.length) { |
| 6893 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6894 | responseData.length + "bytes. Buffer Size is " + |
| 6895 | oemResp.length + "bytes."); |
| 6896 | } |
| 6897 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6898 | returnValue = responseData.length; |
| 6899 | } |
| 6900 | } else { |
| 6901 | CommandException ex = (CommandException) result.exception; |
| 6902 | returnValue = ex.getCommandError().ordinal(); |
| 6903 | if(returnValue > 0) returnValue *= -1; |
| 6904 | } |
| 6905 | } catch (RuntimeException e) { |
| 6906 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6907 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6908 | if(returnValue > 0) returnValue *= -1; |
| 6909 | } |
| 6910 | |
| 6911 | return returnValue; |
| 6912 | } |
| 6913 | |
| 6914 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6915 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6916 | try { |
| 6917 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6918 | } catch (RuntimeException e) { |
| 6919 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6920 | } |
| 6921 | } |
| 6922 | |
| 6923 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6924 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6925 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6926 | try { |
| 6927 | TelephonyPermissions |
| 6928 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6929 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6930 | } catch (SecurityException e) { |
| 6931 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6932 | throw e; |
| 6933 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6934 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6935 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6936 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6937 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6938 | final long identity = Binder.clearCallingIdentity(); |
| 6939 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6940 | TelephonyPermissions |
| 6941 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6942 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6943 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6944 | } finally { |
| 6945 | Binder.restoreCallingIdentity(identity); |
| 6946 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6947 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6948 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6949 | |
| 6950 | @Override |
| 6951 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6952 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6953 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6954 | |
| 6955 | final long identity = Binder.clearCallingIdentity(); |
| 6956 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6957 | ImsManager.getInstance(defaultPhone.getContext(), |
| 6958 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6959 | } finally { |
| 6960 | Binder.restoreCallingIdentity(identity); |
| 6961 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6962 | } |
| 6963 | |
| 6964 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6965 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6966 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6967 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 6968 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 6969 | return false; |
| 6970 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6971 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6972 | final long identity = Binder.clearCallingIdentity(); |
| 6973 | try { |
| 6974 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 6975 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 6976 | // In the long run, we may instead need to check if there exists a connection service |
| 6977 | // which can support video calling. |
| 6978 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6979 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6980 | return imsManager.isVtEnabledByPlatform() |
| 6981 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 6982 | && imsManager.isVtEnabledByUser(); |
| 6983 | } finally { |
| 6984 | Binder.restoreCallingIdentity(identity); |
| 6985 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6986 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 6987 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 6988 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6989 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 6990 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6991 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 6992 | mApp, subId, callingPackage, callingFeatureId, |
| 6993 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6994 | return false; |
| 6995 | } |
| 6996 | |
| 6997 | final long identity = Binder.clearCallingIdentity(); |
| 6998 | try { |
| 6999 | CarrierConfigManager configManager = |
| 7000 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7001 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7002 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7003 | } finally { |
| 7004 | Binder.restoreCallingIdentity(identity); |
| 7005 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7006 | } |
| 7007 | |
| 7008 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7009 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7010 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7011 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7012 | return false; |
| 7013 | } |
| 7014 | |
| 7015 | final long identity = Binder.clearCallingIdentity(); |
| 7016 | try { |
| 7017 | CarrierConfigManager configManager = |
| 7018 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7019 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7020 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7021 | } finally { |
| 7022 | Binder.restoreCallingIdentity(identity); |
| 7023 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7024 | } |
| 7025 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7026 | @Override |
| 7027 | public boolean isTtyModeSupported() { |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7028 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7029 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7030 | } |
| 7031 | |
| 7032 | @Override |
| 7033 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7034 | final long identity = Binder.clearCallingIdentity(); |
| 7035 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7036 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7037 | } finally { |
| 7038 | Binder.restoreCallingIdentity(identity); |
| 7039 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7040 | } |
| 7041 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7042 | /** |
| 7043 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7044 | * support for the feature and device firmware support. |
| 7045 | * |
| 7046 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7047 | */ |
| 7048 | @Override |
| 7049 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7050 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7051 | final Phone phone = getPhone(subscriptionId); |
| 7052 | if (phone == null) { |
| 7053 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7054 | return false; |
| 7055 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7056 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7057 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7058 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7059 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7060 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7061 | return isCarrierSupported && isDeviceSupported; |
| 7062 | } finally { |
| 7063 | Binder.restoreCallingIdentity(identity); |
| 7064 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7065 | } |
| 7066 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7067 | /** |
Hall Liu | 6a06be6 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7068 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7069 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7070 | * 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] | 7071 | */ |
| 7072 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7073 | final long identity = Binder.clearCallingIdentity(); |
| 7074 | try { |
Hall Liu | 63767ec | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7075 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7076 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7077 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7078 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7079 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7080 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7081 | } finally { |
| 7082 | Binder.restoreCallingIdentity(identity); |
| 7083 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7084 | } |
| 7085 | |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7086 | @Deprecated |
| 7087 | @Override |
| 7088 | public String getDeviceId(String callingPackage) { |
| 7089 | return getDeviceIdWithFeature(callingPackage, null); |
| 7090 | } |
| 7091 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7092 | /** |
| 7093 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7094 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7095 | * |
| 7096 | * <p>Requires Permission: |
| 7097 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7098 | */ |
| 7099 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7100 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7101 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7102 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7103 | return null; |
| 7104 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7105 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7106 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7107 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7108 | return null; |
| 7109 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7110 | |
| 7111 | final long identity = Binder.clearCallingIdentity(); |
| 7112 | try { |
| 7113 | return phone.getDeviceId(); |
| 7114 | } finally { |
| 7115 | Binder.restoreCallingIdentity(identity); |
| 7116 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7117 | } |
| 7118 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7119 | /** |
| 7120 | * {@hide} |
| 7121 | * Returns the IMS Registration Status on a particular subid |
| 7122 | * |
| 7123 | * @param subId |
| 7124 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7125 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7126 | Phone phone = getPhone(subId); |
| 7127 | if (phone != null) { |
| 7128 | return phone.isImsRegistered(); |
| 7129 | } else { |
| 7130 | return false; |
| 7131 | } |
| 7132 | } |
| 7133 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7134 | @Override |
| 7135 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7136 | final long identity = Binder.clearCallingIdentity(); |
| 7137 | try { |
| 7138 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7139 | } finally { |
| 7140 | Binder.restoreCallingIdentity(identity); |
| 7141 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7142 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7143 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7144 | @Override |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7145 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7146 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7147 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7148 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 0762a78 | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7149 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7150 | } |
| 7151 | final long identity = Binder.clearCallingIdentity(); |
| 7152 | try { |
| 7153 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7154 | } finally { |
| 7155 | Binder.restoreCallingIdentity(identity); |
| 7156 | } |
| 7157 | } |
| 7158 | |
| 7159 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7160 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7161 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7162 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7163 | final long identity = Binder.clearCallingIdentity(); |
| 7164 | try { |
| 7165 | Phone phone = getPhone(subscriptionId); |
| 7166 | if (phone == null) { |
| 7167 | return null; |
| 7168 | } |
| 7169 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7170 | } finally { |
| 7171 | Binder.restoreCallingIdentity(identity); |
| 7172 | } |
| 7173 | } |
| 7174 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7175 | /** |
| 7176 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7177 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7178 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7179 | final long identity = Binder.clearCallingIdentity(); |
| 7180 | try { |
| 7181 | Phone phone = getPhone(subId); |
| 7182 | if (phone != null) { |
| 7183 | return phone.isWifiCallingEnabled(); |
| 7184 | } else { |
| 7185 | return false; |
| 7186 | } |
| 7187 | } finally { |
| 7188 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7189 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7190 | } |
| 7191 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7192 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7193 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7194 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7195 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7196 | final long identity = Binder.clearCallingIdentity(); |
| 7197 | try { |
| 7198 | Phone phone = getPhone(subId); |
| 7199 | if (phone != null) { |
| 7200 | return phone.isVideoEnabled(); |
| 7201 | } else { |
| 7202 | return false; |
| 7203 | } |
| 7204 | } finally { |
| 7205 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7206 | } |
| 7207 | } |
| 7208 | |
| 7209 | /** |
| 7210 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7211 | * defined in {@link ImsRegistrationImplBase}. |
| 7212 | */ |
| 7213 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7214 | final long identity = Binder.clearCallingIdentity(); |
| 7215 | try { |
| 7216 | Phone phone = getPhone(subId); |
| 7217 | if (phone != null) { |
| 7218 | return phone.getImsRegistrationTech(); |
| 7219 | } else { |
| 7220 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7221 | } |
| 7222 | } finally { |
| 7223 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7224 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7225 | } |
| 7226 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7227 | @Override |
| 7228 | public void factoryReset(int subId) { |
paulhu | 423b5f2 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7229 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7230 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7231 | return; |
| 7232 | } |
| 7233 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7234 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7235 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7236 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7237 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7238 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7239 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7240 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7241 | setNetworkSelectionModeAutomatic(subId); |
SongFerngWang | 9e06037 | 2020-12-21 16:41:52 +0800 | [diff] [blame^] | 7242 | setAllowedNetworkTypesForReason(subId, |
| 7243 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_USER, |
| 7244 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7245 | setAllowedNetworkTypesForReason(subId, |
| 7246 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_CARRIER, |
| 7247 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
| 7248 | setAllowedNetworkTypesForReason(subId, |
| 7249 | TelephonyManager.ALLOWED_NETWORK_TYPES_REASON_POWER, |
| 7250 | RadioAccessFamily.getRafFromNetworkType(getDefaultNetworkType(subId))); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7251 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7252 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7253 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7254 | // There has been issues when Sms raw table somehow stores orphan |
| 7255 | // fragments. They lead to garbled message when new fragments come |
| 7256 | // in and combined with those stale ones. In case this happens again, |
| 7257 | // user can reset all network settings which will clean up this table. |
| 7258 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | 77b832e | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7259 | // Clean up IMS settings as well here. |
| 7260 | int slotId = getSlotIndex(subId); |
| 7261 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7262 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7263 | } |
Naina Nalluri | 8ff344d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7264 | |
| 7265 | // Erase modem config if erase modem on network setting is enabled. |
| 7266 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7267 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7268 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7269 | sendEraseModemConfig(getDefaultPhone()); |
| 7270 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7271 | } finally { |
| 7272 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7273 | } |
| 7274 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7275 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7276 | private void cleanUpSmsRawTable(Context context) { |
| 7277 | ContentResolver resolver = context.getContentResolver(); |
| 7278 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7279 | resolver.delete(uri, null, null); |
| 7280 | } |
| 7281 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7282 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7283 | public String getSimLocaleForSubscriber(int subId) { |
| 7284 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7285 | final Phone phone = getPhone(subId); |
| 7286 | if (phone == null) { |
| 7287 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7288 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7289 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7290 | final long identity = Binder.clearCallingIdentity(); |
| 7291 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7292 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7293 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7294 | if (info == null) { |
| 7295 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7296 | return null; |
| 7297 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7298 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7299 | // preferences (EF-PL and EF-LI)... |
| 7300 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7301 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7302 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7303 | if (localeFromDefaultSim != null) { |
| 7304 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7305 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7306 | + localeFromDefaultSim); |
| 7307 | return localeFromDefaultSim.toLanguageTag(); |
| 7308 | } else { |
| 7309 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7310 | } |
| 7311 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7312 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7313 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7314 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7315 | // the SIM and carrier preferences does not include a country we add the country |
| 7316 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | 84e2b21 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7317 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7318 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7319 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7320 | return mccLocale.toLanguageTag(); |
| 7321 | } |
| 7322 | |
| 7323 | if (DBG) log("No locale found - returning null"); |
| 7324 | return null; |
| 7325 | } finally { |
| 7326 | Binder.restoreCallingIdentity(identity); |
| 7327 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7328 | } |
| 7329 | |
| 7330 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7331 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7332 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7333 | } |
| 7334 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7335 | /** |
| 7336 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7337 | */ |
| 7338 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7339 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 0079aae | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7340 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7341 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7342 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7343 | private final ModemActivityInfo mLastModemActivityInfo = |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7344 | new ModemActivityInfo(0, 0, 0, new int[0], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7345 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7346 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7347 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7348 | * representing the state of the modem. |
| 7349 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7350 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7351 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7352 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7353 | */ |
| 7354 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7355 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7356 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7357 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7358 | |
| 7359 | final long identity = Binder.clearCallingIdentity(); |
| 7360 | try { |
sqian | 1a1be54 | 2020-03-05 11:37:28 -0800 | [diff] [blame] | 7361 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7362 | } finally { |
| 7363 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7364 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7365 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7366 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7367 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7368 | // less than total activity duration. |
| 7369 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7370 | if (info == null) { |
| 7371 | return false; |
| 7372 | } |
| 7373 | int activityDurationMs = |
| 7374 | (int) (info.getTimestamp() - mLastModemActivityInfo.getTimestamp()); |
| 7375 | int totalTxTimeMs = 0; |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7376 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 7377 | for (int i = 0; i < info.getTransmitPowerInfo().size(); i++) { |
| 7378 | totalTxTimeMs += txTimeMs[i]; |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7379 | } |
| 7380 | return (info.isValid() |
| 7381 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7382 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | 1385103 | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7383 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7384 | && (totalTxTimeMs <= activityDurationMs)); |
| 7385 | } |
| 7386 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7387 | /** |
| 7388 | * {@hide} |
| 7389 | * Returns the service state information on specified subscription. |
| 7390 | */ |
| 7391 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7392 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7393 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7394 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7395 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7396 | return null; |
| 7397 | } |
| 7398 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7399 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7400 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7401 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7402 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7403 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7404 | .setCallingPid(Binder.getCallingPid()) |
| 7405 | .setCallingUid(Binder.getCallingUid()) |
| 7406 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7407 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7408 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 7409 | .build()); |
| 7410 | |
| 7411 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7412 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7413 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7414 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7415 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7416 | .setCallingPid(Binder.getCallingPid()) |
| 7417 | .setCallingUid(Binder.getCallingUid()) |
| 7418 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7419 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7420 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7421 | .build()); |
| 7422 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7423 | boolean hasFinePermission = |
| 7424 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7425 | boolean hasCoarsePermission = |
| 7426 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7427 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7428 | final long identity = Binder.clearCallingIdentity(); |
| 7429 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7430 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7431 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7432 | Rlog.d(LOG_TAG, |
| 7433 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7434 | return null; |
| 7435 | } |
| 7436 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7437 | final Phone phone = getPhone(subId); |
| 7438 | if (phone == null) { |
| 7439 | return null; |
| 7440 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7441 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7442 | ServiceState ss = phone.getServiceState(); |
| 7443 | |
| 7444 | // Scrub out the location info in ServiceState depending on what level of access |
| 7445 | // the caller has. |
| 7446 | if (hasFinePermission) return ss; |
Malcolm Chen | db33797 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7447 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7448 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7449 | } finally { |
| 7450 | Binder.restoreCallingIdentity(identity); |
| 7451 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7452 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7453 | |
| 7454 | /** |
| 7455 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7456 | * |
| 7457 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7458 | * voicemail ringtone. |
| 7459 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7460 | * PhoneAccount. |
| 7461 | */ |
| 7462 | @Override |
| 7463 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7464 | final long identity = Binder.clearCallingIdentity(); |
| 7465 | try { |
| 7466 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7467 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7468 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7469 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7470 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7471 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7472 | } finally { |
| 7473 | Binder.restoreCallingIdentity(identity); |
| 7474 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7475 | } |
| 7476 | |
| 7477 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7478 | * Sets the per-account voicemail ringtone. |
| 7479 | * |
| 7480 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7481 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7482 | * |
| 7483 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7484 | * voicemail ringtone. |
| 7485 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7486 | * PhoneAccount. |
| 7487 | */ |
| 7488 | @Override |
| 7489 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7490 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7491 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7492 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7493 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7494 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7495 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7496 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7497 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7498 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7499 | |
| 7500 | final long identity = Binder.clearCallingIdentity(); |
| 7501 | try { |
| 7502 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7503 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7504 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7505 | } |
| 7506 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7507 | } finally { |
| 7508 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7509 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7510 | } |
| 7511 | |
| 7512 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7513 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7514 | * |
| 7515 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7516 | * voicemail vibration setting. |
| 7517 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7518 | */ |
| 7519 | @Override |
| 7520 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7521 | final long identity = Binder.clearCallingIdentity(); |
| 7522 | try { |
| 7523 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7524 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7525 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7526 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7527 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7528 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7529 | } finally { |
| 7530 | Binder.restoreCallingIdentity(identity); |
| 7531 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7532 | } |
| 7533 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7534 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7535 | * Sets the per-account voicemail vibration. |
| 7536 | * |
| 7537 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7538 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7539 | * |
| 7540 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7541 | * voicemail vibration setting. |
| 7542 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7543 | * specific PhoneAccount. |
| 7544 | */ |
| 7545 | @Override |
| 7546 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7547 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7548 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7549 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 77ee938 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7550 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7551 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7552 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7553 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7554 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7555 | } |
| 7556 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7557 | final long identity = Binder.clearCallingIdentity(); |
| 7558 | try { |
| 7559 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7560 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7561 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7562 | } |
| 7563 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7564 | } finally { |
| 7565 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7566 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7567 | } |
| 7568 | |
| 7569 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7570 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7571 | * |
| 7572 | * @throws SecurityException if the caller does not have the required permission |
| 7573 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7574 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7575 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7576 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7577 | } |
| 7578 | |
| 7579 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7580 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7581 | * permission. |
| 7582 | * |
| 7583 | * @throws SecurityException if the caller does not have the required permission |
| 7584 | */ |
| 7585 | private void enforceSendSmsPermission() { |
| 7586 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7587 | } |
| 7588 | |
| 7589 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7590 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7591 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7592 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7593 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7594 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7595 | final long identity = Binder.clearCallingIdentity(); |
| 7596 | try { |
| 7597 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7598 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7599 | if (componentName == null) { |
| 7600 | throw new SecurityException( |
| 7601 | "Caller not current active visual voicemail package[null]"); |
| 7602 | } |
| 7603 | String vvmPackage = componentName.getPackageName(); |
| 7604 | if (!callingPackage.equals(vvmPackage)) { |
| 7605 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7606 | + vvmPackage + "]"); |
| 7607 | } |
| 7608 | } finally { |
| 7609 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7610 | } |
| 7611 | } |
| 7612 | |
| 7613 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7614 | * Return the application ID for the app type. |
| 7615 | * |
| 7616 | * @param subId the subscription ID that this request applies to. |
| 7617 | * @param appType the uicc app type. |
| 7618 | * @return Application ID for specificied app type, or null if no uicc. |
| 7619 | */ |
| 7620 | @Override |
| 7621 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7622 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7623 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7624 | |
| 7625 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7626 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7627 | if (phone == null) { |
| 7628 | return null; |
| 7629 | } |
| 7630 | String aid = null; |
| 7631 | try { |
| 7632 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7633 | .getApplicationByType(appType).getAid(); |
| 7634 | } catch (Exception e) { |
| 7635 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7636 | } |
| 7637 | return aid; |
| 7638 | } finally { |
| 7639 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7640 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7641 | } |
| 7642 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7643 | /** |
| 7644 | * Return the Electronic Serial Number. |
| 7645 | * |
| 7646 | * @param subId the subscription ID that this request applies to. |
| 7647 | * @return ESN or null if error. |
| 7648 | */ |
| 7649 | @Override |
| 7650 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7651 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7652 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7653 | |
| 7654 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7655 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7656 | if (phone == null) { |
| 7657 | return null; |
| 7658 | } |
| 7659 | String esn = null; |
| 7660 | try { |
| 7661 | esn = phone.getEsn(); |
| 7662 | } catch (Exception e) { |
| 7663 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7664 | } |
| 7665 | return esn; |
| 7666 | } finally { |
| 7667 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7668 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7669 | } |
| 7670 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7671 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7672 | * Return the Preferred Roaming List Version. |
| 7673 | * |
| 7674 | * @param subId the subscription ID that this request applies to. |
| 7675 | * @return PRLVersion or null if error. |
| 7676 | */ |
| 7677 | @Override |
| 7678 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7679 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7680 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7681 | |
| 7682 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7683 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7684 | if (phone == null) { |
| 7685 | return null; |
| 7686 | } |
| 7687 | String cdmaPrlVersion = null; |
| 7688 | try { |
| 7689 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7690 | } catch (Exception e) { |
| 7691 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7692 | } |
| 7693 | return cdmaPrlVersion; |
| 7694 | } finally { |
| 7695 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7696 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7697 | } |
| 7698 | |
| 7699 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7700 | * Get snapshot of Telephony histograms |
| 7701 | * @return List of Telephony histograms |
| 7702 | * @hide |
| 7703 | */ |
| 7704 | @Override |
| 7705 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7706 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7707 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7708 | |
| 7709 | final long identity = Binder.clearCallingIdentity(); |
| 7710 | try { |
| 7711 | return RIL.getTelephonyRILTimingHistograms(); |
| 7712 | } finally { |
| 7713 | Binder.restoreCallingIdentity(identity); |
| 7714 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7715 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7716 | |
| 7717 | /** |
| 7718 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7719 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7720 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7721 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7722 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7723 | * @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] | 7724 | */ |
| 7725 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7726 | @TelephonyManager.SetCarrierRestrictionResult |
| 7727 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7728 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7729 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7730 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7731 | if (carrierRestrictionRules == null) { |
| 7732 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7733 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7734 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | final long identity = Binder.clearCallingIdentity(); |
| 7736 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7737 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7738 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7739 | } finally { |
| 7740 | Binder.restoreCallingIdentity(identity); |
| 7741 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7742 | } |
| 7743 | |
| 7744 | /** |
| 7745 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7746 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7747 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7748 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7749 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7750 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7751 | */ |
| 7752 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7753 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7754 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7755 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7756 | |
| 7757 | final long identity = Binder.clearCallingIdentity(); |
| 7758 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7759 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7760 | if (response instanceof CarrierRestrictionRules) { |
| 7761 | return (CarrierRestrictionRules) response; |
| 7762 | } |
| 7763 | // Response is an Exception of some kind, |
| 7764 | // which is signalled to the user as a NULL retval |
| 7765 | return null; |
| 7766 | } catch (Exception e) { |
| 7767 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7768 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7769 | } finally { |
| 7770 | Binder.restoreCallingIdentity(identity); |
| 7771 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7772 | } |
| 7773 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7774 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7775 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7776 | * @param subId the subscription ID that this action applies to. |
| 7777 | * @param enabled control enable or disable radio. |
| 7778 | * {@hide} |
| 7779 | */ |
| 7780 | @Override |
| 7781 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7782 | enforceModifyPermission(); |
| 7783 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7784 | |
| 7785 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7786 | if (phone == null) { |
| 7787 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7788 | return; |
| 7789 | } |
| 7790 | try { |
| 7791 | phone.carrierActionSetRadioEnabled(enabled); |
| 7792 | } catch (Exception e) { |
| 7793 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7794 | } finally { |
| 7795 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7796 | } |
| 7797 | } |
| 7798 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7799 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7800 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7801 | * network status based on which carrier apps could apply actions accordingly, |
| 7802 | * enable/disable default url handler for example. |
| 7803 | * |
| 7804 | * @param subId the subscription ID that this action applies to. |
| 7805 | * @param report control start/stop reporting the default network status. |
| 7806 | * {@hide} |
| 7807 | */ |
| 7808 | @Override |
| 7809 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7810 | enforceModifyPermission(); |
| 7811 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7812 | |
| 7813 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7814 | if (phone == null) { |
| 7815 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7816 | return; |
| 7817 | } |
| 7818 | try { |
| 7819 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7820 | } catch (Exception e) { |
| 7821 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7822 | } finally { |
| 7823 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7824 | } |
| 7825 | } |
| 7826 | |
| 7827 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7828 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7829 | * @param subId the subscription ID that this action applies to. |
| 7830 | * {@hide} |
| 7831 | */ |
| 7832 | @Override |
| 7833 | public void carrierActionResetAll(int subId) { |
| 7834 | enforceModifyPermission(); |
| 7835 | final Phone phone = getPhone(subId); |
| 7836 | if (phone == null) { |
| 7837 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7838 | return; |
| 7839 | } |
| 7840 | try { |
| 7841 | phone.carrierActionResetAll(); |
| 7842 | } catch (Exception e) { |
| 7843 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7844 | } |
| 7845 | } |
| 7846 | |
| 7847 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7848 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7849 | * bug report is being generated. |
| 7850 | */ |
| 7851 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7852 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7853 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7854 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7855 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7856 | + Binder.getCallingPid() |
| 7857 | + ", uid=" + Binder.getCallingUid() |
| 7858 | + "without permission " |
| 7859 | + android.Manifest.permission.DUMP); |
| 7860 | return; |
| 7861 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7862 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7863 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7864 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7865 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7866 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7867 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7868 | @NonNull String[] args) { |
| 7869 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7870 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7871 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7872 | } |
| 7873 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7874 | /** |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7875 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7876 | * @param subId Subscription index |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7877 | * @param reason the reason the data enable change is taking place |
| 7878 | * @param enabled True if enabling the data, otherwise disabling. |
| 7879 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7880 | */ |
| 7881 | @Override |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7882 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7883 | boolean enabled) { |
| 7884 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7885 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7886 | try { |
| 7887 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | ff75de6 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7888 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7889 | } catch (SecurityException se) { |
| 7890 | enforceModifyPermission(); |
| 7891 | } |
| 7892 | } else { |
| 7893 | enforceModifyPermission(); |
| 7894 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7895 | |
| 7896 | final long identity = Binder.clearCallingIdentity(); |
| 7897 | try { |
| 7898 | Phone phone = getPhone(subId); |
| 7899 | if (phone != null) { |
Sooraj Sasindran | 2675c0b | 2020-04-19 18:14:03 -0700 | [diff] [blame] | 7900 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7901 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7902 | } else { |
| 7903 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7904 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7905 | } |
| 7906 | } finally { |
| 7907 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7908 | } |
| 7909 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7910 | |
| 7911 | /** |
| 7912 | * Get Client request stats |
| 7913 | * @return List of Client Request Stats |
| 7914 | * @hide |
| 7915 | */ |
| 7916 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7917 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7918 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7919 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 7920 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7921 | return null; |
| 7922 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7923 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7924 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7925 | final long identity = Binder.clearCallingIdentity(); |
| 7926 | try { |
| 7927 | if (phone != null) { |
| 7928 | return phone.getClientRequestStats(); |
| 7929 | } |
| 7930 | |
| 7931 | return null; |
| 7932 | } finally { |
| 7933 | Binder.restoreCallingIdentity(identity); |
| 7934 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7935 | } |
| 7936 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7937 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7938 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7939 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7940 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7941 | |
| 7942 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7943 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7944 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7945 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7946 | * @param state State of SIM (power down, power up, pass through) |
| 7947 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7948 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7949 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7950 | * |
| 7951 | **/ |
| 7952 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7953 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7954 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7955 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7956 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7957 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7958 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7959 | final long identity = Binder.clearCallingIdentity(); |
| 7960 | try { |
| 7961 | if (phone != null) { |
Jordan Liu | d5366d9 | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 7962 | phone.setSimPowerState(state, null, workSource); |
| 7963 | } |
| 7964 | } finally { |
| 7965 | Binder.restoreCallingIdentity(identity); |
| 7966 | } |
| 7967 | } |
| 7968 | |
| 7969 | /** |
| 7970 | * Set SIM card power state. |
| 7971 | * |
| 7972 | * @param slotIndex SIM slot id. |
| 7973 | * @param state State of SIM (power down, power up, pass through) |
| 7974 | * @param callback callback to trigger after success or failure |
| 7975 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7976 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 7977 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 7978 | * |
| 7979 | **/ |
| 7980 | @Override |
| 7981 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 7982 | IIntegerConsumer callback) { |
| 7983 | enforceModifyPermission(); |
| 7984 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 7985 | |
| 7986 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 7987 | |
| 7988 | final long identity = Binder.clearCallingIdentity(); |
| 7989 | try { |
| 7990 | if (phone != null) { |
| 7991 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 7992 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7993 | } |
| 7994 | } finally { |
| 7995 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7996 | } |
| 7997 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 7998 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 7999 | private boolean isUssdApiAllowed(int subId) { |
| 8000 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8001 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8002 | if (configManager == null) { |
| 8003 | return false; |
| 8004 | } |
| 8005 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8006 | if (pb == null) { |
| 8007 | return false; |
| 8008 | } |
| 8009 | return pb.getBoolean( |
| 8010 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8011 | } |
| 8012 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8013 | /** |
| 8014 | * Check if phone is in emergency callback mode |
| 8015 | * @return true if phone is in emergency callback mode |
| 8016 | * @param subId sub id |
| 8017 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8018 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8019 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8020 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8021 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8022 | |
| 8023 | final long identity = Binder.clearCallingIdentity(); |
| 8024 | try { |
| 8025 | if (phone != null) { |
| 8026 | return phone.isInEcm(); |
| 8027 | } else { |
| 8028 | return false; |
| 8029 | } |
| 8030 | } finally { |
| 8031 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8032 | } |
| 8033 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8034 | |
| 8035 | /** |
| 8036 | * Get the current signal strength information for the given subscription. |
| 8037 | * Because this information is not updated when the device is in a low power state |
| 8038 | * it should not be relied-upon to be current. |
| 8039 | * @param subId Subscription index |
| 8040 | * @return the most recent cached signal strength info from the modem |
| 8041 | */ |
| 8042 | @Override |
| 8043 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8044 | final long identity = Binder.clearCallingIdentity(); |
| 8045 | try { |
| 8046 | Phone p = getPhone(subId); |
| 8047 | if (p == null) { |
| 8048 | return null; |
| 8049 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8050 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8051 | return p.getSignalStrength(); |
| 8052 | } finally { |
| 8053 | Binder.restoreCallingIdentity(identity); |
| 8054 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8055 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8056 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8057 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8058 | * Get the current modem radio state for the given slot. |
| 8059 | * @param slotIndex slot index. |
| 8060 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8061 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8062 | * @return the current radio power state from the modem |
| 8063 | */ |
| 8064 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8065 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8066 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8067 | if (phone != null) { |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8068 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8069 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8070 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8071 | } |
| 8072 | |
| 8073 | final long identity = Binder.clearCallingIdentity(); |
| 8074 | try { |
| 8075 | return phone.getRadioPowerState(); |
| 8076 | } finally { |
| 8077 | Binder.restoreCallingIdentity(identity); |
| 8078 | } |
| 8079 | } |
| 8080 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8081 | } |
| 8082 | |
| 8083 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8084 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8085 | * |
| 8086 | * <p>Requires one of the following permissions: |
| 8087 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8088 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8089 | * privileges. |
| 8090 | * |
| 8091 | * @param subId subscription id |
| 8092 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8093 | * {@code false}. |
| 8094 | */ |
| 8095 | @Override |
| 8096 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 11263f3 | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8097 | try { |
| 8098 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8099 | null); |
| 8100 | } catch (Exception e) { |
| 8101 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8102 | mApp, subId, "isDataRoamingEnabled"); |
| 8103 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8104 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8105 | boolean isEnabled = false; |
| 8106 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8107 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8108 | Phone phone = getPhone(subId); |
| 8109 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8110 | } finally { |
| 8111 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8112 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8113 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8114 | } |
| 8115 | |
| 8116 | |
| 8117 | /** |
| 8118 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8119 | * |
| 8120 | * <p> Requires permission: |
| 8121 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8122 | * privileges. |
| 8123 | * |
| 8124 | * @param subId subscription id |
| 8125 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8126 | */ |
| 8127 | @Override |
| 8128 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8130 | mApp, subId, "setDataRoamingEnabled"); |
| 8131 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8132 | final long identity = Binder.clearCallingIdentity(); |
| 8133 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8134 | Phone phone = getPhone(subId); |
| 8135 | if (phone != null) { |
| 8136 | phone.setDataRoamingEnabled(isEnabled); |
| 8137 | } |
| 8138 | } finally { |
| 8139 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8140 | } |
| 8141 | } |
| 8142 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8143 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8144 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8145 | TelephonyPermissions |
| 8146 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8147 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8148 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8149 | boolean isAllowed = true; |
| 8150 | final long identity = Binder.clearCallingIdentity(); |
| 8151 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8152 | Phone phone = getPhone(subId); |
| 8153 | if (phone != null) { |
| 8154 | isAllowed = phone.isCspPlmnEnabled(); |
| 8155 | } |
| 8156 | } finally { |
| 8157 | Binder.restoreCallingIdentity(identity); |
| 8158 | } |
| 8159 | return isAllowed; |
| 8160 | } |
| 8161 | |
| 8162 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8163 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | cfdfe3a | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8164 | // Verify that tha callingPackage belongs to the calling UID |
| 8165 | mApp.getSystemService(AppOpsManager.class) |
| 8166 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8167 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8168 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8169 | try { |
| 8170 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8171 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8172 | } catch (SecurityException e) { |
| 8173 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8174 | // has carrier privileges on an active UICC |
| 8175 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8176 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8177 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8178 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8179 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8180 | |
| 8181 | final long identity = Binder.clearCallingIdentity(); |
| 8182 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8183 | UiccController uiccController = UiccController.getInstance(); |
| 8184 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8185 | if (hasReadPermission) { |
| 8186 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8187 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8188 | |
| 8189 | // Remove private info if the caller doesn't have access |
| 8190 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8191 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8192 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8193 | // is available |
| 8194 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8195 | if (card == null || card.getUiccProfile() == null) { |
| 8196 | // assume no access if the card or profile is unavailable |
| 8197 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8198 | continue; |
| 8199 | } |
| 8200 | UiccProfile profile = card.getUiccProfile(); |
| 8201 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8202 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8203 | filteredInfos.add(cardInfo); |
| 8204 | } else { |
| 8205 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8206 | } |
| 8207 | } |
| 8208 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8209 | } finally { |
| 8210 | Binder.restoreCallingIdentity(identity); |
| 8211 | } |
| 8212 | } |
| 8213 | |
| 8214 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8215 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8216 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8217 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8218 | final long identity = Binder.clearCallingIdentity(); |
| 8219 | try { |
| 8220 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8221 | if (slots == null) { |
| 8222 | Rlog.i(LOG_TAG, "slots is null."); |
| 8223 | return null; |
| 8224 | } |
| 8225 | |
| 8226 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8227 | for (int i = 0; i < slots.length; i++) { |
| 8228 | UiccSlot slot = slots[i]; |
| 8229 | if (slot == null) { |
| 8230 | continue; |
| 8231 | } |
| 8232 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8233 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8234 | UiccCard card = slot.getUiccCard(); |
| 8235 | if (card != null) { |
| 8236 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8237 | } else { |
Jordan Liu | d96b529 | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8238 | cardId = slot.getEid(); |
| 8239 | if (TextUtils.isEmpty(cardId)) { |
| 8240 | cardId = slot.getIccId(); |
| 8241 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8242 | } |
| 8243 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8244 | if (cardId != null) { |
| 8245 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8246 | // if cardId is an EID, it's all digits so this is fine |
| 8247 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8248 | } |
| 8249 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8250 | int cardState = 0; |
| 8251 | switch (slot.getCardState()) { |
| 8252 | case CARDSTATE_ABSENT: |
| 8253 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8254 | break; |
| 8255 | case CARDSTATE_PRESENT: |
| 8256 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8257 | break; |
| 8258 | case CARDSTATE_ERROR: |
| 8259 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8260 | break; |
| 8261 | case CARDSTATE_RESTRICTED: |
| 8262 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8263 | break; |
| 8264 | default: |
| 8265 | break; |
| 8266 | |
| 8267 | } |
| 8268 | |
| 8269 | infos[i] = new UiccSlotInfo( |
| 8270 | slot.isActive(), |
| 8271 | slot.isEuicc(), |
| 8272 | cardId, |
| 8273 | cardState, |
| 8274 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8275 | slot.isExtendedApduSupported(), |
| 8276 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8277 | } |
| 8278 | return infos; |
| 8279 | } finally { |
| 8280 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8281 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8282 | } |
| 8283 | |
| 8284 | @Override |
| 8285 | public boolean switchSlots(int[] physicalSlots) { |
| 8286 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8287 | |
| 8288 | final long identity = Binder.clearCallingIdentity(); |
| 8289 | try { |
| 8290 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8291 | } finally { |
| 8292 | Binder.restoreCallingIdentity(identity); |
| 8293 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8294 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8295 | |
| 8296 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8297 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8298 | final long identity = Binder.clearCallingIdentity(); |
| 8299 | try { |
| 8300 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8301 | } finally { |
| 8302 | Binder.restoreCallingIdentity(identity); |
| 8303 | } |
| 8304 | } |
| 8305 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8306 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8307 | * A test API to reload the UICC profile. |
| 8308 | * |
| 8309 | * <p>Requires that the calling app has permission |
| 8310 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8311 | * @hide |
| 8312 | */ |
| 8313 | @Override |
| 8314 | public void refreshUiccProfile(int subId) { |
| 8315 | enforceModifyPermission(); |
| 8316 | |
| 8317 | final long identity = Binder.clearCallingIdentity(); |
| 8318 | try { |
| 8319 | Phone phone = getPhone(subId); |
| 8320 | if (phone == null) { |
| 8321 | return; |
| 8322 | } |
| 8323 | UiccCard uiccCard = phone.getUiccCard(); |
| 8324 | if (uiccCard == null) { |
| 8325 | return; |
| 8326 | } |
| 8327 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8328 | if (uiccProfile == null) { |
| 8329 | return; |
| 8330 | } |
| 8331 | uiccProfile.refresh(); |
| 8332 | } finally { |
| 8333 | Binder.restoreCallingIdentity(identity); |
| 8334 | } |
| 8335 | } |
| 8336 | |
| 8337 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8338 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8339 | */ |
| 8340 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8341 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8342 | } |
| 8343 | |
| 8344 | /** |
| 8345 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8346 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8347 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8348 | */ |
| 8349 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8350 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8351 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | faaa63d | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8352 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8353 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8354 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8355 | return isDataRoamingEnabled; |
| 8356 | } |
| 8357 | |
| 8358 | /** |
| 8359 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8360 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8361 | */ |
| 8362 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 8d298d4 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8363 | List<Integer> list = TelephonyProperties.default_network(); |
| 8364 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8365 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8366 | return list.get(phoneId); |
| 8367 | } |
| 8368 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8369 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8370 | |
| 8371 | @Override |
| 8372 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8373 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8374 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8375 | |
| 8376 | final long identity = Binder.clearCallingIdentity(); |
| 8377 | try { |
| 8378 | final Phone phone = getPhone(subId); |
| 8379 | if (phone == null) { |
| 8380 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8381 | return; |
| 8382 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8383 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8384 | carrierPrivilegeRules, apn); |
Jeff Davidson | 0103e8c | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8385 | if (carrierPrivilegeRules == null) { |
| 8386 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8387 | } else { |
| 8388 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8389 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8390 | } finally { |
| 8391 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8392 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8393 | } |
| 8394 | |
| 8395 | @Override |
| 8396 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8397 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8398 | |
| 8399 | final long identity = Binder.clearCallingIdentity(); |
| 8400 | try { |
| 8401 | final Phone phone = getPhone(subId); |
| 8402 | if (phone == null) { |
| 8403 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8404 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8405 | } |
| 8406 | return phone.getCarrierIdListVersion(); |
| 8407 | } finally { |
| 8408 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8409 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8410 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8411 | |
| 8412 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8413 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8414 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8415 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8416 | mApp, subId, callingPackage, callingFeatureId, |
| 8417 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8418 | return -1; |
| 8419 | } |
| 8420 | |
| 8421 | final long identity = Binder.clearCallingIdentity(); |
| 8422 | try { |
| 8423 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8424 | } finally { |
| 8425 | Binder.restoreCallingIdentity(identity); |
| 8426 | } |
| 8427 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8428 | |
| 8429 | @Override |
| 8430 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 0723870 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8431 | TelephonyPermissions |
| 8432 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8433 | mApp, subId, "getCdmaRoamingMode"); |
| 8434 | |
| 8435 | final long identity = Binder.clearCallingIdentity(); |
| 8436 | try { |
| 8437 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8438 | } finally { |
| 8439 | Binder.restoreCallingIdentity(identity); |
| 8440 | } |
| 8441 | } |
| 8442 | |
| 8443 | @Override |
| 8444 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8445 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8446 | mApp, subId, "setCdmaRoamingMode"); |
| 8447 | |
| 8448 | final long identity = Binder.clearCallingIdentity(); |
| 8449 | try { |
| 8450 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8451 | } finally { |
| 8452 | Binder.restoreCallingIdentity(identity); |
| 8453 | } |
| 8454 | } |
| 8455 | |
| 8456 | @Override |
Sarah Chin | 49f22af | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8457 | public int getCdmaSubscriptionMode(int subId) { |
| 8458 | TelephonyPermissions |
| 8459 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8460 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8461 | |
| 8462 | final long identity = Binder.clearCallingIdentity(); |
| 8463 | try { |
| 8464 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8465 | } finally { |
| 8466 | Binder.restoreCallingIdentity(identity); |
| 8467 | } |
| 8468 | } |
| 8469 | |
| 8470 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8471 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8472 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8473 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8474 | |
| 8475 | final long identity = Binder.clearCallingIdentity(); |
| 8476 | try { |
| 8477 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8478 | } finally { |
| 8479 | Binder.restoreCallingIdentity(identity); |
| 8480 | } |
| 8481 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8482 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8483 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8484 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8485 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8486 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8487 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8488 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8489 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8490 | } |
| 8491 | final long identity = Binder.clearCallingIdentity(); |
| 8492 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8493 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8494 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8495 | if (phone.getEmergencyNumberTracker() != null |
| 8496 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8497 | emergencyNumberListInternal.put( |
| 8498 | phone.getSubId(), |
| 8499 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8500 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8501 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8502 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8503 | } finally { |
| 8504 | Binder.restoreCallingIdentity(identity); |
| 8505 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8506 | } |
| 8507 | |
| 8508 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8509 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8510 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8511 | if (!exactMatch) { |
| 8512 | TelephonyPermissions |
| 8513 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8514 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8515 | } |
| 8516 | final long identity = Binder.clearCallingIdentity(); |
| 8517 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8518 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8519 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8520 | && phone.getEmergencyNumberTracker() |
| 8521 | .isEmergencyNumber(number, exactMatch)) { |
| 8522 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8523 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8524 | } |
| 8525 | return false; |
| 8526 | } finally { |
| 8527 | Binder.restoreCallingIdentity(identity); |
| 8528 | } |
| 8529 | } |
| 8530 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8531 | /** |
| 8532 | * Update emergency number list for test mode. |
| 8533 | */ |
| 8534 | @Override |
| 8535 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8536 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8537 | "updateEmergencyNumberListTestMode"); |
| 8538 | |
| 8539 | final long identity = Binder.clearCallingIdentity(); |
| 8540 | try { |
| 8541 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8542 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8543 | if (tracker != null) { |
| 8544 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8545 | } |
| 8546 | } |
| 8547 | } finally { |
| 8548 | Binder.restoreCallingIdentity(identity); |
| 8549 | } |
| 8550 | } |
| 8551 | |
| 8552 | /** |
| 8553 | * Get the full emergency number list for test mode. |
| 8554 | */ |
| 8555 | @Override |
| 8556 | public List<String> getEmergencyNumberListTestMode() { |
| 8557 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8558 | "getEmergencyNumberListTestMode"); |
| 8559 | |
| 8560 | final long identity = Binder.clearCallingIdentity(); |
| 8561 | try { |
| 8562 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8563 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8564 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8565 | if (tracker != null) { |
| 8566 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8567 | emergencyNumbers.add(num.getNumber()); |
| 8568 | } |
| 8569 | } |
| 8570 | } |
| 8571 | return new ArrayList<>(emergencyNumbers); |
| 8572 | } finally { |
| 8573 | Binder.restoreCallingIdentity(identity); |
| 8574 | } |
| 8575 | } |
| 8576 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8577 | @Override |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8578 | public int getEmergencyNumberDbVersion(int subId) { |
| 8579 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8580 | |
| 8581 | final long identity = Binder.clearCallingIdentity(); |
| 8582 | try { |
| 8583 | final Phone phone = getPhone(subId); |
| 8584 | if (phone == null) { |
| 8585 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8586 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8587 | } |
| 8588 | return phone.getEmergencyNumberDbVersion(); |
| 8589 | } finally { |
| 8590 | Binder.restoreCallingIdentity(identity); |
| 8591 | } |
| 8592 | } |
| 8593 | |
| 8594 | @Override |
| 8595 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8596 | enforceModifyPermission(); |
| 8597 | |
| 8598 | final long identity = Binder.clearCallingIdentity(); |
| 8599 | try { |
| 8600 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8601 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8602 | if (tracker != null) { |
| 8603 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8604 | } |
| 8605 | } |
| 8606 | } finally { |
| 8607 | Binder.restoreCallingIdentity(identity); |
| 8608 | } |
| 8609 | } |
| 8610 | |
| 8611 | @Override |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8612 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8613 | enforceActiveEmergencySessionPermission(); |
| 8614 | |
| 8615 | final long identity = Binder.clearCallingIdentity(); |
| 8616 | try { |
| 8617 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8618 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8619 | if (tracker != null) { |
Shuo Qian | b15c6be | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8620 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8621 | } |
| 8622 | } |
| 8623 | } finally { |
| 8624 | Binder.restoreCallingIdentity(identity); |
| 8625 | } |
| 8626 | } |
| 8627 | |
| 8628 | @Override |
| 8629 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8630 | enforceActiveEmergencySessionPermission(); |
| 8631 | |
| 8632 | final long identity = Binder.clearCallingIdentity(); |
| 8633 | try { |
| 8634 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8635 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8636 | if (tracker != null) { |
| 8637 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | f2b2df4 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8638 | } |
| 8639 | } |
| 8640 | } finally { |
| 8641 | Binder.restoreCallingIdentity(identity); |
| 8642 | } |
| 8643 | } |
| 8644 | |
| 8645 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8646 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8647 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8648 | Phone phone = getPhone(subId); |
| 8649 | if (phone == null) { |
| 8650 | return null; |
| 8651 | } |
| 8652 | final long identity = Binder.clearCallingIdentity(); |
| 8653 | try { |
| 8654 | UiccProfile profile = UiccController.getInstance() |
| 8655 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8656 | if (profile != null) { |
| 8657 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8658 | } |
| 8659 | } finally { |
| 8660 | Binder.restoreCallingIdentity(identity); |
| 8661 | } |
| 8662 | return null; |
| 8663 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8664 | |
| 8665 | /** |
| 8666 | * Enable or disable a modem stack. |
| 8667 | */ |
| 8668 | @Override |
| 8669 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8670 | enforceModifyPermission(); |
| 8671 | |
| 8672 | final long identity = Binder.clearCallingIdentity(); |
| 8673 | try { |
| 8674 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8675 | if (phone == null) { |
| 8676 | return false; |
| 8677 | } else { |
| 8678 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8679 | } |
| 8680 | } finally { |
| 8681 | Binder.restoreCallingIdentity(identity); |
| 8682 | } |
| 8683 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8684 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8685 | /** |
| 8686 | * Whether a modem stack is enabled or not. |
| 8687 | */ |
| 8688 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8689 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8690 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8691 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8692 | if (phone == null) return false; |
| 8693 | |
| 8694 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8695 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8696 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8697 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8698 | } |
| 8699 | |
| 8700 | final long identity = Binder.clearCallingIdentity(); |
| 8701 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8702 | try { |
| 8703 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8704 | } catch (NoSuchElementException ex) { |
| 8705 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8706 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8707 | } finally { |
| 8708 | Binder.restoreCallingIdentity(identity); |
| 8709 | } |
| 8710 | } |
| 8711 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8712 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8713 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8714 | enforceModifyPermission(); |
| 8715 | |
| 8716 | final long identity = Binder.clearCallingIdentity(); |
| 8717 | try { |
| 8718 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8719 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8720 | .commit(); |
| 8721 | } finally { |
| 8722 | Binder.restoreCallingIdentity(identity); |
| 8723 | } |
| 8724 | } |
| 8725 | |
| 8726 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8727 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8728 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8729 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8730 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8731 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8732 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8733 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8734 | |
| 8735 | final long identity = Binder.clearCallingIdentity(); |
| 8736 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8737 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8738 | } finally { |
| 8739 | Binder.restoreCallingIdentity(identity); |
| 8740 | } |
| 8741 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8742 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8743 | @TelephonyManager.IsMultiSimSupportedResult |
| 8744 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8745 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8746 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8747 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8748 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8749 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8750 | } |
| 8751 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8752 | // supported by the modem, indicate that it is restricted. |
| 8753 | PhoneCapability staticCapability = |
| 8754 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8755 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8756 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8757 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8758 | } |
Sarah Chin | 09f38ee | 2020-02-25 00:13:10 +0000 | [diff] [blame] | 8759 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8760 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8761 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8762 | } |
| 8763 | // Check if support of multiple SIMs is restricted by carrier |
| 8764 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8765 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8766 | } |
| 8767 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8768 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8769 | } |
| 8770 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8771 | /** |
| 8772 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8773 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8774 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8775 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8776 | * @param numOfSims number of active sims we want to switch to |
| 8777 | */ |
| 8778 | @Override |
| 8779 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8780 | if (numOfSims == 1) { |
| 8781 | enforceModifyPermission(); |
| 8782 | } else { |
| 8783 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8784 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8785 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8786 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8787 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8788 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8789 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8790 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8791 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8792 | return; |
| 8793 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8794 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8795 | } finally { |
| 8796 | Binder.restoreCallingIdentity(identity); |
| 8797 | } |
| 8798 | } |
| 8799 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8800 | @Override |
| 8801 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8802 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8803 | Phone phone = getPhone(subId); |
| 8804 | if (phone == null) { |
| 8805 | return false; |
| 8806 | } |
| 8807 | final long identity = Binder.clearCallingIdentity(); |
| 8808 | try { |
| 8809 | UiccCard uiccCard = phone.getUiccCard(); |
| 8810 | if (uiccCard == null) { |
| 8811 | return false; |
| 8812 | } |
| 8813 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8814 | if (uiccProfile == null) { |
| 8815 | return false; |
| 8816 | } |
| 8817 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8818 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8819 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8820 | } |
| 8821 | return false; |
| 8822 | } finally { |
| 8823 | Binder.restoreCallingIdentity(identity); |
| 8824 | } |
| 8825 | } |
| 8826 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8827 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8828 | * Get whether making changes to modem configurations will trigger reboot. |
| 8829 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8830 | */ |
| 8831 | @Override |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8832 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8833 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8834 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 9797cbb | 2020-01-07 13:45:00 -0800 | [diff] [blame] | 8835 | mApp, subId, callingPackage, callingFeatureId, |
| 8836 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8837 | return false; |
| 8838 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8839 | final long identity = Binder.clearCallingIdentity(); |
| 8840 | try { |
| 8841 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8842 | } finally { |
| 8843 | Binder.restoreCallingIdentity(identity); |
| 8844 | } |
| 8845 | } |
| 8846 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8847 | private void updateModemStateMetrics() { |
| 8848 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8849 | // TODO: check the state for each modem if the api is ready. |
| 8850 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8851 | } |
| 8852 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8853 | @Override |
| 8854 | public int[] getSlotsMapping() { |
| 8855 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8856 | |
| 8857 | final long identity = Binder.clearCallingIdentity(); |
| 8858 | try { |
| 8859 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8860 | // All logical slots should have a mapping to a physical slot. |
| 8861 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8862 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8863 | for (int i = 0; i < slotInfos.length; i++) { |
| 8864 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8865 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8866 | } |
| 8867 | } |
| 8868 | return logicalSlotsMapping; |
| 8869 | } finally { |
| 8870 | Binder.restoreCallingIdentity(identity); |
| 8871 | } |
| 8872 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8873 | |
| 8874 | /** |
| 8875 | * Get the IRadio HAL Version |
| 8876 | */ |
| 8877 | @Override |
| 8878 | public int getRadioHalVersion() { |
| 8879 | Phone phone = getDefaultPhone(); |
| 8880 | if (phone == null) return -1; |
| 8881 | HalVersion hv = phone.getHalVersion(); |
| 8882 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8883 | return hv.major * 100 + hv.minor; |
| 8884 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8885 | |
| 8886 | /** |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8887 | * Get the current calling package name. |
| 8888 | * @return the current calling package name |
| 8889 | */ |
| 8890 | @Override |
| 8891 | public String getCurrentPackageName() { |
| 8892 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8893 | } |
| 8894 | |
| 8895 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8896 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8897 | * corresponding network requests on a subId. |
| 8898 | * |
| 8899 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8900 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8901 | * 2) APN is un-metered for this subscription, or |
| 8902 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8903 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8904 | * |
| 8905 | * @return whether data is allowed for a apn type. |
| 8906 | * |
| 8907 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8908 | */ |
| 8909 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8910 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | f250974 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8911 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8912 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8913 | |
| 8914 | // Now that all security checks passes, perform the operation as ourselves. |
| 8915 | final long identity = Binder.clearCallingIdentity(); |
| 8916 | try { |
| 8917 | Phone phone = getPhone(subId); |
| 8918 | if (phone == null) return false; |
| 8919 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8920 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8921 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8922 | } finally { |
| 8923 | Binder.restoreCallingIdentity(identity); |
| 8924 | } |
| 8925 | } |
| 8926 | |
| 8927 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8928 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8929 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8930 | |
| 8931 | // Now that all security checks passes, perform the operation as ourselves. |
| 8932 | final long identity = Binder.clearCallingIdentity(); |
| 8933 | try { |
| 8934 | Phone phone = getPhone(subId); |
| 8935 | if (phone == null) return true; // By default return true. |
| 8936 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8937 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8938 | } finally { |
| 8939 | Binder.restoreCallingIdentity(identity); |
| 8940 | } |
| 8941 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8942 | |
| 8943 | @Override |
Hall Liu | d0d1dc9 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8944 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8945 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8946 | enforceModifyPermission(); |
| 8947 | long token = Binder.clearCallingIdentity(); |
| 8948 | try { |
| 8949 | Phone phone = getPhone(subscriptionId); |
| 8950 | if (phone == null) { |
| 8951 | try { |
| 8952 | if (resultCallback != null) { |
| 8953 | resultCallback.accept(false); |
| 8954 | } |
| 8955 | } catch (RemoteException e) { |
| 8956 | // ignore |
| 8957 | } |
| 8958 | return; |
| 8959 | } |
| 8960 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 8961 | Pair.create(specifiers, (x) -> { |
| 8962 | try { |
| 8963 | if (resultCallback != null) { |
| 8964 | resultCallback.accept(x); |
| 8965 | } |
| 8966 | } catch (RemoteException e) { |
| 8967 | // ignore |
| 8968 | } |
| 8969 | }); |
| 8970 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 8971 | } finally { |
| 8972 | Binder.restoreCallingIdentity(token); |
| 8973 | } |
| 8974 | } |
| 8975 | |
| 8976 | @Override |
Sarah Chin | cc05573 | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 8977 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 8978 | TelephonyPermissions |
| 8979 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8980 | mApp, subId, "getSystemSelectionChannels"); |
| 8981 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8982 | final long identity = Binder.clearCallingIdentity(); |
| 8983 | try { |
| 8984 | List<RadioAccessSpecifier> specifiers = |
| 8985 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 8986 | null, subId, workSource); |
| 8987 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 8988 | return specifiers; |
| 8989 | } finally { |
| 8990 | Binder.restoreCallingIdentity(identity); |
| 8991 | } |
| 8992 | } |
| 8993 | |
| 8994 | @Override |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8995 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 8996 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 363e8ac | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 8997 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 8998 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 8999 | if (iccRecords == null) { |
| 9000 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9001 | return false; |
| 9002 | } |
| 9003 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9004 | } |
| 9005 | |
| 9006 | @Override |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9007 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9008 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | af42a31 | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9009 | if (callingPackage == null) { |
| 9010 | callingPackage = getCurrentPackageName(); |
| 9011 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9012 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9013 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | 295beed | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9014 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9015 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9016 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9017 | } |
| 9018 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9019 | Intent intent = new Intent(); |
| 9020 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9021 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9022 | // Bring up choose default SMS subscription dialog right now |
| 9023 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9024 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9025 | mApp.startActivity(intent); |
| 9026 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9027 | |
| 9028 | @Override |
| 9029 | public String getMmsUAProfUrl(int subId) { |
| 9030 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9031 | final long identity = Binder.clearCallingIdentity(); |
| 9032 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9033 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9034 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9035 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9036 | return carrierUAProfUrl; |
| 9037 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9038 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9039 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
| 9040 | } finally { |
| 9041 | Binder.restoreCallingIdentity(identity); |
| 9042 | } |
| 9043 | } |
| 9044 | |
| 9045 | @Override |
| 9046 | public String getMmsUserAgent(int subId) { |
| 9047 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9048 | final long identity = Binder.clearCallingIdentity(); |
| 9049 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9050 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9051 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9052 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9053 | return carrierUserAgent; |
| 9054 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9055 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9056 | .getString(com.android.internal.R.string.config_mms_user_agent); |
| 9057 | } finally { |
| 9058 | Binder.restoreCallingIdentity(identity); |
| 9059 | } |
| 9060 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9061 | |
| 9062 | @Override |
Hall Liu | c041a55 | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9063 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9064 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
| 9065 | |
| 9066 | final long identity = Binder.clearCallingIdentity(); |
| 9067 | try { |
| 9068 | Phone phone = getPhone(subscriptionId); |
| 9069 | if (phone == null) return false; |
| 9070 | |
| 9071 | switch (policy) { |
| 9072 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9073 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9074 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9075 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9076 | default: |
| 9077 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9078 | } |
| 9079 | } finally { |
| 9080 | Binder.restoreCallingIdentity(identity); |
| 9081 | } |
| 9082 | } |
| 9083 | |
| 9084 | @Override |
| 9085 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9086 | boolean enabled) { |
| 9087 | enforceModifyPermission(); |
| 9088 | |
| 9089 | final long identity = Binder.clearCallingIdentity(); |
| 9090 | try { |
| 9091 | Phone phone = getPhone(subscriptionId); |
| 9092 | if (phone == null) return; |
| 9093 | |
| 9094 | switch (policy) { |
| 9095 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9096 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9097 | break; |
| 9098 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9099 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9100 | break; |
| 9101 | default: |
| 9102 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9103 | } |
| 9104 | } finally { |
| 9105 | Binder.restoreCallingIdentity(identity); |
| 9106 | } |
| 9107 | } |
| 9108 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9109 | /** |
Hall Liu | b48cf45 | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9110 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9111 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9112 | * otherwise. |
| 9113 | */ |
| 9114 | @Override |
| 9115 | public void setCepEnabled(boolean isCepEnabled) { |
| 9116 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9117 | |
| 9118 | final long identity = Binder.clearCallingIdentity(); |
| 9119 | try { |
| 9120 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9121 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9122 | Phone defaultPhone = phone.getImsPhone(); |
| 9123 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9124 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9125 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9126 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9127 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9128 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9129 | + imsPhone.getMsisdn()); |
| 9130 | } |
| 9131 | } |
| 9132 | } finally { |
| 9133 | Binder.restoreCallingIdentity(identity); |
| 9134 | } |
| 9135 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9136 | |
| 9137 | /** |
| 9138 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9139 | * |
| 9140 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9141 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9142 | * before being read. |
| 9143 | */ |
| 9144 | @Override |
| 9145 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9146 | isCompressed) { |
| 9147 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9148 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9149 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9150 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9151 | } |
| 9152 | if (!isImsAvailableOnDevice()) { |
| 9153 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9154 | "IMS not available on device."); |
| 9155 | } |
| 9156 | |
| 9157 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9158 | try { |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9159 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9160 | } finally { |
| 9161 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9162 | } |
| 9163 | } |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9164 | |
| 9165 | @Override |
| 9166 | public boolean isIccLockEnabled(int subId) { |
| 9167 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9168 | |
| 9169 | // Now that all security checks passes, perform the operation as ourselves. |
| 9170 | final long identity = Binder.clearCallingIdentity(); |
| 9171 | try { |
| 9172 | Phone phone = getPhone(subId); |
| 9173 | if (phone != null && phone.getIccCard() != null) { |
| 9174 | return phone.getIccCard().getIccLockEnabled(); |
| 9175 | } else { |
| 9176 | return false; |
| 9177 | } |
| 9178 | } finally { |
| 9179 | Binder.restoreCallingIdentity(identity); |
| 9180 | } |
| 9181 | } |
| 9182 | |
| 9183 | /** |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9184 | * Set the ICC pin lock enabled or disabled. |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9185 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9186 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9187 | * three cases: |
| 9188 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9189 | * successfully. |
| 9190 | * - Positive number and zero for remaining password attempts. |
| 9191 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9192 | * |
| 9193 | */ |
| 9194 | @Override |
| 9195 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9196 | enforceModifyPermission(); |
| 9197 | |
| 9198 | Phone phone = getPhone(subId); |
| 9199 | if (phone == null) { |
| 9200 | return 0; |
| 9201 | } |
| 9202 | // Now that all security checks passes, perform the operation as ourselves. |
| 9203 | final long identity = Binder.clearCallingIdentity(); |
| 9204 | try { |
| 9205 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9206 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9207 | return attemptsRemaining; |
| 9208 | |
| 9209 | } catch (Exception e) { |
| 9210 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9211 | } finally { |
| 9212 | Binder.restoreCallingIdentity(identity); |
| 9213 | } |
| 9214 | return 0; |
| 9215 | } |
| 9216 | |
| 9217 | /** |
| 9218 | * Change the ICC password used in ICC pin lock. |
| 9219 | * |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9220 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9221 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9222 | * - Positive number and zero for remaining password attempts. |
| 9223 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
zoey chen | f95ca59 | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9224 | * |
| 9225 | */ |
| 9226 | @Override |
| 9227 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9228 | enforceModifyPermission(); |
| 9229 | |
| 9230 | Phone phone = getPhone(subId); |
| 9231 | if (phone == null) { |
| 9232 | return 0; |
| 9233 | } |
| 9234 | // Now that all security checks passes, perform the operation as ourselves. |
| 9235 | final long identity = Binder.clearCallingIdentity(); |
| 9236 | try { |
| 9237 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9238 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9239 | return attemptsRemaining; |
| 9240 | |
| 9241 | } catch (Exception e) { |
| 9242 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9243 | } finally { |
| 9244 | Binder.restoreCallingIdentity(identity); |
| 9245 | } |
| 9246 | return 0; |
| 9247 | } |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9248 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9249 | /** |
| 9250 | * Request for receiving user activity notification |
| 9251 | */ |
| 9252 | @Override |
| 9253 | public void requestUserActivityNotification() { |
| 9254 | if (!mNotifyUserActivity.get() |
| 9255 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9256 | mNotifyUserActivity.set(true); |
| 9257 | } |
| 9258 | } |
| 9259 | |
| 9260 | /** |
| 9261 | * Called when userActivity is signalled in the power manager. |
| 9262 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9263 | */ |
| 9264 | @Override |
| 9265 | public void userActivity() { |
| 9266 | // *************************************** |
| 9267 | // * Inherited from PhoneWindowManager * |
| 9268 | // *************************************** |
| 9269 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9270 | // WITH ITS LOCKS HELD. |
| 9271 | // |
| 9272 | // This code must be VERY careful about the locks |
| 9273 | // it acquires. |
| 9274 | // In fact, the current code acquires way too many, |
| 9275 | // and probably has lurking deadlocks. |
| 9276 | |
| 9277 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9278 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9279 | } |
| 9280 | |
| 9281 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9282 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9283 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9284 | } |
| 9285 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9286 | |
Malcolm Chen | 884180b | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9287 | @Override |
| 9288 | public boolean canConnectTo5GInDsdsMode() { |
| 9289 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9290 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9291 | |
| 9292 | @Override |
| 9293 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9294 | String callingFeatureId) { |
| 9295 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9296 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9297 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9298 | } |
| 9299 | |
| 9300 | Phone phone = getPhone(subId); |
| 9301 | if (phone == null) { |
| 9302 | throw new RuntimeException("phone is not available"); |
| 9303 | } |
| 9304 | // Now that all security checks passes, perform the operation as ourselves. |
| 9305 | final long identity = Binder.clearCallingIdentity(); |
| 9306 | try { |
| 9307 | return phone.getEquivalentHomePlmns(); |
| 9308 | } finally { |
| 9309 | Binder.restoreCallingIdentity(identity); |
| 9310 | } |
| 9311 | } |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9312 | |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9313 | @Override |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9314 | public boolean isRadioInterfaceCapabilitySupported( |
| 9315 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9316 | Set<String> radioInterfaceCapabilities = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9317 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9318 | if (radioInterfaceCapabilities == null) { |
| 9319 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9320 | } else { |
Daniel Bright | 0176b32 | 2021-02-24 21:03:28 +0000 | [diff] [blame] | 9321 | return radioInterfaceCapabilities.contains(capability); |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9322 | } |
| 9323 | } |
| 9324 | |
| 9325 | @Override |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9326 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9327 | UaSecurityProtocolIdentifier securityProtocol, |
| 9328 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9329 | throws RemoteException { |
| 9330 | enforceModifyPermission(); |
| 9331 | if (DBG) { |
| 9332 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9333 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9334 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9335 | } |
| 9336 | |
| 9337 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9338 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9339 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9340 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9341 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9342 | if (callback != null) { |
| 9343 | try { |
| 9344 | callback.onAuthenticationFailure( |
| 9345 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9346 | } catch (RemoteException exception) { |
| 9347 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9348 | } |
| 9349 | return; |
| 9350 | } |
| 9351 | } |
| 9352 | |
| 9353 | final long token = Binder.clearCallingIdentity(); |
| 9354 | try { |
| 9355 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9356 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9357 | forceBootStrapping, callback)); |
| 9358 | } finally { |
| 9359 | Binder.restoreCallingIdentity(token); |
| 9360 | } |
| 9361 | } |
| 9362 | |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9363 | /** |
| 9364 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9365 | * requested radio power state will actually be set. See {@link |
| 9366 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9367 | * |
| 9368 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9369 | * @param enable {@code true} if trying to turn radio on. |
| 9370 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9371 | * false}. |
| 9372 | */ |
| 9373 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9374 | Phone phone = getPhone(subId); |
| 9375 | if (phone != null) { |
| 9376 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9377 | return true; |
| 9378 | } |
| 9379 | return false; |
| 9380 | } |
| 9381 | |
| 9382 | private int handleDataThrottlingRequest(int subId, |
| 9383 | DataThrottlingRequest dataThrottlingRequest) { |
| 9384 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9385 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9386 | if (!setRadioPowerForThermal(subId, true)) { |
| 9387 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9388 | } |
| 9389 | |
| 9390 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9391 | |
| 9392 | int thermalMitigationResult = |
| 9393 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9394 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9395 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9396 | } |
| 9397 | return thermalMitigationResult; |
| 9398 | } |
| 9399 | |
| 9400 | /** |
| 9401 | * Thermal mitigation request to control functionalities at modem. |
| 9402 | * |
| 9403 | * @param subId the id of the subscription. |
| 9404 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9405 | * |
| 9406 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9407 | */ |
| 9408 | @Override |
| 9409 | @ThermalMitigationResult |
| 9410 | public int sendThermalMitigationRequest( |
| 9411 | int subId, |
| 9412 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9413 | enforceModifyPermission(); |
| 9414 | |
| 9415 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9416 | final long identity = Binder.clearCallingIdentity(); |
| 9417 | |
| 9418 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9419 | try { |
| 9420 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9421 | switch (thermalMitigationAction) { |
| 9422 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9423 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9424 | handleDataThrottlingRequest(subId, |
| 9425 | thermalMitigationRequest.getDataThrottlingRequest()); |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9426 | break; |
| 9427 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9428 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9429 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9430 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9431 | } |
| 9432 | |
| 9433 | // Ensure that radio is on. If not able to power on due to phone being |
| 9434 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9435 | if (!setRadioPowerForThermal(subId, true)) { |
| 9436 | thermalMitigationResult = |
| 9437 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9438 | break; |
| 9439 | } |
| 9440 | |
| 9441 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9442 | false); |
| 9443 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9444 | break; |
| 9445 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9446 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9447 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9448 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9449 | } |
| 9450 | |
| 9451 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9452 | if (registry != null) { |
| 9453 | TelephonyConnectionService service = |
| 9454 | registry.getTelephonyConnectionService(); |
| 9455 | Phone phone = getPhone(subId); |
| 9456 | if (phone == null) { |
| 9457 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9458 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9459 | break; |
| 9460 | } |
| 9461 | |
| 9462 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9463 | != TelephonyManager.CALL_STATE_IDLE |
| 9464 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9465 | || (service != null && service.isEmergencyCallPending())) { |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9466 | String errorMessage = "Phone state is not valid. call state = " |
| 9467 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9468 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9469 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9470 | errorMessage += service == null |
| 9471 | ? " TelephonyConnectionService is null" |
| 9472 | : " isEmergencyCallPending = " |
| 9473 | + service.isEmergencyCallPending(); |
| 9474 | Log.e(LOG_TAG, errorMessage); |
| 9475 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9476 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9477 | break; |
| 9478 | } |
| 9479 | } else { |
| 9480 | thermalMitigationResult = |
| 9481 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9482 | break; |
| 9483 | } |
| 9484 | |
| 9485 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9486 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9487 | if (!setRadioPowerForThermal(subId, false)) { |
| 9488 | thermalMitigationResult = |
| 9489 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9490 | break; |
| 9491 | } |
| 9492 | thermalMitigationResult = |
Daniel Bright | 74f1ca8 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9493 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
Jack Nudelman | 24d51a5 | 2020-11-24 12:08:04 -0800 | [diff] [blame] | 9494 | break; |
| 9495 | default: |
| 9496 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9497 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9498 | } |
| 9499 | } catch (IllegalArgumentException e) { |
| 9500 | throw e; |
| 9501 | } catch (Exception e) { |
| 9502 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9503 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9504 | } finally { |
| 9505 | Binder.restoreCallingIdentity(identity); |
| 9506 | } |
| 9507 | |
| 9508 | if (DBG) { |
| 9509 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9510 | + thermalMitigationResult); |
| 9511 | } |
| 9512 | |
| 9513 | return thermalMitigationResult; |
| 9514 | } |
Hui Wang | 0866fcc | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9515 | |
| 9516 | /** |
| 9517 | * Set the GbaService Package Name that Telephony will bind to. |
| 9518 | * |
| 9519 | * @param subId The sim that the GbaService is associated with. |
| 9520 | * @param packageName The name of the package to be replaced with. |
| 9521 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9522 | */ |
| 9523 | @Override |
| 9524 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9525 | enforceModifyPermission(); |
| 9526 | |
| 9527 | final long identity = Binder.clearCallingIdentity(); |
| 9528 | try { |
| 9529 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9530 | } finally { |
| 9531 | Binder.restoreCallingIdentity(identity); |
| 9532 | } |
| 9533 | } |
| 9534 | |
| 9535 | /** |
| 9536 | * Return the package name of the currently bound GbaService. |
| 9537 | * |
| 9538 | * @param subId The sim that the GbaService is associated with. |
| 9539 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9540 | */ |
| 9541 | @Override |
| 9542 | public String getBoundGbaService(int subId) { |
| 9543 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9544 | |
| 9545 | final long identity = Binder.clearCallingIdentity(); |
| 9546 | try { |
| 9547 | return getGbaManager(subId).getServicePackage(); |
| 9548 | } finally { |
| 9549 | Binder.restoreCallingIdentity(identity); |
| 9550 | } |
| 9551 | } |
| 9552 | |
| 9553 | /** |
| 9554 | * Set the release time for telephony to unbind GbaService. |
| 9555 | * |
| 9556 | * @param subId The sim that the GbaService is associated with. |
| 9557 | * @param interval The release time to unbind GbaService by millisecond. |
| 9558 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9559 | */ |
| 9560 | @Override |
| 9561 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9562 | enforceModifyPermission(); |
| 9563 | |
| 9564 | final long identity = Binder.clearCallingIdentity(); |
| 9565 | try { |
| 9566 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9567 | } finally { |
| 9568 | Binder.restoreCallingIdentity(identity); |
| 9569 | } |
| 9570 | } |
| 9571 | |
| 9572 | /** |
| 9573 | * Return the release time for telephony to unbind GbaService. |
| 9574 | * |
| 9575 | * @param subId The sim that the GbaService is associated with. |
| 9576 | * @return The release time to unbind GbaService by millisecond. |
| 9577 | */ |
| 9578 | @Override |
| 9579 | public int getGbaReleaseTime(int subId) { |
| 9580 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9581 | |
| 9582 | final long identity = Binder.clearCallingIdentity(); |
| 9583 | try { |
| 9584 | return getGbaManager(subId).getReleaseTime(); |
| 9585 | } finally { |
| 9586 | Binder.restoreCallingIdentity(identity); |
| 9587 | } |
| 9588 | } |
| 9589 | |
| 9590 | private GbaManager getGbaManager(int subId) { |
| 9591 | GbaManager instance = GbaManager.getInstance(subId); |
| 9592 | if (instance == null) { |
| 9593 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9594 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9595 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9596 | } |
| 9597 | return instance; |
| 9598 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9599 | |
| 9600 | /** |
| 9601 | * indicate whether the device and the carrier can support |
| 9602 | * RCS VoLTE single registration. |
| 9603 | */ |
| 9604 | @Override |
| 9605 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9606 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9607 | |
| 9608 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9609 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9610 | } |
| 9611 | |
| 9612 | final long identity = Binder.clearCallingIdentity(); |
| 9613 | try { |
| 9614 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9615 | if (rpm != null) { |
| 9616 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9617 | } |
| 9618 | return false; |
| 9619 | } finally { |
| 9620 | Binder.restoreCallingIdentity(identity); |
| 9621 | } |
| 9622 | } |
| 9623 | |
| 9624 | /** |
| 9625 | * Register RCS provisioning callback. |
| 9626 | */ |
| 9627 | @Override |
| 9628 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9629 | IRcsConfigCallback callback) { |
| 9630 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9631 | |
| 9632 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9633 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9634 | } |
| 9635 | if (!isImsAvailableOnDevice()) { |
| 9636 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9637 | "IMS not available on device."); |
| 9638 | } |
| 9639 | |
| 9640 | final long identity = Binder.clearCallingIdentity(); |
| 9641 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9642 | if (!RcsProvisioningMonitor.getInstance() |
| 9643 | .registerRcsProvisioningChangedCallback(subId, callback)) { |
| 9644 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9645 | "Service not available for the subscription."); |
| 9646 | } |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9647 | } finally { |
| 9648 | Binder.restoreCallingIdentity(identity); |
| 9649 | } |
| 9650 | } |
| 9651 | |
| 9652 | /** |
| 9653 | * Unregister RCS provisioning callback. |
| 9654 | */ |
| 9655 | @Override |
| 9656 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9657 | IRcsConfigCallback callback) { |
| 9658 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9659 | |
| 9660 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9661 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9662 | } |
| 9663 | if (!isImsAvailableOnDevice()) { |
| 9664 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9665 | "IMS not available on device."); |
| 9666 | } |
| 9667 | |
| 9668 | final long identity = Binder.clearCallingIdentity(); |
| 9669 | try { |
Hui Wang | 713d45f | 2021-01-11 20:04:53 -0800 | [diff] [blame] | 9670 | RcsProvisioningMonitor.getInstance() |
| 9671 | .unregisterRcsProvisioningChangedCallback(subId, callback); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9672 | } finally { |
| 9673 | Binder.restoreCallingIdentity(identity); |
| 9674 | } |
| 9675 | } |
| 9676 | |
| 9677 | /** |
| 9678 | * trigger RCS reconfiguration. |
| 9679 | */ |
| 9680 | public void triggerRcsReconfiguration(int subId) { |
| 9681 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9682 | mApp, subId, "triggerRcsReconfiguration"); |
| 9683 | |
| 9684 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9685 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9686 | } |
| 9687 | if (!isImsAvailableOnDevice()) { |
| 9688 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9689 | "IMS not available on device."); |
| 9690 | } |
| 9691 | |
| 9692 | final long identity = Binder.clearCallingIdentity(); |
| 9693 | try { |
| 9694 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9695 | } finally { |
| 9696 | Binder.restoreCallingIdentity(identity); |
| 9697 | } |
| 9698 | } |
| 9699 | |
| 9700 | /** |
| 9701 | * Provide the client configuration parameters of the RCS application. |
| 9702 | */ |
| 9703 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9704 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9705 | mApp, subId, "setRcsClientConfiguration"); |
| 9706 | |
| 9707 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9708 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9709 | } |
| 9710 | if (!isImsAvailableOnDevice()) { |
| 9711 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9712 | "IMS not available on device."); |
| 9713 | } |
| 9714 | |
| 9715 | final long identity = Binder.clearCallingIdentity(); |
| 9716 | |
| 9717 | try { |
| 9718 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9719 | if (configBinder == null) { |
| 9720 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9721 | } else { |
| 9722 | configBinder.setRcsClientConfiguration(rcc); |
| 9723 | } |
| 9724 | } catch (RemoteException e) { |
| 9725 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9726 | } finally { |
| 9727 | Binder.restoreCallingIdentity(identity); |
| 9728 | } |
| 9729 | } |
| 9730 | |
| 9731 | /** |
Hui Wang | 19a2187 | 2021-02-19 20:45:36 -0800 | [diff] [blame] | 9732 | * Enables or disables the test mode for RCS VoLTE single registration. |
| 9733 | */ |
| 9734 | @Override |
| 9735 | public void setRcsSingleRegistrationTestModeEnabled(boolean enabled) { |
| 9736 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9737 | "setRcsSingleRegistrationTestModeEnabled"); |
| 9738 | |
| 9739 | RcsProvisioningMonitor.getInstance().setTestModeEnabled(enabled); |
| 9740 | } |
| 9741 | |
| 9742 | /** |
| 9743 | * Gets the test mode for RCS VoLTE single registration. |
| 9744 | */ |
| 9745 | @Override |
| 9746 | public boolean getRcsSingleRegistrationTestModeEnabled() { |
| 9747 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9748 | "getRcsSingleRegistrationTestModeEnabled"); |
| 9749 | |
| 9750 | return RcsProvisioningMonitor.getInstance().getTestModeEnabled(); |
| 9751 | } |
| 9752 | |
| 9753 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9754 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9755 | */ |
| 9756 | @Override |
| 9757 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9758 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9759 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9760 | enforceModifyPermission(); |
| 9761 | |
| 9762 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9763 | : Boolean.parseBoolean(enabledStr); |
| 9764 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
Brad Ebinger | 49a72b4 | 2021-01-29 00:55:24 +0000 | [diff] [blame] | 9765 | mApp.imsRcsController.setDeviceSingleRegistrationSupportOverride(enabled); |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9766 | } |
| 9767 | |
| 9768 | /** |
Tyler Gunn | 9247915 | 2021-01-20 16:30:10 -0800 | [diff] [blame] | 9769 | * Sends a device to device communication message. Only usable via shell. |
| 9770 | * @param message message to send. |
| 9771 | * @param value message value. |
| 9772 | */ |
| 9773 | @Override |
| 9774 | public void sendDeviceToDeviceMessage(int message, int value) { |
| 9775 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9776 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9777 | enforceModifyPermission(); |
| 9778 | |
| 9779 | final long identity = Binder.clearCallingIdentity(); |
| 9780 | try { |
| 9781 | TelephonyConnectionService service = |
| 9782 | TelecomAccountRegistry.getInstance(null).getTelephonyConnectionService(); |
| 9783 | if (service == null) { |
| 9784 | Rlog.e(LOG_TAG, "sendDeviceToDeviceMessage: not in a call."); |
| 9785 | return; |
| 9786 | } |
| 9787 | service.sendTestDeviceToDeviceMessage(message, value); |
| 9788 | } finally { |
| 9789 | Binder.restoreCallingIdentity(identity); |
| 9790 | } |
| 9791 | } |
| 9792 | |
| 9793 | |
| 9794 | /** |
Hui Wang | 068ab86 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9795 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9796 | */ |
| 9797 | @Override |
| 9798 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9799 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9800 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9801 | } |
| 9802 | |
| 9803 | /** |
| 9804 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9805 | */ |
| 9806 | @Override |
| 9807 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9808 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9809 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9810 | enforceModifyPermission(); |
| 9811 | |
| 9812 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9813 | : Boolean.parseBoolean(enabledStr); |
| 9814 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9815 | subId, enabled); |
| 9816 | } |
| 9817 | |
| 9818 | /** |
| 9819 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9820 | */ |
| 9821 | @Override |
| 9822 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9823 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9824 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9825 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9826 | |
| 9827 | /** |
| 9828 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9829 | * their mobile plan. |
| 9830 | */ |
| 9831 | @Override |
| 9832 | public String getMobileProvisioningUrl() { |
| 9833 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9834 | final long identity = Binder.clearCallingIdentity(); |
| 9835 | try { |
| 9836 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9837 | } finally { |
| 9838 | Binder.restoreCallingIdentity(identity); |
| 9839 | } |
| 9840 | } |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9841 | |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9842 | /** |
calvinpan | e4a8a1d | 2021-01-25 13:51:18 +0800 | [diff] [blame] | 9843 | * Get the EAB contact from the EAB database. |
| 9844 | */ |
| 9845 | @Override |
| 9846 | public String getContactFromEab(String contact) { |
| 9847 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getContactFromEab"); |
| 9848 | enforceModifyPermission(); |
| 9849 | final long identity = Binder.clearCallingIdentity(); |
| 9850 | try { |
| 9851 | return EabUtil.getContactFromEab(getDefaultPhone().getContext(), contact); |
| 9852 | } finally { |
| 9853 | Binder.restoreCallingIdentity(identity); |
| 9854 | } |
| 9855 | } |
| 9856 | |
| 9857 | /** |
James.cf Lin | bcdf8b3 | 2021-01-14 16:44:13 +0800 | [diff] [blame] | 9858 | * Remove the EAB contacts from the EAB database. |
| 9859 | */ |
| 9860 | @Override |
| 9861 | public int removeContactFromEab(int subId, String contacts) { |
| 9862 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "removeCapabilitiesFromEab"); |
| 9863 | enforceModifyPermission(); |
| 9864 | final long identity = Binder.clearCallingIdentity(); |
| 9865 | try { |
| 9866 | return EabUtil.removeContactFromEab(subId, contacts, getDefaultPhone().getContext()); |
| 9867 | } finally { |
| 9868 | Binder.restoreCallingIdentity(identity); |
| 9869 | } |
| 9870 | } |
| 9871 | |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9872 | @Override |
James.cf Lin | 4b784aa | 2021-01-31 03:25:15 +0800 | [diff] [blame] | 9873 | public boolean getDeviceUceEnabled() { |
| 9874 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "getDeviceUceEnabled"); |
| 9875 | final long identity = Binder.clearCallingIdentity(); |
| 9876 | try { |
| 9877 | return mApp.getDeviceUceEnabled(); |
| 9878 | } finally { |
| 9879 | Binder.restoreCallingIdentity(identity); |
| 9880 | } |
| 9881 | } |
| 9882 | |
| 9883 | @Override |
| 9884 | public void setDeviceUceEnabled(boolean isEnabled) { |
| 9885 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setDeviceUceEnabled"); |
| 9886 | final long identity = Binder.clearCallingIdentity(); |
| 9887 | try { |
| 9888 | mApp.setDeviceUceEnabled(isEnabled); |
| 9889 | } finally { |
| 9890 | Binder.restoreCallingIdentity(identity); |
| 9891 | } |
| 9892 | } |
| 9893 | |
| 9894 | @Override |
Rambo Wang | a5cc9b7 | 2021-01-07 10:51:54 -0800 | [diff] [blame] | 9895 | public void setSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9896 | String callingPackage) { |
| 9897 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9898 | mApp, subId, "setSignalStrengthUpdateRequest"); |
| 9899 | |
| 9900 | final int callingUid = Binder.getCallingUid(); |
| 9901 | // Verify that tha callingPackage belongs to the calling UID |
| 9902 | mApp.getSystemService(AppOpsManager.class) |
| 9903 | .checkPackage(callingUid, callingPackage); |
| 9904 | |
| 9905 | validateSignalStrengthUpdateRequest(request, callingUid); |
| 9906 | |
| 9907 | final long identity = Binder.clearCallingIdentity(); |
| 9908 | try { |
| 9909 | Object result = sendRequest(CMD_SET_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9910 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9911 | |
| 9912 | if (result instanceof IllegalStateException) { |
| 9913 | throw (IllegalStateException) result; |
| 9914 | } |
| 9915 | } finally { |
| 9916 | Binder.restoreCallingIdentity(identity); |
| 9917 | } |
| 9918 | } |
| 9919 | |
| 9920 | @Override |
| 9921 | public void clearSignalStrengthUpdateRequest(int subId, SignalStrengthUpdateRequest request, |
| 9922 | String callingPackage) { |
| 9923 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9924 | mApp, subId, "clearSignalStrengthUpdateRequest"); |
| 9925 | |
| 9926 | final int callingUid = Binder.getCallingUid(); |
| 9927 | // Verify that tha callingPackage belongs to the calling UID |
| 9928 | mApp.getSystemService(AppOpsManager.class) |
| 9929 | .checkPackage(callingUid, callingPackage); |
| 9930 | |
| 9931 | final long identity = Binder.clearCallingIdentity(); |
| 9932 | try { |
| 9933 | Object result = sendRequest(CMD_CLEAR_SIGNAL_STRENGTH_UPDATE_REQUEST, |
| 9934 | new Pair<Integer, SignalStrengthUpdateRequest>(callingUid, request), subId); |
| 9935 | |
| 9936 | if (result instanceof IllegalStateException) { |
| 9937 | throw (IllegalStateException) result; |
| 9938 | } |
| 9939 | } finally { |
| 9940 | Binder.restoreCallingIdentity(identity); |
| 9941 | } |
| 9942 | } |
| 9943 | |
| 9944 | private static void validateSignalStrengthUpdateRequest(SignalStrengthUpdateRequest request, |
| 9945 | int callingUid) { |
| 9946 | if (callingUid == Process.PHONE_UID || callingUid == Process.SYSTEM_UID) { |
| 9947 | // phone/system process do not have further restriction on request |
| 9948 | return; |
| 9949 | } |
| 9950 | |
| 9951 | // Applications has restrictions on how to use the request: |
| 9952 | // Only system caller can set mIsSystemThresholdReportingRequestedWhileIdle |
| 9953 | if (request.isSystemThresholdReportingRequestedWhileIdle()) { |
| 9954 | // This is not system caller which has been checked above |
| 9955 | throw new IllegalArgumentException( |
| 9956 | "Only system can set isSystemThresholdReportingRequestedWhileIdle"); |
| 9957 | } |
| 9958 | |
| 9959 | for (SignalThresholdInfo info : request.getSignalThresholdInfos()) { |
| 9960 | // Only system caller can set mHysteresisMs/mHysteresisDb/mIsEnabled. |
| 9961 | if (info.getHysteresisMs() != SignalThresholdInfo.HYSTERESIS_MS_DISABLED |
| 9962 | || info.getHysteresisDb() != SignalThresholdInfo.HYSTERESIS_DB_DISABLED |
| 9963 | || info.isEnabled()) { |
| 9964 | throw new IllegalArgumentException( |
| 9965 | "Only system can set hide fields in SignalThresholdInfo"); |
| 9966 | } |
| 9967 | |
| 9968 | // Thresholds length for each RAN need in range. This has been validated in |
| 9969 | // SignalThresholdInfo#Builder#setThreshold. Here we prevent apps calling hide method |
| 9970 | // setThresholdUnlimited (e.g. through reflection) with too short or too long thresholds |
| 9971 | final int[] thresholds = info.getThresholds(); |
| 9972 | Objects.requireNonNull(thresholds); |
| 9973 | if (thresholds.length < SignalThresholdInfo.getMinimumNumberOfThresholdsAllowed() |
| 9974 | || thresholds.length |
| 9975 | > SignalThresholdInfo.getMaximumNumberOfThresholdsAllowed()) { |
| 9976 | throw new IllegalArgumentException( |
| 9977 | "thresholds length is out of range: " + thresholds.length); |
| 9978 | } |
| 9979 | } |
| 9980 | } |
Michele Berionne | d9fbae5 | 2020-11-13 02:36:59 +0000 | [diff] [blame] | 9981 | |
| 9982 | /** |
| 9983 | * Prepare TelephonyManager for an unattended reboot. The reboot is |
| 9984 | * required to be done shortly after the API is invoked. |
| 9985 | */ |
| 9986 | @Override |
| 9987 | @TelephonyManager.PrepareUnattendedRebootResult |
| 9988 | public int prepareForUnattendedReboot() { |
| 9989 | enforceRebootPermission(); |
| 9990 | |
| 9991 | final long identity = Binder.clearCallingIdentity(); |
| 9992 | try { |
| 9993 | return (int) sendRequest(CMD_PREPARE_UNATTENDED_REBOOT, null); |
| 9994 | } finally { |
| 9995 | Binder.restoreCallingIdentity(identity); |
| 9996 | } |
| 9997 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9998 | } |