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; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -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; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame^] | 29 | import android.app.role.RoleManager; |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 30 | import android.content.ComponentName; |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 31 | import android.content.ContentResolver; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 32 | import android.content.Context; |
| 33 | import android.content.Intent; |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 34 | import android.content.SharedPreferences; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 35 | import android.content.pm.ComponentInfo; |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 36 | import android.content.pm.PackageInfo; |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 37 | import android.content.pm.PackageManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 38 | import android.net.Uri; |
| 39 | import android.os.AsyncResult; |
| 40 | import android.os.Binder; |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 41 | import android.os.Build; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 42 | import android.os.Bundle; |
| 43 | import android.os.Handler; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 44 | import android.os.IBinder; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 45 | import android.os.Looper; |
| 46 | import android.os.Message; |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 47 | import android.os.Messenger; |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 48 | import android.os.ParcelFileDescriptor; |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 49 | import android.os.ParcelUuid; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 50 | import android.os.PersistableBundle; |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 51 | import android.os.Process; |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 52 | import android.os.RemoteException; |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 53 | import android.os.ResultReceiver; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 54 | import android.os.ServiceSpecificException; |
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 | d63128d | 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 | 14bb3d0 | 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 | 227e06f | 2019-09-26 22:48:11 -0700 | [diff] [blame] | 66 | import android.telephony.Annotation.ApnType; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 67 | import android.telephony.Annotation.ThermalMitigationResult; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 68 | import android.telephony.CallForwardingInfo; |
Sooraj Sasindran | 4deb887 | 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 | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 72 | import android.telephony.CellIdentity; |
Meng Wang | a10e89e | 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 | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 79 | import android.telephony.DataThrottlingRequest; |
Hui Wang | 641e81c | 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; |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 91 | import android.telephony.RadioInterfaceCapabilities; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 92 | import android.telephony.ServiceState; |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 93 | import android.telephony.SignalStrength; |
Wink Saville | 0f3b5fc | 2014-11-11 08:40:49 -0800 | [diff] [blame] | 94 | import android.telephony.SubscriptionInfo; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 95 | import android.telephony.SubscriptionManager; |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 96 | import android.telephony.TelephonyFrameworkInitializer; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 97 | import android.telephony.TelephonyHistogram; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 98 | import android.telephony.TelephonyManager; |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 99 | import android.telephony.TelephonyScanManager; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 100 | import android.telephony.ThermalMitigationRequest; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 101 | import android.telephony.UiccCardInfo; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 102 | import android.telephony.UiccSlotInfo; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 103 | import android.telephony.UssdResponse; |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 104 | import android.telephony.VisualVoicemailSmsFilterSettings; |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 105 | import android.telephony.data.ApnSetting; |
| 106 | import android.telephony.emergency.EmergencyNumber; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 107 | import android.telephony.gba.GbaAuthRequest; |
| 108 | import android.telephony.gba.UaSecurityProtocolIdentifier; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 109 | import android.telephony.ims.ImsException; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 110 | import android.telephony.ims.ProvisioningManager; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 111 | import android.telephony.ims.RcsClientConfiguration; |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 112 | import android.telephony.ims.RegistrationManager; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 113 | import android.telephony.ims.aidl.IImsCapabilityCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 114 | import android.telephony.ims.aidl.IImsConfig; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 115 | import android.telephony.ims.aidl.IImsConfigCallback; |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 116 | import android.telephony.ims.aidl.IImsRegistration; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 117 | import android.telephony.ims.aidl.IImsRegistrationCallback; |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 118 | import android.telephony.ims.aidl.IRcsConfigCallback; |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 119 | import android.telephony.ims.feature.ImsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 120 | import android.telephony.ims.feature.MmTelFeature; |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 121 | import android.telephony.ims.feature.RcsFeature; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 122 | import android.telephony.ims.stub.ImsConfigImplBase; |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 123 | import android.telephony.ims.stub.ImsRegistrationImplBase; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 124 | import android.text.TextUtils; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 125 | import android.util.ArraySet; |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 126 | import android.util.EventLog; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 127 | import android.util.Log; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 128 | import android.util.Pair; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 129 | |
Andrew Lee | 312e817 | 2014-10-23 17:01:36 -0700 | [diff] [blame] | 130 | import com.android.ims.ImsManager; |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 131 | import com.android.ims.internal.IImsServiceFeatureCallback; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 132 | import com.android.internal.telephony.CallForwardInfo; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 133 | import com.android.internal.telephony.CallManager; |
Tyler Gunn | 52dcf77 | 2017-04-26 11:30:31 -0700 | [diff] [blame] | 134 | import com.android.internal.telephony.CallStateException; |
pkanwar | 79ec054 | 2017-07-31 14:10:01 -0700 | [diff] [blame] | 135 | import com.android.internal.telephony.CarrierInfoManager; |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 136 | import com.android.internal.telephony.CarrierResolver; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 137 | import com.android.internal.telephony.CellNetworkScanResult; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 138 | import com.android.internal.telephony.CommandException; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 139 | import com.android.internal.telephony.CommandsInterface; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 140 | import com.android.internal.telephony.DefaultPhoneNotifier; |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 141 | import com.android.internal.telephony.GbaManager; |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 142 | import com.android.internal.telephony.HalVersion; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 143 | import com.android.internal.telephony.IBooleanConsumer; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 144 | import com.android.internal.telephony.ICallForwardingInfoCallback; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 145 | import com.android.internal.telephony.IIntegerConsumer; |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 146 | import com.android.internal.telephony.INumberVerificationCallback; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 147 | import com.android.internal.telephony.ITelephony; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 148 | import com.android.internal.telephony.IccCard; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 149 | import com.android.internal.telephony.LocaleTracker; |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 150 | import com.android.internal.telephony.NetworkScanRequestTracker; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 151 | import com.android.internal.telephony.OperatorInfo; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 152 | import com.android.internal.telephony.Phone; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 153 | import com.android.internal.telephony.PhoneConfigurationManager; |
Nathan Harold | a667c15 | 2016-12-14 11:27:20 -0800 | [diff] [blame] | 154 | import com.android.internal.telephony.PhoneConstantConversions; |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 155 | import com.android.internal.telephony.PhoneConstants; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 156 | import com.android.internal.telephony.PhoneFactory; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 157 | import com.android.internal.telephony.ProxyController; |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 158 | import com.android.internal.telephony.RIL; |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 159 | import com.android.internal.telephony.RILConstants; |
Jack Yu | 5f7092c | 2018-04-13 14:05:37 -0700 | [diff] [blame] | 160 | import com.android.internal.telephony.ServiceStateTracker; |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 161 | import com.android.internal.telephony.SmsController; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 162 | import com.android.internal.telephony.SmsPermissions; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 163 | import com.android.internal.telephony.SubscriptionController; |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 164 | import com.android.internal.telephony.TelephonyIntents; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 165 | import com.android.internal.telephony.TelephonyPermissions; |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 166 | import com.android.internal.telephony.dataconnection.ApnSettingUtils; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 167 | import com.android.internal.telephony.emergency.EmergencyNumberTracker; |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 168 | import com.android.internal.telephony.euicc.EuiccConnector; |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 169 | import com.android.internal.telephony.ims.ImsResolver; |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 170 | import com.android.internal.telephony.imsphone.ImsPhone; |
| 171 | import com.android.internal.telephony.imsphone.ImsPhoneCallTracker; |
Pengquan Meng | 6c2dc9f | 2019-02-06 11:12:53 -0800 | [diff] [blame] | 172 | import com.android.internal.telephony.metrics.TelephonyMetrics; |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 173 | import com.android.internal.telephony.uicc.IccCardApplicationStatus.AppType; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 174 | import com.android.internal.telephony.uicc.IccIoResult; |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 175 | import com.android.internal.telephony.uicc.IccRecords; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 176 | import com.android.internal.telephony.uicc.IccUtils; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 177 | import com.android.internal.telephony.uicc.SIMRecords; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 178 | import com.android.internal.telephony.uicc.UiccCard; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 179 | import com.android.internal.telephony.uicc.UiccCardApplication; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 180 | import com.android.internal.telephony.uicc.UiccController; |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 181 | import com.android.internal.telephony.uicc.UiccProfile; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 182 | import com.android.internal.telephony.uicc.UiccSlot; |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 183 | import com.android.internal.telephony.util.LocaleUtils; |
fionaxu | 7ed723d | 2017-05-30 18:58:54 -0700 | [diff] [blame] | 184 | import com.android.internal.telephony.util.VoicemailNotificationSettingsUtil; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 185 | import com.android.internal.util.FunctionalUtils; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 186 | import com.android.internal.util.HexDump; |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 187 | import com.android.phone.settings.PickSmsSubscriptionActivity; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 188 | import com.android.phone.vvm.PhoneAccountHandleConverter; |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 189 | import com.android.phone.vvm.RemoteVvmTaskManager; |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 190 | import com.android.phone.vvm.VisualVoicemailSettingsUtil; |
Ta-wei Yen | c890531 | 2017-03-28 11:14:45 -0700 | [diff] [blame] | 191 | import com.android.phone.vvm.VisualVoicemailSmsFilterConfig; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 192 | import com.android.services.telephony.TelecomAccountRegistry; |
| 193 | import com.android.services.telephony.TelephonyConnectionService; |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 194 | import com.android.telephony.Rlog; |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 195 | |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame^] | 196 | import java.io.ByteArrayOutputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 197 | import java.io.FileDescriptor; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame^] | 198 | import java.io.IOException; |
| 199 | import java.io.InputStream; |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 200 | import java.io.PrintWriter; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 201 | import java.util.ArrayList; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 202 | import java.util.Arrays; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 203 | import java.util.HashMap; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 204 | import java.util.HashSet; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 205 | import java.util.List; |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 206 | import java.util.Locale; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 207 | import java.util.Map; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 208 | import java.util.NoSuchElementException; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame^] | 209 | import java.util.Objects; |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 210 | import java.util.Set; |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame^] | 211 | import java.util.UUID; |
| 212 | import java.util.concurrent.Executors; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 213 | import java.util.concurrent.atomic.AtomicBoolean; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 214 | import java.util.function.Consumer; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * Implementation of the ITelephony interface. |
| 218 | */ |
Santos Cordon | 117fee7 | 2014-05-16 17:56:12 -0700 | [diff] [blame] | 219 | public class PhoneInterfaceManager extends ITelephony.Stub { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 220 | private static final String LOG_TAG = "PhoneInterfaceManager"; |
| 221 | private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2); |
| 222 | private static final boolean DBG_LOC = false; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 223 | private static final boolean DBG_MERGE = false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 224 | |
| 225 | // Message codes used with mMainThreadHandler |
| 226 | private static final int CMD_HANDLE_PIN_MMI = 1; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 227 | private static final int CMD_TRANSMIT_APDU_LOGICAL_CHANNEL = 7; |
| 228 | private static final int EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE = 8; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 229 | private static final int CMD_OPEN_CHANNEL = 9; |
| 230 | private static final int EVENT_OPEN_CHANNEL_DONE = 10; |
| 231 | private static final int CMD_CLOSE_CHANNEL = 11; |
| 232 | private static final int EVENT_CLOSE_CHANNEL_DONE = 12; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 233 | private static final int CMD_NV_READ_ITEM = 13; |
| 234 | private static final int EVENT_NV_READ_ITEM_DONE = 14; |
| 235 | private static final int CMD_NV_WRITE_ITEM = 15; |
| 236 | private static final int EVENT_NV_WRITE_ITEM_DONE = 16; |
| 237 | private static final int CMD_NV_WRITE_CDMA_PRL = 17; |
| 238 | private static final int EVENT_NV_WRITE_CDMA_PRL_DONE = 18; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 239 | private static final int CMD_RESET_MODEM_CONFIG = 19; |
| 240 | private static final int EVENT_RESET_MODEM_CONFIG_DONE = 20; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 241 | private static final int CMD_GET_PREFERRED_NETWORK_TYPE = 21; |
| 242 | private static final int EVENT_GET_PREFERRED_NETWORK_TYPE_DONE = 22; |
| 243 | private static final int CMD_SET_PREFERRED_NETWORK_TYPE = 23; |
| 244 | private static final int EVENT_SET_PREFERRED_NETWORK_TYPE_DONE = 24; |
Sailesh Nepal | 35b5945 | 2014-03-06 09:26:56 -0800 | [diff] [blame] | 245 | private static final int CMD_SEND_ENVELOPE = 25; |
| 246 | private static final int EVENT_SEND_ENVELOPE_DONE = 26; |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 247 | private static final int CMD_INVOKE_OEM_RIL_REQUEST_RAW = 27; |
| 248 | private static final int EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE = 28; |
Derek Tan | 6b088ee | 2014-09-05 14:15:18 -0700 | [diff] [blame] | 249 | private static final int CMD_TRANSMIT_APDU_BASIC_CHANNEL = 29; |
| 250 | private static final int EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE = 30; |
| 251 | private static final int CMD_EXCHANGE_SIM_IO = 31; |
| 252 | private static final int EVENT_EXCHANGE_SIM_IO_DONE = 32; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 253 | private static final int CMD_SET_VOICEMAIL_NUMBER = 33; |
| 254 | private static final int EVENT_SET_VOICEMAIL_NUMBER_DONE = 34; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 255 | private static final int CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC = 35; |
| 256 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE = 36; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 257 | private static final int CMD_GET_MODEM_ACTIVITY_INFO = 37; |
| 258 | private static final int EVENT_GET_MODEM_ACTIVITY_INFO_DONE = 38; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 259 | private static final int CMD_PERFORM_NETWORK_SCAN = 39; |
| 260 | private static final int EVENT_PERFORM_NETWORK_SCAN_DONE = 40; |
| 261 | private static final int CMD_SET_NETWORK_SELECTION_MODE_MANUAL = 41; |
| 262 | private static final int EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE = 42; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 263 | private static final int CMD_SET_ALLOWED_CARRIERS = 43; |
| 264 | private static final int EVENT_SET_ALLOWED_CARRIERS_DONE = 44; |
| 265 | private static final int CMD_GET_ALLOWED_CARRIERS = 45; |
| 266 | private static final int EVENT_GET_ALLOWED_CARRIERS_DONE = 46; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 267 | private static final int CMD_HANDLE_USSD_REQUEST = 47; |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 268 | private static final int CMD_GET_FORBIDDEN_PLMNS = 48; |
| 269 | private static final int EVENT_GET_FORBIDDEN_PLMNS_DONE = 49; |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 270 | private static final int CMD_SWITCH_SLOTS = 50; |
| 271 | private static final int EVENT_SWITCH_SLOTS_DONE = 51; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 272 | private static final int CMD_GET_NETWORK_SELECTION_MODE = 52; |
| 273 | private static final int EVENT_GET_NETWORK_SELECTION_MODE_DONE = 53; |
| 274 | private static final int CMD_GET_CDMA_ROAMING_MODE = 54; |
| 275 | private static final int EVENT_GET_CDMA_ROAMING_MODE_DONE = 55; |
| 276 | private static final int CMD_SET_CDMA_ROAMING_MODE = 56; |
| 277 | private static final int EVENT_SET_CDMA_ROAMING_MODE_DONE = 57; |
| 278 | private static final int CMD_SET_CDMA_SUBSCRIPTION_MODE = 58; |
| 279 | private static final int EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE = 59; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 280 | private static final int CMD_GET_ALL_CELL_INFO = 60; |
| 281 | private static final int EVENT_GET_ALL_CELL_INFO_DONE = 61; |
| 282 | private static final int CMD_GET_CELL_LOCATION = 62; |
| 283 | private static final int EVENT_GET_CELL_LOCATION_DONE = 63; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 284 | private static final int CMD_MODEM_REBOOT = 64; |
| 285 | private static final int EVENT_CMD_MODEM_REBOOT_DONE = 65; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 286 | private static final int CMD_REQUEST_CELL_INFO_UPDATE = 66; |
| 287 | private static final int EVENT_REQUEST_CELL_INFO_UPDATE_DONE = 67; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 288 | private static final int CMD_REQUEST_ENABLE_MODEM = 68; |
| 289 | private static final int EVENT_ENABLE_MODEM_DONE = 69; |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 290 | private static final int CMD_GET_MODEM_STATUS = 70; |
| 291 | private static final int EVENT_GET_MODEM_STATUS_DONE = 71; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 292 | private static final int CMD_SET_FORBIDDEN_PLMNS = 72; |
| 293 | private static final int EVENT_SET_FORBIDDEN_PLMNS_DONE = 73; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 294 | private static final int CMD_ERASE_MODEM_CONFIG = 74; |
| 295 | private static final int EVENT_ERASE_MODEM_CONFIG_DONE = 75; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 296 | private static final int CMD_CHANGE_ICC_LOCK_PASSWORD = 76; |
| 297 | private static final int EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE = 77; |
| 298 | private static final int CMD_SET_ICC_LOCK_ENABLED = 78; |
| 299 | private static final int EVENT_SET_ICC_LOCK_ENABLED_DONE = 79; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 300 | private static final int CMD_SET_SYSTEM_SELECTION_CHANNELS = 80; |
| 301 | private static final int EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE = 81; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 302 | private static final int MSG_NOTIFY_USER_ACTIVITY = 82; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 303 | private static final int CMD_GET_CALL_FORWARDING = 83; |
| 304 | private static final int EVENT_GET_CALL_FORWARDING_DONE = 84; |
| 305 | private static final int CMD_SET_CALL_FORWARDING = 85; |
| 306 | private static final int EVENT_SET_CALL_FORWARDING_DONE = 86; |
| 307 | private static final int CMD_GET_CALL_WAITING = 87; |
| 308 | private static final int EVENT_GET_CALL_WAITING_DONE = 88; |
| 309 | private static final int CMD_SET_CALL_WAITING = 89; |
| 310 | private static final int EVENT_SET_CALL_WAITING_DONE = 90; |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 311 | private static final int CMD_ENABLE_NR_DUAL_CONNECTIVITY = 91; |
| 312 | private static final int EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE = 92; |
| 313 | private static final int CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED = 93; |
| 314 | private static final int EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE = 94; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 315 | private static final int CMD_GET_CDMA_SUBSCRIPTION_MODE = 95; |
| 316 | private static final int EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE = 96; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 317 | private static final int CMD_GET_SYSTEM_SELECTION_CHANNELS = 97; |
| 318 | private static final int EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE = 98; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 319 | private static final int CMD_SET_DATA_THROTTLING = 99; |
| 320 | private static final int EVENT_SET_DATA_THROTTLING_DONE = 100; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 321 | private static final int CMD_SET_SIM_POWER = 101; |
| 322 | private static final int EVENT_SET_SIM_POWER_DONE = 102; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 323 | |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 324 | // Parameters of select command. |
| 325 | private static final int SELECT_COMMAND = 0xA4; |
| 326 | private static final int SELECT_P1 = 0x04; |
| 327 | private static final int SELECT_P2 = 0; |
| 328 | private static final int SELECT_P3 = 0x10; |
| 329 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 330 | /** The singleton instance. */ |
| 331 | private static PhoneInterfaceManager sInstance; |
| 332 | |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 333 | private PhoneGlobals mApp; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 334 | private CallManager mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 335 | private ImsResolver mImsResolver; |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 336 | private UserManager mUserManager; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 337 | private AppOpsManager mAppOps; |
| 338 | private MainThreadHandler mMainThreadHandler; |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 339 | private SubscriptionController mSubscriptionController; |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 340 | private SharedPreferences mTelephonySharedPreferences; |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 341 | private PhoneConfigurationManager mPhoneConfigurationManager; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 342 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 343 | /** User Activity */ |
| 344 | private AtomicBoolean mNotifyUserActivity; |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 345 | private static final int USER_ACTIVITY_NOTIFICATION_DELAY = 200; |
| 346 | |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 347 | private Set<Integer> mCarrierPrivilegeTestOverrideSubIds = new ArraySet<>(); |
| 348 | |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 349 | private static final String PREF_CARRIERS_ALPHATAG_PREFIX = "carrier_alphtag_"; |
| 350 | private static final String PREF_CARRIERS_NUMBER_PREFIX = "carrier_number_"; |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 351 | private static final String PREF_CARRIERS_SUBSCRIBER_PREFIX = "carrier_subscriber_"; |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 352 | private static final String PREF_PROVISION_IMS_MMTEL_PREFIX = "provision_ims_mmtel_"; |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 353 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 354 | // String to store multi SIM allowed |
| 355 | private static final String PREF_MULTI_SIM_RESTRICTED = "multisim_restricted"; |
| 356 | |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 357 | // The AID of ISD-R. |
| 358 | private static final String ISDR_AID = "A0000005591010FFFFFFFF8900000100"; |
| 359 | |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 360 | private NetworkScanRequestTracker mNetworkScanRequestTracker; |
| 361 | |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 362 | private static final int TYPE_ALLOCATION_CODE_LENGTH = 8; |
| 363 | private static final int MANUFACTURER_CODE_LENGTH = 8; |
| 364 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 365 | private static final int SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS = -1; |
| 366 | |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 367 | /** |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 368 | * Experiment flag to enable erase modem config on reset network, default value is false |
| 369 | */ |
| 370 | public static final String RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED = |
| 371 | "reset_network_erase_modem_config_enabled"; |
| 372 | |
| 373 | /** |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 374 | * A request object to use for transmitting data to an ICC. |
| 375 | */ |
| 376 | private static final class IccAPDUArgument { |
| 377 | public int channel, cla, command, p1, p2, p3; |
| 378 | public String data; |
| 379 | |
| 380 | public IccAPDUArgument(int channel, int cla, int command, |
| 381 | int p1, int p2, int p3, String data) { |
| 382 | this.channel = channel; |
| 383 | this.cla = cla; |
| 384 | this.command = command; |
| 385 | this.p1 = p1; |
| 386 | this.p2 = p2; |
| 387 | this.p3 = p3; |
| 388 | this.data = data; |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /** |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 393 | * A request object to use for transmitting data to an ICC. |
| 394 | */ |
| 395 | private static final class ManualNetworkSelectionArgument { |
| 396 | public OperatorInfo operatorInfo; |
| 397 | public boolean persistSelection; |
| 398 | |
| 399 | public ManualNetworkSelectionArgument(OperatorInfo operatorInfo, boolean persistSelection) { |
| 400 | this.operatorInfo = operatorInfo; |
| 401 | this.persistSelection = persistSelection; |
| 402 | } |
| 403 | } |
| 404 | |
| 405 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 406 | * A request object for use with {@link MainThreadHandler}. Requesters should wait() on the |
| 407 | * request after sending. The main thread will notify the request when it is complete. |
| 408 | */ |
| 409 | private static final class MainThreadRequest { |
| 410 | /** The argument to use for the request */ |
| 411 | public Object argument; |
| 412 | /** The result of the request that is run on the main thread */ |
| 413 | public Object result; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 414 | // The subscriber id that this request applies to. Defaults to |
| 415 | // SubscriptionManager.INVALID_SUBSCRIPTION_ID |
| 416 | public Integer subId = SubscriptionManager.INVALID_SUBSCRIPTION_ID; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 417 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 418 | // In cases where subId is unavailable, the caller needs to specify the phone. |
| 419 | public Phone phone; |
| 420 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 421 | public WorkSource workSource; |
| 422 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 423 | public MainThreadRequest(Object argument) { |
| 424 | this.argument = argument; |
| 425 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 426 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 427 | MainThreadRequest(Object argument, Phone phone, WorkSource workSource) { |
| 428 | this.argument = argument; |
| 429 | if (phone != null) { |
| 430 | this.phone = phone; |
| 431 | } |
| 432 | this.workSource = workSource; |
| 433 | } |
| 434 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 435 | MainThreadRequest(Object argument, Integer subId, WorkSource workSource) { |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 436 | this.argument = argument; |
Sanket Padawe | 56e75a3 | 2016-02-08 12:18:19 -0800 | [diff] [blame] | 437 | if (subId != null) { |
| 438 | this.subId = subId; |
| 439 | } |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 440 | this.workSource = workSource; |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 441 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 442 | } |
| 443 | |
Sailesh Nepal | cc0375f | 2013-11-13 09:15:18 -0800 | [diff] [blame] | 444 | private static final class IncomingThirdPartyCallArgs { |
| 445 | public final ComponentName component; |
| 446 | public final String callId; |
| 447 | public final String callerDisplayName; |
| 448 | |
| 449 | public IncomingThirdPartyCallArgs(ComponentName component, String callId, |
| 450 | String callerDisplayName) { |
| 451 | this.component = component; |
| 452 | this.callId = callId; |
| 453 | this.callerDisplayName = callerDisplayName; |
| 454 | } |
| 455 | } |
| 456 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 457 | /** |
| 458 | * A handler that processes messages on the main thread in the phone process. Since many |
| 459 | * of the Phone calls are not thread safe this is needed to shuttle the requests from the |
| 460 | * inbound binder threads to the main thread in the phone process. The Binder thread |
| 461 | * may provide a {@link MainThreadRequest} object in the msg.obj field that they are waiting |
| 462 | * on, which will be notified when the operation completes and will contain the result of the |
| 463 | * request. |
| 464 | * |
| 465 | * <p>If a MainThreadRequest object is provided in the msg.obj field, |
| 466 | * note that request.result must be set to something non-null for the calling thread to |
| 467 | * unblock. |
| 468 | */ |
| 469 | private final class MainThreadHandler extends Handler { |
| 470 | @Override |
| 471 | public void handleMessage(Message msg) { |
| 472 | MainThreadRequest request; |
| 473 | Message onCompleted; |
| 474 | AsyncResult ar; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 475 | UiccCard uiccCard; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 476 | IccAPDUArgument iccArgument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 477 | final Phone defaultPhone = getDefaultPhone(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 478 | |
| 479 | switch (msg.what) { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 480 | case CMD_HANDLE_USSD_REQUEST: { |
| 481 | request = (MainThreadRequest) msg.obj; |
| 482 | final Phone phone = getPhoneFromRequest(request); |
| 483 | Pair<String, ResultReceiver> ussdObject = (Pair) request.argument; |
| 484 | String ussdRequest = ussdObject.first; |
| 485 | ResultReceiver wrappedCallback = ussdObject.second; |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 486 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 487 | if (!isUssdApiAllowed(request.subId)) { |
| 488 | // Carrier does not support use of this API, return failure. |
| 489 | Rlog.w(LOG_TAG, "handleUssdRequest: carrier does not support USSD apis."); |
| 490 | UssdResponse response = new UssdResponse(ussdRequest, null); |
| 491 | Bundle returnData = new Bundle(); |
| 492 | returnData.putParcelable(TelephonyManager.USSD_RESPONSE, response); |
| 493 | wrappedCallback.send(TelephonyManager.USSD_RETURN_FAILURE, returnData); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 494 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 495 | request.result = true; |
| 496 | notifyRequester(request); |
| 497 | return; |
| 498 | } |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 499 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 500 | try { |
| 501 | request.result = phone != null |
| 502 | ? phone.handleUssdRequest(ussdRequest, wrappedCallback) : false; |
| 503 | } catch (CallStateException cse) { |
| 504 | request.result = false; |
| 505 | } |
| 506 | // Wake up the requesting thread |
| 507 | notifyRequester(request); |
| 508 | break; |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 509 | } |
| 510 | |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 511 | case CMD_HANDLE_PIN_MMI: { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 512 | request = (MainThreadRequest) msg.obj; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 513 | final Phone phone = getPhoneFromRequest(request); |
| 514 | request.result = phone != null ? |
| 515 | getPhoneFromRequest(request).handlePinMmi((String) request.argument) |
| 516 | : false; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 517 | // Wake up the requesting thread |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 518 | notifyRequester(request); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 519 | break; |
Yorke Lee | 716f67e | 2015-06-17 15:39:16 -0700 | [diff] [blame] | 520 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 521 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 522 | case CMD_TRANSMIT_APDU_LOGICAL_CHANNEL: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 523 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 524 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 525 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 526 | if (uiccCard == null) { |
| 527 | loge("iccTransmitApduLogicalChannel: No UICC"); |
| 528 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 529 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 530 | } else { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 531 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE, |
| 532 | request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 533 | uiccCard.iccTransmitApduLogicalChannel( |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 534 | iccArgument.channel, iccArgument.cla, iccArgument.command, |
| 535 | iccArgument.p1, iccArgument.p2, iccArgument.p3, iccArgument.data, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 536 | onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 537 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 538 | break; |
| 539 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 540 | case EVENT_TRANSMIT_APDU_LOGICAL_CHANNEL_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 541 | ar = (AsyncResult) msg.obj; |
| 542 | request = (MainThreadRequest) ar.userObj; |
| 543 | if (ar.exception == null && ar.result != null) { |
| 544 | request.result = ar.result; |
| 545 | } else { |
| 546 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 547 | if (ar.result == null) { |
| 548 | loge("iccTransmitApduLogicalChannel: Empty response"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 549 | } else if (ar.exception instanceof CommandException) { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 550 | loge("iccTransmitApduLogicalChannel: CommandException: " + |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 551 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 552 | } else { |
| 553 | loge("iccTransmitApduLogicalChannel: Unknown exception"); |
| 554 | } |
| 555 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 556 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 557 | break; |
| 558 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 559 | case CMD_TRANSMIT_APDU_BASIC_CHANNEL: |
| 560 | request = (MainThreadRequest) msg.obj; |
| 561 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 562 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 563 | if (uiccCard == null) { |
| 564 | loge("iccTransmitApduBasicChannel: No UICC"); |
| 565 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 566 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 567 | } else { |
| 568 | onCompleted = obtainMessage(EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE, |
| 569 | request); |
| 570 | uiccCard.iccTransmitApduBasicChannel( |
| 571 | iccArgument.cla, iccArgument.command, iccArgument.p1, iccArgument.p2, |
| 572 | iccArgument.p3, iccArgument.data, onCompleted); |
| 573 | } |
| 574 | break; |
| 575 | |
| 576 | case EVENT_TRANSMIT_APDU_BASIC_CHANNEL_DONE: |
| 577 | ar = (AsyncResult) msg.obj; |
| 578 | request = (MainThreadRequest) ar.userObj; |
| 579 | if (ar.exception == null && ar.result != null) { |
| 580 | request.result = ar.result; |
| 581 | } else { |
| 582 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 583 | if (ar.result == null) { |
| 584 | loge("iccTransmitApduBasicChannel: Empty response"); |
| 585 | } else if (ar.exception instanceof CommandException) { |
| 586 | loge("iccTransmitApduBasicChannel: CommandException: " + |
| 587 | ar.exception); |
| 588 | } else { |
| 589 | loge("iccTransmitApduBasicChannel: Unknown exception"); |
| 590 | } |
| 591 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 592 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 593 | break; |
| 594 | |
| 595 | case CMD_EXCHANGE_SIM_IO: |
| 596 | request = (MainThreadRequest) msg.obj; |
| 597 | iccArgument = (IccAPDUArgument) request.argument; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 598 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 599 | if (uiccCard == null) { |
| 600 | loge("iccExchangeSimIO: No UICC"); |
| 601 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 602 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 603 | } else { |
| 604 | onCompleted = obtainMessage(EVENT_EXCHANGE_SIM_IO_DONE, |
| 605 | request); |
| 606 | uiccCard.iccExchangeSimIO(iccArgument.cla, /* fileID */ |
| 607 | iccArgument.command, iccArgument.p1, iccArgument.p2, iccArgument.p3, |
| 608 | iccArgument.data, onCompleted); |
| 609 | } |
| 610 | break; |
| 611 | |
| 612 | case EVENT_EXCHANGE_SIM_IO_DONE: |
| 613 | ar = (AsyncResult) msg.obj; |
| 614 | request = (MainThreadRequest) ar.userObj; |
| 615 | if (ar.exception == null && ar.result != null) { |
| 616 | request.result = ar.result; |
| 617 | } else { |
| 618 | request.result = new IccIoResult(0x6f, 0, (byte[])null); |
| 619 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 620 | notifyRequester(request); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 621 | break; |
| 622 | |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 623 | case CMD_SEND_ENVELOPE: |
| 624 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 625 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 626 | if (uiccCard == null) { |
| 627 | loge("sendEnvelopeWithStatus: No UICC"); |
| 628 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 629 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 630 | } else { |
| 631 | onCompleted = obtainMessage(EVENT_SEND_ENVELOPE_DONE, request); |
| 632 | uiccCard.sendEnvelopeWithStatus((String)request.argument, onCompleted); |
| 633 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 634 | break; |
| 635 | |
| 636 | case EVENT_SEND_ENVELOPE_DONE: |
| 637 | ar = (AsyncResult) msg.obj; |
| 638 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 639 | if (ar.exception == null && ar.result != null) { |
| 640 | request.result = ar.result; |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 641 | } else { |
Shishir Agrawal | 9f9877d | 2014-03-14 09:36:27 -0700 | [diff] [blame] | 642 | request.result = new IccIoResult(0x6F, 0, (byte[])null); |
| 643 | if (ar.result == null) { |
| 644 | loge("sendEnvelopeWithStatus: Empty response"); |
| 645 | } else if (ar.exception instanceof CommandException) { |
| 646 | loge("sendEnvelopeWithStatus: CommandException: " + |
| 647 | ar.exception); |
| 648 | } else { |
| 649 | loge("sendEnvelopeWithStatus: exception:" + ar.exception); |
| 650 | } |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 651 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 652 | notifyRequester(request); |
Derek Tan | 4d5e5c1 | 2014-02-04 11:54:58 -0800 | [diff] [blame] | 653 | break; |
| 654 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 655 | case CMD_OPEN_CHANNEL: |
| 656 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 657 | uiccCard = getUiccCardFromRequest(request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 658 | Pair<String, Integer> openChannelArgs = (Pair<String, Integer>) request.argument; |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 659 | if (uiccCard == null) { |
| 660 | loge("iccOpenLogicalChannel: No UICC"); |
Shishir Agrawal | fc0492a | 2016-02-17 11:15:33 -0800 | [diff] [blame] | 661 | request.result = new IccOpenLogicalChannelResponse(-1, |
| 662 | IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE, null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 663 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 664 | } else { |
| 665 | onCompleted = obtainMessage(EVENT_OPEN_CHANNEL_DONE, request); |
Ajay Nambi | d7454d3 | 2015-12-03 13:50:00 -0800 | [diff] [blame] | 666 | uiccCard.iccOpenLogicalChannel(openChannelArgs.first, |
| 667 | openChannelArgs.second, onCompleted); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 668 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 669 | break; |
| 670 | |
| 671 | case EVENT_OPEN_CHANNEL_DONE: |
| 672 | ar = (AsyncResult) msg.obj; |
| 673 | request = (MainThreadRequest) ar.userObj; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 674 | IccOpenLogicalChannelResponse openChannelResp; |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 675 | if (ar.exception == null && ar.result != null) { |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 676 | int[] result = (int[]) ar.result; |
| 677 | int channelId = result[0]; |
| 678 | byte[] selectResponse = null; |
| 679 | if (result.length > 1) { |
| 680 | selectResponse = new byte[result.length - 1]; |
| 681 | for (int i = 1; i < result.length; ++i) { |
| 682 | selectResponse[i - 1] = (byte) result[i]; |
| 683 | } |
| 684 | } |
| 685 | openChannelResp = new IccOpenLogicalChannelResponse(channelId, |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 686 | IccOpenLogicalChannelResponse.STATUS_NO_ERROR, selectResponse); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 687 | } else { |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 688 | if (ar.result == null) { |
| 689 | loge("iccOpenLogicalChannel: Empty response"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 690 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 691 | if (ar.exception != null) { |
| 692 | loge("iccOpenLogicalChannel: Exception: " + ar.exception); |
| 693 | } |
| 694 | |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 695 | int errorCode = IccOpenLogicalChannelResponse.STATUS_UNKNOWN_ERROR; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 696 | if (ar.exception instanceof CommandException) { |
| 697 | CommandException.Error error = |
| 698 | ((CommandException) (ar.exception)).getCommandError(); |
| 699 | if (error == CommandException.Error.MISSING_RESOURCE) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 700 | errorCode = IccOpenLogicalChannelResponse.STATUS_MISSING_RESOURCE; |
Junda Liu | a754ba1 | 2015-05-20 01:17:52 -0700 | [diff] [blame] | 701 | } else if (error == CommandException.Error.NO_SUCH_ELEMENT) { |
Shishir Agrawal | 527e8bf | 2014-08-25 08:54:56 -0700 | [diff] [blame] | 702 | errorCode = IccOpenLogicalChannelResponse.STATUS_NO_SUCH_ELEMENT; |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 703 | } |
| 704 | } |
| 705 | openChannelResp = new IccOpenLogicalChannelResponse( |
| 706 | IccOpenLogicalChannelResponse.INVALID_CHANNEL, errorCode, null); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 707 | } |
Shishir Agrawal | 82c8a46 | 2014-07-31 18:13:17 -0700 | [diff] [blame] | 708 | request.result = openChannelResp; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 709 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 710 | break; |
| 711 | |
| 712 | case CMD_CLOSE_CHANNEL: |
| 713 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 714 | uiccCard = getUiccCardFromRequest(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 715 | if (uiccCard == null) { |
| 716 | loge("iccCloseLogicalChannel: No UICC"); |
Yoshiaki Naka | 2e29d82 | 2016-09-02 19:27:39 +0900 | [diff] [blame] | 717 | request.result = false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 718 | notifyRequester(request); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 719 | } else { |
| 720 | onCompleted = obtainMessage(EVENT_CLOSE_CHANNEL_DONE, request); |
| 721 | uiccCard.iccCloseLogicalChannel((Integer) request.argument, onCompleted); |
| 722 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 723 | break; |
| 724 | |
| 725 | case EVENT_CLOSE_CHANNEL_DONE: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 726 | handleNullReturnEvent(msg, "iccCloseLogicalChannel"); |
| 727 | break; |
| 728 | |
| 729 | case CMD_NV_READ_ITEM: |
| 730 | request = (MainThreadRequest) msg.obj; |
| 731 | onCompleted = obtainMessage(EVENT_NV_READ_ITEM_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 732 | defaultPhone.nvReadItem((Integer) request.argument, onCompleted, |
| 733 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 734 | break; |
| 735 | |
| 736 | case EVENT_NV_READ_ITEM_DONE: |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 737 | ar = (AsyncResult) msg.obj; |
| 738 | request = (MainThreadRequest) ar.userObj; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 739 | if (ar.exception == null && ar.result != null) { |
| 740 | request.result = ar.result; // String |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 741 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 742 | request.result = ""; |
| 743 | if (ar.result == null) { |
| 744 | loge("nvReadItem: Empty response"); |
| 745 | } else if (ar.exception instanceof CommandException) { |
| 746 | loge("nvReadItem: CommandException: " + |
| 747 | ar.exception); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 748 | } else { |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 749 | loge("nvReadItem: Unknown exception"); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 750 | } |
| 751 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 752 | notifyRequester(request); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 753 | break; |
| 754 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 755 | case CMD_NV_WRITE_ITEM: |
| 756 | request = (MainThreadRequest) msg.obj; |
| 757 | onCompleted = obtainMessage(EVENT_NV_WRITE_ITEM_DONE, request); |
| 758 | Pair<Integer, String> idValue = (Pair<Integer, String>) request.argument; |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 759 | defaultPhone.nvWriteItem(idValue.first, idValue.second, onCompleted, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 760 | request.workSource); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 761 | break; |
| 762 | |
| 763 | case EVENT_NV_WRITE_ITEM_DONE: |
| 764 | handleNullReturnEvent(msg, "nvWriteItem"); |
| 765 | break; |
| 766 | |
| 767 | case CMD_NV_WRITE_CDMA_PRL: |
| 768 | request = (MainThreadRequest) msg.obj; |
| 769 | onCompleted = obtainMessage(EVENT_NV_WRITE_CDMA_PRL_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 770 | defaultPhone.nvWriteCdmaPrl((byte[]) request.argument, onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 771 | break; |
| 772 | |
| 773 | case EVENT_NV_WRITE_CDMA_PRL_DONE: |
| 774 | handleNullReturnEvent(msg, "nvWriteCdmaPrl"); |
| 775 | break; |
| 776 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 777 | case CMD_RESET_MODEM_CONFIG: |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 778 | request = (MainThreadRequest) msg.obj; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 779 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 780 | defaultPhone.resetModemConfig(onCompleted); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 781 | break; |
| 782 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 783 | case EVENT_RESET_MODEM_CONFIG_DONE: |
| 784 | handleNullReturnEvent(msg, "resetModemConfig"); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 785 | break; |
| 786 | |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 787 | case CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED: { |
| 788 | request = (MainThreadRequest) msg.obj; |
| 789 | onCompleted = obtainMessage(EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE, |
| 790 | request); |
| 791 | Phone phone = getPhoneFromRequest(request); |
| 792 | if (phone != null) { |
| 793 | phone.isNrDualConnectivityEnabled(onCompleted, request.workSource); |
| 794 | } else { |
| 795 | loge("isNRDualConnectivityEnabled: No phone object"); |
| 796 | request.result = false; |
| 797 | notifyRequester(request); |
| 798 | } |
| 799 | break; |
| 800 | } |
| 801 | |
| 802 | case EVENT_IS_NR_DUAL_CONNECTIVITY_ENABLED_DONE: |
| 803 | ar = (AsyncResult) msg.obj; |
| 804 | request = (MainThreadRequest) ar.userObj; |
| 805 | if (ar.exception == null && ar.result != null) { |
| 806 | request.result = ar.result; |
| 807 | } else { |
| 808 | // request.result must be set to something non-null |
| 809 | // for the calling thread to unblock |
| 810 | if (request.result != null) { |
| 811 | request.result = ar.result; |
| 812 | } else { |
| 813 | request.result = false; |
| 814 | } |
| 815 | if (ar.result == null) { |
| 816 | loge("isNRDualConnectivityEnabled: Empty response"); |
| 817 | } else if (ar.exception instanceof CommandException) { |
| 818 | loge("isNRDualConnectivityEnabled: CommandException: " |
| 819 | + ar.exception); |
| 820 | } else { |
| 821 | loge("isNRDualConnectivityEnabled: Unknown exception"); |
| 822 | } |
| 823 | } |
| 824 | notifyRequester(request); |
| 825 | break; |
| 826 | |
| 827 | case CMD_ENABLE_NR_DUAL_CONNECTIVITY: { |
| 828 | request = (MainThreadRequest) msg.obj; |
| 829 | onCompleted = obtainMessage(EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE, request); |
| 830 | Phone phone = getPhoneFromRequest(request); |
| 831 | if (phone != null) { |
| 832 | phone.setNrDualConnectivityState((int) request.argument, onCompleted, |
| 833 | request.workSource); |
| 834 | } else { |
| 835 | loge("enableNrDualConnectivity: No phone object"); |
| 836 | request.result = |
| 837 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 838 | notifyRequester(request); |
| 839 | } |
| 840 | break; |
| 841 | } |
| 842 | |
| 843 | case EVENT_ENABLE_NR_DUAL_CONNECTIVITY_DONE: { |
| 844 | ar = (AsyncResult) msg.obj; |
| 845 | request = (MainThreadRequest) ar.userObj; |
| 846 | if (ar.exception == null) { |
| 847 | request.result = |
| 848 | TelephonyManager.ENABLE_NR_DUAL_CONNECTIVITY_SUCCESS; |
| 849 | } else { |
| 850 | request.result = |
| 851 | TelephonyManager |
| 852 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_ERROR; |
| 853 | if (ar.exception instanceof CommandException) { |
| 854 | CommandException.Error error = |
| 855 | ((CommandException) (ar.exception)).getCommandError(); |
| 856 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 857 | request.result = |
| 858 | TelephonyManager |
| 859 | .ENABLE_NR_DUAL_CONNECTIVITY_RADIO_NOT_AVAILABLE; |
| 860 | } |
| 861 | loge("enableNrDualConnectivity" + ": CommandException: " |
| 862 | + ar.exception); |
| 863 | } else { |
| 864 | loge("enableNrDualConnectivity" + ": Unknown exception"); |
| 865 | } |
| 866 | } |
| 867 | notifyRequester(request); |
| 868 | break; |
| 869 | } |
| 870 | |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 871 | case CMD_GET_PREFERRED_NETWORK_TYPE: |
| 872 | request = (MainThreadRequest) msg.obj; |
| 873 | onCompleted = obtainMessage(EVENT_GET_PREFERRED_NETWORK_TYPE_DONE, request); |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 874 | getPhoneFromRequest(request).getPreferredNetworkType(onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 875 | break; |
| 876 | |
| 877 | case EVENT_GET_PREFERRED_NETWORK_TYPE_DONE: |
| 878 | ar = (AsyncResult) msg.obj; |
| 879 | request = (MainThreadRequest) ar.userObj; |
| 880 | if (ar.exception == null && ar.result != null) { |
| 881 | request.result = ar.result; // Integer |
| 882 | } else { |
Nazish Tabassum | e8ba43a | 2020-07-28 14:49:25 +0530 | [diff] [blame] | 883 | // request.result must be set to something non-null |
| 884 | // for the calling thread to unblock |
| 885 | request.result = new int[]{-1}; |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 886 | if (ar.result == null) { |
| 887 | loge("getPreferredNetworkType: Empty response"); |
| 888 | } else if (ar.exception instanceof CommandException) { |
| 889 | loge("getPreferredNetworkType: CommandException: " + |
| 890 | ar.exception); |
| 891 | } else { |
| 892 | loge("getPreferredNetworkType: Unknown exception"); |
| 893 | } |
| 894 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 895 | notifyRequester(request); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 896 | break; |
| 897 | |
| 898 | case CMD_SET_PREFERRED_NETWORK_TYPE: |
| 899 | request = (MainThreadRequest) msg.obj; |
| 900 | onCompleted = obtainMessage(EVENT_SET_PREFERRED_NETWORK_TYPE_DONE, request); |
| 901 | int networkType = (Integer) request.argument; |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 902 | getPhoneFromRequest(request).setPreferredNetworkType(networkType, onCompleted); |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 903 | break; |
| 904 | |
| 905 | case EVENT_SET_PREFERRED_NETWORK_TYPE_DONE: |
| 906 | handleNullReturnEvent(msg, "setPreferredNetworkType"); |
| 907 | break; |
| 908 | |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 909 | case CMD_INVOKE_OEM_RIL_REQUEST_RAW: |
| 910 | request = (MainThreadRequest)msg.obj; |
| 911 | onCompleted = obtainMessage(EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 912 | defaultPhone.invokeOemRilRequestRaw((byte[]) request.argument, onCompleted); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 913 | break; |
| 914 | |
| 915 | case EVENT_INVOKE_OEM_RIL_REQUEST_RAW_DONE: |
| 916 | ar = (AsyncResult)msg.obj; |
| 917 | request = (MainThreadRequest)ar.userObj; |
| 918 | request.result = ar; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 919 | notifyRequester(request); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 920 | break; |
| 921 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 922 | case CMD_SET_VOICEMAIL_NUMBER: |
| 923 | request = (MainThreadRequest) msg.obj; |
| 924 | onCompleted = obtainMessage(EVENT_SET_VOICEMAIL_NUMBER_DONE, request); |
| 925 | Pair<String, String> tagNum = (Pair<String, String>) request.argument; |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 926 | getPhoneFromRequest(request).setVoiceMailNumber(tagNum.first, tagNum.second, |
| 927 | onCompleted); |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 928 | break; |
| 929 | |
| 930 | case EVENT_SET_VOICEMAIL_NUMBER_DONE: |
| 931 | handleNullReturnEvent(msg, "setVoicemailNumber"); |
| 932 | break; |
| 933 | |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 934 | case CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC: |
| 935 | request = (MainThreadRequest) msg.obj; |
| 936 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE, |
| 937 | request); |
| 938 | getPhoneFromRequest(request).setNetworkSelectionModeAutomatic(onCompleted); |
| 939 | break; |
| 940 | |
| 941 | case EVENT_SET_NETWORK_SELECTION_MODE_AUTOMATIC_DONE: |
| 942 | handleNullReturnEvent(msg, "setNetworkSelectionModeAutomatic"); |
| 943 | break; |
| 944 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 945 | case CMD_PERFORM_NETWORK_SCAN: |
| 946 | request = (MainThreadRequest) msg.obj; |
| 947 | onCompleted = obtainMessage(EVENT_PERFORM_NETWORK_SCAN_DONE, request); |
| 948 | getPhoneFromRequest(request).getAvailableNetworks(onCompleted); |
| 949 | break; |
| 950 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 951 | case CMD_GET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 952 | request = (MainThreadRequest) msg.obj; |
| 953 | onCompleted = obtainMessage(EVENT_GET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 954 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> args = |
| 955 | (Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 956 | request.argument; |
| 957 | int callForwardingReason = args.first; |
| 958 | request.phone.getCallForwardingOption(callForwardingReason, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 959 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 960 | } |
| 961 | case EVENT_GET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 962 | ar = (AsyncResult) msg.obj; |
| 963 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 964 | TelephonyManager.CallForwardingInfoCallback callback = |
| 965 | ((Pair<Integer, TelephonyManager.CallForwardingInfoCallback>) |
| 966 | request.argument).second; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 967 | if (ar.exception == null && ar.result != null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 968 | CallForwardingInfo callForwardingInfo = null; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 969 | CallForwardInfo[] callForwardInfos = (CallForwardInfo[]) ar.result; |
| 970 | for (CallForwardInfo callForwardInfo : callForwardInfos) { |
| 971 | // Service Class is a bit mask per 3gpp 27.007. Search for |
| 972 | // any service for voice call. |
| 973 | if ((callForwardInfo.serviceClass |
| 974 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 975 | callForwardingInfo = new CallForwardingInfo(true, |
| 976 | callForwardInfo.reason, |
| 977 | callForwardInfo.number, |
| 978 | callForwardInfo.timeSeconds); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 979 | break; |
| 980 | } |
| 981 | } |
| 982 | // Didn't find a call forward info for voice call. |
| 983 | if (callForwardingInfo == null) { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 984 | callForwardingInfo = new CallForwardingInfo(false /* enabled */, |
| 985 | 0 /* reason */, null /* number */, 0 /* timeout */); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 986 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 987 | callback.onCallForwardingInfoAvailable(callForwardingInfo); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 988 | } else { |
| 989 | if (ar.result == null) { |
| 990 | loge("EVENT_GET_CALL_FORWARDING_DONE: Empty response"); |
| 991 | } |
| 992 | if (ar.exception != null) { |
| 993 | loge("EVENT_GET_CALL_FORWARDING_DONE: Exception: " + ar.exception); |
| 994 | } |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 995 | int errorCode = TelephonyManager |
| 996 | .CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 997 | if (ar.exception instanceof CommandException) { |
| 998 | CommandException.Error error = |
| 999 | ((CommandException) (ar.exception)).getCommandError(); |
| 1000 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1001 | errorCode = TelephonyManager |
| 1002 | .CallForwardingInfoCallback.RESULT_ERROR_FDN_CHECK_FAILURE; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1003 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1004 | errorCode = TelephonyManager |
| 1005 | .CallForwardingInfoCallback.RESULT_ERROR_NOT_SUPPORTED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1006 | } |
| 1007 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1008 | callback.onError(errorCode); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1009 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1010 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1011 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1012 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1013 | case CMD_SET_CALL_FORWARDING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1014 | request = (MainThreadRequest) msg.obj; |
| 1015 | onCompleted = obtainMessage(EVENT_SET_CALL_FORWARDING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1016 | request = (MainThreadRequest) msg.obj; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1017 | CallForwardingInfo callForwardingInfoToSet = |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1018 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1019 | request.argument).first; |
| 1020 | request.phone.setCallForwardingOption( |
| 1021 | callForwardingInfoToSet.isEnabled() |
| 1022 | ? CommandsInterface.CF_ACTION_ENABLE |
| 1023 | : CommandsInterface.CF_ACTION_DISABLE, |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1024 | callForwardingInfoToSet.getReason(), |
| 1025 | callForwardingInfoToSet.getNumber(), |
| 1026 | callForwardingInfoToSet.getTimeoutSeconds(), onCompleted); |
| 1027 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1028 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1029 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1030 | case EVENT_SET_CALL_FORWARDING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1031 | ar = (AsyncResult) msg.obj; |
| 1032 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1033 | Consumer<Integer> callback = |
| 1034 | ((Pair<CallForwardingInfo, Consumer<Integer>>) |
| 1035 | request.argument).second; |
| 1036 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1037 | loge("setCallForwarding exception: " + ar.exception); |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1038 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1039 | .RESULT_ERROR_UNKNOWN; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1040 | if (ar.exception instanceof CommandException) { |
| 1041 | CommandException.Error error = |
| 1042 | ((CommandException) (ar.exception)).getCommandError(); |
| 1043 | if (error == CommandException.Error.FDN_CHECK_FAILURE) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1044 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1045 | .RESULT_ERROR_FDN_CHECK_FAILURE; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1046 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1047 | errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1048 | .RESULT_ERROR_NOT_SUPPORTED; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1049 | } |
| 1050 | } |
| 1051 | callback.accept(errorCode); |
| 1052 | } else { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 1053 | callback.accept(TelephonyManager.CallForwardingInfoCallback.RESULT_SUCCESS); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1054 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1055 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1056 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1057 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1058 | case CMD_GET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1059 | request = (MainThreadRequest) msg.obj; |
| 1060 | onCompleted = obtainMessage(EVENT_GET_CALL_WAITING_DONE, request); |
| 1061 | getPhoneFromRequest(request).getCallWaiting(onCompleted); |
| 1062 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1063 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1064 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1065 | case EVENT_GET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1066 | ar = (AsyncResult) msg.obj; |
| 1067 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1068 | Consumer<Integer> callback = (Consumer<Integer>) request.argument; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1069 | int callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR; |
| 1070 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1071 | int[] callForwardResults = (int[]) ar.result; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1072 | // Service Class is a bit mask per 3gpp 27.007. |
| 1073 | // Search for any service for voice call. |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1074 | if (callForwardResults.length > 1 |
| 1075 | && ((callForwardResults[1] |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1076 | & CommandsInterface.SERVICE_CLASS_VOICE) > 0)) { |
Shuo Qian | d6a0dba | 2020-02-18 18:13:49 -0800 | [diff] [blame] | 1077 | callForwardingStatus = callForwardResults[0] == 0 |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1078 | ? TelephonyManager.CALL_WAITING_STATUS_DISABLED |
| 1079 | : TelephonyManager.CALL_WAITING_STATUS_ENABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1080 | } else { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1081 | callForwardingStatus = TelephonyManager.CALL_WAITING_STATUS_DISABLED; |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1082 | } |
| 1083 | } else { |
| 1084 | if (ar.result == null) { |
| 1085 | loge("EVENT_GET_CALL_WAITING_DONE: Empty response"); |
| 1086 | } |
| 1087 | if (ar.exception != null) { |
| 1088 | loge("EVENT_GET_CALL_WAITING_DONE: Exception: " + ar.exception); |
| 1089 | } |
| 1090 | if (ar.exception instanceof CommandException) { |
| 1091 | CommandException.Error error = |
| 1092 | ((CommandException) (ar.exception)).getCommandError(); |
| 1093 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1094 | callForwardingStatus = |
| 1095 | TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED; |
| 1096 | } |
| 1097 | } |
| 1098 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1099 | callback.accept(callForwardingStatus); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1100 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1101 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1102 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1103 | case CMD_SET_CALL_WAITING: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1104 | request = (MainThreadRequest) msg.obj; |
| 1105 | onCompleted = obtainMessage(EVENT_SET_CALL_WAITING_DONE, request); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1106 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1107 | getPhoneFromRequest(request).setCallWaiting(enable, onCompleted); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1108 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1109 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1110 | |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1111 | case EVENT_SET_CALL_WAITING_DONE: { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1112 | ar = (AsyncResult) msg.obj; |
| 1113 | request = (MainThreadRequest) ar.userObj; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1114 | boolean enable = ((Pair<Boolean, Consumer<Integer>>) request.argument).first; |
| 1115 | Consumer<Integer> callback = |
| 1116 | ((Pair<Boolean, Consumer<Integer>>) request.argument).second; |
| 1117 | if (ar.exception != null) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1118 | loge("setCallWaiting exception: " + ar.exception); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1119 | if (ar.exception instanceof CommandException) { |
| 1120 | CommandException.Error error = |
| 1121 | ((CommandException) (ar.exception)).getCommandError(); |
| 1122 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1123 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_NOT_SUPPORTED); |
| 1124 | } else { |
| 1125 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1126 | } |
| 1127 | } else { |
| 1128 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 1129 | } |
| 1130 | } else { |
| 1131 | callback.accept(enable ? TelephonyManager.CALL_WAITING_STATUS_ENABLED |
| 1132 | : TelephonyManager.CALL_WAITING_STATUS_DISABLED); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1133 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1134 | break; |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 1135 | } |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 1136 | |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1137 | case EVENT_PERFORM_NETWORK_SCAN_DONE: |
| 1138 | ar = (AsyncResult) msg.obj; |
| 1139 | request = (MainThreadRequest) ar.userObj; |
| 1140 | CellNetworkScanResult cellScanResult; |
| 1141 | if (ar.exception == null && ar.result != null) { |
| 1142 | cellScanResult = new CellNetworkScanResult( |
| 1143 | CellNetworkScanResult.STATUS_SUCCESS, |
| 1144 | (List<OperatorInfo>) ar.result); |
| 1145 | } else { |
| 1146 | if (ar.result == null) { |
| 1147 | loge("getCellNetworkScanResults: Empty response"); |
| 1148 | } |
| 1149 | if (ar.exception != null) { |
| 1150 | loge("getCellNetworkScanResults: Exception: " + ar.exception); |
| 1151 | } |
| 1152 | int errorCode = CellNetworkScanResult.STATUS_UNKNOWN_ERROR; |
| 1153 | if (ar.exception instanceof CommandException) { |
| 1154 | CommandException.Error error = |
| 1155 | ((CommandException) (ar.exception)).getCommandError(); |
| 1156 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1157 | errorCode = CellNetworkScanResult.STATUS_RADIO_NOT_AVAILABLE; |
| 1158 | } else if (error == CommandException.Error.GENERIC_FAILURE) { |
| 1159 | errorCode = CellNetworkScanResult.STATUS_RADIO_GENERIC_FAILURE; |
| 1160 | } |
| 1161 | } |
| 1162 | cellScanResult = new CellNetworkScanResult(errorCode, null); |
| 1163 | } |
| 1164 | request.result = cellScanResult; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1165 | notifyRequester(request); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1166 | break; |
| 1167 | |
| 1168 | case CMD_SET_NETWORK_SELECTION_MODE_MANUAL: |
| 1169 | request = (MainThreadRequest) msg.obj; |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1170 | ManualNetworkSelectionArgument selArg = |
| 1171 | (ManualNetworkSelectionArgument) request.argument; |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1172 | onCompleted = obtainMessage(EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE, |
| 1173 | request); |
Shishir Agrawal | 77ba317 | 2015-09-10 14:50:19 -0700 | [diff] [blame] | 1174 | getPhoneFromRequest(request).selectNetworkManually(selArg.operatorInfo, |
| 1175 | selArg.persistSelection, onCompleted); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1176 | break; |
| 1177 | |
| 1178 | case EVENT_SET_NETWORK_SELECTION_MODE_MANUAL_DONE: |
Pengquan Meng | e3d01e2 | 2018-09-20 15:25:35 -0700 | [diff] [blame] | 1179 | ar = (AsyncResult) msg.obj; |
| 1180 | request = (MainThreadRequest) ar.userObj; |
| 1181 | if (ar.exception == null) { |
| 1182 | request.result = true; |
| 1183 | } else { |
| 1184 | request.result = false; |
| 1185 | loge("setNetworkSelectionModeManual " + ar.exception); |
| 1186 | } |
| 1187 | notifyRequester(request); |
| 1188 | mApp.onNetworkSelectionChanged(request.subId); |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 1189 | break; |
| 1190 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1191 | case CMD_GET_MODEM_ACTIVITY_INFO: |
| 1192 | request = (MainThreadRequest) msg.obj; |
| 1193 | onCompleted = obtainMessage(EVENT_GET_MODEM_ACTIVITY_INFO_DONE, request); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1194 | if (defaultPhone != null) { |
| 1195 | defaultPhone.getModemActivityInfo(onCompleted, request.workSource); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1196 | } else { |
| 1197 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1198 | Bundle bundle = new Bundle(); |
| 1199 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1200 | new ModemActivityInfo(0, 0, 0, |
| 1201 | new int[ModemActivityInfo.getNumTxPowerLevels()], 0)); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1202 | result.send(0, bundle); |
James Mattis | ab94770 | 2019-04-03 14:18:34 -0700 | [diff] [blame] | 1203 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1204 | break; |
| 1205 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1206 | case EVENT_GET_MODEM_ACTIVITY_INFO_DONE: { |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1207 | ar = (AsyncResult) msg.obj; |
| 1208 | request = (MainThreadRequest) ar.userObj; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1209 | ResultReceiver result = (ResultReceiver) request.argument; |
| 1210 | |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1211 | ModemActivityInfo ret = null; |
| 1212 | int error = 0; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1213 | if (ar.exception == null && ar.result != null) { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1214 | // Update the last modem activity info and the result of the request. |
| 1215 | ModemActivityInfo info = (ModemActivityInfo) ar.result; |
| 1216 | if (isModemActivityInfoValid(info)) { |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1217 | int[] mergedTxTimeMs = new int[ModemActivityInfo.getNumTxPowerLevels()]; |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1218 | int[] txTimeMs = info.getTransmitTimeMillis(); |
| 1219 | int[] lastModemTxTimeMs = mLastModemActivityInfo |
| 1220 | .getTransmitTimeMillis(); |
| 1221 | for (int i = 0; i < mergedTxTimeMs.length; i++) { |
| 1222 | mergedTxTimeMs[i] = txTimeMs[i] + lastModemTxTimeMs[i]; |
| 1223 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1224 | mLastModemActivityInfo.setTimestamp(info.getTimestampMillis()); |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1225 | mLastModemActivityInfo.setSleepTimeMillis(info.getSleepTimeMillis() |
| 1226 | + mLastModemActivityInfo.getSleepTimeMillis()); |
| 1227 | mLastModemActivityInfo.setIdleTimeMillis(info.getIdleTimeMillis() |
| 1228 | + mLastModemActivityInfo.getIdleTimeMillis()); |
| 1229 | mLastModemActivityInfo.setTransmitTimeMillis(mergedTxTimeMs); |
| 1230 | mLastModemActivityInfo.setReceiveTimeMillis( |
| 1231 | info.getReceiveTimeMillis() |
| 1232 | + mLastModemActivityInfo.getReceiveTimeMillis()); |
| 1233 | } |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 1234 | ret = new ModemActivityInfo(mLastModemActivityInfo.getTimestampMillis(), |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1235 | mLastModemActivityInfo.getSleepTimeMillis(), |
| 1236 | mLastModemActivityInfo.getIdleTimeMillis(), |
| 1237 | mLastModemActivityInfo.getTransmitTimeMillis(), |
| 1238 | mLastModemActivityInfo.getReceiveTimeMillis()); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1239 | } else { |
| 1240 | if (ar.result == null) { |
| 1241 | loge("queryModemActivityInfo: Empty response"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1242 | error = TelephonyManager.ModemActivityInfoException |
| 1243 | .ERROR_INVALID_INFO_RECEIVED; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1244 | } else if (ar.exception instanceof CommandException) { |
| 1245 | loge("queryModemActivityInfo: CommandException: " + |
| 1246 | ar.exception); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1247 | error = TelephonyManager.ModemActivityInfoException |
| 1248 | .ERROR_MODEM_RESPONSE_ERROR; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1249 | } else { |
| 1250 | loge("queryModemActivityInfo: Unknown exception"); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1251 | error = TelephonyManager.ModemActivityInfoException |
| 1252 | .ERROR_UNKNOWN; |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1253 | } |
| 1254 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1255 | Bundle bundle = new Bundle(); |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1256 | if (ret != null) { |
| 1257 | bundle.putParcelable(TelephonyManager.MODEM_ACTIVITY_RESULT_KEY, ret); |
| 1258 | } else { |
| 1259 | bundle.putInt(TelephonyManager.EXCEPTION_RESULT_KEY, error); |
| 1260 | } |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 1261 | result.send(0, bundle); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1262 | notifyRequester(request); |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1263 | break; |
Hall Liu | d0f208c | 2020-10-14 16:54:44 -0700 | [diff] [blame] | 1264 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 1265 | |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1266 | case CMD_SET_ALLOWED_CARRIERS: |
| 1267 | request = (MainThreadRequest) msg.obj; |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1268 | CarrierRestrictionRules argument = |
| 1269 | (CarrierRestrictionRules) request.argument; |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1270 | onCompleted = obtainMessage(EVENT_SET_ALLOWED_CARRIERS_DONE, request); |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1271 | defaultPhone.setAllowedCarriers(argument, onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1272 | break; |
| 1273 | |
| 1274 | case EVENT_SET_ALLOWED_CARRIERS_DONE: |
| 1275 | ar = (AsyncResult) msg.obj; |
| 1276 | request = (MainThreadRequest) ar.userObj; |
| 1277 | if (ar.exception == null && ar.result != null) { |
| 1278 | request.result = ar.result; |
| 1279 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1280 | request.result = TelephonyManager.SET_CARRIER_RESTRICTION_ERROR; |
| 1281 | if (ar.exception instanceof CommandException) { |
| 1282 | loge("setAllowedCarriers: CommandException: " + ar.exception); |
| 1283 | CommandException.Error error = |
| 1284 | ((CommandException) (ar.exception)).getCommandError(); |
| 1285 | if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1286 | request.result = |
| 1287 | TelephonyManager.SET_CARRIER_RESTRICTION_NOT_SUPPORTED; |
| 1288 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1289 | } else { |
| 1290 | loge("setAllowedCarriers: Unknown exception"); |
| 1291 | } |
| 1292 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1293 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1294 | break; |
| 1295 | |
| 1296 | case CMD_GET_ALLOWED_CARRIERS: |
| 1297 | request = (MainThreadRequest) msg.obj; |
| 1298 | onCompleted = obtainMessage(EVENT_GET_ALLOWED_CARRIERS_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1299 | defaultPhone.getAllowedCarriers(onCompleted, request.workSource); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1300 | break; |
| 1301 | |
| 1302 | case EVENT_GET_ALLOWED_CARRIERS_DONE: |
| 1303 | ar = (AsyncResult) msg.obj; |
| 1304 | request = (MainThreadRequest) ar.userObj; |
| 1305 | if (ar.exception == null && ar.result != null) { |
| 1306 | request.result = ar.result; |
| 1307 | } else { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 1308 | request.result = new IllegalStateException( |
| 1309 | "Failed to get carrier restrictions"); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1310 | if (ar.result == null) { |
| 1311 | loge("getAllowedCarriers: Empty response"); |
| 1312 | } else if (ar.exception instanceof CommandException) { |
| 1313 | loge("getAllowedCarriers: CommandException: " + |
| 1314 | ar.exception); |
| 1315 | } else { |
| 1316 | loge("getAllowedCarriers: Unknown exception"); |
| 1317 | } |
| 1318 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1319 | notifyRequester(request); |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 1320 | break; |
| 1321 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1322 | case EVENT_GET_FORBIDDEN_PLMNS_DONE: |
| 1323 | ar = (AsyncResult) msg.obj; |
| 1324 | request = (MainThreadRequest) ar.userObj; |
| 1325 | if (ar.exception == null && ar.result != null) { |
| 1326 | request.result = ar.result; |
| 1327 | } else { |
| 1328 | request.result = new IllegalArgumentException( |
| 1329 | "Failed to retrieve Forbidden Plmns"); |
| 1330 | if (ar.result == null) { |
| 1331 | loge("getForbiddenPlmns: Empty response"); |
| 1332 | } else { |
| 1333 | loge("getForbiddenPlmns: Unknown exception"); |
| 1334 | } |
| 1335 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1336 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1337 | break; |
| 1338 | |
| 1339 | case CMD_GET_FORBIDDEN_PLMNS: |
| 1340 | request = (MainThreadRequest) msg.obj; |
| 1341 | uiccCard = getUiccCardFromRequest(request); |
| 1342 | if (uiccCard == null) { |
| 1343 | loge("getForbiddenPlmns() UiccCard is null"); |
| 1344 | request.result = new IllegalArgumentException( |
| 1345 | "getForbiddenPlmns() UiccCard is null"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1346 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1347 | break; |
| 1348 | } |
| 1349 | Integer appType = (Integer) request.argument; |
| 1350 | UiccCardApplication uiccApp = uiccCard.getApplicationByType(appType); |
| 1351 | if (uiccApp == null) { |
| 1352 | loge("getForbiddenPlmns() no app with specified type -- " |
| 1353 | + appType); |
| 1354 | request.result = new IllegalArgumentException("Failed to get UICC App"); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1355 | notifyRequester(request); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 1356 | break; |
| 1357 | } else { |
| 1358 | if (DBG) logv("getForbiddenPlmns() found app " + uiccApp.getAid() |
| 1359 | + " specified type -- " + appType); |
| 1360 | } |
| 1361 | onCompleted = obtainMessage(EVENT_GET_FORBIDDEN_PLMNS_DONE, request); |
| 1362 | ((SIMRecords) uiccApp.getIccRecords()).getForbiddenPlmns( |
| 1363 | onCompleted); |
| 1364 | break; |
| 1365 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1366 | case CMD_SWITCH_SLOTS: |
| 1367 | request = (MainThreadRequest) msg.obj; |
| 1368 | int[] physicalSlots = (int[]) request.argument; |
| 1369 | onCompleted = obtainMessage(EVENT_SWITCH_SLOTS_DONE, request); |
| 1370 | UiccController.getInstance().switchSlots(physicalSlots, onCompleted); |
| 1371 | break; |
| 1372 | |
| 1373 | case EVENT_SWITCH_SLOTS_DONE: |
| 1374 | ar = (AsyncResult) msg.obj; |
| 1375 | request = (MainThreadRequest) ar.userObj; |
| 1376 | request.result = (ar.exception == null); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1377 | notifyRequester(request); |
| 1378 | break; |
| 1379 | case CMD_GET_NETWORK_SELECTION_MODE: |
| 1380 | request = (MainThreadRequest) msg.obj; |
| 1381 | onCompleted = obtainMessage(EVENT_GET_NETWORK_SELECTION_MODE_DONE, request); |
| 1382 | getPhoneFromRequest(request).getNetworkSelectionMode(onCompleted); |
| 1383 | break; |
| 1384 | |
| 1385 | case EVENT_GET_NETWORK_SELECTION_MODE_DONE: |
| 1386 | ar = (AsyncResult) msg.obj; |
| 1387 | request = (MainThreadRequest) ar.userObj; |
| 1388 | if (ar.exception != null) { |
| 1389 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 1390 | } else { |
| 1391 | int mode = ((int[]) ar.result)[0]; |
| 1392 | if (mode == 0) { |
| 1393 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_AUTO; |
| 1394 | } else { |
| 1395 | request.result = TelephonyManager.NETWORK_SELECTION_MODE_MANUAL; |
| 1396 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1397 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1398 | notifyRequester(request); |
| 1399 | break; |
| 1400 | case CMD_GET_CDMA_ROAMING_MODE: |
| 1401 | request = (MainThreadRequest) msg.obj; |
| 1402 | onCompleted = obtainMessage(EVENT_GET_CDMA_ROAMING_MODE_DONE, request); |
| 1403 | getPhoneFromRequest(request).queryCdmaRoamingPreference(onCompleted); |
| 1404 | break; |
| 1405 | case EVENT_GET_CDMA_ROAMING_MODE_DONE: |
| 1406 | ar = (AsyncResult) msg.obj; |
| 1407 | request = (MainThreadRequest) ar.userObj; |
| 1408 | if (ar.exception != null) { |
| 1409 | request.result = TelephonyManager.CDMA_ROAMING_MODE_RADIO_DEFAULT; |
| 1410 | } else { |
| 1411 | request.result = ((int[]) ar.result)[0]; |
| 1412 | } |
| 1413 | notifyRequester(request); |
| 1414 | break; |
| 1415 | case CMD_SET_CDMA_ROAMING_MODE: |
| 1416 | request = (MainThreadRequest) msg.obj; |
| 1417 | onCompleted = obtainMessage(EVENT_SET_CDMA_ROAMING_MODE_DONE, request); |
| 1418 | int mode = (int) request.argument; |
| 1419 | getPhoneFromRequest(request).setCdmaRoamingPreference(mode, onCompleted); |
| 1420 | break; |
| 1421 | case EVENT_SET_CDMA_ROAMING_MODE_DONE: |
| 1422 | ar = (AsyncResult) msg.obj; |
| 1423 | request = (MainThreadRequest) ar.userObj; |
| 1424 | request.result = ar.exception == null; |
| 1425 | notifyRequester(request); |
| 1426 | break; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1427 | case CMD_GET_CDMA_SUBSCRIPTION_MODE: |
| 1428 | request = (MainThreadRequest) msg.obj; |
| 1429 | onCompleted = obtainMessage(EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1430 | getPhoneFromRequest(request).queryCdmaSubscriptionMode(onCompleted); |
| 1431 | break; |
| 1432 | case EVENT_GET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1433 | ar = (AsyncResult) msg.obj; |
| 1434 | request = (MainThreadRequest) ar.userObj; |
| 1435 | if (ar.exception != null) { |
| 1436 | request.result = TelephonyManager.CDMA_SUBSCRIPTION_RUIM_SIM; |
| 1437 | } else { |
| 1438 | request.result = ((int[]) ar.result)[0]; |
| 1439 | } |
| 1440 | notifyRequester(request); |
| 1441 | break; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1442 | case CMD_SET_CDMA_SUBSCRIPTION_MODE: |
| 1443 | request = (MainThreadRequest) msg.obj; |
| 1444 | onCompleted = obtainMessage(EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE, request); |
| 1445 | int subscriptionMode = (int) request.argument; |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 1446 | getPhoneFromRequest(request).setCdmaSubscriptionMode( |
| 1447 | subscriptionMode, onCompleted); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1448 | break; |
| 1449 | case EVENT_SET_CDMA_SUBSCRIPTION_MODE_DONE: |
| 1450 | ar = (AsyncResult) msg.obj; |
| 1451 | request = (MainThreadRequest) ar.userObj; |
| 1452 | request.result = ar.exception == null; |
| 1453 | notifyRequester(request); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 1454 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1455 | case CMD_GET_ALL_CELL_INFO: |
| 1456 | request = (MainThreadRequest) msg.obj; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1457 | onCompleted = obtainMessage(EVENT_GET_ALL_CELL_INFO_DONE, request); |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1458 | request.phone.requestCellInfoUpdate(request.workSource, onCompleted); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1459 | break; |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1460 | case EVENT_GET_ALL_CELL_INFO_DONE: |
| 1461 | ar = (AsyncResult) msg.obj; |
| 1462 | request = (MainThreadRequest) ar.userObj; |
Nathan Harold | 8d0f174 | 2018-10-02 12:14:47 -0700 | [diff] [blame] | 1463 | // If a timeout occurs, the response will be null |
| 1464 | request.result = (ar.exception == null && ar.result != null) |
| 1465 | ? ar.result : new ArrayList<CellInfo>(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1466 | synchronized (request) { |
| 1467 | request.notifyAll(); |
| 1468 | } |
| 1469 | break; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1470 | case CMD_REQUEST_CELL_INFO_UPDATE: |
| 1471 | request = (MainThreadRequest) msg.obj; |
| 1472 | request.phone.requestCellInfoUpdate(request.workSource, |
| 1473 | obtainMessage(EVENT_REQUEST_CELL_INFO_UPDATE_DONE, request)); |
| 1474 | break; |
| 1475 | case EVENT_REQUEST_CELL_INFO_UPDATE_DONE: |
| 1476 | ar = (AsyncResult) msg.obj; |
| 1477 | request = (MainThreadRequest) ar.userObj; |
| 1478 | ICellInfoCallback cb = (ICellInfoCallback) request.argument; |
| 1479 | try { |
| 1480 | if (ar.exception != null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1481 | Log.e(LOG_TAG, "Exception retrieving CellInfo=" + ar.exception); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1482 | cb.onError( |
| 1483 | TelephonyManager.CellInfoCallback.ERROR_MODEM_ERROR, |
| 1484 | ar.exception.getClass().getName(), |
| 1485 | ar.exception.toString()); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1486 | } else if (ar.result == null) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1487 | Log.w(LOG_TAG, "Timeout Waiting for CellInfo!"); |
Meng Wang | d8921f4 | 2019-09-30 17:13:54 -0700 | [diff] [blame] | 1488 | cb.onError(TelephonyManager.CellInfoCallback.ERROR_TIMEOUT, null, null); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1489 | } else { |
| 1490 | // use the result as returned |
| 1491 | cb.onCellInfo((List<CellInfo>) ar.result); |
| 1492 | } |
| 1493 | } catch (RemoteException re) { |
| 1494 | Log.w(LOG_TAG, "Discarded CellInfo due to Callback RemoteException"); |
| 1495 | } |
| 1496 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1497 | case CMD_GET_CELL_LOCATION: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1498 | request = (MainThreadRequest) msg.obj; |
| 1499 | WorkSource ws = (WorkSource) request.argument; |
| 1500 | Phone phone = getPhoneFromRequest(request); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1501 | phone.getCellIdentity(ws, obtainMessage(EVENT_GET_CELL_LOCATION_DONE, request)); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1502 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1503 | } |
| 1504 | case EVENT_GET_CELL_LOCATION_DONE: { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1505 | ar = (AsyncResult) msg.obj; |
| 1506 | request = (MainThreadRequest) ar.userObj; |
| 1507 | if (ar.exception == null) { |
| 1508 | request.result = ar.result; |
| 1509 | } else { |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1510 | Phone phone = getPhoneFromRequest(request); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1511 | request.result = (phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 1512 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 1513 | } |
| 1514 | |
| 1515 | synchronized (request) { |
| 1516 | request.notifyAll(); |
| 1517 | } |
| 1518 | break; |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1519 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1520 | case CMD_MODEM_REBOOT: |
| 1521 | request = (MainThreadRequest) msg.obj; |
| 1522 | onCompleted = obtainMessage(EVENT_RESET_MODEM_CONFIG_DONE, request); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1523 | defaultPhone.rebootModem(onCompleted); |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1524 | break; |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 1525 | case EVENT_CMD_MODEM_REBOOT_DONE: |
| 1526 | handleNullReturnEvent(msg, "rebootModem"); |
| 1527 | break; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1528 | case CMD_REQUEST_ENABLE_MODEM: |
| 1529 | request = (MainThreadRequest) msg.obj; |
| 1530 | boolean enable = (boolean) request.argument; |
| 1531 | onCompleted = obtainMessage(EVENT_ENABLE_MODEM_DONE, request); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1532 | onCompleted.arg1 = enable ? 1 : 0; |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1533 | PhoneConfigurationManager.getInstance() |
| 1534 | .enablePhone(request.phone, enable, onCompleted); |
| 1535 | break; |
| 1536 | case EVENT_ENABLE_MODEM_DONE: |
| 1537 | ar = (AsyncResult) msg.obj; |
| 1538 | request = (MainThreadRequest) ar.userObj; |
| 1539 | request.result = (ar.exception == null); |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1540 | int phoneId = request.phone.getPhoneId(); |
Nazanin Bakhshi | 33d584b | 2019-02-27 10:44:32 -0800 | [diff] [blame] | 1541 | //update the cache as modem status has changed |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 1542 | if ((boolean) request.result) { |
| 1543 | mPhoneConfigurationManager.addToPhoneStatusCache(phoneId, msg.arg1 == 1); |
| 1544 | updateModemStateMetrics(); |
| 1545 | } else { |
| 1546 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1547 | + ar.exception); |
| 1548 | } |
| 1549 | notifyRequester(request); |
| 1550 | break; |
| 1551 | case CMD_GET_MODEM_STATUS: |
| 1552 | request = (MainThreadRequest) msg.obj; |
| 1553 | onCompleted = obtainMessage(EVENT_GET_MODEM_STATUS_DONE, request); |
| 1554 | PhoneConfigurationManager.getInstance() |
| 1555 | .getPhoneStatusFromModem(request.phone, onCompleted); |
| 1556 | break; |
| 1557 | case EVENT_GET_MODEM_STATUS_DONE: |
| 1558 | ar = (AsyncResult) msg.obj; |
| 1559 | request = (MainThreadRequest) ar.userObj; |
| 1560 | int id = request.phone.getPhoneId(); |
| 1561 | if (ar.exception == null && ar.result != null) { |
| 1562 | request.result = ar.result; |
| 1563 | //update the cache as modem status has changed |
| 1564 | mPhoneConfigurationManager.addToPhoneStatusCache(id, |
| 1565 | (boolean) request.result); |
| 1566 | } else { |
| 1567 | // Return true if modem status cannot be retrieved. For most cases, |
| 1568 | // modem status is on. And for older version modems, GET_MODEM_STATUS |
| 1569 | // and disable modem are not supported. Modem is always on. |
| 1570 | // TODO: this should be fixed in R to support a third |
| 1571 | // status UNKNOWN b/131631629 |
| 1572 | request.result = true; |
| 1573 | Log.e(LOG_TAG, msg.what + " failure. Not updating modem status." |
| 1574 | + ar.exception); |
| 1575 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 1576 | notifyRequester(request); |
| 1577 | break; |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 1578 | case CMD_SET_SYSTEM_SELECTION_CHANNELS: { |
| 1579 | request = (MainThreadRequest) msg.obj; |
| 1580 | onCompleted = obtainMessage(EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1581 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1582 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1583 | request.phone.setSystemSelectionChannels(args.first, onCompleted); |
| 1584 | break; |
| 1585 | } |
| 1586 | case EVENT_SET_SYSTEM_SELECTION_CHANNELS_DONE: { |
| 1587 | ar = (AsyncResult) msg.obj; |
| 1588 | request = (MainThreadRequest) ar.userObj; |
| 1589 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> args = |
| 1590 | (Pair<List<RadioAccessSpecifier>, Consumer<Boolean>>) request.argument; |
| 1591 | args.second.accept(ar.exception == null); |
| 1592 | notifyRequester(request); |
| 1593 | break; |
| 1594 | } |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 1595 | case CMD_GET_SYSTEM_SELECTION_CHANNELS: { |
| 1596 | request = (MainThreadRequest) msg.obj; |
| 1597 | onCompleted = obtainMessage(EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE, request); |
| 1598 | Phone phone = getPhoneFromRequest(request); |
| 1599 | if (phone != null) { |
| 1600 | phone.getSystemSelectionChannels(onCompleted); |
| 1601 | } else { |
| 1602 | loge("getSystemSelectionChannels: No phone object"); |
| 1603 | request.result = new ArrayList<RadioAccessSpecifier>(); |
| 1604 | notifyRequester(request); |
| 1605 | } |
| 1606 | break; |
| 1607 | } |
| 1608 | case EVENT_GET_SYSTEM_SELECTION_CHANNELS_DONE: |
| 1609 | ar = (AsyncResult) msg.obj; |
| 1610 | request = (MainThreadRequest) ar.userObj; |
| 1611 | if (ar.exception == null && ar.result != null) { |
| 1612 | request.result = ar.result; |
| 1613 | } else { |
| 1614 | request.result = new IllegalArgumentException( |
| 1615 | "Failed to retrieve system selection channels"); |
| 1616 | if (ar.result == null) { |
| 1617 | loge("getSystemSelectionChannels: Empty response"); |
| 1618 | } else { |
| 1619 | loge("getSystemSelectionChannels: Unknown exception"); |
| 1620 | } |
| 1621 | } |
| 1622 | notifyRequester(request); |
| 1623 | break; |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1624 | case EVENT_SET_FORBIDDEN_PLMNS_DONE: |
| 1625 | ar = (AsyncResult) msg.obj; |
| 1626 | request = (MainThreadRequest) ar.userObj; |
| 1627 | if (ar.exception == null && ar.result != null) { |
| 1628 | request.result = ar.result; |
| 1629 | } else { |
| 1630 | request.result = -1; |
| 1631 | loge("Failed to set Forbidden Plmns"); |
| 1632 | if (ar.result == null) { |
| 1633 | loge("setForbidenPlmns: Empty response"); |
| 1634 | } else if (ar.exception != null) { |
| 1635 | loge("setForbiddenPlmns: Exception: " + ar.exception); |
| 1636 | request.result = -1; |
| 1637 | } else { |
| 1638 | loge("setForbiddenPlmns: Unknown exception"); |
| 1639 | } |
| 1640 | } |
| 1641 | notifyRequester(request); |
| 1642 | break; |
| 1643 | case CMD_SET_FORBIDDEN_PLMNS: |
| 1644 | request = (MainThreadRequest) msg.obj; |
| 1645 | uiccCard = getUiccCardFromRequest(request); |
| 1646 | if (uiccCard == null) { |
| 1647 | loge("setForbiddenPlmns: UiccCard is null"); |
| 1648 | request.result = -1; |
| 1649 | notifyRequester(request); |
| 1650 | break; |
| 1651 | } |
| 1652 | Pair<Integer, List<String>> setFplmnsArgs = |
| 1653 | (Pair<Integer, List<String>>) request.argument; |
| 1654 | appType = setFplmnsArgs.first; |
| 1655 | List<String> fplmns = setFplmnsArgs.second; |
| 1656 | uiccApp = uiccCard.getApplicationByType(appType); |
| 1657 | if (uiccApp == null) { |
| 1658 | loge("setForbiddenPlmns: no app with specified type -- " + appType); |
| 1659 | request.result = -1; |
| 1660 | loge("Failed to get UICC App"); |
| 1661 | notifyRequester(request); |
| 1662 | } else { |
| 1663 | onCompleted = obtainMessage(EVENT_SET_FORBIDDEN_PLMNS_DONE, request); |
| 1664 | ((SIMRecords) uiccApp.getIccRecords()) |
| 1665 | .setForbiddenPlmns(onCompleted, fplmns); |
| 1666 | } |
yinchengzhao | 4d163c0 | 2019-12-12 15:21:47 -0800 | [diff] [blame] | 1667 | break; |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 1668 | case CMD_ERASE_MODEM_CONFIG: |
| 1669 | request = (MainThreadRequest) msg.obj; |
| 1670 | onCompleted = obtainMessage(EVENT_ERASE_MODEM_CONFIG_DONE, request); |
| 1671 | defaultPhone.eraseModemConfig(onCompleted); |
| 1672 | break; |
| 1673 | case EVENT_ERASE_MODEM_CONFIG_DONE: |
| 1674 | handleNullReturnEvent(msg, "eraseModemConfig"); |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 1675 | break; |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 1676 | |
| 1677 | case CMD_CHANGE_ICC_LOCK_PASSWORD: |
| 1678 | request = (MainThreadRequest) msg.obj; |
| 1679 | onCompleted = obtainMessage(EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE, request); |
| 1680 | Pair<String, String> changed = (Pair<String, String>) request.argument; |
| 1681 | getPhoneFromRequest(request).getIccCard().changeIccLockPassword( |
| 1682 | changed.first, changed.second, onCompleted); |
| 1683 | break; |
| 1684 | case EVENT_CHANGE_ICC_LOCK_PASSWORD_DONE: |
| 1685 | ar = (AsyncResult) msg.obj; |
| 1686 | request = (MainThreadRequest) ar.userObj; |
| 1687 | if (ar.exception == null) { |
| 1688 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1689 | } else { |
| 1690 | request.result = msg.arg1; |
| 1691 | } |
| 1692 | notifyRequester(request); |
| 1693 | break; |
| 1694 | |
| 1695 | case CMD_SET_ICC_LOCK_ENABLED: |
| 1696 | request = (MainThreadRequest) msg.obj; |
| 1697 | onCompleted = obtainMessage(EVENT_SET_ICC_LOCK_ENABLED_DONE, request); |
| 1698 | Pair<Boolean, String> enabled = (Pair<Boolean, String>) request.argument; |
| 1699 | getPhoneFromRequest(request).getIccCard().setIccLockEnabled( |
| 1700 | enabled.first, enabled.second, onCompleted); |
| 1701 | break; |
| 1702 | case EVENT_SET_ICC_LOCK_ENABLED_DONE: |
| 1703 | ar = (AsyncResult) msg.obj; |
| 1704 | request = (MainThreadRequest) ar.userObj; |
| 1705 | if (ar.exception == null) { |
| 1706 | request.result = TelephonyManager.CHANGE_ICC_LOCK_SUCCESS; |
| 1707 | } else { |
| 1708 | request.result = msg.arg1; |
| 1709 | } |
| 1710 | notifyRequester(request); |
| 1711 | break; |
| 1712 | |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1713 | case MSG_NOTIFY_USER_ACTIVITY: |
| 1714 | removeMessages(MSG_NOTIFY_USER_ACTIVITY); |
Peter Wang | 59571be | 2020-01-27 12:35:15 +0800 | [diff] [blame] | 1715 | Intent intent = new Intent(TelephonyIntents.ACTION_USER_ACTIVITY_NOTIFICATION); |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 1716 | intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY); |
| 1717 | getDefaultPhone().getContext().sendBroadcastAsUser( |
| 1718 | intent, UserHandle.ALL, permission.USER_ACTIVITY); |
| 1719 | break; |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 1720 | |
| 1721 | case CMD_SET_DATA_THROTTLING: { |
| 1722 | request = (MainThreadRequest) msg.obj; |
| 1723 | onCompleted = obtainMessage(EVENT_SET_DATA_THROTTLING_DONE, request); |
| 1724 | DataThrottlingRequest dataThrottlingRequest = |
| 1725 | (DataThrottlingRequest) request.argument; |
| 1726 | Phone phone = getPhoneFromRequest(request); |
| 1727 | if (phone != null) { |
| 1728 | phone.setDataThrottling(onCompleted, |
| 1729 | request.workSource, dataThrottlingRequest.getDataThrottlingAction(), |
| 1730 | dataThrottlingRequest.getCompletionDurationMillis()); |
| 1731 | } else { |
| 1732 | loge("setDataThrottling: No phone object"); |
| 1733 | request.result = |
| 1734 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1735 | notifyRequester(request); |
| 1736 | } |
| 1737 | |
| 1738 | break; |
| 1739 | } |
| 1740 | case EVENT_SET_DATA_THROTTLING_DONE: |
| 1741 | ar = (AsyncResult) msg.obj; |
| 1742 | request = (MainThreadRequest) ar.userObj; |
| 1743 | |
| 1744 | if (ar.exception == null) { |
| 1745 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 1746 | } else if (ar.exception instanceof CommandException) { |
| 1747 | loge("setDataThrottling: CommandException: " + ar.exception); |
| 1748 | CommandException.Error error = |
| 1749 | ((CommandException) (ar.exception)).getCommandError(); |
| 1750 | |
| 1751 | if (error == CommandException.Error.RADIO_NOT_AVAILABLE) { |
| 1752 | request.result = TelephonyManager |
| 1753 | .THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 1754 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1755 | request.result = SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS; |
| 1756 | } else { |
| 1757 | request.result = |
| 1758 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1759 | } |
| 1760 | } else { |
| 1761 | request.result = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 1762 | } |
| 1763 | Log.w(LOG_TAG, "DataThrottlingResult = " + request.result); |
| 1764 | notifyRequester(request); |
| 1765 | break; |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 1766 | |
| 1767 | case CMD_SET_SIM_POWER: { |
| 1768 | request = (MainThreadRequest) msg.obj; |
| 1769 | onCompleted = obtainMessage(EVENT_SET_SIM_POWER_DONE, request); |
| 1770 | request = (MainThreadRequest) msg.obj; |
| 1771 | int stateToSet = |
| 1772 | ((Pair<Integer, IIntegerConsumer>) |
| 1773 | request.argument).first; |
| 1774 | request.phone.setSimPowerState(stateToSet, onCompleted, request.workSource); |
| 1775 | break; |
| 1776 | } |
| 1777 | case EVENT_SET_SIM_POWER_DONE: { |
| 1778 | ar = (AsyncResult) msg.obj; |
| 1779 | request = (MainThreadRequest) ar.userObj; |
| 1780 | IIntegerConsumer callback = |
| 1781 | ((Pair<Integer, IIntegerConsumer>) request.argument).second; |
| 1782 | if (ar.exception != null) { |
| 1783 | loge("setSimPower exception: " + ar.exception); |
| 1784 | int errorCode = TelephonyManager.CallForwardingInfoCallback |
| 1785 | .RESULT_ERROR_UNKNOWN; |
| 1786 | if (ar.exception instanceof CommandException) { |
| 1787 | CommandException.Error error = |
| 1788 | ((CommandException) (ar.exception)).getCommandError(); |
| 1789 | if (error == CommandException.Error.SIM_ERR) { |
| 1790 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_SIM_ERROR; |
| 1791 | } else if (error == CommandException.Error.INVALID_ARGUMENTS) { |
| 1792 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_ALREADY_IN_STATE; |
| 1793 | } else if (error == CommandException.Error.REQUEST_NOT_SUPPORTED) { |
| 1794 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_NOT_SUPPORTED; |
| 1795 | } else { |
| 1796 | errorCode = TelephonyManager.SET_SIM_POWER_STATE_MODEM_ERROR; |
| 1797 | } |
| 1798 | } |
| 1799 | try { |
| 1800 | callback.accept(errorCode); |
| 1801 | } catch (RemoteException e) { |
| 1802 | // Ignore if the remote process is no longer available to call back. |
| 1803 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1804 | } |
| 1805 | } else { |
| 1806 | try { |
| 1807 | callback.accept(TelephonyManager.SET_SIM_POWER_STATE_SUCCESS); |
| 1808 | } catch (RemoteException e) { |
| 1809 | // Ignore if the remote process is no longer available to call back. |
| 1810 | Log.w(LOG_TAG, "setSimPower: callback not available."); |
| 1811 | } |
| 1812 | } |
| 1813 | break; |
| 1814 | } |
| 1815 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1816 | default: |
| 1817 | Log.w(LOG_TAG, "MainThreadHandler: unexpected message code: " + msg.what); |
| 1818 | break; |
| 1819 | } |
| 1820 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1821 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1822 | private void notifyRequester(MainThreadRequest request) { |
| 1823 | synchronized (request) { |
| 1824 | request.notifyAll(); |
| 1825 | } |
| 1826 | } |
| 1827 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1828 | private void handleNullReturnEvent(Message msg, String command) { |
| 1829 | AsyncResult ar = (AsyncResult) msg.obj; |
| 1830 | MainThreadRequest request = (MainThreadRequest) ar.userObj; |
| 1831 | if (ar.exception == null) { |
| 1832 | request.result = true; |
| 1833 | } else { |
| 1834 | request.result = false; |
| 1835 | if (ar.exception instanceof CommandException) { |
| 1836 | loge(command + ": CommandException: " + ar.exception); |
| 1837 | } else { |
| 1838 | loge(command + ": Unknown exception"); |
| 1839 | } |
| 1840 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 1841 | notifyRequester(request); |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 1842 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1843 | } |
| 1844 | |
| 1845 | /** |
| 1846 | * Posts the specified command to be executed on the main thread, |
| 1847 | * waits for the request to complete, and returns the result. |
| 1848 | * @see #sendRequestAsync |
| 1849 | */ |
| 1850 | private Object sendRequest(int command, Object argument) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1851 | return sendRequest( |
| 1852 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1853 | } |
| 1854 | |
| 1855 | /** |
| 1856 | * Posts the specified command to be executed on the main thread, |
| 1857 | * waits for the request to complete, and returns the result. |
| 1858 | * @see #sendRequestAsync |
| 1859 | */ |
| 1860 | private Object sendRequest(int command, Object argument, WorkSource workSource) { |
| 1861 | return sendRequest(command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1862 | null, workSource); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 1863 | } |
| 1864 | |
| 1865 | /** |
| 1866 | * Posts the specified command to be executed on the main thread, |
| 1867 | * waits for the request to complete, and returns the result. |
| 1868 | * @see #sendRequestAsync |
| 1869 | */ |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 1870 | private Object sendRequest(int command, Object argument, Integer subId) { |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1871 | return sendRequest(command, argument, subId, null, null); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 1872 | } |
| 1873 | |
| 1874 | /** |
| 1875 | * Posts the specified command to be executed on the main thread, |
| 1876 | * waits for the request to complete, and returns the result. |
| 1877 | * @see #sendRequestAsync |
| 1878 | */ |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1879 | private Object sendRequest(int command, Object argument, int subId, WorkSource workSource) { |
| 1880 | return sendRequest(command, argument, subId, null, workSource); |
| 1881 | } |
| 1882 | |
| 1883 | /** |
| 1884 | * Posts the specified command to be executed on the main thread, |
| 1885 | * waits for the request to complete, and returns the result. |
| 1886 | * @see #sendRequestAsync |
| 1887 | */ |
| 1888 | private Object sendRequest(int command, Object argument, Phone phone, WorkSource workSource) { |
| 1889 | return sendRequest( |
| 1890 | command, argument, SubscriptionManager.INVALID_SUBSCRIPTION_ID, phone, workSource); |
| 1891 | } |
| 1892 | |
| 1893 | /** |
| 1894 | * Posts the specified command to be executed on the main thread, |
| 1895 | * waits for the request to complete, and returns the result. |
| 1896 | * @see #sendRequestAsync |
| 1897 | */ |
| 1898 | private Object sendRequest( |
| 1899 | int command, Object argument, Integer subId, Phone phone, WorkSource workSource) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1900 | if (Looper.myLooper() == mMainThreadHandler.getLooper()) { |
| 1901 | throw new RuntimeException("This method will deadlock if called from the main thread."); |
| 1902 | } |
| 1903 | |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 1904 | MainThreadRequest request = null; |
| 1905 | if (subId != SubscriptionManager.INVALID_SUBSCRIPTION_ID && phone != null) { |
| 1906 | throw new IllegalArgumentException("subId and phone cannot both be specified!"); |
| 1907 | } else if (phone != null) { |
| 1908 | request = new MainThreadRequest(argument, phone, workSource); |
| 1909 | } else { |
| 1910 | request = new MainThreadRequest(argument, subId, workSource); |
| 1911 | } |
| 1912 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1913 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1914 | msg.sendToTarget(); |
| 1915 | |
| 1916 | // Wait for the request to complete |
| 1917 | synchronized (request) { |
| 1918 | while (request.result == null) { |
| 1919 | try { |
| 1920 | request.wait(); |
| 1921 | } catch (InterruptedException e) { |
| 1922 | // Do nothing, go back and wait until the request is complete |
| 1923 | } |
| 1924 | } |
| 1925 | } |
| 1926 | return request.result; |
| 1927 | } |
| 1928 | |
| 1929 | /** |
| 1930 | * Asynchronous ("fire and forget") version of sendRequest(): |
| 1931 | * Posts the specified command to be executed on the main thread, and |
| 1932 | * returns immediately. |
| 1933 | * @see #sendRequest |
| 1934 | */ |
| 1935 | private void sendRequestAsync(int command) { |
| 1936 | mMainThreadHandler.sendEmptyMessage(command); |
| 1937 | } |
| 1938 | |
| 1939 | /** |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1940 | * Same as {@link #sendRequestAsync(int)} except it takes an argument. |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1941 | * @see {@link #sendRequest(int)} |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1942 | */ |
| 1943 | private void sendRequestAsync(int command, Object argument) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 1944 | sendRequestAsync(command, argument, null, null); |
| 1945 | } |
| 1946 | |
| 1947 | /** |
| 1948 | * Same as {@link #sendRequestAsync(int,Object)} except it takes a Phone and WorkSource. |
| 1949 | * @see {@link #sendRequest(int,Object)} |
| 1950 | */ |
| 1951 | private void sendRequestAsync( |
| 1952 | int command, Object argument, Phone phone, WorkSource workSource) { |
| 1953 | MainThreadRequest request = new MainThreadRequest(argument, phone, workSource); |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 1954 | Message msg = mMainThreadHandler.obtainMessage(command, request); |
| 1955 | msg.sendToTarget(); |
| 1956 | } |
| 1957 | |
| 1958 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1959 | * Initialize the singleton PhoneInterfaceManager instance. |
| 1960 | * This is only done once, at startup, from PhoneApp.onCreate(). |
| 1961 | */ |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1962 | /* package */ static PhoneInterfaceManager init(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1963 | synchronized (PhoneInterfaceManager.class) { |
| 1964 | if (sInstance == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1965 | sInstance = new PhoneInterfaceManager(app); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1966 | } else { |
| 1967 | Log.wtf(LOG_TAG, "init() called multiple times! sInstance = " + sInstance); |
| 1968 | } |
| 1969 | return sInstance; |
| 1970 | } |
| 1971 | } |
| 1972 | |
| 1973 | /** Private constructor; @see init() */ |
Jordan Liu | 1979a04 | 2020-03-20 21:39:35 +0000 | [diff] [blame] | 1974 | private PhoneInterfaceManager(PhoneGlobals app) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1975 | mApp = app; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1976 | mCM = PhoneGlobals.getInstance().mCM; |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 1977 | mImsResolver = PhoneGlobals.getInstance().getImsResolver(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 1978 | mUserManager = (UserManager) app.getSystemService(Context.USER_SERVICE); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1979 | mAppOps = (AppOpsManager)app.getSystemService(Context.APP_OPS_SERVICE); |
| 1980 | mMainThreadHandler = new MainThreadHandler(); |
Tobias Thierer | b19e1f1 | 2018-12-11 17:54:03 +0000 | [diff] [blame] | 1981 | mSubscriptionController = SubscriptionController.getInstance(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1982 | mTelephonySharedPreferences = |
| 1983 | PreferenceManager.getDefaultSharedPreferences(mApp); |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 1984 | mNetworkScanRequestTracker = new NetworkScanRequestTracker(); |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 1985 | mPhoneConfigurationManager = PhoneConfigurationManager.getInstance(); |
Peter Wang | a3cf4ac | 2020-01-27 09:39:46 +0800 | [diff] [blame] | 1986 | mNotifyUserActivity = new AtomicBoolean(false); |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 1987 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1988 | publish(); |
| 1989 | } |
| 1990 | |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 1991 | private Phone getDefaultPhone() { |
| 1992 | Phone thePhone = getPhone(getDefaultSubscription()); |
| 1993 | return (thePhone != null) ? thePhone : PhoneFactory.getDefaultPhone(); |
| 1994 | } |
| 1995 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 1996 | private void publish() { |
| 1997 | if (DBG) log("publish: " + this); |
| 1998 | |
Peter Wang | c035ce4 | 2020-01-08 21:00:22 -0800 | [diff] [blame] | 1999 | TelephonyFrameworkInitializer |
| 2000 | .getTelephonyServiceManager() |
| 2001 | .getTelephonyServiceRegisterer() |
| 2002 | .register(this); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2005 | private Phone getPhoneFromRequest(MainThreadRequest request) { |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 2006 | if (request.phone != null) { |
| 2007 | return request.phone; |
| 2008 | } else { |
| 2009 | return getPhoneFromSubId(request.subId); |
| 2010 | } |
| 2011 | } |
| 2012 | |
| 2013 | private Phone getPhoneFromSubId(int subId) { |
| 2014 | return (subId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) |
| 2015 | ? getDefaultPhone() : getPhone(subId); |
Stuart Scott | 584921c | 2015-01-15 17:10:34 -0800 | [diff] [blame] | 2016 | } |
| 2017 | |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 2018 | private UiccCard getUiccCardFromRequest(MainThreadRequest request) { |
| 2019 | Phone phone = getPhoneFromRequest(request); |
| 2020 | return phone == null ? null : |
| 2021 | UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
| 2022 | } |
| 2023 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2024 | // returns phone associated with the subId. |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2025 | private Phone getPhone(int subId) { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 2026 | return PhoneFactory.getPhone(mSubscriptionController.getPhoneId(subId)); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2027 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2028 | |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 2029 | private void sendEraseModemConfig(Phone phone) { |
| 2030 | if (phone != null) { |
| 2031 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 2032 | mApp, phone.getSubId(), "eraseModemConfig"); |
| 2033 | final long identity = Binder.clearCallingIdentity(); |
| 2034 | try { |
| 2035 | Boolean success = (Boolean) sendRequest(CMD_ERASE_MODEM_CONFIG, null); |
| 2036 | if (DBG) log("eraseModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 2037 | } finally { |
| 2038 | Binder.restoreCallingIdentity(identity); |
| 2039 | } |
| 2040 | } |
| 2041 | } |
| 2042 | |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 2043 | private boolean isImsAvailableOnDevice() { |
| 2044 | PackageManager pm = getDefaultPhone().getContext().getPackageManager(); |
| 2045 | if (pm == null) { |
| 2046 | // For some reason package manger is not available.. This will fail internally anyway, |
| 2047 | // so do not throw error and allow. |
| 2048 | return true; |
| 2049 | } |
| 2050 | return pm.hasSystemFeature(PackageManager.FEATURE_TELEPHONY_IMS, 0); |
| 2051 | } |
| 2052 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2053 | public void dial(String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2054 | dialForSubscriber(getPreferredVoiceSubscription(), number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2055 | } |
| 2056 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2057 | public void dialForSubscriber(int subId, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2058 | if (DBG) log("dial: " + number); |
| 2059 | // No permission check needed here: This is just a wrapper around the |
| 2060 | // ACTION_DIAL intent, which is available to any app since it puts up |
| 2061 | // the UI before it does anything. |
| 2062 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2063 | final long identity = Binder.clearCallingIdentity(); |
| 2064 | try { |
| 2065 | String url = createTelUrl(number); |
| 2066 | if (url == null) { |
| 2067 | return; |
| 2068 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2069 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2070 | // PENDING: should we just silently fail if phone is offhook or ringing? |
| 2071 | PhoneConstants.State state = mCM.getState(subId); |
| 2072 | if (state != PhoneConstants.State.OFFHOOK && state != PhoneConstants.State.RINGING) { |
| 2073 | Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse(url)); |
| 2074 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2075 | mApp.startActivity(intent); |
| 2076 | } |
| 2077 | } finally { |
| 2078 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2079 | } |
| 2080 | } |
| 2081 | |
| 2082 | public void call(String callingPackage, String number) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2083 | callForSubscriber(getPreferredVoiceSubscription(), callingPackage, number); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2086 | public void callForSubscriber(int subId, String callingPackage, String number) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2087 | if (DBG) log("call: " + number); |
| 2088 | |
| 2089 | // This is just a wrapper around the ACTION_CALL intent, but we still |
| 2090 | // need to do a permission check since we're calling startActivity() |
| 2091 | // from the context of the phone app. |
| 2092 | enforceCallPermission(); |
| 2093 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2094 | if (mAppOps.noteOp(AppOpsManager.OPSTR_CALL_PHONE, Binder.getCallingUid(), callingPackage) |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2095 | != AppOpsManager.MODE_ALLOWED) { |
| 2096 | return; |
| 2097 | } |
| 2098 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2099 | final long identity = Binder.clearCallingIdentity(); |
| 2100 | try { |
| 2101 | String url = createTelUrl(number); |
| 2102 | if (url == null) { |
| 2103 | return; |
| 2104 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2105 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2106 | boolean isValid = false; |
| 2107 | final List<SubscriptionInfo> slist = getActiveSubscriptionInfoListPrivileged(); |
| 2108 | if (slist != null) { |
| 2109 | for (SubscriptionInfo subInfoRecord : slist) { |
| 2110 | if (subInfoRecord.getSubscriptionId() == subId) { |
| 2111 | isValid = true; |
| 2112 | break; |
| 2113 | } |
Wink Saville | 3ab207e | 2014-11-20 13:07:20 -0800 | [diff] [blame] | 2114 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2115 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2116 | if (!isValid) { |
| 2117 | return; |
| 2118 | } |
Wink Saville | 0887461 | 2014-08-31 19:19:58 -0700 | [diff] [blame] | 2119 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2120 | Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse(url)); |
| 2121 | intent.putExtra(SUBSCRIPTION_KEY, subId); |
| 2122 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 2123 | mApp.startActivity(intent); |
| 2124 | } finally { |
| 2125 | Binder.restoreCallingIdentity(identity); |
| 2126 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2127 | } |
| 2128 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2129 | public boolean supplyPinForSubscriber(int subId, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2130 | int [] resultArray = supplyPinReportResultForSubscriber(subId, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2131 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2132 | } |
| 2133 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2134 | public boolean supplyPukForSubscriber(int subId, String puk, String pin) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2135 | int [] resultArray = supplyPukReportResultForSubscriber(subId, puk, pin); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2136 | return (resultArray[0] == PhoneConstants.PIN_RESULT_SUCCESS) ? true : false; |
| 2137 | } |
| 2138 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2139 | public int[] supplyPinReportResultForSubscriber(int subId, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2140 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2141 | |
| 2142 | final long identity = Binder.clearCallingIdentity(); |
| 2143 | try { |
| 2144 | final UnlockSim checkSimPin = new UnlockSim(getPhone(subId).getIccCard()); |
| 2145 | checkSimPin.start(); |
| 2146 | return checkSimPin.unlockSim(null, pin); |
| 2147 | } finally { |
| 2148 | Binder.restoreCallingIdentity(identity); |
| 2149 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2150 | } |
| 2151 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2152 | public int[] supplyPukReportResultForSubscriber(int subId, String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2153 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2154 | |
| 2155 | final long identity = Binder.clearCallingIdentity(); |
| 2156 | try { |
| 2157 | final UnlockSim checkSimPuk = new UnlockSim(getPhone(subId).getIccCard()); |
| 2158 | checkSimPuk.start(); |
| 2159 | return checkSimPuk.unlockSim(puk, pin); |
| 2160 | } finally { |
| 2161 | Binder.restoreCallingIdentity(identity); |
| 2162 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | /** |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2166 | * Helper thread to turn async call to SimCard#supplyPin into |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2167 | * a synchronous one. |
| 2168 | */ |
| 2169 | private static class UnlockSim extends Thread { |
| 2170 | |
| 2171 | private final IccCard mSimCard; |
| 2172 | |
| 2173 | private boolean mDone = false; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2174 | private int mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2175 | private int mRetryCount = -1; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2176 | |
| 2177 | // For replies from SimCard interface |
| 2178 | private Handler mHandler; |
| 2179 | |
| 2180 | // For async handler to identify request type |
| 2181 | private static final int SUPPLY_PIN_COMPLETE = 100; |
| 2182 | |
| 2183 | public UnlockSim(IccCard simCard) { |
| 2184 | mSimCard = simCard; |
| 2185 | } |
| 2186 | |
| 2187 | @Override |
| 2188 | public void run() { |
| 2189 | Looper.prepare(); |
| 2190 | synchronized (UnlockSim.this) { |
| 2191 | mHandler = new Handler() { |
| 2192 | @Override |
| 2193 | public void handleMessage(Message msg) { |
| 2194 | AsyncResult ar = (AsyncResult) msg.obj; |
| 2195 | switch (msg.what) { |
| 2196 | case SUPPLY_PIN_COMPLETE: |
| 2197 | Log.d(LOG_TAG, "SUPPLY_PIN_COMPLETE"); |
| 2198 | synchronized (UnlockSim.this) { |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2199 | mRetryCount = msg.arg1; |
| 2200 | if (ar.exception != null) { |
| 2201 | if (ar.exception instanceof CommandException && |
| 2202 | ((CommandException)(ar.exception)).getCommandError() |
| 2203 | == CommandException.Error.PASSWORD_INCORRECT) { |
| 2204 | mResult = PhoneConstants.PIN_PASSWORD_INCORRECT; |
vivi.li | b5e9ada | 2019-09-12 16:04:24 +0800 | [diff] [blame] | 2205 | } //When UiccCardApp dispose,handle message and return exception |
| 2206 | else if (ar.exception instanceof CommandException && |
| 2207 | ((CommandException) (ar.exception)).getCommandError() |
| 2208 | == CommandException.Error.ABORTED) { |
| 2209 | mResult = PhoneConstants.PIN_OPERATION_ABORTED; |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2210 | } else { |
| 2211 | mResult = PhoneConstants.PIN_GENERAL_FAILURE; |
| 2212 | } |
| 2213 | } else { |
| 2214 | mResult = PhoneConstants.PIN_RESULT_SUCCESS; |
| 2215 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2216 | mDone = true; |
| 2217 | UnlockSim.this.notifyAll(); |
| 2218 | } |
| 2219 | break; |
| 2220 | } |
| 2221 | } |
| 2222 | }; |
| 2223 | UnlockSim.this.notifyAll(); |
| 2224 | } |
| 2225 | Looper.loop(); |
| 2226 | } |
| 2227 | |
| 2228 | /* |
| 2229 | * Use PIN or PUK to unlock SIM card |
| 2230 | * |
| 2231 | * If PUK is null, unlock SIM card with PIN |
| 2232 | * |
| 2233 | * If PUK is not null, unlock SIM card with PUK and set PIN code |
| 2234 | */ |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2235 | synchronized int[] unlockSim(String puk, String pin) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2236 | |
| 2237 | while (mHandler == null) { |
| 2238 | try { |
| 2239 | wait(); |
| 2240 | } catch (InterruptedException e) { |
| 2241 | Thread.currentThread().interrupt(); |
| 2242 | } |
| 2243 | } |
| 2244 | Message callback = Message.obtain(mHandler, SUPPLY_PIN_COMPLETE); |
| 2245 | |
| 2246 | if (puk == null) { |
| 2247 | mSimCard.supplyPin(pin, callback); |
| 2248 | } else { |
| 2249 | mSimCard.supplyPuk(puk, pin, callback); |
| 2250 | } |
| 2251 | |
| 2252 | while (!mDone) { |
| 2253 | try { |
| 2254 | Log.d(LOG_TAG, "wait for done"); |
| 2255 | wait(); |
| 2256 | } catch (InterruptedException e) { |
| 2257 | // Restore the interrupted status |
| 2258 | Thread.currentThread().interrupt(); |
| 2259 | } |
| 2260 | } |
| 2261 | Log.d(LOG_TAG, "done"); |
Wink Saville | 9de0f75 | 2013-10-22 19:04:03 -0700 | [diff] [blame] | 2262 | int[] resultArray = new int[2]; |
| 2263 | resultArray[0] = mResult; |
| 2264 | resultArray[1] = mRetryCount; |
| 2265 | return resultArray; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2266 | } |
| 2267 | } |
| 2268 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2269 | /** |
| 2270 | * This method has been removed due to privacy and stability concerns. |
| 2271 | */ |
| 2272 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2273 | public void updateServiceLocation() { |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2274 | Log.e(LOG_TAG, "Call to unsupported method updateServiceLocation()"); |
| 2275 | return; |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2276 | } |
| 2277 | |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2278 | @Override |
| 2279 | public void updateServiceLocationWithPackageName(String callingPackage) { |
| 2280 | mApp.getSystemService(AppOpsManager.class) |
| 2281 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 2282 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2283 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2284 | if (targetSdk > android.os.Build.VERSION_CODES.R) { |
| 2285 | // Callers targeting S have no business invoking this method. |
| 2286 | return; |
| 2287 | } |
| 2288 | |
| 2289 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2290 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2291 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2292 | .setCallingPackage(callingPackage) |
| 2293 | .setCallingFeatureId(null) |
| 2294 | .setCallingPid(Binder.getCallingPid()) |
| 2295 | .setCallingUid(Binder.getCallingUid()) |
| 2296 | .setMethod("updateServiceLocation") |
| 2297 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2298 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2299 | .build()); |
| 2300 | // Apps that lack location permission have no business calling this method; |
| 2301 | // however, because no permission was declared in the public API, denials must |
| 2302 | // all be "soft". |
| 2303 | switch (locationResult) { |
| 2304 | case DENIED_HARD: /* fall through */ |
| 2305 | case DENIED_SOFT: |
| 2306 | return; |
| 2307 | } |
| 2308 | |
| 2309 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2310 | final long identity = Binder.clearCallingIdentity(); |
| 2311 | try { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2312 | final Phone phone = getPhone(getDefaultSubscription()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2313 | if (phone != null) { |
Nathan Harold | 1f889d8 | 2020-06-04 17:05:26 -0700 | [diff] [blame] | 2314 | phone.updateServiceLocation(workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2315 | } |
| 2316 | } finally { |
| 2317 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2318 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2319 | } |
| 2320 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2321 | @Deprecated |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2322 | @Override |
| 2323 | public boolean isRadioOn(String callingPackage) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2324 | return isRadioOnWithFeature(callingPackage, null); |
| 2325 | } |
| 2326 | |
| 2327 | |
| 2328 | @Override |
| 2329 | public boolean isRadioOnWithFeature(String callingPackage, String callingFeatureId) { |
| 2330 | return isRadioOnForSubscriberWithFeature(getDefaultSubscription(), callingPackage, |
| 2331 | callingFeatureId); |
| 2332 | } |
| 2333 | |
| 2334 | @Deprecated |
| 2335 | @Override |
| 2336 | public boolean isRadioOnForSubscriber(int subId, String callingPackage) { |
| 2337 | return isRadioOnForSubscriberWithFeature(subId, callingPackage, null); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2338 | } |
| 2339 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2340 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2341 | public boolean isRadioOnForSubscriberWithFeature(int subId, String callingPackage, |
| 2342 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2343 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2344 | mApp, subId, callingPackage, callingFeatureId, "isRadioOnForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2345 | return false; |
| 2346 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2347 | |
| 2348 | final long identity = Binder.clearCallingIdentity(); |
| 2349 | try { |
| 2350 | return isRadioOnForSubscriber(subId); |
| 2351 | } finally { |
| 2352 | Binder.restoreCallingIdentity(identity); |
| 2353 | } |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | private boolean isRadioOnForSubscriber(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2357 | final long identity = Binder.clearCallingIdentity(); |
| 2358 | try { |
| 2359 | final Phone phone = getPhone(subId); |
| 2360 | if (phone != null) { |
| 2361 | return phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF; |
| 2362 | } else { |
| 2363 | return false; |
| 2364 | } |
| 2365 | } finally { |
| 2366 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2367 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2368 | } |
| 2369 | |
| 2370 | public void toggleRadioOnOff() { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2371 | toggleRadioOnOffForSubscriber(getDefaultSubscription()); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2372 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2373 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2374 | public void toggleRadioOnOffForSubscriber(int subId) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2375 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2376 | |
| 2377 | final long identity = Binder.clearCallingIdentity(); |
| 2378 | try { |
| 2379 | final Phone phone = getPhone(subId); |
| 2380 | if (phone != null) { |
| 2381 | phone.setRadioPower(!isRadioOnForSubscriber(subId)); |
| 2382 | } |
| 2383 | } finally { |
| 2384 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2385 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2386 | } |
| 2387 | |
| 2388 | public boolean setRadio(boolean turnOn) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2389 | return setRadioForSubscriber(getDefaultSubscription(), turnOn); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2390 | } |
| 2391 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2392 | public boolean setRadioForSubscriber(int subId, boolean turnOn) { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2393 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2394 | |
| 2395 | final long identity = Binder.clearCallingIdentity(); |
| 2396 | try { |
| 2397 | final Phone phone = getPhone(subId); |
| 2398 | if (phone == null) { |
| 2399 | return false; |
| 2400 | } |
| 2401 | if ((phone.getServiceState().getState() != ServiceState.STATE_POWER_OFF) != turnOn) { |
| 2402 | toggleRadioOnOffForSubscriber(subId); |
| 2403 | } |
| 2404 | return true; |
| 2405 | } finally { |
| 2406 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2407 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2408 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2409 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2410 | public boolean needMobileRadioShutdown() { |
Shuo Qian | fa7b6b3 | 2019-12-10 10:40:38 -0800 | [diff] [blame] | 2411 | enforceReadPrivilegedPermission("needMobileRadioShutdown"); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2412 | /* |
| 2413 | * If any of the Radios are available, it will need to be |
| 2414 | * shutdown. So return true if any Radio is available. |
| 2415 | */ |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2416 | final long identity = Binder.clearCallingIdentity(); |
| 2417 | try { |
| 2418 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2419 | Phone phone = PhoneFactory.getPhone(i); |
| 2420 | if (phone != null && phone.isRadioAvailable()) return true; |
| 2421 | } |
| 2422 | logv(TelephonyManager.getDefault().getPhoneCount() + " Phones are shutdown."); |
| 2423 | return false; |
| 2424 | } finally { |
| 2425 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2426 | } |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2427 | } |
| 2428 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2429 | @Override |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2430 | public void shutdownMobileRadios() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2431 | enforceModifyPermission(); |
| 2432 | |
| 2433 | final long identity = Binder.clearCallingIdentity(); |
| 2434 | try { |
| 2435 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 2436 | logv("Shutting down Phone " + i); |
| 2437 | shutdownRadioUsingPhoneId(i); |
| 2438 | } |
| 2439 | } finally { |
| 2440 | Binder.restoreCallingIdentity(identity); |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2441 | } |
| 2442 | } |
| 2443 | |
| 2444 | private void shutdownRadioUsingPhoneId(int phoneId) { |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 2445 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 2446 | if (phone != null && phone.isRadioAvailable()) { |
| 2447 | phone.shutdownRadio(); |
| 2448 | } |
| 2449 | } |
| 2450 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2451 | public boolean setRadioPower(boolean turnOn) { |
Jack Yu | b4e1616 | 2017-05-15 12:48:40 -0700 | [diff] [blame] | 2452 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2453 | |
| 2454 | final long identity = Binder.clearCallingIdentity(); |
| 2455 | try { |
| 2456 | final Phone defaultPhone = PhoneFactory.getDefaultPhone(); |
| 2457 | if (defaultPhone != null) { |
| 2458 | defaultPhone.setRadioPower(turnOn); |
| 2459 | return true; |
| 2460 | } else { |
| 2461 | loge("There's no default phone."); |
| 2462 | return false; |
| 2463 | } |
| 2464 | } finally { |
| 2465 | Binder.restoreCallingIdentity(identity); |
Wei Liu | 9ae2a06 | 2016-08-08 11:09:34 -0700 | [diff] [blame] | 2466 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2467 | } |
| 2468 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2469 | public boolean setRadioPowerForSubscriber(int subId, boolean turnOn) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2470 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2471 | |
| 2472 | final long identity = Binder.clearCallingIdentity(); |
| 2473 | try { |
| 2474 | final Phone phone = getPhone(subId); |
| 2475 | if (phone != null) { |
| 2476 | phone.setRadioPower(turnOn); |
| 2477 | return true; |
| 2478 | } else { |
| 2479 | return false; |
| 2480 | } |
| 2481 | } finally { |
| 2482 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2483 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2484 | } |
| 2485 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2486 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2487 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2488 | public boolean enableDataConnectivity() { |
| 2489 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2490 | |
| 2491 | final long identity = Binder.clearCallingIdentity(); |
| 2492 | try { |
| 2493 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2494 | final Phone phone = getPhone(subId); |
| 2495 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2496 | phone.getDataEnabledSettings().setDataEnabled( |
| 2497 | TelephonyManager.DATA_ENABLED_REASON_USER, true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2498 | return true; |
| 2499 | } else { |
| 2500 | return false; |
| 2501 | } |
| 2502 | } finally { |
| 2503 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2504 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2505 | } |
| 2506 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2507 | // FIXME: subId version needed |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2508 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2509 | public boolean disableDataConnectivity() { |
| 2510 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2511 | |
| 2512 | final long identity = Binder.clearCallingIdentity(); |
| 2513 | try { |
| 2514 | int subId = mSubscriptionController.getDefaultDataSubId(); |
| 2515 | final Phone phone = getPhone(subId); |
| 2516 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 2517 | phone.getDataEnabledSettings().setDataEnabled( |
| 2518 | TelephonyManager.DATA_ENABLED_REASON_USER, false); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2519 | return true; |
| 2520 | } else { |
| 2521 | return false; |
| 2522 | } |
| 2523 | } finally { |
| 2524 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2525 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2526 | } |
| 2527 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2528 | @Override |
Jack Yu | acf8a13 | 2017-05-01 17:00:48 -0700 | [diff] [blame] | 2529 | public boolean isDataConnectivityPossible(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2530 | final long identity = Binder.clearCallingIdentity(); |
| 2531 | try { |
| 2532 | final Phone phone = getPhone(subId); |
| 2533 | if (phone != null) { |
Jack Yu | b5d8f64 | 2018-11-26 11:20:48 -0800 | [diff] [blame] | 2534 | return phone.isDataAllowed(ApnSetting.TYPE_DEFAULT); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2535 | } else { |
| 2536 | return false; |
| 2537 | } |
| 2538 | } finally { |
| 2539 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2540 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2541 | } |
| 2542 | |
| 2543 | public boolean handlePinMmi(String dialString) { |
Wink Saville | add7cc5 | 2014-09-08 14:23:09 -0700 | [diff] [blame] | 2544 | return handlePinMmiForSubscriber(getDefaultSubscription(), dialString); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2545 | } |
| 2546 | |
pkanwar | ae03a6b | 2016-11-06 20:37:09 -0800 | [diff] [blame] | 2547 | public void handleUssdRequest(int subId, String ussdRequest, ResultReceiver wrappedCallback) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2548 | enforceCallPermission(); |
| 2549 | |
| 2550 | final long identity = Binder.clearCallingIdentity(); |
| 2551 | try { |
| 2552 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2553 | return; |
| 2554 | } |
| 2555 | Pair<String, ResultReceiver> ussdObject = new Pair(ussdRequest, wrappedCallback); |
| 2556 | sendRequest(CMD_HANDLE_USSD_REQUEST, ussdObject, subId); |
| 2557 | } finally { |
| 2558 | Binder.restoreCallingIdentity(identity); |
| 2559 | } |
pkanwar | 32d516d | 2016-10-14 19:37:38 -0700 | [diff] [blame] | 2560 | }; |
| 2561 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 2562 | public boolean handlePinMmiForSubscriber(int subId, String dialString) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2563 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2564 | |
| 2565 | final long identity = Binder.clearCallingIdentity(); |
| 2566 | try { |
| 2567 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 2568 | return false; |
| 2569 | } |
| 2570 | return (Boolean) sendRequest(CMD_HANDLE_PIN_MMI, dialString, subId); |
| 2571 | } finally { |
| 2572 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2573 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2576 | public int getCallState() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2577 | return getCallStateForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 2578 | } |
| 2579 | |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 2580 | public int getCallStateForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2581 | final long identity = Binder.clearCallingIdentity(); |
| 2582 | try { |
| 2583 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2584 | return phone == null ? TelephonyManager.CALL_STATE_IDLE : |
| 2585 | PhoneConstantConversions.convertCallState(phone.getState()); |
| 2586 | } finally { |
| 2587 | Binder.restoreCallingIdentity(identity); |
| 2588 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2591 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2592 | public int getDataState() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2593 | return getDataStateForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2594 | } |
| 2595 | |
| 2596 | @Override |
| 2597 | public int getDataStateForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2598 | final long identity = Binder.clearCallingIdentity(); |
| 2599 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2600 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2601 | if (phone != null) { |
| 2602 | return PhoneConstantConversions.convertDataState(phone.getDataConnectionState()); |
| 2603 | } else { |
| 2604 | return PhoneConstantConversions.convertDataState( |
| 2605 | PhoneConstants.DataState.DISCONNECTED); |
| 2606 | } |
| 2607 | } finally { |
| 2608 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2609 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2610 | } |
| 2611 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2612 | @Override |
Nathan Harold | e037c47 | 2019-06-26 00:41:07 +0000 | [diff] [blame] | 2613 | public int getDataActivity() { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2614 | return getDataActivityForSubId(mSubscriptionController.getDefaultDataSubId()); |
| 2615 | } |
| 2616 | |
| 2617 | @Override |
| 2618 | public int getDataActivityForSubId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2619 | final long identity = Binder.clearCallingIdentity(); |
| 2620 | try { |
Nathan Harold | c4689b1 | 2019-06-14 16:58:30 -0700 | [diff] [blame] | 2621 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2622 | if (phone != null) { |
| 2623 | return DefaultPhoneNotifier.convertDataActivityState(phone.getDataActivityState()); |
| 2624 | } else { |
| 2625 | return TelephonyManager.DATA_ACTIVITY_NONE; |
| 2626 | } |
| 2627 | } finally { |
| 2628 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 2629 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2630 | } |
| 2631 | |
| 2632 | @Override |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2633 | public CellIdentity getCellLocation(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2634 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2635 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2636 | |
| 2637 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2638 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2639 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2640 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2641 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2642 | .setCallingPid(Binder.getCallingPid()) |
| 2643 | .setCallingUid(Binder.getCallingUid()) |
| 2644 | .setMethod("getCellLocation") |
Hall Liu | 773ba02 | 2020-01-24 18:07:12 -0800 | [diff] [blame] | 2645 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2646 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2647 | .build()); |
| 2648 | switch (locationResult) { |
| 2649 | case DENIED_HARD: |
| 2650 | throw new SecurityException("Not allowed to access cell location"); |
| 2651 | case DENIED_SOFT: |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2652 | return (getDefaultPhone().getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) |
| 2653 | ? new CellIdentityCdma() : new CellIdentityGsm(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2656 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2657 | final long identity = Binder.clearCallingIdentity(); |
| 2658 | try { |
| 2659 | if (DBG_LOC) log("getCellLocation: is active user"); |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2660 | int subId = mSubscriptionController.getDefaultDataSubId(); |
Meng Wang | a10e89e | 2019-12-09 13:13:01 -0800 | [diff] [blame] | 2661 | return (CellIdentity) sendRequest(CMD_GET_CELL_LOCATION, workSource, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2662 | } finally { |
| 2663 | Binder.restoreCallingIdentity(identity); |
| 2664 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2665 | } |
| 2666 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2667 | @Override |
Jack Yu | eb1e7fe | 2020-02-22 19:38:58 -0800 | [diff] [blame] | 2668 | public String getNetworkCountryIsoForPhone(int phoneId) { |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2669 | // Reporting the correct network country is ambiguous when IWLAN could conflict with |
| 2670 | // registered cell info, so return a NULL country instead. |
| 2671 | final long identity = Binder.clearCallingIdentity(); |
| 2672 | try { |
Malcolm Chen | 3732c2b | 2018-07-18 20:15:24 -0700 | [diff] [blame] | 2673 | if (phoneId == SubscriptionManager.INVALID_PHONE_INDEX) { |
| 2674 | // Get default phone in this case. |
| 2675 | phoneId = SubscriptionManager.DEFAULT_PHONE_INDEX; |
| 2676 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2677 | final int subId = mSubscriptionController.getSubIdUsingPhoneId(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2678 | Phone phone = PhoneFactory.getPhone(phoneId); |
Nathan Harold | 532f51c | 2020-04-21 19:31:10 -0700 | [diff] [blame] | 2679 | if (phone == null) return ""; |
| 2680 | ServiceStateTracker sst = phone.getServiceStateTracker(); |
| 2681 | if (sst == null) return ""; |
| 2682 | LocaleTracker lt = sst.getLocaleTracker(); |
| 2683 | if (lt == null) return ""; |
| 2684 | if (!TextUtils.isEmpty(lt.getCurrentCountry())) return lt.getCurrentCountry(); |
| 2685 | EmergencyNumberTracker ent = phone.getEmergencyNumberTracker(); |
| 2686 | return (ent == null) ? "" : ent.getEmergencyCountryIso(); |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2687 | } finally { |
| 2688 | Binder.restoreCallingIdentity(identity); |
| 2689 | } |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2690 | } |
| 2691 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2692 | /** |
| 2693 | * This method was removed due to potential issues caused by performing partial |
| 2694 | * updates of service state, and lack of a credible use case. |
| 2695 | * |
| 2696 | * This has the ability to break the telephony implementation by disabling notification of |
| 2697 | * changes in device connectivity. DO NOT USE THIS! |
| 2698 | */ |
Jonathan Basseri | bf5362b | 2017-07-19 12:22:35 -0700 | [diff] [blame] | 2699 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2700 | public void enableLocationUpdates() { |
| 2701 | mApp.enforceCallingOrSelfPermission( |
| 2702 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2703 | } |
| 2704 | |
Nathan Harold | 7c8d0f1 | 2020-05-28 20:40:31 -0700 | [diff] [blame] | 2705 | /** |
| 2706 | * This method was removed due to potential issues caused by performing partial |
| 2707 | * updates of service state, and lack of a credible use case. |
| 2708 | * |
| 2709 | * This has the ability to break the telephony implementation by disabling notification of |
| 2710 | * changes in device connectivity. DO NOT USE THIS! |
| 2711 | */ |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2712 | @Override |
| 2713 | public void disableLocationUpdates() { |
| 2714 | mApp.enforceCallingOrSelfPermission( |
| 2715 | android.Manifest.permission.CONTROL_LOCATION_UPDATES, null); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2716 | } |
| 2717 | |
| 2718 | @Override |
| 2719 | @SuppressWarnings("unchecked") |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2720 | public List<NeighboringCellInfo> getNeighboringCellInfo(String callingPackage, |
| 2721 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2722 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | dbea45a | 2018-08-30 14:35:07 -0700 | [diff] [blame] | 2723 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2724 | throw new SecurityException( |
| 2725 | "getNeighboringCellInfo() is unavailable to callers targeting Q+ SDK levels."); |
| 2726 | } |
Nathan Harold | b4d5561 | 2018-07-20 13:13:08 -0700 | [diff] [blame] | 2727 | |
Jordan Liu | 1617b71 | 2019-07-10 15:06:26 -0700 | [diff] [blame] | 2728 | if (mAppOps.noteOp(AppOpsManager.OPSTR_NEIGHBORING_CELLS, Binder.getCallingUid(), |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2729 | callingPackage) != AppOpsManager.MODE_ALLOWED) { |
| 2730 | return null; |
| 2731 | } |
Svetoslav | 64fad26 | 2015-04-14 14:35:21 -0700 | [diff] [blame] | 2732 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2733 | if (DBG_LOC) log("getNeighboringCellInfo: is active user"); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2734 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2735 | List<CellInfo> info = getAllCellInfo(callingPackage, callingFeatureId); |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2736 | if (info == null) return null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2737 | |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2738 | List<NeighboringCellInfo> neighbors = new ArrayList<NeighboringCellInfo>(); |
| 2739 | for (CellInfo ci : info) { |
| 2740 | if (ci instanceof CellInfoGsm) { |
| 2741 | neighbors.add(new NeighboringCellInfo((CellInfoGsm) ci)); |
| 2742 | } else if (ci instanceof CellInfoWcdma) { |
| 2743 | neighbors.add(new NeighboringCellInfo((CellInfoWcdma) ci)); |
| 2744 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2745 | } |
Nathan Harold | f180aac | 2018-06-01 18:43:55 -0700 | [diff] [blame] | 2746 | return (neighbors.size()) > 0 ? neighbors : null; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2747 | } |
| 2748 | |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2749 | private List<CellInfo> getCachedCellInfo() { |
| 2750 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2751 | for (Phone phone : PhoneFactory.getPhones()) { |
| 2752 | List<CellInfo> info = phone.getAllCellInfo(); |
| 2753 | if (info != null) cellInfos.addAll(info); |
| 2754 | } |
| 2755 | return cellInfos; |
| 2756 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2757 | |
| 2758 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2759 | public List<CellInfo> getAllCellInfo(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2760 | mApp.getSystemService(AppOpsManager.class) |
Hall Liu | 1aa510f | 2017-11-22 17:40:08 -0800 | [diff] [blame] | 2761 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2762 | |
| 2763 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2764 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2765 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2766 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2767 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2768 | .setCallingPid(Binder.getCallingPid()) |
| 2769 | .setCallingUid(Binder.getCallingUid()) |
| 2770 | .setMethod("getAllCellInfo") |
Nathan Harold | 5ae50b5 | 2019-02-20 15:46:36 -0800 | [diff] [blame] | 2771 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2772 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
| 2773 | .build()); |
| 2774 | switch (locationResult) { |
| 2775 | case DENIED_HARD: |
| 2776 | throw new SecurityException("Not allowed to access cell info"); |
| 2777 | case DENIED_SOFT: |
| 2778 | return new ArrayList<>(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2779 | } |
| 2780 | |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2781 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2782 | if (targetSdk >= android.os.Build.VERSION_CODES.Q) { |
| 2783 | return getCachedCellInfo(); |
| 2784 | } |
| 2785 | |
Svetoslav Ganov | 4a9d448 | 2017-06-20 19:53:35 -0700 | [diff] [blame] | 2786 | if (DBG_LOC) log("getAllCellInfo: is active user"); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2787 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2788 | final long identity = Binder.clearCallingIdentity(); |
| 2789 | try { |
| 2790 | List<CellInfo> cellInfos = new ArrayList<CellInfo>(); |
| 2791 | for (Phone phone : PhoneFactory.getPhones()) { |
Nathan Harold | 3ff8893 | 2018-08-14 10:19:49 -0700 | [diff] [blame] | 2792 | final List<CellInfo> info = (List<CellInfo>) sendRequest( |
Nathan Harold | 92bed18 | 2018-10-12 18:16:49 -0700 | [diff] [blame] | 2793 | CMD_GET_ALL_CELL_INFO, null, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2794 | if (info != null) cellInfos.addAll(info); |
| 2795 | } |
| 2796 | return cellInfos; |
| 2797 | } finally { |
| 2798 | Binder.restoreCallingIdentity(identity); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2799 | } |
| 2800 | } |
| 2801 | |
Sailesh Nepal | bd76e4e | 2013-10-27 13:59:44 -0700 | [diff] [blame] | 2802 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2803 | public void requestCellInfoUpdate(int subId, ICellInfoCallback cb, String callingPackage, |
| 2804 | String callingFeatureId) { |
| 2805 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, |
| 2806 | getWorkSource(Binder.getCallingUid())); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2807 | } |
| 2808 | |
| 2809 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2810 | public void requestCellInfoUpdateWithWorkSource(int subId, ICellInfoCallback cb, |
| 2811 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2812 | enforceModifyPermission(); |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2813 | requestCellInfoUpdateInternal(subId, cb, callingPackage, callingFeatureId, workSource); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2814 | } |
| 2815 | |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2816 | private void requestCellInfoUpdateInternal(int subId, ICellInfoCallback cb, |
| 2817 | String callingPackage, String callingFeatureId, WorkSource workSource) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2818 | mApp.getSystemService(AppOpsManager.class) |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2819 | .checkPackage(Binder.getCallingUid(), callingPackage); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2820 | |
| 2821 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 2822 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 2823 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 2824 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 2825 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2826 | .setCallingPid(Binder.getCallingPid()) |
| 2827 | .setCallingUid(Binder.getCallingUid()) |
| 2828 | .setMethod("requestCellInfoUpdate") |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2829 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.BASE) |
| 2830 | .setMinSdkVersionForFine(Build.VERSION_CODES.BASE) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2831 | .build()); |
| 2832 | switch (locationResult) { |
| 2833 | case DENIED_HARD: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2834 | if (TelephonyPermissions |
| 2835 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2836 | // Safetynet logging for b/154934934 |
| 2837 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2838 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2839 | throw new SecurityException("Not allowed to access cell info"); |
| 2840 | case DENIED_SOFT: |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 2841 | if (TelephonyPermissions |
| 2842 | .getTargetSdk(mApp, callingPackage) < Build.VERSION_CODES.Q) { |
Hall Liu | d60acc9 | 2020-05-21 17:09:35 -0700 | [diff] [blame] | 2843 | // Safetynet logging for b/154934934 |
| 2844 | EventLog.writeEvent(0x534e4554, "154934934", Binder.getCallingUid()); |
| 2845 | } |
Nathan Harold | 5320c42 | 2019-05-09 10:26:08 -0700 | [diff] [blame] | 2846 | try { |
| 2847 | cb.onCellInfo(new ArrayList<CellInfo>()); |
| 2848 | } catch (RemoteException re) { |
| 2849 | // Drop without consequences |
| 2850 | } |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 2851 | return; |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2852 | } |
| 2853 | |
Nathan Harold | a939a96 | 2019-05-09 10:13:47 -0700 | [diff] [blame] | 2854 | |
| 2855 | final Phone phone = getPhoneFromSubId(subId); |
Nathan Harold | fa8da0f | 2018-09-27 18:51:29 -0700 | [diff] [blame] | 2856 | if (phone == null) throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
| 2857 | |
| 2858 | sendRequestAsync(CMD_REQUEST_CELL_INFO_UPDATE, cb, phone, workSource); |
| 2859 | } |
| 2860 | |
| 2861 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2862 | public void setCellInfoListRate(int rateInMillis) { |
Jack Yu | a8d8cb8 | 2017-01-16 10:15:34 -0800 | [diff] [blame] | 2863 | enforceModifyPermission(); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 2864 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2865 | |
| 2866 | final long identity = Binder.clearCallingIdentity(); |
| 2867 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2868 | getDefaultPhone().setCellInfoListRate(rateInMillis, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2869 | } finally { |
| 2870 | Binder.restoreCallingIdentity(identity); |
| 2871 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 2872 | } |
| 2873 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2874 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2875 | public String getImeiForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2876 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2877 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2878 | return null; |
| 2879 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2880 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2881 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2882 | callingPackage, callingFeatureId, "getImeiForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2883 | return null; |
| 2884 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2885 | |
| 2886 | final long identity = Binder.clearCallingIdentity(); |
| 2887 | try { |
| 2888 | return phone.getImei(); |
| 2889 | } finally { |
| 2890 | Binder.restoreCallingIdentity(identity); |
| 2891 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2892 | } |
| 2893 | |
| 2894 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2895 | public String getTypeAllocationCodeForSlot(int slotIndex) { |
| 2896 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2897 | String tac = null; |
| 2898 | if (phone != null) { |
| 2899 | String imei = phone.getImei(); |
| 2900 | tac = imei == null ? null : imei.substring(0, TYPE_ALLOCATION_CODE_LENGTH); |
| 2901 | } |
| 2902 | return tac; |
| 2903 | } |
| 2904 | |
| 2905 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2906 | public String getMeidForSlot(int slotIndex, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2907 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2908 | if (phone == null) { |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2909 | return null; |
| 2910 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 2911 | |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2912 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 2913 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2914 | callingPackage, callingFeatureId, "getMeidForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2915 | return null; |
| 2916 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2917 | |
| 2918 | final long identity = Binder.clearCallingIdentity(); |
| 2919 | try { |
| 2920 | return phone.getMeid(); |
| 2921 | } finally { |
| 2922 | Binder.restoreCallingIdentity(identity); |
| 2923 | } |
Jack Yu | 2af8d71 | 2017-03-15 17:14:14 -0700 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | @Override |
David Kelly | 5e06a7f | 2018-03-12 14:10:59 +0000 | [diff] [blame] | 2927 | public String getManufacturerCodeForSlot(int slotIndex) { |
| 2928 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2929 | String manufacturerCode = null; |
| 2930 | if (phone != null) { |
| 2931 | String meid = phone.getMeid(); |
| 2932 | manufacturerCode = meid == null ? null : meid.substring(0, MANUFACTURER_CODE_LENGTH); |
| 2933 | } |
| 2934 | return manufacturerCode; |
| 2935 | } |
| 2936 | |
| 2937 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2938 | public String getDeviceSoftwareVersionForSlot(int slotIndex, String callingPackage, |
| 2939 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2940 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 2941 | if (phone == null) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 2942 | return null; |
| 2943 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2944 | int subId = phone.getSubId(); |
| 2945 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 2946 | mApp, subId, callingPackage, callingFeatureId, |
| 2947 | "getDeviceSoftwareVersionForSlot")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 2948 | return null; |
| 2949 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2950 | |
| 2951 | final long identity = Binder.clearCallingIdentity(); |
| 2952 | try { |
| 2953 | return phone.getDeviceSvn(); |
| 2954 | } finally { |
| 2955 | Binder.restoreCallingIdentity(identity); |
| 2956 | } |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 2957 | } |
| 2958 | |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2959 | @Override |
| 2960 | public int getSubscriptionCarrierId(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2961 | final long identity = Binder.clearCallingIdentity(); |
| 2962 | try { |
| 2963 | final Phone phone = getPhone(subId); |
| 2964 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID : phone.getCarrierId(); |
| 2965 | } finally { |
| 2966 | Binder.restoreCallingIdentity(identity); |
| 2967 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2968 | } |
| 2969 | |
| 2970 | @Override |
| 2971 | public String getSubscriptionCarrierName(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 2972 | final long identity = Binder.clearCallingIdentity(); |
| 2973 | try { |
| 2974 | final Phone phone = getPhone(subId); |
| 2975 | return phone == null ? null : phone.getCarrierName(); |
| 2976 | } finally { |
| 2977 | Binder.restoreCallingIdentity(identity); |
| 2978 | } |
fionaxu | 43304da | 2017-11-27 22:51:16 -0800 | [diff] [blame] | 2979 | } |
| 2980 | |
calvinpan | ffe225e | 2018-11-01 19:43:06 +0800 | [diff] [blame] | 2981 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2982 | public int getSubscriptionSpecificCarrierId(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2983 | final long identity = Binder.clearCallingIdentity(); |
| 2984 | try { |
| 2985 | final Phone phone = getPhone(subId); |
| 2986 | return phone == null ? TelephonyManager.UNKNOWN_CARRIER_ID |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2987 | : phone.getSpecificCarrierId(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2988 | } finally { |
| 2989 | Binder.restoreCallingIdentity(identity); |
| 2990 | } |
| 2991 | } |
| 2992 | |
| 2993 | @Override |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2994 | public String getSubscriptionSpecificCarrierName(int subId) { |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2995 | final long identity = Binder.clearCallingIdentity(); |
| 2996 | try { |
| 2997 | final Phone phone = getPhone(subId); |
chen xu | 0026ca6 | 2019-03-06 15:28:50 -0800 | [diff] [blame] | 2998 | return phone == null ? null : phone.getSpecificCarrierName(); |
chen xu | 2563722 | 2018-11-04 17:17:00 -0800 | [diff] [blame] | 2999 | } finally { |
| 3000 | Binder.restoreCallingIdentity(identity); |
| 3001 | } |
| 3002 | } |
| 3003 | |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3004 | @Override |
chen xu | 864e11c | 2018-12-06 22:10:03 -0800 | [diff] [blame] | 3005 | public int getCarrierIdFromMccMnc(int slotIndex, String mccmnc, boolean isSubscriptionMccMnc) { |
| 3006 | if (!isSubscriptionMccMnc) { |
| 3007 | enforceReadPrivilegedPermission("getCarrierIdFromMccMnc"); |
| 3008 | } |
chen xu | 651eec7 | 2018-11-11 19:03:44 -0800 | [diff] [blame] | 3009 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3010 | if (phone == null) { |
| 3011 | return TelephonyManager.UNKNOWN_CARRIER_ID; |
| 3012 | } |
| 3013 | final long identity = Binder.clearCallingIdentity(); |
| 3014 | try { |
| 3015 | return CarrierResolver.getCarrierIdFromMccMnc(phone.getContext(), mccmnc); |
| 3016 | } finally { |
| 3017 | Binder.restoreCallingIdentity(identity); |
| 3018 | } |
| 3019 | } |
| 3020 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3021 | // |
| 3022 | // Internal helper methods. |
| 3023 | // |
| 3024 | |
Sanket Padawe | ee13a9b | 2016-03-08 17:30:28 -0800 | [diff] [blame] | 3025 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3026 | * Make sure the caller has the MODIFY_PHONE_STATE permission. |
| 3027 | * |
| 3028 | * @throws SecurityException if the caller does not have the required permission |
| 3029 | */ |
| 3030 | private void enforceModifyPermission() { |
| 3031 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE, null); |
| 3032 | } |
| 3033 | |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 3034 | /** |
| 3035 | * Make sure the caller is system. |
| 3036 | * |
| 3037 | * @throws SecurityException if the caller is not system. |
| 3038 | */ |
| 3039 | private void enforceSystemCaller() { |
| 3040 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 3041 | throw new SecurityException("Caller must be system"); |
| 3042 | } |
| 3043 | } |
| 3044 | |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 3045 | private void enforceActiveEmergencySessionPermission() { |
| 3046 | mApp.enforceCallingOrSelfPermission( |
| 3047 | android.Manifest.permission.READ_ACTIVE_EMERGENCY_SESSION, null); |
| 3048 | } |
| 3049 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3050 | /** |
| 3051 | * Make sure the caller has the CALL_PHONE permission. |
| 3052 | * |
| 3053 | * @throws SecurityException if the caller does not have the required permission |
| 3054 | */ |
| 3055 | private void enforceCallPermission() { |
| 3056 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.CALL_PHONE, null); |
| 3057 | } |
| 3058 | |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 3059 | private void enforceSettingsPermission() { |
| 3060 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.NETWORK_SETTINGS, null); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 3061 | } |
| 3062 | |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3063 | private String createTelUrl(String number) { |
| 3064 | if (TextUtils.isEmpty(number)) { |
| 3065 | return null; |
| 3066 | } |
| 3067 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 3068 | return "tel:" + number; |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3069 | } |
| 3070 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3071 | private static void log(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3072 | Log.d(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3073 | } |
| 3074 | |
Naveen Kalla | 1fd79bd | 2014-08-08 00:48:59 -0700 | [diff] [blame] | 3075 | private static void logv(String msg) { |
| 3076 | Log.v(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3077 | } |
| 3078 | |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 3079 | private static void loge(String msg) { |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3080 | Log.e(LOG_TAG, "[PhoneIntfMgr] " + msg); |
| 3081 | } |
| 3082 | |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3083 | @Override |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3084 | public int getActivePhoneType() { |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 3085 | return getActivePhoneTypeForSlot(getSlotForDefaultSubscription()); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3086 | } |
| 3087 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3088 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 3089 | public int getActivePhoneTypeForSlot(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3090 | final long identity = Binder.clearCallingIdentity(); |
| 3091 | try { |
| 3092 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 3093 | if (phone == null) { |
| 3094 | return PhoneConstants.PHONE_TYPE_NONE; |
| 3095 | } else { |
| 3096 | return phone.getPhoneType(); |
| 3097 | } |
| 3098 | } finally { |
| 3099 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3100 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
| 3103 | /** |
| 3104 | * Returns the CDMA ERI icon index to display |
| 3105 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3106 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3107 | public int getCdmaEriIconIndex(String callingPackage, String callingFeatureId) { |
| 3108 | return getCdmaEriIconIndexForSubscriber(getDefaultSubscription(), callingPackage, |
| 3109 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3110 | } |
| 3111 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3112 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3113 | public int getCdmaEriIconIndexForSubscriber(int subId, String callingPackage, |
| 3114 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3115 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3116 | mApp, subId, callingPackage, callingFeatureId, |
| 3117 | "getCdmaEriIconIndexForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3118 | return -1; |
| 3119 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3120 | |
| 3121 | final long identity = Binder.clearCallingIdentity(); |
| 3122 | try { |
| 3123 | final Phone phone = getPhone(subId); |
| 3124 | if (phone != null) { |
| 3125 | return phone.getCdmaEriIconIndex(); |
| 3126 | } else { |
| 3127 | return -1; |
| 3128 | } |
| 3129 | } finally { |
| 3130 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3131 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3132 | } |
| 3133 | |
| 3134 | /** |
| 3135 | * Returns the CDMA ERI icon mode, |
| 3136 | * 0 - ON |
| 3137 | * 1 - FLASHING |
| 3138 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3139 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3140 | public int getCdmaEriIconMode(String callingPackage, String callingFeatureId) { |
| 3141 | return getCdmaEriIconModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 3142 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3143 | } |
| 3144 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3145 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3146 | public int getCdmaEriIconModeForSubscriber(int subId, String callingPackage, |
| 3147 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3148 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3149 | mApp, subId, callingPackage, callingFeatureId, |
| 3150 | "getCdmaEriIconModeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3151 | return -1; |
| 3152 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3153 | |
| 3154 | final long identity = Binder.clearCallingIdentity(); |
| 3155 | try { |
| 3156 | final Phone phone = getPhone(subId); |
| 3157 | if (phone != null) { |
| 3158 | return phone.getCdmaEriIconMode(); |
| 3159 | } else { |
| 3160 | return -1; |
| 3161 | } |
| 3162 | } finally { |
| 3163 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3164 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3165 | } |
| 3166 | |
| 3167 | /** |
| 3168 | * Returns the CDMA ERI text, |
| 3169 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3170 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3171 | public String getCdmaEriText(String callingPackage, String callingFeatureId) { |
| 3172 | return getCdmaEriTextForSubscriber(getDefaultSubscription(), callingPackage, |
| 3173 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3174 | } |
| 3175 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3176 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3177 | public String getCdmaEriTextForSubscriber(int subId, String callingPackage, |
| 3178 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3179 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3180 | mApp, subId, callingPackage, callingFeatureId, |
| 3181 | "getCdmaEriIconTextForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 3182 | return null; |
| 3183 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3184 | |
| 3185 | final long identity = Binder.clearCallingIdentity(); |
| 3186 | try { |
| 3187 | final Phone phone = getPhone(subId); |
| 3188 | if (phone != null) { |
| 3189 | return phone.getCdmaEriText(); |
| 3190 | } else { |
| 3191 | return null; |
| 3192 | } |
| 3193 | } finally { |
| 3194 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3195 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3196 | } |
| 3197 | |
| 3198 | /** |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3199 | * Returns the CDMA MDN. |
| 3200 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3201 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3202 | public String getCdmaMdn(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3203 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3204 | mApp, subId, "getCdmaMdn"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3205 | |
| 3206 | final long identity = Binder.clearCallingIdentity(); |
| 3207 | try { |
| 3208 | final Phone phone = getPhone(subId); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3209 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3210 | return phone.getLine1Number(); |
| 3211 | } else { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3212 | loge("getCdmaMdn: no phone found. Invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3213 | return null; |
| 3214 | } |
| 3215 | } finally { |
| 3216 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3217 | } |
| 3218 | } |
| 3219 | |
| 3220 | /** |
| 3221 | * Returns the CDMA MIN. |
| 3222 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3223 | @Override |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 3224 | public String getCdmaMin(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3225 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3226 | mApp, subId, "getCdmaMin"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3227 | |
| 3228 | final long identity = Binder.clearCallingIdentity(); |
| 3229 | try { |
| 3230 | final Phone phone = getPhone(subId); |
| 3231 | if (phone != null && phone.getPhoneType() == PhoneConstants.PHONE_TYPE_CDMA) { |
| 3232 | return phone.getCdmaMin(); |
| 3233 | } else { |
| 3234 | return null; |
| 3235 | } |
| 3236 | } finally { |
| 3237 | Binder.restoreCallingIdentity(identity); |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3238 | } |
| 3239 | } |
| 3240 | |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3241 | @Override |
| 3242 | public void requestNumberVerification(PhoneNumberRange range, long timeoutMillis, |
| 3243 | INumberVerificationCallback callback, String callingPackage) { |
| 3244 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.MODIFY_PHONE_STATE) |
| 3245 | != PERMISSION_GRANTED) { |
| 3246 | throw new SecurityException("Caller must hold the MODIFY_PHONE_STATE permission"); |
| 3247 | } |
| 3248 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 3249 | |
| 3250 | String authorizedPackage = NumberVerificationManager.getAuthorizedPackage(mApp); |
| 3251 | if (!TextUtils.equals(callingPackage, authorizedPackage)) { |
| 3252 | throw new SecurityException("Calling package must be configured in the device config"); |
| 3253 | } |
| 3254 | |
| 3255 | if (range == null) { |
| 3256 | throw new NullPointerException("Range must be non-null"); |
| 3257 | } |
| 3258 | |
| 3259 | timeoutMillis = Math.min(timeoutMillis, |
Hall Liu | bd069e3 | 2019-02-28 18:56:30 -0800 | [diff] [blame] | 3260 | TelephonyManager.getMaxNumberVerificationTimeoutMillis()); |
Hall Liu | d892bec | 2018-11-30 14:51:45 -0800 | [diff] [blame] | 3261 | |
| 3262 | NumberVerificationManager.getInstance().requestVerification(range, callback, timeoutMillis); |
| 3263 | } |
| 3264 | |
Junda Liu | ca05d5d | 2014-08-14 22:36:34 -0700 | [diff] [blame] | 3265 | /** |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3266 | * Returns true if CDMA provisioning needs to run. |
| 3267 | */ |
| 3268 | public boolean needsOtaServiceProvisioning() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3269 | final long identity = Binder.clearCallingIdentity(); |
| 3270 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3271 | return getDefaultPhone().needsOtaServiceProvisioning(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3272 | } finally { |
| 3273 | Binder.restoreCallingIdentity(identity); |
| 3274 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3275 | } |
| 3276 | |
| 3277 | /** |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3278 | * Sets the voice mail number of a given subId. |
| 3279 | */ |
| 3280 | @Override |
| 3281 | public boolean setVoiceMailNumber(int subId, String alphaTag, String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3282 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 3283 | mApp, subId, "setVoiceMailNumber"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3284 | |
| 3285 | final long identity = Binder.clearCallingIdentity(); |
| 3286 | try { |
| 3287 | Boolean success = (Boolean) sendRequest(CMD_SET_VOICEMAIL_NUMBER, |
| 3288 | new Pair<String, String>(alphaTag, number), new Integer(subId)); |
| 3289 | return success; |
| 3290 | } finally { |
| 3291 | Binder.restoreCallingIdentity(identity); |
| 3292 | } |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3293 | } |
| 3294 | |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3295 | @Override |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3296 | public Bundle getVisualVoicemailSettings(String callingPackage, int subId) { |
| 3297 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3298 | TelecomManager tm = mApp.getSystemService(TelecomManager.class); |
| 3299 | String systemDialer = tm.getSystemDialerPackage(); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3300 | if (!TextUtils.equals(callingPackage, systemDialer)) { |
| 3301 | throw new SecurityException("caller must be system dialer"); |
| 3302 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3303 | |
| 3304 | final long identity = Binder.clearCallingIdentity(); |
| 3305 | try { |
| 3306 | PhoneAccountHandle phoneAccountHandle = PhoneAccountHandleConverter.fromSubId(subId); |
| 3307 | if (phoneAccountHandle == null) { |
| 3308 | return null; |
| 3309 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3310 | return VisualVoicemailSettingsUtil.dump(mApp, phoneAccountHandle); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3311 | } finally { |
| 3312 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3313 | } |
Ta-wei Yen | c9df043 | 2017-04-17 17:09:07 -0700 | [diff] [blame] | 3314 | } |
| 3315 | |
| 3316 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3317 | public String getVisualVoicemailPackageName(String callingPackage, String callingFeatureId, |
| 3318 | int subId) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3319 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3320 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3321 | mApp, subId, callingPackage, callingFeatureId, |
| 3322 | "getVisualVoicemailPackageName")) { |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3323 | return null; |
| 3324 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3325 | |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3326 | final long identity = Binder.clearCallingIdentity(); |
| 3327 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3328 | return RemoteVvmTaskManager.getRemotePackage(mApp, subId).getPackageName(); |
Jeff Davidson | a8e4e24 | 2018-03-15 17:16:18 -0700 | [diff] [blame] | 3329 | } finally { |
| 3330 | Binder.restoreCallingIdentity(identity); |
| 3331 | } |
Ta-wei Yen | dca928f | 2017-01-10 16:17:08 -0800 | [diff] [blame] | 3332 | } |
| 3333 | |
| 3334 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3335 | public void enableVisualVoicemailSmsFilter(String callingPackage, int subId, |
| 3336 | VisualVoicemailSmsFilterSettings settings) { |
| 3337 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3338 | |
| 3339 | final long identity = Binder.clearCallingIdentity(); |
| 3340 | try { |
| 3341 | VisualVoicemailSmsFilterConfig.enableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3342 | mApp, callingPackage, subId, settings); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3343 | } finally { |
| 3344 | Binder.restoreCallingIdentity(identity); |
| 3345 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3346 | } |
| 3347 | |
| 3348 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3349 | public void disableVisualVoicemailSmsFilter(String callingPackage, int subId) { |
| 3350 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3351 | |
| 3352 | final long identity = Binder.clearCallingIdentity(); |
| 3353 | try { |
| 3354 | VisualVoicemailSmsFilterConfig.disableVisualVoicemailSmsFilter( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3355 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3356 | } finally { |
| 3357 | Binder.restoreCallingIdentity(identity); |
| 3358 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3359 | } |
| 3360 | |
| 3361 | @Override |
Ta-wei Yen | b692960 | 2016-05-24 15:48:27 -0700 | [diff] [blame] | 3362 | public VisualVoicemailSmsFilterSettings getVisualVoicemailSmsFilterSettings( |
| 3363 | String callingPackage, int subId) { |
| 3364 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3365 | |
| 3366 | final long identity = Binder.clearCallingIdentity(); |
| 3367 | try { |
| 3368 | return VisualVoicemailSmsFilterConfig.getVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3369 | mApp, callingPackage, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3370 | } finally { |
| 3371 | Binder.restoreCallingIdentity(identity); |
| 3372 | } |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3373 | } |
| 3374 | |
| 3375 | @Override |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3376 | public VisualVoicemailSmsFilterSettings getActiveVisualVoicemailSmsFilterSettings(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3377 | enforceReadPrivilegedPermission("getActiveVisualVoicemailSmsFilterSettings"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3378 | |
| 3379 | final long identity = Binder.clearCallingIdentity(); |
| 3380 | try { |
| 3381 | return VisualVoicemailSmsFilterConfig.getActiveVisualVoicemailSmsFilterSettings( |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3382 | mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3383 | } finally { |
| 3384 | Binder.restoreCallingIdentity(identity); |
| 3385 | } |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3386 | } |
| 3387 | |
| 3388 | @Override |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3389 | public void sendVisualVoicemailSmsForSubscriber(String callingPackage, |
| 3390 | String callingAttributionTag, int subId, String number, int port, String text, |
| 3391 | PendingIntent sentIntent) { |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3392 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 3393 | enforceVisualVoicemailPackage(callingPackage, subId); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 3394 | enforceSendSmsPermission(); |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3395 | SmsController smsController = PhoneFactory.getSmsController(); |
Philip P. Moltmann | 2f6f8ce | 2020-03-18 18:17:02 -0700 | [diff] [blame] | 3396 | smsController.sendVisualVoicemailSmsForSubscriber(callingPackage, callingAttributionTag, |
| 3397 | subId, number, port, text, sentIntent); |
Ta-wei Yen | 87c4984 | 2016-05-13 21:19:52 -0700 | [diff] [blame] | 3398 | } |
Amit Mahajan | dccb3f1 | 2019-05-13 13:48:32 -0700 | [diff] [blame] | 3399 | |
Shishir Agrawal | 76d5da9 | 2014-11-09 16:17:25 -0800 | [diff] [blame] | 3400 | /** |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3401 | * Sets the voice activation state of a given subId. |
| 3402 | */ |
| 3403 | @Override |
| 3404 | public void setVoiceActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3405 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3406 | mApp, subId, "setVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3407 | |
| 3408 | final long identity = Binder.clearCallingIdentity(); |
| 3409 | try { |
| 3410 | final Phone phone = getPhone(subId); |
| 3411 | if (phone != null) { |
| 3412 | phone.setVoiceActivationState(activationState); |
| 3413 | } else { |
| 3414 | loge("setVoiceActivationState fails with invalid subId: " + subId); |
| 3415 | } |
| 3416 | } finally { |
| 3417 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3418 | } |
| 3419 | } |
| 3420 | |
| 3421 | /** |
| 3422 | * Sets the data activation state of a given subId. |
| 3423 | */ |
| 3424 | @Override |
| 3425 | public void setDataActivationState(int subId, int activationState) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3426 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 3427 | mApp, subId, "setDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3428 | |
| 3429 | final long identity = Binder.clearCallingIdentity(); |
| 3430 | try { |
| 3431 | final Phone phone = getPhone(subId); |
| 3432 | if (phone != null) { |
| 3433 | phone.setDataActivationState(activationState); |
| 3434 | } else { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 3435 | loge("setDataActivationState fails with invalid subId: " + subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3436 | } |
| 3437 | } finally { |
| 3438 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3439 | } |
| 3440 | } |
| 3441 | |
| 3442 | /** |
| 3443 | * Returns the voice activation state of a given subId. |
| 3444 | */ |
| 3445 | @Override |
| 3446 | public int getVoiceActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3447 | enforceReadPrivilegedPermission("getVoiceActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3448 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3449 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3450 | final long identity = Binder.clearCallingIdentity(); |
| 3451 | try { |
| 3452 | if (phone != null) { |
| 3453 | return phone.getVoiceActivationState(); |
| 3454 | } else { |
| 3455 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3456 | } |
| 3457 | } finally { |
| 3458 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3459 | } |
| 3460 | } |
| 3461 | |
| 3462 | /** |
| 3463 | * Returns the data activation state of a given subId. |
| 3464 | */ |
| 3465 | @Override |
| 3466 | public int getDataActivationState(int subId, String callingPackage) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3467 | enforceReadPrivilegedPermission("getDataActivationState"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3468 | |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3469 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3470 | final long identity = Binder.clearCallingIdentity(); |
| 3471 | try { |
| 3472 | if (phone != null) { |
| 3473 | return phone.getDataActivationState(); |
| 3474 | } else { |
| 3475 | return TelephonyManager.SIM_ACTIVATION_STATE_UNKNOWN; |
| 3476 | } |
| 3477 | } finally { |
| 3478 | Binder.restoreCallingIdentity(identity); |
fionaxu | 0152e51 | 2016-11-14 13:36:14 -0800 | [diff] [blame] | 3479 | } |
| 3480 | } |
| 3481 | |
| 3482 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 3483 | * Returns the unread count of voicemails for a subId |
| 3484 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3485 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3486 | public int getVoiceMessageCountForSubscriber(int subId, String callingPackage, |
| 3487 | String callingFeatureId) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3488 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 3489 | mApp, subId, callingPackage, callingFeatureId, |
| 3490 | "getVoiceMessageCountForSubscriber")) { |
Brad Ebinger | f7664ba | 2018-11-29 12:43:38 -0800 | [diff] [blame] | 3491 | return 0; |
| 3492 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3493 | final long identity = Binder.clearCallingIdentity(); |
| 3494 | try { |
| 3495 | final Phone phone = getPhone(subId); |
| 3496 | if (phone != null) { |
| 3497 | return phone.getVoiceMessageCount(); |
| 3498 | } else { |
| 3499 | return 0; |
| 3500 | } |
| 3501 | } finally { |
| 3502 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 3503 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 3504 | } |
| 3505 | |
| 3506 | /** |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3507 | * returns true, if the device is in a state where both voice and data |
| 3508 | * are supported simultaneously. This can change based on location or network condition. |
| 3509 | */ |
| 3510 | @Override |
| 3511 | public boolean isConcurrentVoiceAndDataAllowed(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3512 | final long identity = Binder.clearCallingIdentity(); |
| 3513 | try { |
| 3514 | final Phone phone = getPhone(subId); |
| 3515 | return (phone == null ? false : phone.isConcurrentVoiceAndDataAllowed()); |
| 3516 | } finally { |
| 3517 | Binder.restoreCallingIdentity(identity); |
| 3518 | } |
pkanwar | 8a4dcfb | 2017-01-19 13:43:16 -0800 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | /** |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3522 | * Send the dialer code if called from the current default dialer or the caller has |
| 3523 | * carrier privilege. |
| 3524 | * @param inputCode The dialer code to send |
| 3525 | */ |
| 3526 | @Override |
| 3527 | public void sendDialerSpecialCode(String callingPackage, String inputCode) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3528 | final Phone defaultPhone = getDefaultPhone(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3529 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 3530 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 3531 | String defaultDialer = tm.getDefaultDialerPackage(); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3532 | if (!TextUtils.equals(callingPackage, defaultDialer)) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 3533 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 3534 | getDefaultSubscription(), "sendDialerSpecialCode"); |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3535 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3536 | |
| 3537 | final long identity = Binder.clearCallingIdentity(); |
| 3538 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3539 | defaultPhone.sendDialerSpecialCode(inputCode); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 3540 | } finally { |
| 3541 | Binder.restoreCallingIdentity(identity); |
| 3542 | } |
fionaxu | 235cc5e | 2017-03-06 22:25:57 -0800 | [diff] [blame] | 3543 | } |
| 3544 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3545 | @Override |
| 3546 | public int getNetworkSelectionMode(int subId) { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 3547 | TelephonyPermissions |
| 3548 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3549 | mApp, subId, "getNetworkSelectionMode"); |
| 3550 | final long identity = Binder.clearCallingIdentity(); |
| 3551 | try { |
| 3552 | if (!isActiveSubscription(subId)) { |
| 3553 | return TelephonyManager.NETWORK_SELECTION_MODE_UNKNOWN; |
| 3554 | } |
| 3555 | return (int) sendRequest(CMD_GET_NETWORK_SELECTION_MODE, null /* argument */, subId); |
| 3556 | } finally { |
| 3557 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 3558 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 3559 | } |
| 3560 | |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3561 | @Override |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3562 | public boolean isInEmergencySmsMode() { |
| 3563 | enforceReadPrivilegedPermission("isInEmergencySmsMode"); |
| 3564 | final long identity = Binder.clearCallingIdentity(); |
| 3565 | try { |
| 3566 | for (Phone phone : PhoneFactory.getPhones()) { |
| 3567 | if (phone.isInEmergencySmsMode()) { |
| 3568 | return true; |
| 3569 | } |
| 3570 | } |
| 3571 | } finally { |
| 3572 | Binder.restoreCallingIdentity(identity); |
| 3573 | } |
| 3574 | return false; |
| 3575 | } |
| 3576 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3577 | /** |
| 3578 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3579 | * @param subId The subscription to use to check the configuration. |
| 3580 | * @param c The callback that will be used to send the result. |
| 3581 | */ |
Brad Ebinger | b2b6552 | 2019-03-15 13:48:47 -0700 | [diff] [blame] | 3582 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3583 | public void registerImsRegistrationCallback(int subId, IImsRegistrationCallback c) |
| 3584 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3585 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3586 | mApp, subId, "registerImsRegistrationCallback"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3587 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3588 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3589 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3590 | "IMS not available on device."); |
| 3591 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3592 | final long token = Binder.clearCallingIdentity(); |
| 3593 | try { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3594 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3595 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3596 | .addRegistrationCallbackForSubscription(c, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3597 | } catch (ImsException e) { |
| 3598 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3599 | } finally { |
| 3600 | Binder.restoreCallingIdentity(token); |
| 3601 | } |
| 3602 | } |
| 3603 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3604 | /** |
| 3605 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3606 | * @param subId The subscription to use to check the configuration. |
| 3607 | * @param c The callback that will be used to send the result. |
| 3608 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3609 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3610 | public void unregisterImsRegistrationCallback(int subId, IImsRegistrationCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3611 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3612 | mApp, subId, "unregisterImsRegistrationCallback"); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3613 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 3614 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 3615 | } |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3616 | final long token = Binder.clearCallingIdentity(); |
| 3617 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3618 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3619 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 3620 | .removeRegistrationCallbackForSubscription(c, subId); |
| 3621 | } catch (ImsException e) { |
| 3622 | Log.i(LOG_TAG, "unregisterImsRegistrationCallback: " + subId |
| 3623 | + "is inactive, ignoring unregister."); |
| 3624 | // If the subscription is no longer active, just return, since the callback |
| 3625 | // will already have been removed internally. |
| 3626 | } finally { |
| 3627 | Binder.restoreCallingIdentity(token); |
| 3628 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3629 | } |
| 3630 | |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3631 | /** |
| 3632 | * Get the IMS service registration state for the MmTelFeature associated with this sub id. |
| 3633 | */ |
| 3634 | @Override |
| 3635 | public void getImsMmTelRegistrationState(int subId, IIntegerConsumer consumer) { |
| 3636 | enforceReadPrivilegedPermission("getImsMmTelRegistrationState"); |
| 3637 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3638 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3639 | "IMS not available on device."); |
| 3640 | } |
| 3641 | final long token = Binder.clearCallingIdentity(); |
| 3642 | try { |
| 3643 | Phone phone = getPhone(subId); |
| 3644 | if (phone == null) { |
| 3645 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3646 | + subId + "'"); |
| 3647 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3648 | } |
| 3649 | phone.getImsRegistrationState(regState -> { |
| 3650 | try { |
| 3651 | consumer.accept((regState == null) |
| 3652 | ? RegistrationManager.REGISTRATION_STATE_NOT_REGISTERED : regState); |
| 3653 | } catch (RemoteException e) { |
| 3654 | // Ignore if the remote process is no longer available to call back. |
| 3655 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3656 | } |
| 3657 | }); |
| 3658 | } finally { |
| 3659 | Binder.restoreCallingIdentity(token); |
| 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | /** |
| 3664 | * Get the transport type for the IMS service registration state. |
| 3665 | */ |
| 3666 | @Override |
| 3667 | public void getImsMmTelRegistrationTransportType(int subId, IIntegerConsumer consumer) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3668 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3669 | mApp, subId, "getImsMmTelRegistrationTransportType"); |
Brad Ebinger | a34a6c2 | 2019-10-22 17:36:18 -0700 | [diff] [blame] | 3670 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3671 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3672 | "IMS not available on device."); |
| 3673 | } |
| 3674 | final long token = Binder.clearCallingIdentity(); |
| 3675 | try { |
| 3676 | Phone phone = getPhone(subId); |
| 3677 | if (phone == null) { |
| 3678 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: called with an invalid subscription '" |
| 3679 | + subId + "'"); |
| 3680 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3681 | } |
| 3682 | phone.getImsRegistrationTech(regTech -> { |
| 3683 | // Convert registration tech from ImsRegistrationImplBase -> RegistrationManager |
| 3684 | int regTechConverted = (regTech == null) |
| 3685 | ? ImsRegistrationImplBase.REGISTRATION_TECH_NONE : regTech; |
| 3686 | regTechConverted = RegistrationManager.IMS_REG_TO_ACCESS_TYPE_MAP.get( |
| 3687 | regTechConverted); |
| 3688 | try { |
| 3689 | consumer.accept(regTechConverted); |
| 3690 | } catch (RemoteException e) { |
| 3691 | // Ignore if the remote process is no longer available to call back. |
| 3692 | Log.w(LOG_TAG, "getImsMmTelRegistrationState: callback not available."); |
| 3693 | } |
| 3694 | }); |
| 3695 | } finally { |
| 3696 | Binder.restoreCallingIdentity(token); |
| 3697 | } |
| 3698 | } |
| 3699 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3700 | /** |
| 3701 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3702 | * @param subId The subscription to use to check the configuration. |
| 3703 | * @param c The callback that will be used to send the result. |
| 3704 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3705 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3706 | public void registerMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) |
| 3707 | throws RemoteException { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3708 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3709 | mApp, subId, "registerMmTelCapabilityCallback"); |
Brad Ebinger | bc7dd58 | 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 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3715 | final long token = Binder.clearCallingIdentity(); |
| 3716 | try { |
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 | .addCapabilitiesCallbackForSubscription(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 unregisterMmTelCapabilityCallback(int subId, IImsCapabilityCallback c) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3733 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3734 | mApp, subId, "unregisterMmTelCapabilityCallback"); |
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 | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3738 | |
| 3739 | final long token = Binder.clearCallingIdentity(); |
| 3740 | try { |
Meng Wang | 8ea57e3 | 2020-06-25 11:03:56 -0700 | [diff] [blame] | 3741 | // TODO(b/159910732): Remove ImsManager dependence and query through ImsPhone directly. |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3742 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 3743 | .removeCapabilitiesCallbackForSubscription(c, subId); |
Meng Wang | afbc585 | 2019-09-19 17:37:13 -0700 | [diff] [blame] | 3744 | } catch (ImsException e) { |
| 3745 | Log.i(LOG_TAG, "unregisterMmTelCapabilityCallback: " + subId |
| 3746 | + "is inactive, ignoring unregister."); |
| 3747 | // If the subscription is no longer active, just return, since the callback |
| 3748 | // will already have been removed internally. |
| 3749 | } finally { |
| 3750 | Binder.restoreCallingIdentity(token); |
| 3751 | } |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3752 | } |
| 3753 | |
| 3754 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3755 | public boolean isCapable(int subId, int capability, int regTech) { |
| 3756 | enforceReadPrivilegedPermission("isCapable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3757 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 3758 | final long token = Binder.clearCallingIdentity(); |
| 3759 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3760 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3761 | getSlotIndexOrException(subId)).queryMmTelCapability(capability, regTech); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3762 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3763 | Log.w(LOG_TAG, "IMS isCapable - service unavailable: " + e.getMessage()); |
| 3764 | return false; |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3765 | } catch (ImsException e) { |
Brad Ebinger | 6b5ac22 | 2019-02-04 14:36:52 -0800 | [diff] [blame] | 3766 | Log.i(LOG_TAG, "isCapable: " + subId + " is inactive, returning false."); |
| 3767 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3768 | } finally { |
| 3769 | Binder.restoreCallingIdentity(token); |
| 3770 | } |
| 3771 | } |
| 3772 | |
| 3773 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3774 | public boolean isAvailable(int subId, int capability, int regTech) { |
| 3775 | enforceReadPrivilegedPermission("isAvailable"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3776 | final long token = Binder.clearCallingIdentity(); |
| 3777 | try { |
| 3778 | Phone phone = getPhone(subId); |
| 3779 | if (phone == null) return false; |
| 3780 | return phone.isImsCapabilityAvailable(capability, regTech); |
Daniel Bright | 5e40e4e | 2020-03-11 16:35:39 -0700 | [diff] [blame] | 3781 | } catch (com.android.ims.ImsException e) { |
| 3782 | Log.w(LOG_TAG, "IMS isAvailable - service unavailable: " + e.getMessage()); |
| 3783 | return false; |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3784 | } finally { |
| 3785 | Binder.restoreCallingIdentity(token); |
| 3786 | } |
| 3787 | } |
| 3788 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 3789 | /** |
| 3790 | * Determines if the MmTel feature capability is supported by the carrier configuration for this |
| 3791 | * subscription. |
| 3792 | * @param subId The subscription to use to check the configuration. |
| 3793 | * @param callback The callback that will be used to send the result. |
| 3794 | * @param capability The MmTelFeature capability that will be used to send the result. |
| 3795 | * @param transportType The transport type of the MmTelFeature capability. |
| 3796 | */ |
| 3797 | @Override |
| 3798 | public void isMmTelCapabilitySupported(int subId, IIntegerConsumer callback, int capability, |
| 3799 | int transportType) { |
| 3800 | enforceReadPrivilegedPermission("isMmTelCapabilitySupported"); |
| 3801 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 3802 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 3803 | "IMS not available on device."); |
| 3804 | } |
| 3805 | final long token = Binder.clearCallingIdentity(); |
| 3806 | try { |
| 3807 | int slotId = getSlotIndex(subId); |
| 3808 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 3809 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: called with an inactive subscription '" |
| 3810 | + subId + "'"); |
| 3811 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 3812 | } |
| 3813 | ImsManager.getInstance(mApp, slotId).isSupported(capability, |
| 3814 | transportType, aBoolean -> { |
| 3815 | try { |
| 3816 | callback.accept((aBoolean == null) ? 0 : (aBoolean ? 1 : 0)); |
| 3817 | } catch (RemoteException e) { |
| 3818 | Log.w(LOG_TAG, "isMmTelCapabilitySupported: remote caller is not " |
| 3819 | + "running. Ignore"); |
| 3820 | } |
| 3821 | }); |
| 3822 | } finally { |
| 3823 | Binder.restoreCallingIdentity(token); |
| 3824 | } |
| 3825 | } |
| 3826 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3827 | /** |
| 3828 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3829 | * @param subId The subscription to use to check the configuration. |
| 3830 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3831 | @Override |
| 3832 | public boolean isAdvancedCallingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3833 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3834 | mApp, subId, "isAdvancedCallingSettingEnabled"); |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 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 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3840 | getSlotIndexOrException(subId)).isEnhanced4gLteModeSettingEnabledByUser(); |
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 | |
| 3848 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3849 | public void setAdvancedCallingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3850 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3851 | "setAdvancedCallingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3852 | final long identity = Binder.clearCallingIdentity(); |
| 3853 | try { |
| 3854 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3855 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3856 | getSlotIndexOrException(subId)).setEnhanced4gLteModeSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3857 | } catch (ImsException e) { |
| 3858 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3859 | } finally { |
| 3860 | Binder.restoreCallingIdentity(identity); |
| 3861 | } |
| 3862 | } |
| 3863 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3864 | /** |
| 3865 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3866 | * @param subId The subscription to use to check the configuration. |
| 3867 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3868 | @Override |
Brad Ebinger | 9878b0b | 2018-11-08 17:43:22 -0800 | [diff] [blame] | 3869 | public boolean isVtSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3870 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3871 | mApp, subId, "isVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3872 | final long identity = Binder.clearCallingIdentity(); |
| 3873 | try { |
| 3874 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3875 | return ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).isVtEnabledByUser(); |
| 3876 | } catch (ImsException e) { |
| 3877 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3878 | } finally { |
| 3879 | Binder.restoreCallingIdentity(identity); |
| 3880 | } |
| 3881 | } |
| 3882 | |
| 3883 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3884 | public void setVtSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3885 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3886 | "setVtSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3887 | final long identity = Binder.clearCallingIdentity(); |
| 3888 | try { |
| 3889 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3890 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setVtSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3891 | } catch (ImsException e) { |
| 3892 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3893 | } finally { |
| 3894 | Binder.restoreCallingIdentity(identity); |
| 3895 | } |
| 3896 | } |
| 3897 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3898 | /** |
| 3899 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3900 | * @param subId The subscription to use to check the configuration. |
| 3901 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3902 | @Override |
| 3903 | public boolean isVoWiFiSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3904 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3905 | mApp, subId, "isVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3906 | final long identity = Binder.clearCallingIdentity(); |
| 3907 | try { |
| 3908 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3909 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3910 | getSlotIndexOrException(subId)).isWfcEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3911 | } catch (ImsException e) { |
| 3912 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3913 | } finally { |
| 3914 | Binder.restoreCallingIdentity(identity); |
| 3915 | } |
| 3916 | } |
| 3917 | |
| 3918 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3919 | public void setVoWiFiSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3920 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3921 | "setVoWiFiSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3922 | final long identity = Binder.clearCallingIdentity(); |
| 3923 | try { |
| 3924 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3925 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setWfcSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3926 | } catch (ImsException e) { |
| 3927 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3928 | } finally { |
| 3929 | Binder.restoreCallingIdentity(identity); |
| 3930 | } |
| 3931 | } |
| 3932 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3933 | /** |
| 3934 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3935 | * @param subId The subscription to use to check the configuration. |
| 3936 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3937 | @Override |
| 3938 | public boolean isVoWiFiRoamingSettingEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3939 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3940 | mApp, subId, "isVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3941 | final long identity = Binder.clearCallingIdentity(); |
| 3942 | try { |
| 3943 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3944 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3945 | getSlotIndexOrException(subId)).isWfcRoamingEnabledByUser(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3946 | } catch (ImsException e) { |
| 3947 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3948 | } finally { |
| 3949 | Binder.restoreCallingIdentity(identity); |
| 3950 | } |
| 3951 | } |
| 3952 | |
| 3953 | @Override |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3954 | public void setVoWiFiRoamingSettingEnabled(int subId, boolean isEnabled) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3955 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
Brad Ebinger | 1c16204 | 2019-02-21 14:49:10 -0800 | [diff] [blame] | 3956 | "setVoWiFiRoamingSettingEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3957 | final long identity = Binder.clearCallingIdentity(); |
| 3958 | try { |
| 3959 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3960 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3961 | getSlotIndexOrException(subId)).setWfcRoamingSetting(isEnabled); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3962 | } catch (ImsException e) { |
| 3963 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3964 | } finally { |
| 3965 | Binder.restoreCallingIdentity(identity); |
| 3966 | } |
| 3967 | } |
| 3968 | |
| 3969 | @Override |
| 3970 | public void setVoWiFiNonPersistent(int subId, boolean isCapable, int mode) { |
| 3971 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 3972 | "setVoWiFiNonPersistent"); |
| 3973 | final long identity = Binder.clearCallingIdentity(); |
| 3974 | try { |
| 3975 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3976 | ImsManager.getInstance(mApp, |
Brad Ebinger | 2d29c01 | 2019-05-07 18:33:46 -0700 | [diff] [blame] | 3977 | getSlotIndexOrException(subId)).setWfcNonPersistent(isCapable, mode); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 3978 | } catch (ImsException e) { |
| 3979 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3980 | } finally { |
| 3981 | Binder.restoreCallingIdentity(identity); |
| 3982 | } |
| 3983 | } |
| 3984 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 3985 | /** |
| 3986 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 3987 | * @param subId The subscription to use to check the configuration. |
| 3988 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3989 | @Override |
| 3990 | public int getVoWiFiModeSetting(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 3991 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 3992 | mApp, subId, "getVoWiFiModeSetting"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3993 | final long identity = Binder.clearCallingIdentity(); |
| 3994 | try { |
| 3995 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 3996 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 3997 | getSlotIndexOrException(subId)).getWfcMode(false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 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 |
| 4006 | public void setVoWiFiModeSetting(int subId, int mode) { |
| 4007 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4008 | "setVoWiFiModeSetting"); |
| 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, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4013 | getSlotIndexOrException(subId)).setWfcMode(mode, false /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4014 | } catch (ImsException e) { |
| 4015 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4016 | } finally { |
| 4017 | Binder.restoreCallingIdentity(identity); |
| 4018 | } |
| 4019 | } |
| 4020 | |
| 4021 | @Override |
| 4022 | public int getVoWiFiRoamingModeSetting(int subId) { |
| 4023 | enforceReadPrivilegedPermission("getVoWiFiRoamingModeSetting"); |
| 4024 | final long identity = Binder.clearCallingIdentity(); |
| 4025 | try { |
| 4026 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4027 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4028 | getSlotIndexOrException(subId)).getWfcMode(true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4029 | } catch (ImsException e) { |
| 4030 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4031 | } finally { |
| 4032 | Binder.restoreCallingIdentity(identity); |
| 4033 | } |
| 4034 | } |
| 4035 | |
| 4036 | @Override |
| 4037 | public void setVoWiFiRoamingModeSetting(int subId, int mode) { |
| 4038 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4039 | "setVoWiFiRoamingModeSetting"); |
| 4040 | final long identity = Binder.clearCallingIdentity(); |
| 4041 | try { |
| 4042 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4043 | ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4044 | getSlotIndexOrException(subId)).setWfcMode(mode, true /*isRoaming*/); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4045 | } catch (ImsException e) { |
| 4046 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4047 | } finally { |
| 4048 | Binder.restoreCallingIdentity(identity); |
| 4049 | } |
| 4050 | } |
| 4051 | |
| 4052 | @Override |
| 4053 | public void setRttCapabilitySetting(int subId, boolean isEnabled) { |
| 4054 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4055 | "setRttCapabilityEnabled"); |
| 4056 | final long identity = Binder.clearCallingIdentity(); |
| 4057 | try { |
| 4058 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4059 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)).setRttEnabled(isEnabled); |
| 4060 | } catch (ImsException e) { |
| 4061 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4062 | } finally { |
| 4063 | Binder.restoreCallingIdentity(identity); |
| 4064 | } |
| 4065 | } |
| 4066 | |
shilu | 366312e | 2019-12-17 09:28:10 -0800 | [diff] [blame] | 4067 | /** |
| 4068 | * Requires carrier privileges or READ_PRECISE_PHONE_STATE permission. |
| 4069 | * @param subId The subscription to use to check the configuration. |
| 4070 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4071 | @Override |
| 4072 | public boolean isTtyOverVolteEnabled(int subId) { |
Rambo Wang | 37f9c24 | 2020-02-10 14:45:28 -0800 | [diff] [blame] | 4073 | TelephonyPermissions.enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 4074 | mApp, subId, "isTtyOverVolteEnabled"); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4075 | final long identity = Binder.clearCallingIdentity(); |
| 4076 | try { |
| 4077 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4078 | return ImsManager.getInstance(mApp, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4079 | getSlotIndexOrException(subId)).isTtyOnVoLteCapable(); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4080 | } catch (ImsException e) { |
| 4081 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4082 | } finally { |
| 4083 | Binder.restoreCallingIdentity(identity); |
| 4084 | } |
| 4085 | } |
| 4086 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4087 | @Override |
| 4088 | public void registerImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4089 | enforceReadPrivilegedPermission("registerImsProvisioningChangedCallback"); |
| 4090 | final long identity = Binder.clearCallingIdentity(); |
| 4091 | try { |
Brad Ebinger | d033173 | 2020-01-16 11:21:18 -0800 | [diff] [blame] | 4092 | if (!isImsAvailableOnDevice()) { |
| 4093 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 4094 | "IMS not available on device."); |
Peter Wang | 44b186e | 2020-01-13 23:33:09 -0800 | [diff] [blame] | 4095 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4096 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4097 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4098 | .addProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4099 | } catch (ImsException e) { |
| 4100 | throw new ServiceSpecificException(e.getCode()); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4101 | } finally { |
| 4102 | Binder.restoreCallingIdentity(identity); |
| 4103 | } |
| 4104 | } |
| 4105 | |
| 4106 | @Override |
| 4107 | public void unregisterImsProvisioningChangedCallback(int subId, IImsConfigCallback callback) { |
| 4108 | enforceReadPrivilegedPermission("unregisterImsProvisioningChangedCallback"); |
| 4109 | final long identity = Binder.clearCallingIdentity(); |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4110 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4111 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 4112 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4113 | try { |
| 4114 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4115 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4116 | .removeProvisioningCallbackForSubscription(callback, subId); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4117 | } catch (ImsException e) { |
Brad Ebinger | 4ae57f9 | 2019-01-09 16:51:30 -0800 | [diff] [blame] | 4118 | Log.i(LOG_TAG, "unregisterImsProvisioningChangedCallback: " + subId |
| 4119 | + "is inactive, ignoring unregister."); |
| 4120 | // If the subscription is no longer active, just return, since the callback will already |
| 4121 | // have been removed internally. |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4122 | } finally { |
| 4123 | Binder.restoreCallingIdentity(identity); |
| 4124 | } |
| 4125 | } |
| 4126 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4127 | |
| 4128 | private void checkModifyPhoneStatePermission(int subId, String message) { |
| 4129 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4130 | message); |
| 4131 | } |
| 4132 | |
| 4133 | private boolean isImsProvisioningRequired(int subId, int capability, |
| 4134 | boolean isMmtelCapability) { |
| 4135 | Phone phone = getPhone(subId); |
| 4136 | if (phone == null) { |
| 4137 | loge("phone instance null for subid " + subId); |
| 4138 | return false; |
| 4139 | } |
| 4140 | if (isMmtelCapability) { |
| 4141 | if (!doesImsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4142 | return false; |
| 4143 | } |
| 4144 | } else { |
| 4145 | if (!doesRcsCapabilityRequireProvisioning(phone.getContext(), subId, capability)) { |
| 4146 | return false; |
| 4147 | } |
| 4148 | } |
| 4149 | return true; |
| 4150 | } |
| 4151 | |
| 4152 | @Override |
| 4153 | public void setRcsProvisioningStatusForCapability(int subId, int capability, |
| 4154 | boolean isProvisioned) { |
| 4155 | checkModifyPhoneStatePermission(subId, "setRcsProvisioningStatusForCapability"); |
| 4156 | |
| 4157 | final long identity = Binder.clearCallingIdentity(); |
| 4158 | try { |
| 4159 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4160 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4161 | return; |
| 4162 | } |
| 4163 | |
| 4164 | // this capability requires provisioning, route to the correct API. |
| 4165 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4166 | switch (capability) { |
| 4167 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4168 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4169 | ims.setEabProvisioned(isProvisioned); |
| 4170 | break; |
| 4171 | default: { |
| 4172 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4173 | + "rcs capability '" + capability + "', which does not require " |
| 4174 | + "provisioning."); |
| 4175 | } |
| 4176 | } |
| 4177 | } finally { |
| 4178 | Binder.restoreCallingIdentity(identity); |
| 4179 | } |
| 4180 | |
| 4181 | } |
| 4182 | |
| 4183 | |
| 4184 | @Override |
| 4185 | public boolean getRcsProvisioningStatusForCapability(int subId, int capability) { |
| 4186 | enforceReadPrivilegedPermission("getRcsProvisioningStatusForCapability"); |
| 4187 | final long identity = Binder.clearCallingIdentity(); |
| 4188 | try { |
| 4189 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
| 4190 | if (!isImsProvisioningRequired(subId, capability, false)) { |
| 4191 | return true; |
| 4192 | } |
| 4193 | |
| 4194 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4195 | switch (capability) { |
| 4196 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: |
| 4197 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4198 | return ims.isEabProvisionedOnDevice(); |
| 4199 | |
| 4200 | default: { |
| 4201 | throw new IllegalArgumentException("Tried to get rcs provisioning for " |
| 4202 | + "capability '" + capability + "', which does not require " |
| 4203 | + "provisioning."); |
| 4204 | } |
| 4205 | } |
| 4206 | |
| 4207 | } finally { |
| 4208 | Binder.restoreCallingIdentity(identity); |
| 4209 | } |
| 4210 | } |
| 4211 | |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4212 | @Override |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4213 | public void setImsProvisioningStatusForCapability(int subId, int capability, int tech, |
| 4214 | boolean isProvisioned) { |
| 4215 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4216 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4217 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4218 | } |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4219 | checkModifyPhoneStatePermission(subId, "setImsProvisioningStatusForCapability"); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4220 | final long identity = Binder.clearCallingIdentity(); |
| 4221 | try { |
| 4222 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4223 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4224 | return; |
| 4225 | } |
| 4226 | |
| 4227 | // this capability requires provisioning, route to the correct API. |
| 4228 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4229 | switch (capability) { |
| 4230 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4231 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4232 | ims.setVolteProvisioned(isProvisioned); |
| 4233 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4234 | ims.setWfcProvisioned(isProvisioned); |
| 4235 | } |
| 4236 | break; |
| 4237 | } |
| 4238 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4239 | // There is currently no difference in VT provisioning type. |
| 4240 | ims.setVtProvisioned(isProvisioned); |
| 4241 | break; |
| 4242 | } |
| 4243 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4244 | // There is no "deprecated" UT provisioning mechanism through ImsConfig, so |
| 4245 | // change the capability of the feature instead if needed. |
| 4246 | if (isMmTelCapabilityProvisionedInCache(subId, capability, tech) |
| 4247 | == isProvisioned) { |
| 4248 | // No change in provisioning. |
| 4249 | return; |
| 4250 | } |
| 4251 | cacheMmTelCapabilityProvisioning(subId, capability, tech, isProvisioned); |
| 4252 | try { |
| 4253 | ims.changeMmTelCapability(capability, tech, isProvisioned); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4254 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4255 | loge("setImsProvisioningStatusForCapability: couldn't change UT capability" |
| 4256 | + ", Exception" + e.getMessage()); |
| 4257 | } |
| 4258 | break; |
| 4259 | } |
| 4260 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4261 | throw new IllegalArgumentException("Tried to set provisioning for " |
| 4262 | + "MmTel capability '" + capability + "', which does not require " |
| 4263 | + "provisioning. "); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4264 | } |
| 4265 | } |
| 4266 | |
| 4267 | } finally { |
| 4268 | Binder.restoreCallingIdentity(identity); |
| 4269 | } |
| 4270 | } |
| 4271 | |
| 4272 | @Override |
| 4273 | public boolean getImsProvisioningStatusForCapability(int subId, int capability, int tech) { |
| 4274 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4275 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4276 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4277 | } |
| 4278 | enforceReadPrivilegedPermission("getProvisioningStatusForCapability"); |
| 4279 | final long identity = Binder.clearCallingIdentity(); |
| 4280 | try { |
| 4281 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4282 | if (!isImsProvisioningRequired(subId, capability, true)) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4283 | return true; |
| 4284 | } |
| 4285 | |
| 4286 | ImsManager ims = ImsManager.getInstance(mApp, getSlotIndex(subId)); |
| 4287 | switch (capability) { |
| 4288 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: { |
| 4289 | if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4290 | return ims.isVolteProvisionedOnDevice(); |
| 4291 | } else if (tech == ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN) { |
| 4292 | return ims.isWfcProvisionedOnDevice(); |
| 4293 | } |
| 4294 | // This should never happen, since we are checking tech above to make sure it |
| 4295 | // is either LTE or IWLAN. |
| 4296 | throw new IllegalArgumentException("Invalid radio technology for voice " |
| 4297 | + "capability."); |
| 4298 | } |
| 4299 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4300 | // There is currently no difference in VT provisioning type. |
| 4301 | return ims.isVtProvisionedOnDevice(); |
| 4302 | } |
| 4303 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4304 | // There is no "deprecated" UT provisioning mechanism, so get from shared prefs. |
| 4305 | return isMmTelCapabilityProvisionedInCache(subId, capability, tech); |
| 4306 | } |
| 4307 | default: { |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4308 | throw new IllegalArgumentException( |
| 4309 | "Tried to get provisioning for MmTel capability '" + capability |
| 4310 | + "', which does not require provisioning."); |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4311 | } |
| 4312 | } |
| 4313 | |
| 4314 | } finally { |
| 4315 | Binder.restoreCallingIdentity(identity); |
| 4316 | } |
| 4317 | } |
| 4318 | |
| 4319 | @Override |
| 4320 | public boolean isMmTelCapabilityProvisionedInCache(int subId, int capability, int tech) { |
| 4321 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4322 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4323 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4324 | } |
| 4325 | enforceReadPrivilegedPermission("isMmTelCapabilityProvisionedInCache"); |
| 4326 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4327 | return (provisionedBits & capability) > 0; |
| 4328 | } |
| 4329 | |
| 4330 | @Override |
| 4331 | public void cacheMmTelCapabilityProvisioning(int subId, int capability, int tech, |
| 4332 | boolean isProvisioned) { |
| 4333 | if (tech != ImsRegistrationImplBase.REGISTRATION_TECH_IWLAN |
| 4334 | && tech != ImsRegistrationImplBase.REGISTRATION_TECH_LTE) { |
| 4335 | throw new IllegalArgumentException("Registration technology '" + tech + "' is invalid"); |
| 4336 | } |
| 4337 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4338 | "setProvisioningStatusForCapability"); |
| 4339 | int provisionedBits = getMmTelCapabilityProvisioningBitfield(subId, tech); |
| 4340 | // If the current provisioning status for capability already matches isProvisioned, |
| 4341 | // do nothing. |
| 4342 | if (((provisionedBits & capability) > 0) == isProvisioned) { |
| 4343 | return; |
| 4344 | } |
| 4345 | if (isProvisioned) { |
| 4346 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits | capability)); |
| 4347 | } else { |
| 4348 | setMmTelCapabilityProvisioningBitfield(subId, tech, (provisionedBits & ~capability)); |
| 4349 | } |
| 4350 | } |
| 4351 | |
| 4352 | /** |
| 4353 | * @return the bitfield containing the MmTel provisioning for the provided subscription and |
| 4354 | * technology. The bitfield should mirror the bitfield defined by |
| 4355 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}. |
| 4356 | */ |
| 4357 | private int getMmTelCapabilityProvisioningBitfield(int subId, int tech) { |
| 4358 | String key = getMmTelProvisioningKey(subId, tech); |
| 4359 | // Default is no capabilities are provisioned. |
| 4360 | return mTelephonySharedPreferences.getInt(key, 0 /*default*/); |
| 4361 | } |
| 4362 | |
| 4363 | /** |
| 4364 | * Sets the MmTel capability provisioning bitfield (defined by |
| 4365 | * {@link MmTelFeature.MmTelCapabilities.MmTelCapability}) for the subscription and |
| 4366 | * technology specified. |
| 4367 | * |
| 4368 | * Note: This is a synchronous command and should not be called on UI thread. |
| 4369 | */ |
| 4370 | private void setMmTelCapabilityProvisioningBitfield(int subId, int tech, int newField) { |
| 4371 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 4372 | String key = getMmTelProvisioningKey(subId, tech); |
| 4373 | editor.putInt(key, newField); |
| 4374 | editor.commit(); |
| 4375 | } |
| 4376 | |
| 4377 | private static String getMmTelProvisioningKey(int subId, int tech) { |
| 4378 | // resulting key is provision_ims_mmtel_{subId}_{tech} |
| 4379 | return PREF_PROVISION_IMS_MMTEL_PREFIX + subId + "_" + tech; |
| 4380 | } |
| 4381 | |
| 4382 | /** |
| 4383 | * Query CarrierConfig to see if the specified capability requires provisioning for the |
| 4384 | * carrier associated with the subscription id. |
| 4385 | */ |
| 4386 | private boolean doesImsCapabilityRequireProvisioning(Context context, int subId, |
| 4387 | int capability) { |
| 4388 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4389 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4390 | boolean requireUtProvisioning = c.getBoolean( |
Brad Ebinger | 076903f | 2019-05-13 10:00:22 -0700 | [diff] [blame] | 4391 | CarrierConfigManager.KEY_CARRIER_SUPPORTS_SS_OVER_UT_BOOL, false) |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4392 | && c.getBoolean(CarrierConfigManager.KEY_CARRIER_UT_PROVISIONING_REQUIRED_BOOL, |
| 4393 | false); |
| 4394 | boolean requireVoiceVtProvisioning = c.getBoolean( |
| 4395 | CarrierConfigManager.KEY_CARRIER_VOLTE_PROVISIONING_REQUIRED_BOOL, false); |
| 4396 | |
| 4397 | // First check to make sure that the capability requires provisioning. |
| 4398 | switch (capability) { |
| 4399 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VOICE: |
| 4400 | // intentional fallthrough |
| 4401 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_VIDEO: { |
| 4402 | if (requireVoiceVtProvisioning) { |
| 4403 | // Voice and Video requires provisioning |
| 4404 | return true; |
| 4405 | } |
| 4406 | break; |
| 4407 | } |
| 4408 | case MmTelFeature.MmTelCapabilities.CAPABILITY_TYPE_UT: { |
| 4409 | if (requireUtProvisioning) { |
| 4410 | // UT requires provisioning |
| 4411 | return true; |
| 4412 | } |
| 4413 | break; |
| 4414 | } |
| 4415 | } |
| 4416 | return false; |
| 4417 | } |
| 4418 | |
allenwtsu | 99c623b | 2020-01-03 18:24:23 +0800 | [diff] [blame] | 4419 | private boolean doesRcsCapabilityRequireProvisioning(Context context, int subId, |
| 4420 | int capability) { |
| 4421 | CarrierConfigManager configManager = new CarrierConfigManager(context); |
| 4422 | PersistableBundle c = configManager.getConfigForSubId(subId); |
| 4423 | |
| 4424 | boolean requireRcsProvisioning = c.getBoolean( |
| 4425 | CarrierConfigManager.KEY_CARRIER_RCS_PROVISIONING_REQUIRED_BOOL, false); |
| 4426 | |
| 4427 | // First check to make sure that the capability requires provisioning. |
| 4428 | switch (capability) { |
| 4429 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_PRESENCE_UCE: |
| 4430 | // intentional fallthrough |
| 4431 | case RcsFeature.RcsImsCapabilities.CAPABILITY_TYPE_OPTIONS_UCE: { |
| 4432 | if (requireRcsProvisioning) { |
| 4433 | // OPTION or PRESENCE requires provisioning |
| 4434 | return true; |
| 4435 | } |
| 4436 | break; |
| 4437 | } |
| 4438 | } |
| 4439 | return false; |
| 4440 | } |
| 4441 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4442 | @Override |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4443 | public int getImsProvisioningInt(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4444 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4445 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4446 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4447 | enforceReadPrivilegedPermission("getImsProvisioningInt"); |
| 4448 | final long identity = Binder.clearCallingIdentity(); |
| 4449 | try { |
| 4450 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4451 | int slotId = getSlotIndex(subId); |
| 4452 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4453 | Log.w(LOG_TAG, "getImsProvisioningInt: called with an inactive subscription '" |
| 4454 | + subId + "' for key:" + key); |
| 4455 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
| 4456 | } |
| 4457 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigInt(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4458 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4459 | Log.w(LOG_TAG, "getImsProvisioningInt: ImsService is not available for subscription '" |
| 4460 | + subId + "' for key:" + key); |
| 4461 | return ImsConfigImplBase.CONFIG_RESULT_UNKNOWN; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4462 | } finally { |
| 4463 | Binder.restoreCallingIdentity(identity); |
| 4464 | } |
| 4465 | } |
| 4466 | |
| 4467 | @Override |
| 4468 | public String getImsProvisioningString(int subId, int key) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4469 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4470 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4471 | } |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4472 | enforceReadPrivilegedPermission("getImsProvisioningString"); |
| 4473 | final long identity = Binder.clearCallingIdentity(); |
| 4474 | try { |
| 4475 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4476 | int slotId = getSlotIndex(subId); |
| 4477 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4478 | Log.w(LOG_TAG, "getImsProvisioningString: called for an inactive subscription id '" |
| 4479 | + subId + "' for key:" + key); |
| 4480 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_GENERIC; |
| 4481 | } |
| 4482 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().getConfigString(key); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4483 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4484 | Log.w(LOG_TAG, "getImsProvisioningString: ImsService is not available for sub '" |
| 4485 | + subId + "' for key:" + key); |
| 4486 | return ProvisioningManager.STRING_QUERY_RESULT_ERROR_NOT_READY; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4487 | } finally { |
| 4488 | Binder.restoreCallingIdentity(identity); |
| 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | @Override |
| 4493 | public int setImsProvisioningInt(int subId, int key, int value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4494 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4495 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4496 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4497 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4498 | "setImsProvisioningInt"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4499 | final long identity = Binder.clearCallingIdentity(); |
| 4500 | try { |
| 4501 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4502 | int slotId = getSlotIndex(subId); |
| 4503 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4504 | Log.w(LOG_TAG, "setImsProvisioningInt: called with an inactive subscription id '" |
| 4505 | + subId + "' for key:" + key); |
| 4506 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4507 | } |
| 4508 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4509 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4510 | Log.w(LOG_TAG, "setImsProvisioningInt: ImsService unavailable for sub '" + subId |
| 4511 | + "' for key:" + key); |
| 4512 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4513 | } finally { |
| 4514 | Binder.restoreCallingIdentity(identity); |
| 4515 | } |
| 4516 | } |
| 4517 | |
| 4518 | @Override |
| 4519 | public int setImsProvisioningString(int subId, int key, String value) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4520 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 4521 | throw new IllegalArgumentException("Invalid Subscription id '" + subId + "'"); |
| 4522 | } |
Brad Ebinger | 3d0b34e | 2018-11-15 14:13:12 -0800 | [diff] [blame] | 4523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, subId, |
| 4524 | "setImsProvisioningString"); |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4525 | final long identity = Binder.clearCallingIdentity(); |
| 4526 | try { |
| 4527 | // TODO: Refactor to remove ImsManager dependence and query through ImsPhone directly. |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4528 | int slotId = getSlotIndex(subId); |
| 4529 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 4530 | Log.w(LOG_TAG, "setImsProvisioningString: called with an inactive subscription id '" |
| 4531 | + subId + "' for key:" + key); |
| 4532 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
| 4533 | } |
| 4534 | return ImsManager.getInstance(mApp, slotId).getConfigInterface().setConfig(key, value); |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4535 | } catch (com.android.ims.ImsException e) { |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4536 | Log.w(LOG_TAG, "setImsProvisioningString: ImsService unavailable for sub '" + subId |
| 4537 | + "' for key:" + key); |
| 4538 | return ImsConfigImplBase.CONFIG_RESULT_FAILED; |
Brad Ebinger | df5b4f0 | 2018-10-31 11:24:17 -0700 | [diff] [blame] | 4539 | } finally { |
| 4540 | Binder.restoreCallingIdentity(identity); |
| 4541 | } |
| 4542 | } |
| 4543 | |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4544 | private int getSlotIndexOrException(int subId) throws ImsException { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4545 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4546 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
Brad Ebinger | 1ce9c43 | 2019-07-16 13:19:44 -0700 | [diff] [blame] | 4547 | throw new ImsException("Invalid Subscription Id, subId=" + subId, |
| 4548 | ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 4549 | } |
| 4550 | return slotId; |
| 4551 | } |
| 4552 | |
Brad Ebinger | 1c8542e | 2019-01-14 13:43:14 -0800 | [diff] [blame] | 4553 | private int getSlotIndex(int subId) { |
| 4554 | int slotId = SubscriptionManager.getSlotIndex(subId); |
| 4555 | if (!SubscriptionManager.isValidSlotIndex(slotId)) { |
| 4556 | return SubscriptionManager.INVALID_SIM_SLOT_INDEX; |
| 4557 | } |
| 4558 | return slotId; |
| 4559 | } |
| 4560 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4561 | /** |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4562 | * Returns the data network type for a subId; does not throw SecurityException. |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4563 | */ |
| 4564 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4565 | public int getNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4566 | String callingFeatureId) { |
Nathan Harold | f096d98 | 2020-11-18 17:18:06 -0800 | [diff] [blame] | 4567 | final int targetSdk = TelephonyPermissions.getTargetSdk(mApp, callingPackage); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4568 | if (targetSdk > android.os.Build.VERSION_CODES.Q) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4569 | return getDataNetworkTypeForSubscriber(subId, callingPackage, callingFeatureId); |
Nathan Harold | ef60dba | 2019-05-22 13:55:14 -0700 | [diff] [blame] | 4570 | } else if (targetSdk == android.os.Build.VERSION_CODES.Q |
Nathan Harold | 9042f0b | 2019-05-21 15:51:27 -0700 | [diff] [blame] | 4571 | && !TelephonyPermissions.checkCallingOrSelfReadPhoneStateNoThrow( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4572 | mApp, subId, callingPackage, callingFeatureId, |
| 4573 | "getNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4574 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4575 | } |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4576 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4577 | final long identity = Binder.clearCallingIdentity(); |
| 4578 | try { |
| 4579 | final Phone phone = getPhone(subId); |
| 4580 | if (phone != null) { |
| 4581 | return phone.getServiceState().getDataNetworkType(); |
| 4582 | } else { |
| 4583 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4584 | } |
| 4585 | } finally { |
| 4586 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4587 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4588 | } |
| 4589 | |
| 4590 | /** |
| 4591 | * Returns the data network type |
| 4592 | */ |
| 4593 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4594 | public int getDataNetworkType(String callingPackage, String callingFeatureId) { |
| 4595 | return getDataNetworkTypeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4596 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4597 | } |
| 4598 | |
| 4599 | /** |
| 4600 | * Returns the data network type for a subId |
| 4601 | */ |
| 4602 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4603 | public int getDataNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4604 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4605 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4606 | mApp, subId, callingPackage, callingFeatureId, |
| 4607 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4608 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4609 | } |
| 4610 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4611 | final long identity = Binder.clearCallingIdentity(); |
| 4612 | try { |
| 4613 | final Phone phone = getPhone(subId); |
| 4614 | if (phone != null) { |
| 4615 | return phone.getServiceState().getDataNetworkType(); |
| 4616 | } else { |
| 4617 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4618 | } |
| 4619 | } finally { |
| 4620 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4621 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4622 | } |
| 4623 | |
| 4624 | /** |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4625 | * Returns the Voice network type for a subId |
| 4626 | */ |
| 4627 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4628 | public int getVoiceNetworkTypeForSubscriber(int subId, String callingPackage, |
| 4629 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4630 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4631 | mApp, subId, callingPackage, callingFeatureId, |
| 4632 | "getDataNetworkTypeForSubscriber")) { |
Robert Greenwalt | a5dcfcb | 2015-07-10 09:06:29 -0700 | [diff] [blame] | 4633 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4634 | } |
| 4635 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4636 | final long identity = Binder.clearCallingIdentity(); |
| 4637 | try { |
| 4638 | final Phone phone = getPhone(subId); |
| 4639 | if (phone != null) { |
| 4640 | return phone.getServiceState().getVoiceNetworkType(); |
| 4641 | } else { |
| 4642 | return TelephonyManager.NETWORK_TYPE_UNKNOWN; |
| 4643 | } |
| 4644 | } finally { |
| 4645 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4646 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4647 | } |
| 4648 | |
| 4649 | /** |
| 4650 | * @return true if a ICC card is present |
| 4651 | */ |
| 4652 | public boolean hasIccCard() { |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4653 | // FIXME Make changes to pass defaultSimId of type int |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4654 | return hasIccCardUsingSlotIndex(mSubscriptionController.getSlotIndex( |
| 4655 | getDefaultSubscription())); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | /** |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4659 | * @return true if a ICC card is present for a slotIndex |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4660 | */ |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4661 | @Override |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 4662 | public boolean hasIccCardUsingSlotIndex(int slotIndex) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4663 | final long identity = Binder.clearCallingIdentity(); |
| 4664 | try { |
| 4665 | final Phone phone = PhoneFactory.getPhone(slotIndex); |
| 4666 | if (phone != null) { |
| 4667 | return phone.getIccCard().hasIccCard(); |
| 4668 | } else { |
| 4669 | return false; |
| 4670 | } |
| 4671 | } finally { |
| 4672 | Binder.restoreCallingIdentity(identity); |
Amit Mahajan | a6fc2a8 | 2015-01-06 11:53:51 -0800 | [diff] [blame] | 4673 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4674 | } |
| 4675 | |
| 4676 | /** |
| 4677 | * Return if the current radio is LTE on CDMA. This |
| 4678 | * is a tri-state return value as for a period of time |
| 4679 | * the mode may be unknown. |
| 4680 | * |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4681 | * @param callingPackage the name of the package making the call. |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4682 | * @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] | 4683 | * or {@link Phone#LTE_ON_CDMA_TRUE} |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4684 | */ |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4685 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4686 | public int getLteOnCdmaMode(String callingPackage, String callingFeatureId) { |
| 4687 | return getLteOnCdmaModeForSubscriber(getDefaultSubscription(), callingPackage, |
| 4688 | callingFeatureId); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4689 | } |
| 4690 | |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4691 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 4692 | public int getLteOnCdmaModeForSubscriber(int subId, String callingPackage, |
| 4693 | String callingFeatureId) { |
Sarah Chin | 790d292 | 2020-01-16 12:17:23 -0800 | [diff] [blame] | 4694 | try { |
| 4695 | enforceReadPrivilegedPermission("getLteOnCdmaModeForSubscriber"); |
| 4696 | } catch (SecurityException e) { |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 4697 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4698 | } |
| 4699 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4700 | final long identity = Binder.clearCallingIdentity(); |
| 4701 | try { |
| 4702 | final Phone phone = getPhone(subId); |
| 4703 | if (phone == null) { |
| 4704 | return PhoneConstants.LTE_ON_CDMA_UNKNOWN; |
| 4705 | } else { |
Nathan Harold | 05ad633 | 2020-07-10 11:54:36 -0700 | [diff] [blame] | 4706 | return TelephonyProperties.lte_on_cdma_device() |
| 4707 | .orElse(PhoneConstants.LTE_ON_CDMA_FALSE); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4708 | } |
| 4709 | } finally { |
| 4710 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 4711 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4712 | } |
| 4713 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4714 | /** |
| 4715 | * {@hide} |
| 4716 | * Returns Default subId, 0 in the case of single standby. |
| 4717 | */ |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4718 | private int getDefaultSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4719 | return mSubscriptionController.getDefaultSubId(); |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 4720 | } |
| 4721 | |
Shishir Agrawal | a9f3218 | 2016-04-12 12:00:16 -0700 | [diff] [blame] | 4722 | private int getSlotForDefaultSubscription() { |
| 4723 | return mSubscriptionController.getPhoneId(getDefaultSubscription()); |
| 4724 | } |
| 4725 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 4726 | private int getPreferredVoiceSubscription() { |
Wink Saville | ac1bdfd | 2014-11-20 23:04:44 -0800 | [diff] [blame] | 4727 | return mSubscriptionController.getDefaultVoiceSubId(); |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 4728 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4729 | |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 4730 | private boolean isActiveSubscription(int subId) { |
| 4731 | return mSubscriptionController.isActiveSubId(subId); |
| 4732 | } |
| 4733 | |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4734 | /** |
| 4735 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4736 | */ |
| 4737 | public int getWhenToMakeWifiCalls() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4738 | final long identity = Binder.clearCallingIdentity(); |
| 4739 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4740 | return Settings.System.getInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4741 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, |
| 4742 | getWhenToMakeWifiCallsDefaultPreference()); |
| 4743 | } finally { |
| 4744 | Binder.restoreCallingIdentity(identity); |
| 4745 | } |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4746 | } |
| 4747 | |
| 4748 | /** |
| 4749 | * @see android.telephony.TelephonyManager.WifiCallingChoices |
| 4750 | */ |
| 4751 | public void setWhenToMakeWifiCalls(int preference) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4752 | final long identity = Binder.clearCallingIdentity(); |
| 4753 | try { |
| 4754 | if (DBG) log("setWhenToMakeWifiCallsStr, storing setting = " + preference); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4755 | Settings.System.putInt(mApp.getContentResolver(), |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4756 | Settings.System.WHEN_TO_MAKE_WIFI_CALLS, preference); |
| 4757 | } finally { |
| 4758 | Binder.restoreCallingIdentity(identity); |
| 4759 | } |
Ihab Awad | f9e9273 | 2013-12-05 18:02:52 -0800 | [diff] [blame] | 4760 | } |
| 4761 | |
Sailesh Nepal | d1e6815 | 2013-12-12 19:08:02 -0800 | [diff] [blame] | 4762 | private static int getWhenToMakeWifiCallsDefaultPreference() { |
Santos Cordon | da120f4 | 2014-08-06 04:44:34 -0700 | [diff] [blame] | 4763 | // TODO: Use a build property to choose this value. |
Evan Charlton | 9829e88 | 2013-12-19 15:30:38 -0800 | [diff] [blame] | 4764 | return TelephonyManager.WifiCallingChoices.ALWAYS_USE; |
Ihab Awad | f2177b7 | 2013-11-25 13:33:23 -0800 | [diff] [blame] | 4765 | } |
Shishir Agrawal | 69f6812 | 2013-12-16 17:25:49 -0800 | [diff] [blame] | 4766 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4767 | private Phone getPhoneFromSlotIdOrThrowException(int slotIndex) { |
| 4768 | int phoneId = UiccController.getInstance().getPhoneIdFromSlotId(slotIndex); |
| 4769 | if (phoneId == -1) { |
| 4770 | throw new IllegalArgumentException("Given slot index: " + slotIndex |
| 4771 | + " does not correspond to an active phone"); |
| 4772 | } |
| 4773 | return PhoneFactory.getPhone(phoneId); |
| 4774 | } |
| 4775 | |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4776 | @Override |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4777 | public IccOpenLogicalChannelResponse iccOpenLogicalChannel( |
| 4778 | int subId, String callingPackage, String aid, int p2) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4779 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4780 | mApp, subId, "iccOpenLogicalChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4781 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4782 | if (DBG) { |
| 4783 | log("iccOpenLogicalChannel: subId=" + subId + " aid=" + aid + " p2=" + p2); |
| 4784 | } |
| 4785 | return iccOpenLogicalChannelWithPermission(getPhoneFromSubId(subId), callingPackage, aid, |
| 4786 | p2); |
| 4787 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4788 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4789 | |
| 4790 | @Override |
| 4791 | public IccOpenLogicalChannelResponse iccOpenLogicalChannelBySlot( |
| 4792 | int slotIndex, String callingPackage, String aid, int p2) { |
| 4793 | enforceModifyPermission(); |
| 4794 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4795 | if (DBG) { |
| 4796 | log("iccOpenLogicalChannelBySlot: slot=" + slotIndex + " aid=" + aid + " p2=" + p2); |
| 4797 | } |
| 4798 | return iccOpenLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4799 | callingPackage, aid, p2); |
| 4800 | } |
| 4801 | |
| 4802 | private IccOpenLogicalChannelResponse iccOpenLogicalChannelWithPermission(Phone phone, |
| 4803 | String callingPackage, String aid, int p2) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4804 | final long identity = Binder.clearCallingIdentity(); |
| 4805 | try { |
| 4806 | if (TextUtils.equals(ISDR_AID, aid)) { |
| 4807 | // Only allows LPA to open logical channel to ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4808 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4809 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4810 | if (bestComponent == null |
| 4811 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4812 | loge("The calling package is not allowed to access ISD-R."); |
| 4813 | throw new SecurityException( |
| 4814 | "The calling package is not allowed to access ISD-R."); |
| 4815 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4816 | } |
Derek Tan | 740e167 | 2017-06-27 14:56:27 -0700 | [diff] [blame] | 4817 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4818 | IccOpenLogicalChannelResponse response = (IccOpenLogicalChannelResponse) sendRequest( |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4819 | CMD_OPEN_CHANNEL, new Pair<String, Integer>(aid, p2), phone, |
| 4820 | null /* workSource */); |
| 4821 | if (DBG) log("iccOpenLogicalChannelWithPermission: " + response); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4822 | return response; |
| 4823 | } finally { |
| 4824 | Binder.restoreCallingIdentity(identity); |
| 4825 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4826 | } |
| 4827 | |
| 4828 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4829 | public boolean iccCloseLogicalChannel(int subId, int channel) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4830 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4831 | mApp, subId, "iccCloseLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4832 | if (DBG) log("iccCloseLogicalChannel: subId=" + subId + " chnl=" + channel); |
| 4833 | return iccCloseLogicalChannelWithPermission(getPhoneFromSubId(subId), channel); |
| 4834 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4835 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4836 | @Override |
| 4837 | public boolean iccCloseLogicalChannelBySlot(int slotIndex, int channel) { |
| 4838 | enforceModifyPermission(); |
| 4839 | if (DBG) log("iccCloseLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel); |
| 4840 | return iccCloseLogicalChannelWithPermission(getPhoneFromSlotIdOrThrowException(slotIndex), |
| 4841 | channel); |
| 4842 | } |
| 4843 | |
| 4844 | private boolean iccCloseLogicalChannelWithPermission(Phone phone, int channel) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4845 | final long identity = Binder.clearCallingIdentity(); |
| 4846 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4847 | if (channel < 0) { |
| 4848 | return false; |
| 4849 | } |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4850 | Boolean success = (Boolean) sendRequest(CMD_CLOSE_CHANNEL, channel, phone, |
| 4851 | null /* workSource */); |
| 4852 | if (DBG) log("iccCloseLogicalChannelWithPermission: " + success); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4853 | return success; |
| 4854 | } finally { |
| 4855 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4856 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4857 | } |
| 4858 | |
| 4859 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4860 | public String iccTransmitApduLogicalChannel(int subId, int channel, int cla, |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4861 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4862 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4863 | mApp, subId, "iccTransmitApduLogicalChannel"); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4864 | if (DBG) { |
| 4865 | log("iccTransmitApduLogicalChannel: subId=" + subId + " chnl=" + channel |
| 4866 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4867 | + p3 + " data=" + data); |
| 4868 | } |
| 4869 | return iccTransmitApduLogicalChannelWithPermission(getPhoneFromSubId(subId), channel, cla, |
| 4870 | command, p1, p2, p3, data); |
| 4871 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4872 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4873 | @Override |
| 4874 | public String iccTransmitApduLogicalChannelBySlot(int slotIndex, int channel, int cla, |
| 4875 | int command, int p1, int p2, int p3, String data) { |
| 4876 | enforceModifyPermission(); |
| 4877 | if (DBG) { |
| 4878 | log("iccTransmitApduLogicalChannelBySlot: slotIndex=" + slotIndex + " chnl=" + channel |
| 4879 | + " cla=" + cla + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" |
| 4880 | + p3 + " data=" + data); |
| 4881 | } |
| 4882 | return iccTransmitApduLogicalChannelWithPermission( |
| 4883 | getPhoneFromSlotIdOrThrowException(slotIndex), channel, cla, command, p1, p2, p3, |
| 4884 | data); |
| 4885 | } |
| 4886 | |
| 4887 | private String iccTransmitApduLogicalChannelWithPermission(Phone phone, int channel, int cla, |
| 4888 | int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4889 | final long identity = Binder.clearCallingIdentity(); |
| 4890 | try { |
Hall Liu | 4fd771b | 2019-05-02 09:16:29 -0700 | [diff] [blame] | 4891 | if (channel <= 0) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4892 | return ""; |
| 4893 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4894 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4895 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_LOGICAL_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4896 | new IccAPDUArgument(channel, cla, command, p1, p2, p3, data), phone, |
| 4897 | null /* workSource */); |
| 4898 | if (DBG) log("iccTransmitApduLogicalChannelWithPermission: " + response); |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4899 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4900 | // Append the returned status code to the end of the response payload. |
| 4901 | String s = Integer.toHexString( |
| 4902 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4903 | if (response.payload != null) { |
| 4904 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4905 | } |
| 4906 | return s; |
| 4907 | } finally { |
| 4908 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4909 | } |
Shishir Agrawal | 566b761 | 2013-10-28 14:41:00 -0700 | [diff] [blame] | 4910 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 4911 | |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 4912 | @Override |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4913 | public String iccTransmitApduBasicChannel(int subId, String callingPackage, int cla, |
| 4914 | int command, int p1, int p2, int p3, String data) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4915 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4916 | mApp, subId, "iccTransmitApduBasicChannel"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4917 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4918 | if (DBG) { |
| 4919 | log("iccTransmitApduBasicChannel: subId=" + subId + " cla=" + cla + " cmd=" |
| 4920 | + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 + " data=" + data); |
| 4921 | } |
| 4922 | return iccTransmitApduBasicChannelWithPermission(getPhoneFromSubId(subId), callingPackage, |
| 4923 | cla, command, p1, p2, p3, data); |
| 4924 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4925 | |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4926 | @Override |
| 4927 | public String iccTransmitApduBasicChannelBySlot(int slotIndex, String callingPackage, int cla, |
| 4928 | int command, int p1, int p2, int p3, String data) { |
| 4929 | enforceModifyPermission(); |
| 4930 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
| 4931 | if (DBG) { |
| 4932 | log("iccTransmitApduBasicChannelBySlot: slotIndex=" + slotIndex + " cla=" + cla |
| 4933 | + " cmd=" + command + " p1=" + p1 + " p2=" + p2 + " p3=" + p3 |
| 4934 | + " data=" + data); |
| 4935 | } |
| 4936 | |
| 4937 | return iccTransmitApduBasicChannelWithPermission( |
| 4938 | getPhoneFromSlotIdOrThrowException(slotIndex), callingPackage, cla, command, p1, |
| 4939 | p2, p3, data); |
| 4940 | } |
| 4941 | |
| 4942 | // open APDU basic channel assuming the caller has sufficient permissions |
| 4943 | private String iccTransmitApduBasicChannelWithPermission(Phone phone, String callingPackage, |
| 4944 | int cla, int command, int p1, int p2, int p3, String data) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4945 | final long identity = Binder.clearCallingIdentity(); |
| 4946 | try { |
| 4947 | if (command == SELECT_COMMAND && p1 == SELECT_P1 && p2 == SELECT_P2 && p3 == SELECT_P3 |
| 4948 | && TextUtils.equals(ISDR_AID, data)) { |
| 4949 | // Only allows LPA to select ISD-R. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 4950 | ComponentInfo bestComponent = EuiccConnector.findBestComponent(getDefaultPhone() |
| 4951 | .getContext().getPackageManager()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4952 | if (bestComponent == null |
| 4953 | || !TextUtils.equals(callingPackage, bestComponent.packageName)) { |
| 4954 | loge("The calling package is not allowed to select ISD-R."); |
| 4955 | throw new SecurityException( |
| 4956 | "The calling package is not allowed to select ISD-R."); |
| 4957 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4958 | } |
Holly Jiuyu Sun | 1cc2d55 | 2018-01-26 15:51:16 -0800 | [diff] [blame] | 4959 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4960 | IccIoResult response = (IccIoResult) sendRequest(CMD_TRANSMIT_APDU_BASIC_CHANNEL, |
Jordan Liu | 4c73374 | 2019-02-28 12:03:40 -0800 | [diff] [blame] | 4961 | new IccAPDUArgument(0, cla, command, p1, p2, p3, data), phone, |
| 4962 | null /* workSource */); |
| 4963 | if (DBG) log("iccTransmitApduBasicChannelWithPermission: " + response); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4964 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4965 | // Append the returned status code to the end of the response payload. |
| 4966 | String s = Integer.toHexString( |
| 4967 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 4968 | if (response.payload != null) { |
| 4969 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 4970 | } |
| 4971 | return s; |
| 4972 | } finally { |
| 4973 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | 5ec1417 | 2014-08-05 17:05:45 -0700 | [diff] [blame] | 4974 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4975 | } |
| 4976 | |
| 4977 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 4978 | 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] | 4979 | String filePath) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 4980 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 4981 | mApp, subId, "iccExchangeSimIO"); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 4982 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 4983 | final long identity = Binder.clearCallingIdentity(); |
| 4984 | try { |
| 4985 | if (DBG) { |
| 4986 | log("Exchange SIM_IO " + subId + ":" + fileID + ":" + command + " " |
| 4987 | + p1 + " " + p2 + " " + p3 + ":" + filePath); |
| 4988 | } |
| 4989 | |
| 4990 | IccIoResult response = |
| 4991 | (IccIoResult) sendRequest(CMD_EXCHANGE_SIM_IO, |
| 4992 | new IccAPDUArgument(-1, fileID, command, p1, p2, p3, filePath), |
| 4993 | subId); |
| 4994 | |
| 4995 | if (DBG) { |
| 4996 | log("Exchange SIM_IO [R]" + response); |
| 4997 | } |
| 4998 | |
| 4999 | byte[] result = null; |
| 5000 | int length = 2; |
| 5001 | if (response.payload != null) { |
| 5002 | length = 2 + response.payload.length; |
| 5003 | result = new byte[length]; |
| 5004 | System.arraycopy(response.payload, 0, result, 0, response.payload.length); |
| 5005 | } else { |
| 5006 | result = new byte[length]; |
| 5007 | } |
| 5008 | |
| 5009 | result[length - 1] = (byte) response.sw2; |
| 5010 | result[length - 2] = (byte) response.sw1; |
| 5011 | return result; |
| 5012 | } finally { |
| 5013 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5014 | } |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5015 | } |
| 5016 | |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5017 | /** |
| 5018 | * Get the forbidden PLMN List from the given app type (ex APPTYPE_USIM) |
| 5019 | * on a particular subscription |
| 5020 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5021 | public String[] getForbiddenPlmns(int subId, int appType, String callingPackage, |
| 5022 | String callingFeatureId) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5023 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5024 | mApp, subId, callingPackage, callingFeatureId, "getForbiddenPlmns")) { |
sqian | b6e4195 | 2018-03-12 14:54:01 -0700 | [diff] [blame] | 5025 | return null; |
| 5026 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5027 | |
| 5028 | final long identity = Binder.clearCallingIdentity(); |
| 5029 | try { |
| 5030 | if (appType != TelephonyManager.APPTYPE_USIM |
| 5031 | && appType != TelephonyManager.APPTYPE_SIM) { |
| 5032 | loge("getForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5033 | return null; |
| 5034 | } |
| 5035 | Object response = sendRequest( |
| 5036 | CMD_GET_FORBIDDEN_PLMNS, new Integer(appType), subId); |
| 5037 | if (response instanceof String[]) { |
| 5038 | return (String[]) response; |
| 5039 | } |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5040 | // Response is an Exception of some kind |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5041 | // which is signalled to the user as a NULL retval |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5042 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5043 | } finally { |
| 5044 | Binder.restoreCallingIdentity(identity); |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5045 | } |
Nathan Harold | b301405 | 2017-01-25 15:57:32 -0800 | [diff] [blame] | 5046 | } |
| 5047 | |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5048 | /** |
| 5049 | * Set the forbidden PLMN list from the given app type (ex APPTYPE_USIM) on a particular |
| 5050 | * subscription. |
| 5051 | * |
| 5052 | * @param subId the id of the subscription. |
| 5053 | * @param appType the uicc app type, must be USIM or SIM. |
| 5054 | * @param fplmns the Forbiden plmns list that needed to be written to the SIM. |
| 5055 | * @param callingPackage the op Package name. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5056 | * @param callingFeatureId the feature in the package. |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5057 | * @return number of fplmns that is successfully written to the SIM. |
| 5058 | */ |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5059 | public int setForbiddenPlmns(int subId, int appType, List<String> fplmns, String callingPackage, |
| 5060 | String callingFeatureId) { |
| 5061 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, subId, callingPackage, |
| 5062 | callingFeatureId, "setForbiddenPlmns")) { |
yincheng zhao | 2737e88 | 2019-09-06 17:06:54 -0700 | [diff] [blame] | 5063 | if (DBG) logv("no permissions for setForbiddenplmns"); |
| 5064 | throw new IllegalStateException("No Permissions for setForbiddenPlmns"); |
| 5065 | } |
| 5066 | if (appType != TelephonyManager.APPTYPE_USIM && appType != TelephonyManager.APPTYPE_SIM) { |
| 5067 | loge("setForbiddenPlmnList(): App Type must be USIM or SIM"); |
| 5068 | throw new IllegalArgumentException("Invalid appType: App Type must be USIM or SIM"); |
| 5069 | } |
| 5070 | if (fplmns == null) { |
| 5071 | throw new IllegalArgumentException("Fplmn List provided is null"); |
| 5072 | } |
| 5073 | for (String fplmn : fplmns) { |
| 5074 | if (!CellIdentity.isValidPlmn(fplmn)) { |
| 5075 | throw new IllegalArgumentException("Invalid fplmn provided: " + fplmn); |
| 5076 | } |
| 5077 | } |
| 5078 | final long identity = Binder.clearCallingIdentity(); |
| 5079 | try { |
| 5080 | Object response = sendRequest( |
| 5081 | CMD_SET_FORBIDDEN_PLMNS, |
| 5082 | new Pair<Integer, List<String>>(new Integer(appType), fplmns), |
| 5083 | subId); |
| 5084 | return (int) response; |
| 5085 | } finally { |
| 5086 | Binder.restoreCallingIdentity(identity); |
| 5087 | } |
| 5088 | } |
| 5089 | |
Shishir Agrawal | da0bb0d | 2014-07-29 21:18:53 -0700 | [diff] [blame] | 5090 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 5091 | public String sendEnvelopeWithStatus(int subId, String content) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5092 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5093 | mApp, subId, "sendEnvelopeWithStatus"); |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5094 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5095 | final long identity = Binder.clearCallingIdentity(); |
| 5096 | try { |
| 5097 | IccIoResult response = (IccIoResult) sendRequest(CMD_SEND_ENVELOPE, content, subId); |
| 5098 | if (response.payload == null) { |
| 5099 | return ""; |
| 5100 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5101 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5102 | // Append the returned status code to the end of the response payload. |
| 5103 | String s = Integer.toHexString( |
| 5104 | (response.sw1 << 8) + response.sw2 + 0x10000).substring(1); |
| 5105 | s = IccUtils.bytesToHexString(response.payload) + s; |
| 5106 | return s; |
| 5107 | } finally { |
| 5108 | Binder.restoreCallingIdentity(identity); |
| 5109 | } |
Evan Charlton | c66da36 | 2014-05-16 14:06:40 -0700 | [diff] [blame] | 5110 | } |
| 5111 | |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5112 | /** |
| 5113 | * Read one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5114 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5115 | * |
| 5116 | * @param itemID the ID of the item to read |
| 5117 | * @return the NV item as a String, or null on error. |
| 5118 | */ |
| 5119 | @Override |
| 5120 | public String nvReadItem(int itemID) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5121 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5122 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5123 | mApp, getDefaultSubscription(), "nvReadItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5124 | |
| 5125 | final long identity = Binder.clearCallingIdentity(); |
| 5126 | try { |
| 5127 | if (DBG) log("nvReadItem: item " + itemID); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5128 | String value = (String) sendRequest(CMD_NV_READ_ITEM, itemID, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5129 | if (DBG) log("nvReadItem: item " + itemID + " is \"" + value + '"'); |
| 5130 | return value; |
| 5131 | } finally { |
| 5132 | Binder.restoreCallingIdentity(identity); |
| 5133 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5134 | } |
| 5135 | |
| 5136 | /** |
| 5137 | * Write one of the NV items defined in {@link com.android.internal.telephony.RadioNVItems} |
| 5138 | * and {@code ril_nv_items.h}. Used for device configuration by some CDMA operators. |
| 5139 | * |
| 5140 | * @param itemID the ID of the item to read |
| 5141 | * @param itemValue the value to write, as a String |
| 5142 | * @return true on success; false on any failure |
| 5143 | */ |
| 5144 | @Override |
| 5145 | public boolean nvWriteItem(int itemID, String itemValue) { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5146 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5147 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5148 | mApp, getDefaultSubscription(), "nvWriteItem"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5149 | |
| 5150 | final long identity = Binder.clearCallingIdentity(); |
| 5151 | try { |
| 5152 | if (DBG) log("nvWriteItem: item " + itemID + " value \"" + itemValue + '"'); |
| 5153 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_ITEM, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 5154 | new Pair<Integer, String>(itemID, itemValue), workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5155 | if (DBG) log("nvWriteItem: item " + itemID + ' ' + (success ? "ok" : "fail")); |
| 5156 | return success; |
| 5157 | } finally { |
| 5158 | Binder.restoreCallingIdentity(identity); |
| 5159 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5160 | } |
| 5161 | |
| 5162 | /** |
| 5163 | * Update the CDMA Preferred Roaming List (PRL) in the radio NV storage. |
| 5164 | * Used for device configuration by some CDMA operators. |
| 5165 | * |
| 5166 | * @param preferredRoamingList byte array containing the new PRL |
| 5167 | * @return true on success; false on any failure |
| 5168 | */ |
| 5169 | @Override |
| 5170 | public boolean nvWriteCdmaPrl(byte[] preferredRoamingList) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5171 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5172 | mApp, getDefaultSubscription(), "nvWriteCdmaPrl"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5173 | |
| 5174 | final long identity = Binder.clearCallingIdentity(); |
| 5175 | try { |
| 5176 | if (DBG) log("nvWriteCdmaPrl: value: " + HexDump.toHexString(preferredRoamingList)); |
| 5177 | Boolean success = (Boolean) sendRequest(CMD_NV_WRITE_CDMA_PRL, preferredRoamingList); |
| 5178 | if (DBG) log("nvWriteCdmaPrl: " + (success ? "ok" : "fail")); |
| 5179 | return success; |
| 5180 | } finally { |
| 5181 | Binder.restoreCallingIdentity(identity); |
| 5182 | } |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | /** |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5186 | * 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] | 5187 | * Used for device configuration by some CDMA operators. |
| 5188 | * |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5189 | * @param slotIndex - device slot. |
| 5190 | * |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5191 | * @return true on success; false on any failure |
| 5192 | */ |
| 5193 | @Override |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5194 | public boolean resetModemConfig(int slotIndex) { |
| 5195 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5196 | if (phone != null) { |
| 5197 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5198 | mApp, phone.getSubId(), "resetModemConfig"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5199 | |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5200 | final long identity = Binder.clearCallingIdentity(); |
| 5201 | try { |
| 5202 | Boolean success = (Boolean) sendRequest(CMD_RESET_MODEM_CONFIG, null); |
| 5203 | if (DBG) log("resetModemConfig:" + ' ' + (success ? "ok" : "fail")); |
| 5204 | return success; |
| 5205 | } finally { |
| 5206 | Binder.restoreCallingIdentity(identity); |
| 5207 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5208 | } |
chen xu | 6dac5ab | 2018-10-26 17:39:23 -0700 | [diff] [blame] | 5209 | return false; |
| 5210 | } |
| 5211 | |
| 5212 | /** |
| 5213 | * Generate a radio modem reset. Used for device configuration by some CDMA operators. |
| 5214 | * |
| 5215 | * @param slotIndex - device slot. |
| 5216 | * |
| 5217 | * @return true on success; false on any failure |
| 5218 | */ |
| 5219 | @Override |
| 5220 | public boolean rebootModem(int slotIndex) { |
| 5221 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 5222 | if (phone != null) { |
| 5223 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5224 | mApp, phone.getSubId(), "rebootModem"); |
| 5225 | |
| 5226 | final long identity = Binder.clearCallingIdentity(); |
| 5227 | try { |
| 5228 | Boolean success = (Boolean) sendRequest(CMD_MODEM_REBOOT, null); |
| 5229 | if (DBG) log("rebootModem:" + ' ' + (success ? "ok" : "fail")); |
| 5230 | return success; |
| 5231 | } finally { |
| 5232 | Binder.restoreCallingIdentity(identity); |
| 5233 | } |
| 5234 | } |
| 5235 | return false; |
Jake Hamby | e994d46 | 2014-02-03 13:10:13 -0800 | [diff] [blame] | 5236 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5237 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5238 | public String[] getPcscfAddress(String apnType, String callingPackage, |
| 5239 | String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5240 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5241 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 5242 | callingPackage, callingFeatureId, "getPcscfAddress")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5243 | return new String[0]; |
| 5244 | } |
| 5245 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5246 | final long identity = Binder.clearCallingIdentity(); |
| 5247 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5248 | return defaultPhone.getPcscfAddress(apnType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5249 | } finally { |
| 5250 | Binder.restoreCallingIdentity(identity); |
| 5251 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5252 | } |
| 5253 | |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5254 | /** |
Grace Jia | aa2eb6b | 2020-01-09 16:26:08 -0800 | [diff] [blame] | 5255 | * Toggle IMS disable and enable for the framework to reset it. See {@link #enableIms(int)} and |
| 5256 | * {@link #disableIms(int)}. |
| 5257 | * @param slotIndex device slot. |
| 5258 | */ |
| 5259 | public void resetIms(int slotIndex) { |
| 5260 | enforceModifyPermission(); |
| 5261 | |
| 5262 | final long identity = Binder.clearCallingIdentity(); |
| 5263 | try { |
| 5264 | if (mImsResolver == null) { |
| 5265 | // may happen if the does not support IMS. |
| 5266 | return; |
| 5267 | } |
| 5268 | mImsResolver.disableIms(slotIndex); |
| 5269 | mImsResolver.enableIms(slotIndex); |
| 5270 | } finally { |
| 5271 | Binder.restoreCallingIdentity(identity); |
| 5272 | } |
| 5273 | } |
| 5274 | |
| 5275 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5276 | * Enables IMS for the framework. This will trigger IMS registration and ImsFeature capability |
| 5277 | * status updates, if not already enabled. |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5278 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5279 | public void enableIms(int slotId) { |
Brad Ebinger | 51f743a | 2017-01-23 13:50:20 -0800 | [diff] [blame] | 5280 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5281 | |
| 5282 | final long identity = Binder.clearCallingIdentity(); |
| 5283 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5284 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5285 | // may happen if the device does not support IMS. |
| 5286 | return; |
| 5287 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5288 | mImsResolver.enableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5289 | } finally { |
| 5290 | Binder.restoreCallingIdentity(identity); |
| 5291 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5292 | } |
| 5293 | |
| 5294 | /** |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5295 | * Disables IMS for the framework. This will trigger IMS de-registration and trigger ImsFeature |
| 5296 | * status updates to disabled. |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5297 | */ |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5298 | public void disableIms(int slotId) { |
| 5299 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5300 | |
| 5301 | final long identity = Binder.clearCallingIdentity(); |
| 5302 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5303 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5304 | // may happen if the device does not support IMS. |
| 5305 | return; |
| 5306 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5307 | mImsResolver.disableIms(slotId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5308 | } finally { |
| 5309 | Binder.restoreCallingIdentity(identity); |
| 5310 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5311 | } |
| 5312 | |
| 5313 | /** |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5314 | * Registers for updates to the MmTelFeature connection through the IImsServiceFeatureCallback |
| 5315 | * callback. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5316 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5317 | @Override |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5318 | public void registerMmTelFeatureCallback(int slotId, IImsServiceFeatureCallback callback) { |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5319 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5320 | |
| 5321 | final long identity = Binder.clearCallingIdentity(); |
| 5322 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5323 | if (mImsResolver == null) { |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5324 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5325 | "Device does not support IMS"); |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5326 | } |
Brad Ebinger | f6aca00 | 2020-10-01 13:51:05 -0700 | [diff] [blame] | 5327 | mImsResolver.listenForFeature(slotId, ImsFeature.FEATURE_MMTEL, callback); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5328 | } finally { |
| 5329 | Binder.restoreCallingIdentity(identity); |
| 5330 | } |
Brad Ebinger | 34bef92 | 2017-11-09 10:27:08 -0800 | [diff] [blame] | 5331 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5332 | /** |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5333 | * Unregister a previously registered IImsServiceFeatureCallback associated with an ImsFeature. |
| 5334 | */ |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5335 | @Override |
| 5336 | public void unregisterImsFeatureCallback(IImsServiceFeatureCallback callback) { |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5337 | enforceModifyPermission(); |
| 5338 | |
| 5339 | final long identity = Binder.clearCallingIdentity(); |
| 5340 | try { |
| 5341 | if (mImsResolver == null) return; |
Brad Ebinger | 67b3e04 | 2020-09-11 12:45:11 -0700 | [diff] [blame] | 5342 | mImsResolver.unregisterImsFeatureCallback(callback); |
Brad Ebinger | 075ff3a | 2020-05-18 17:52:58 -0700 | [diff] [blame] | 5343 | } finally { |
| 5344 | Binder.restoreCallingIdentity(identity); |
| 5345 | } |
| 5346 | } |
| 5347 | |
| 5348 | /** |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5349 | * Returns the {@link IImsRegistration} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5350 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5351 | */ |
| 5352 | public IImsRegistration getImsRegistration(int slotId, int feature) throws RemoteException { |
| 5353 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5354 | |
| 5355 | final long identity = Binder.clearCallingIdentity(); |
| 5356 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5357 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5358 | // may happen if the device does not support IMS. |
| 5359 | return null; |
| 5360 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5361 | return mImsResolver.getImsRegistration(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5362 | } finally { |
| 5363 | Binder.restoreCallingIdentity(identity); |
| 5364 | } |
Brad Ebinger | 5f64b05 | 2017-12-14 14:26:15 -0800 | [diff] [blame] | 5365 | } |
| 5366 | |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5367 | /** |
| 5368 | * Returns the {@link IImsConfig} structure associated with the slotId and feature |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5369 | * specified or null if IMS is not supported on the slot specified. |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5370 | */ |
| 5371 | public IImsConfig getImsConfig(int slotId, int feature) throws RemoteException { |
| 5372 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5373 | |
| 5374 | final long identity = Binder.clearCallingIdentity(); |
| 5375 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5376 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5377 | // may happen if the device does not support IMS. |
| 5378 | return null; |
| 5379 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5380 | return mImsResolver.getImsConfig(slotId, feature); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5381 | } finally { |
| 5382 | Binder.restoreCallingIdentity(identity); |
| 5383 | } |
Brad Ebinger | 22bc3e4 | 2018-01-16 09:39:35 -0800 | [diff] [blame] | 5384 | } |
| 5385 | |
Brad Ebinger | 884c07b | 2018-02-15 16:17:40 -0800 | [diff] [blame] | 5386 | /** |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5387 | * Sets the ImsService Package Name that Telephony will bind to. |
| 5388 | * |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5389 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5390 | * @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] | 5391 | * ImsService is the device default ImsService. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5392 | * @param featureTypes An integer array of feature types associated with a packageName. |
| 5393 | * @param packageName The name of the package that the current configuration will be replaced |
| 5394 | * with. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5395 | * @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] | 5396 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5397 | public boolean setBoundImsServiceOverride(int slotIndex, boolean isCarrierService, |
| 5398 | int[] featureTypes, String packageName) { |
| 5399 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5400 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5401 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5402 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5403 | "setBoundImsServiceOverride"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5404 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5405 | final long identity = Binder.clearCallingIdentity(); |
| 5406 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5407 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5408 | // may happen if the device does not support IMS. |
| 5409 | return false; |
| 5410 | } |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5411 | Map<Integer, String> featureConfig = new HashMap<>(); |
| 5412 | for (int featureType : featureTypes) { |
| 5413 | featureConfig.put(featureType, packageName); |
| 5414 | } |
| 5415 | return mImsResolver.overrideImsServiceConfiguration(slotIndex, isCarrierService, |
| 5416 | featureConfig); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5417 | } finally { |
| 5418 | Binder.restoreCallingIdentity(identity); |
| 5419 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5420 | } |
| 5421 | |
| 5422 | /** |
Brad Ebinger | 999d330 | 2020-11-25 14:31:39 -0800 | [diff] [blame] | 5423 | * Clears any carrier ImsService overrides for the slot index specified that were previously |
| 5424 | * set with {@link #setBoundImsServiceOverride(int, boolean, int[], String)}. |
| 5425 | * |
| 5426 | * This should only be used for testing. |
| 5427 | * |
| 5428 | * @param slotIndex the slot ID that the ImsService should bind for. |
| 5429 | * @return true if clearing the carrier ImsService override succeeded or false if it did not. |
| 5430 | */ |
| 5431 | @Override |
| 5432 | public boolean clearCarrierImsServiceOverride(int slotIndex) { |
| 5433 | int[] subIds = SubscriptionManager.getSubId(slotIndex); |
| 5434 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 5435 | "clearCarrierImsServiceOverride"); |
| 5436 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege(mApp, |
| 5437 | (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5438 | "clearCarrierImsServiceOverride"); |
| 5439 | |
| 5440 | final long identity = Binder.clearCallingIdentity(); |
| 5441 | try { |
| 5442 | if (mImsResolver == null) { |
| 5443 | // may happen if the device does not support IMS. |
| 5444 | return false; |
| 5445 | } |
| 5446 | return mImsResolver.clearCarrierImsServiceConfiguration(slotIndex); |
| 5447 | } finally { |
| 5448 | Binder.restoreCallingIdentity(identity); |
| 5449 | } |
| 5450 | } |
| 5451 | |
| 5452 | /** |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5453 | * Return the package name of the currently bound ImsService. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5454 | * |
| 5455 | * @param slotId The slot that the ImsService is associated with. |
| 5456 | * @param isCarrierImsService true, if the ImsService is a carrier override, false if it is |
| 5457 | * the device default. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5458 | * @param featureType The feature associated with the queried configuration. |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5459 | * @return the package name of the ImsService configuration. |
| 5460 | */ |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5461 | public String getBoundImsServicePackage(int slotId, boolean isCarrierImsService, |
| 5462 | @ImsFeature.FeatureType int featureType) { |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5463 | int[] subIds = SubscriptionManager.getSubId(slotId); |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5464 | TelephonyPermissions |
| 5465 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5466 | mApp, (subIds != null ? subIds[0] : SubscriptionManager.INVALID_SUBSCRIPTION_ID), |
| 5467 | "getBoundImsServicePackage"); |
Brad Ebinger | de696de | 2018-04-06 09:56:40 -0700 | [diff] [blame] | 5468 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5469 | final long identity = Binder.clearCallingIdentity(); |
| 5470 | try { |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5471 | if (mImsResolver == null) { |
Brad Ebinger | 9c0eb50 | 2019-01-23 15:06:19 -0800 | [diff] [blame] | 5472 | // may happen if the device does not support IMS. |
| 5473 | return ""; |
| 5474 | } |
Brad Ebinger | a80c331 | 2019-12-02 10:59:39 -0800 | [diff] [blame] | 5475 | // TODO: change API to query RCS separately. |
Brad Ebinger | 24c2999 | 2019-12-05 13:03:21 -0800 | [diff] [blame] | 5476 | return mImsResolver.getImsServiceConfiguration(slotId, isCarrierImsService, |
| 5477 | featureType); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5478 | } finally { |
| 5479 | Binder.restoreCallingIdentity(identity); |
| 5480 | } |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 5481 | } |
| 5482 | |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 5483 | /** |
| 5484 | * Get the MmTelFeature state associated with the requested subscription id. |
| 5485 | * @param subId The subscription that the MmTelFeature is associated with. |
| 5486 | * @param callback A callback with an integer containing the |
| 5487 | * {@link android.telephony.ims.feature.ImsFeature.ImsState} associated with the MmTelFeature. |
| 5488 | */ |
| 5489 | @Override |
| 5490 | public void getImsMmTelFeatureState(int subId, IIntegerConsumer callback) { |
| 5491 | enforceReadPrivilegedPermission("getImsMmTelFeatureState"); |
| 5492 | if (!ImsManager.isImsSupportedOnDevice(mApp)) { |
| 5493 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 5494 | "IMS not available on device."); |
| 5495 | } |
| 5496 | final long token = Binder.clearCallingIdentity(); |
| 5497 | try { |
| 5498 | int slotId = getSlotIndex(subId); |
| 5499 | if (slotId <= SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 5500 | Log.w(LOG_TAG, "getImsMmTelFeatureState: called with an inactive subscription '" |
| 5501 | + subId + "'"); |
| 5502 | throw new ServiceSpecificException(ImsException.CODE_ERROR_INVALID_SUBSCRIPTION); |
| 5503 | } |
| 5504 | ImsManager.getInstance(mApp, slotId).getImsServiceState(anInteger -> { |
| 5505 | try { |
| 5506 | callback.accept(anInteger == null ? ImsFeature.STATE_UNAVAILABLE : anInteger); |
| 5507 | } catch (RemoteException e) { |
| 5508 | Log.w(LOG_TAG, "getImsMmTelFeatureState: remote caller is no longer running. " |
| 5509 | + "Ignore"); |
| 5510 | } |
| 5511 | }); |
| 5512 | } finally { |
| 5513 | Binder.restoreCallingIdentity(token); |
| 5514 | } |
| 5515 | } |
| 5516 | |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5517 | public void setImsRegistrationState(boolean registered) { |
| 5518 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5519 | |
| 5520 | final long identity = Binder.clearCallingIdentity(); |
| 5521 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5522 | getDefaultPhone().setImsRegistrationState(registered); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5523 | } finally { |
| 5524 | Binder.restoreCallingIdentity(identity); |
| 5525 | } |
Wink Saville | 36469e7 | 2014-06-11 15:17:00 -0700 | [diff] [blame] | 5526 | } |
| 5527 | |
| 5528 | /** |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5529 | * Set the network selection mode to automatic. |
| 5530 | * |
| 5531 | */ |
| 5532 | @Override |
| 5533 | public void setNetworkSelectionModeAutomatic(int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5534 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5535 | mApp, subId, "setNetworkSelectionModeAutomatic"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5536 | |
| 5537 | final long identity = Binder.clearCallingIdentity(); |
| 5538 | try { |
shilu | fc95839 | 2020-01-20 11:36:01 -0800 | [diff] [blame] | 5539 | if (!isActiveSubscription(subId)) { |
| 5540 | return; |
| 5541 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5542 | if (DBG) log("setNetworkSelectionModeAutomatic: subId " + subId); |
| 5543 | sendRequest(CMD_SET_NETWORK_SELECTION_MODE_AUTOMATIC, null, subId); |
| 5544 | } finally { |
| 5545 | Binder.restoreCallingIdentity(identity); |
| 5546 | } |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5547 | } |
| 5548 | |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 5549 | /** |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5550 | * Ask the radio to connect to the input network and change selection mode to manual. |
| 5551 | * |
| 5552 | * @param subId the id of the subscription. |
| 5553 | * @param operatorInfo the operator information, included the PLMN, long name and short name of |
| 5554 | * the operator to attach to. |
| 5555 | * @param persistSelection whether the selection will persist until reboot. If true, only allows |
| 5556 | * attaching to the selected PLMN until reboot; otherwise, attach to the chosen PLMN and resume |
| 5557 | * normal network selection next time. |
| 5558 | * @return {@code true} on success; {@code true} on any failure. |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5559 | */ |
| 5560 | @Override |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5561 | public boolean setNetworkSelectionModeManual( |
| 5562 | int subId, OperatorInfo operatorInfo, boolean persistSelection) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5563 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5564 | mApp, subId, "setNetworkSelectionModeManual"); |
Pengquan Meng | e92a50d | 2018-09-21 15:54:48 -0700 | [diff] [blame] | 5565 | |
| 5566 | if (!isActiveSubscription(subId)) { |
| 5567 | return false; |
| 5568 | } |
| 5569 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5570 | final long identity = Binder.clearCallingIdentity(); |
| 5571 | try { |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5572 | ManualNetworkSelectionArgument arg = new ManualNetworkSelectionArgument(operatorInfo, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5573 | persistSelection); |
Pengquan Meng | ea84e04 | 2018-09-20 14:57:26 -0700 | [diff] [blame] | 5574 | if (DBG) { |
| 5575 | log("setNetworkSelectionModeManual: subId: " + subId |
| 5576 | + " operator: " + operatorInfo); |
| 5577 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5578 | return (Boolean) sendRequest(CMD_SET_NETWORK_SELECTION_MODE_MANUAL, arg, subId); |
| 5579 | } finally { |
| 5580 | Binder.restoreCallingIdentity(identity); |
| 5581 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5582 | } |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5583 | /** |
| 5584 | * Get the manual network selection |
| 5585 | * |
| 5586 | * @param subId the id of the subscription. |
| 5587 | * |
| 5588 | * @return the previously saved user selected PLMN |
| 5589 | */ |
| 5590 | @Override |
| 5591 | public String getManualNetworkSelectionPlmn(int subId) { |
| 5592 | TelephonyPermissions |
| 5593 | .enforeceCallingOrSelfReadPrecisePhoneStatePermissionOrCarrierPrivilege( |
| 5594 | mApp, subId, "getManualNetworkSelectionPlmn"); |
| 5595 | |
| 5596 | final long identity = Binder.clearCallingIdentity(); |
| 5597 | try { |
| 5598 | if (!isActiveSubscription(subId)) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5599 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5600 | } |
| 5601 | |
| 5602 | final Phone phone = getPhone(subId); |
| 5603 | if (phone == null) { |
shilu | fa1c259 | 2020-03-10 10:59:43 -0700 | [diff] [blame] | 5604 | throw new IllegalArgumentException("Invalid Subscription Id: " + subId); |
shilu | 84f6e8b | 2019-12-19 13:58:01 -0800 | [diff] [blame] | 5605 | } |
| 5606 | OperatorInfo networkSelection = phone.getSavedNetworkSelection(); |
| 5607 | return TextUtils.isEmpty(networkSelection.getOperatorNumeric()) |
| 5608 | ? phone.getManualNetworkSelectionPlmn() : networkSelection.getOperatorNumeric(); |
| 5609 | } finally { |
| 5610 | Binder.restoreCallingIdentity(identity); |
| 5611 | } |
| 5612 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5613 | |
| 5614 | /** |
| 5615 | * Scans for available networks. |
| 5616 | */ |
| 5617 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5618 | public CellNetworkScanResult getCellNetworkScanResults(int subId, String callingPackage, |
| 5619 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5620 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5621 | mApp, subId, "getCellNetworkScanResults"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5622 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5623 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5624 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5625 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5626 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5627 | .setCallingPid(Binder.getCallingPid()) |
| 5628 | .setCallingUid(Binder.getCallingUid()) |
| 5629 | .setMethod("getCellNetworkScanResults") |
| 5630 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 5631 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5632 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5633 | .build()); |
| 5634 | switch (locationResult) { |
| 5635 | case DENIED_HARD: |
| 5636 | throw new SecurityException("Not allowed to access scan results -- location"); |
| 5637 | case DENIED_SOFT: |
| 5638 | return null; |
| 5639 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5640 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5641 | long identity = Binder.clearCallingIdentity(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5642 | try { |
| 5643 | if (DBG) log("getCellNetworkScanResults: subId " + subId); |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 5644 | return (CellNetworkScanResult) sendRequest( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5645 | CMD_PERFORM_NETWORK_SCAN, null, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5646 | } finally { |
| 5647 | Binder.restoreCallingIdentity(identity); |
| 5648 | } |
Shishir Agrawal | 302c869 | 2015-06-19 13:49:39 -0700 | [diff] [blame] | 5649 | } |
| 5650 | |
| 5651 | /** |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5652 | * Get the call forwarding info, given the call forwarding reason. |
| 5653 | */ |
| 5654 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5655 | public void getCallForwarding(int subId, int callForwardingReason, |
| 5656 | ICallForwardingInfoCallback callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5657 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5658 | long identity = Binder.clearCallingIdentity(); |
| 5659 | try { |
| 5660 | if (DBG) { |
| 5661 | log("getCallForwarding: subId " + subId |
| 5662 | + " callForwardingReason" + callForwardingReason); |
| 5663 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5664 | |
| 5665 | Phone phone = getPhone(subId); |
| 5666 | if (phone == null) { |
| 5667 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5668 | callback.onError( |
| 5669 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5670 | } catch (RemoteException e) { |
| 5671 | // ignore |
| 5672 | } |
| 5673 | return; |
| 5674 | } |
| 5675 | |
| 5676 | Pair<Integer, TelephonyManager.CallForwardingInfoCallback> argument = Pair.create( |
| 5677 | callForwardingReason, new TelephonyManager.CallForwardingInfoCallback() { |
| 5678 | @Override |
| 5679 | public void onCallForwardingInfoAvailable(CallForwardingInfo info) { |
| 5680 | try { |
| 5681 | callback.onCallForwardingInfoAvailable(info); |
| 5682 | } catch (RemoteException e) { |
| 5683 | // ignore |
| 5684 | } |
| 5685 | } |
| 5686 | |
| 5687 | @Override |
| 5688 | public void onError(int error) { |
| 5689 | try { |
| 5690 | callback.onError(error); |
| 5691 | } catch (RemoteException e) { |
| 5692 | // ignore |
| 5693 | } |
| 5694 | } |
| 5695 | }); |
| 5696 | sendRequestAsync(CMD_GET_CALL_FORWARDING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5697 | } finally { |
| 5698 | Binder.restoreCallingIdentity(identity); |
| 5699 | } |
| 5700 | } |
| 5701 | |
| 5702 | /** |
| 5703 | * Sets the voice call forwarding info including status (enable/disable), call forwarding |
| 5704 | * reason, the number to forward, and the timeout before the forwarding is attempted. |
| 5705 | */ |
| 5706 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5707 | public void setCallForwarding(int subId, CallForwardingInfo callForwardingInfo, |
| 5708 | IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5709 | enforceModifyPermission(); |
| 5710 | long identity = Binder.clearCallingIdentity(); |
| 5711 | try { |
| 5712 | if (DBG) { |
| 5713 | log("setCallForwarding: subId " + subId |
| 5714 | + " callForwardingInfo" + callForwardingInfo); |
| 5715 | } |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5716 | |
| 5717 | Phone phone = getPhone(subId); |
| 5718 | if (phone == null) { |
| 5719 | try { |
Hall Liu | 940c4ca | 2020-09-29 17:10:18 -0700 | [diff] [blame] | 5720 | callback.accept( |
| 5721 | TelephonyManager.CallForwardingInfoCallback.RESULT_ERROR_UNKNOWN); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5722 | } catch (RemoteException e) { |
| 5723 | // ignore |
| 5724 | } |
| 5725 | return; |
| 5726 | } |
| 5727 | |
| 5728 | Pair<CallForwardingInfo, Consumer<Integer>> arguments = Pair.create(callForwardingInfo, |
| 5729 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5730 | |
| 5731 | sendRequestAsync(CMD_SET_CALL_FORWARDING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5732 | } finally { |
| 5733 | Binder.restoreCallingIdentity(identity); |
| 5734 | } |
| 5735 | } |
| 5736 | |
| 5737 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5738 | * Get the call waiting status for a subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5739 | */ |
| 5740 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5741 | public void getCallWaitingStatus(int subId, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5742 | enforceReadPrivilegedPermission("getCallForwarding"); |
| 5743 | long identity = Binder.clearCallingIdentity(); |
| 5744 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5745 | |
| 5746 | Phone phone = getPhone(subId); |
| 5747 | if (phone == null) { |
| 5748 | try { |
| 5749 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5750 | } catch (RemoteException e) { |
| 5751 | // ignore |
| 5752 | } |
| 5753 | return; |
| 5754 | } |
| 5755 | |
| 5756 | Consumer<Integer> argument = FunctionalUtils.ignoreRemoteException(callback::accept); |
| 5757 | |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5758 | if (DBG) log("getCallWaitingStatus: subId " + subId); |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5759 | sendRequestAsync(CMD_GET_CALL_WAITING, argument, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5760 | } finally { |
| 5761 | Binder.restoreCallingIdentity(identity); |
| 5762 | } |
| 5763 | } |
| 5764 | |
| 5765 | /** |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5766 | * Sets whether call waiting is enabled for a given subId. |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5767 | */ |
| 5768 | @Override |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5769 | public void setCallWaitingStatus(int subId, boolean enable, IIntegerConsumer callback) { |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5770 | enforceModifyPermission(); |
| 5771 | long identity = Binder.clearCallingIdentity(); |
| 5772 | try { |
Hall Liu | 27d2426 | 2020-09-18 19:04:59 -0700 | [diff] [blame] | 5773 | if (DBG) log("setCallWaitingStatus: subId " + subId + " enable: " + enable); |
| 5774 | |
| 5775 | Phone phone = getPhone(subId); |
| 5776 | if (phone == null) { |
| 5777 | try { |
| 5778 | callback.accept(TelephonyManager.CALL_WAITING_STATUS_UNKNOWN_ERROR); |
| 5779 | } catch (RemoteException e) { |
| 5780 | // ignore |
| 5781 | } |
| 5782 | return; |
| 5783 | } |
| 5784 | |
| 5785 | Pair<Boolean, Consumer<Integer>> arguments = Pair.create(enable, |
| 5786 | FunctionalUtils.ignoreRemoteException(callback::accept)); |
| 5787 | |
| 5788 | sendRequestAsync(CMD_SET_CALL_WAITING, arguments, phone, null); |
Shuo Qian | 4a59405 | 2020-01-23 11:59:30 -0800 | [diff] [blame] | 5789 | } finally { |
| 5790 | Binder.restoreCallingIdentity(identity); |
| 5791 | } |
| 5792 | } |
| 5793 | |
| 5794 | /** |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5795 | * Starts a new network scan and returns the id of this scan. |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5796 | * |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5797 | * @param subId id of the subscription |
| 5798 | * @param request contains the radio access networks with bands/channels to scan |
| 5799 | * @param messenger callback messenger for scan results or errors |
| 5800 | * @param binder for the purpose of auto clean when the user thread crashes |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5801 | * @return the id of the requested scan which can be used to stop the scan. |
| 5802 | */ |
| 5803 | @Override |
| 5804 | public int requestNetworkScan(int subId, NetworkScanRequest request, Messenger messenger, |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5805 | IBinder binder, String callingPackage, String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5806 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5807 | mApp, subId, "requestNetworkScan"); |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5808 | LocationAccessPolicy.LocationPermissionResult locationResult = |
| 5809 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 5810 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 5811 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 5812 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5813 | .setCallingPid(Binder.getCallingPid()) |
| 5814 | .setCallingUid(Binder.getCallingUid()) |
| 5815 | .setMethod("requestNetworkScan") |
| 5816 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
James.cf Lin | 1d4d739 | 2020-07-03 18:22:53 +0800 | [diff] [blame] | 5817 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 5818 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 5819 | .build()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5820 | if (locationResult != LocationAccessPolicy.LocationPermissionResult.ALLOWED) { |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5821 | SecurityException e = checkNetworkRequestForSanitizedLocationAccess( |
| 5822 | request, subId, callingPackage); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5823 | if (e != null) { |
| 5824 | if (locationResult == LocationAccessPolicy.LocationPermissionResult.DENIED_HARD) { |
| 5825 | throw e; |
| 5826 | } else { |
Hall Liu | 0e5abaf | 2019-04-04 01:25:30 -0700 | [diff] [blame] | 5827 | loge(e.getMessage()); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5828 | return TelephonyScanManager.INVALID_SCAN_ID; |
| 5829 | } |
| 5830 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5831 | } |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5832 | int callingUid = Binder.getCallingUid(); |
| 5833 | int callingPid = Binder.getCallingPid(); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5834 | final long identity = Binder.clearCallingIdentity(); |
| 5835 | try { |
| 5836 | return mNetworkScanRequestTracker.startNetworkScan( |
| 5837 | request, messenger, binder, getPhone(subId), |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5838 | callingUid, callingPid, callingPackage); |
Ying Xu | 94a4658 | 2019-04-18 17:14:56 -0700 | [diff] [blame] | 5839 | } finally { |
| 5840 | Binder.restoreCallingIdentity(identity); |
| 5841 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5842 | } |
| 5843 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5844 | private SecurityException checkNetworkRequestForSanitizedLocationAccess( |
Nathan Harold | 1c11dba | 2020-09-22 17:54:53 -0700 | [diff] [blame] | 5845 | NetworkScanRequest request, int subId, String callingPackage) { |
| 5846 | boolean hasCarrierPriv = checkCarrierPrivilegesForPackage(subId, callingPackage) |
Hall Liu | 558027f | 2019-05-15 19:14:05 -0700 | [diff] [blame] | 5847 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 5848 | boolean hasNetworkScanPermission = |
| 5849 | mApp.checkCallingOrSelfPermission(android.Manifest.permission.NETWORK_SCAN) |
| 5850 | == PERMISSION_GRANTED; |
| 5851 | |
| 5852 | if (!hasCarrierPriv && !hasNetworkScanPermission) { |
| 5853 | return new SecurityException("permission.NETWORK_SCAN or carrier privileges is needed" |
| 5854 | + " for network scans without location access."); |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5855 | } |
| 5856 | |
| 5857 | if (request.getSpecifiers() != null && request.getSpecifiers().length > 0) { |
| 5858 | for (RadioAccessSpecifier ras : request.getSpecifiers()) { |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5859 | if (ras.getChannels() != null && ras.getChannels().length > 0) { |
| 5860 | return new SecurityException("Specific channels must not be" |
| 5861 | + " scanned without location access."); |
| 5862 | } |
| 5863 | } |
| 5864 | } |
| 5865 | |
Hall Liu | b2ac8ef | 2019-02-28 15:56:23 -0800 | [diff] [blame] | 5866 | return null; |
| 5867 | } |
| 5868 | |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5869 | /** |
| 5870 | * Stops an existing network scan with the given scanId. |
yinxu | b1bed74 | 2017-04-17 11:45:04 -0700 | [diff] [blame] | 5871 | * |
| 5872 | * @param subId id of the subscription |
| 5873 | * @param scanId id of the scan that needs to be stopped |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5874 | */ |
| 5875 | @Override |
| 5876 | public void stopNetworkScan(int subId, int scanId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5877 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5878 | mApp, subId, "stopNetworkScan"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5879 | |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5880 | int callingUid = Binder.getCallingUid(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5881 | final long identity = Binder.clearCallingIdentity(); |
| 5882 | try { |
Hall Liu | 912dfd3 | 2019-04-25 14:02:26 -0700 | [diff] [blame] | 5883 | mNetworkScanRequestTracker.stopNetworkScan(scanId, callingUid); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5884 | } finally { |
| 5885 | Binder.restoreCallingIdentity(identity); |
| 5886 | } |
yinxu | 504e139 | 2017-04-12 16:03:22 -0700 | [diff] [blame] | 5887 | } |
| 5888 | |
| 5889 | /** |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5890 | * Get the calculated preferred network type. |
| 5891 | * Used for debugging incorrect network type. |
| 5892 | * |
| 5893 | * @return the preferred network type, defined in RILConstants.java. |
| 5894 | */ |
| 5895 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5896 | public int getCalculatedPreferredNetworkType(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5897 | final Phone defaultPhone = getDefaultPhone(); |
| 5898 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 5899 | callingPackage, callingFeatureId, "getCalculatedPreferredNetworkType")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 5900 | return RILConstants.PREFERRED_NETWORK_MODE; |
| 5901 | } |
| 5902 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5903 | final long identity = Binder.clearCallingIdentity(); |
| 5904 | try { |
| 5905 | // FIXME: need to get SubId from somewhere. |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 5906 | return PhoneFactory.calculatePreferredNetworkType(defaultPhone.getContext(), 0); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5907 | } finally { |
| 5908 | Binder.restoreCallingIdentity(identity); |
| 5909 | } |
Junda Liu | 84d15a2 | 2014-07-02 11:21:04 -0700 | [diff] [blame] | 5910 | } |
| 5911 | |
| 5912 | /** |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5913 | * Get the preferred network type. |
| 5914 | * Used for device configuration by some CDMA operators. |
| 5915 | * |
| 5916 | * @return the preferred network type, defined in RILConstants.java. |
| 5917 | */ |
| 5918 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5919 | public int getPreferredNetworkType(int subId) { |
Pengquan Meng | a4009cb | 2018-12-20 11:00:24 -0800 | [diff] [blame] | 5920 | TelephonyPermissions |
| 5921 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5922 | mApp, subId, "getPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5923 | |
| 5924 | final long identity = Binder.clearCallingIdentity(); |
| 5925 | try { |
| 5926 | if (DBG) log("getPreferredNetworkType"); |
| 5927 | int[] result = (int[]) sendRequest(CMD_GET_PREFERRED_NETWORK_TYPE, null, subId); |
| 5928 | int networkType = (result != null ? result[0] : -1); |
| 5929 | if (DBG) log("getPreferredNetworkType: " + networkType); |
| 5930 | return networkType; |
| 5931 | } finally { |
| 5932 | Binder.restoreCallingIdentity(identity); |
| 5933 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5934 | } |
| 5935 | |
| 5936 | /** |
| 5937 | * Set the preferred network type. |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5938 | * |
| 5939 | * @param networkType the preferred network type, defined in RILConstants.java. |
| 5940 | * @return true on success; false on any failure. |
| 5941 | */ |
| 5942 | @Override |
Stuart Scott | 5478880 | 2015-03-30 13:18:01 -0700 | [diff] [blame] | 5943 | public boolean setPreferredNetworkType(int subId, int networkType) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 5944 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5945 | mApp, subId, "setPreferredNetworkType"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5946 | |
| 5947 | final long identity = Binder.clearCallingIdentity(); |
| 5948 | try { |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5949 | Boolean success = (Boolean) sendRequest( |
| 5950 | CMD_SET_PREFERRED_NETWORK_TYPE, networkType, subId); |
calvinpan | 03641a7 | 2020-08-18 16:53:59 +0800 | [diff] [blame] | 5951 | |
| 5952 | if (success) { |
| 5953 | Settings.Global.putInt(mApp.getContentResolver(), |
| 5954 | Settings.Global.PREFERRED_NETWORK_MODE + subId, networkType); |
| 5955 | } |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5956 | if (DBG) log("setPreferredNetworkType: " + (success ? "ok" : "fail")); |
| 5957 | return success; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 5958 | } finally { |
| 5959 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 80bc0d1 | 2014-07-14 16:36:44 -0700 | [diff] [blame] | 5960 | } |
Jake Hamby | 7c27be3 | 2014-03-03 13:25:59 -0800 | [diff] [blame] | 5961 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 5962 | |
| 5963 | /** |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5964 | * Get the allowed network types that store in the telephony provider. |
| 5965 | * |
| 5966 | * @param subId the id of the subscription. |
| 5967 | * @return allowedNetworkTypes the allowed network types. |
| 5968 | */ |
| 5969 | @Override |
| 5970 | public long getAllowedNetworkTypes(int subId) { |
| 5971 | TelephonyPermissions |
| 5972 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 5973 | mApp, subId, "getAllowedNetworkTypes"); |
| 5974 | |
| 5975 | final long identity = Binder.clearCallingIdentity(); |
| 5976 | try { |
| 5977 | return SubscriptionManager.getLongSubscriptionProperty( |
| 5978 | subId, SubscriptionManager.ALLOWED_NETWORK_TYPES, -1, mApp); |
| 5979 | } finally { |
| 5980 | Binder.restoreCallingIdentity(identity); |
| 5981 | } |
| 5982 | } |
| 5983 | |
| 5984 | /** |
| 5985 | * Set the allowed network types. |
| 5986 | * |
| 5987 | * @param subId the id of the subscription. |
| 5988 | * @param allowedNetworkTypes the allowed network types. |
| 5989 | * @return true on success; false on any failure. |
| 5990 | */ |
| 5991 | @Override |
| 5992 | public boolean setAllowedNetworkTypes(int subId, long allowedNetworkTypes) { |
| 5993 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 5994 | mApp, subId, "setAllowedNetworkTypes"); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5995 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 5996 | SubscriptionManager.setSubscriptionProperty(subId, |
| 5997 | SubscriptionManager.ALLOWED_NETWORK_TYPES, |
| 5998 | String.valueOf(allowedNetworkTypes)); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 5999 | |
calvinpan | 8ed3373 | 2020-03-12 14:17:55 +0800 | [diff] [blame] | 6000 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6001 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6002 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6003 | return setPreferredNetworkType(subId, preferredNetworkMode); |
calvinpan | 0ac9c1a | 2020-01-14 20:42:55 +0800 | [diff] [blame] | 6004 | } |
| 6005 | |
| 6006 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6007 | * Get the allowed network types for certain reason. |
| 6008 | * |
| 6009 | * @param subId the id of the subscription. |
| 6010 | * @param reason the reason the allowed network type change is taking place |
| 6011 | * @return the allowed network types. |
| 6012 | */ |
| 6013 | @Override |
| 6014 | public long getAllowedNetworkTypesForReason(int subId, |
| 6015 | @TelephonyManager.AllowedNetworkTypesReason int reason) { |
| 6016 | TelephonyPermissions |
| 6017 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6018 | mApp, subId, "getAllowedNetworkTypesForReason"); |
| 6019 | final long identity = Binder.clearCallingIdentity(); |
| 6020 | try { |
| 6021 | return getPhoneFromSubId(subId).getAllowedNetworkTypes(reason); |
| 6022 | } finally { |
| 6023 | Binder.restoreCallingIdentity(identity); |
| 6024 | } |
| 6025 | } |
| 6026 | |
| 6027 | /** |
Sooraj Sasindran | 3744480 | 2020-08-11 10:40:43 -0700 | [diff] [blame] | 6028 | * Enable/Disable E-UTRA-NR Dual Connectivity |
| 6029 | * @param subId subscription id of the sim card |
| 6030 | * @param nrDualConnectivityState expected NR dual connectivity state |
| 6031 | * This can be passed following states |
| 6032 | * <ol> |
| 6033 | * <li>Enable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_ENABLE} |
| 6034 | * <li>Disable NR dual connectivity {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE} |
| 6035 | * <li>Disable NR dual connectivity and force secondary cell to be released |
| 6036 | * {@link TelephonyManager#NR_DUAL_CONNECTIVITY_DISABLE_IMMEDIATE} |
| 6037 | * </ol> |
| 6038 | * @return operation result. |
| 6039 | */ |
| 6040 | @Override |
| 6041 | public int setNrDualConnectivityState(int subId, |
| 6042 | @TelephonyManager.NrDualConnectivityState int nrDualConnectivityState) { |
| 6043 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6044 | mApp, subId, "enableNRDualConnectivity"); |
| 6045 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6046 | final long identity = Binder.clearCallingIdentity(); |
| 6047 | try { |
| 6048 | int result = (int) sendRequest(CMD_ENABLE_NR_DUAL_CONNECTIVITY, |
| 6049 | nrDualConnectivityState, subId, |
| 6050 | workSource); |
| 6051 | if (DBG) log("enableNRDualConnectivity result: " + result); |
| 6052 | return result; |
| 6053 | } finally { |
| 6054 | Binder.restoreCallingIdentity(identity); |
| 6055 | } |
| 6056 | } |
| 6057 | |
| 6058 | /** |
| 6059 | * Is E-UTRA-NR Dual Connectivity enabled |
| 6060 | * @return true if dual connectivity is enabled else false |
| 6061 | */ |
| 6062 | @Override |
| 6063 | public boolean isNrDualConnectivityEnabled(int subId) { |
| 6064 | TelephonyPermissions |
| 6065 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6066 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6067 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6068 | final long identity = Binder.clearCallingIdentity(); |
| 6069 | try { |
| 6070 | boolean isEnabled = (boolean) sendRequest(CMD_IS_NR_DUAL_CONNECTIVITY_ENABLED, |
| 6071 | null, subId, workSource); |
| 6072 | if (DBG) log("isNRDualConnectivityEnabled: " + isEnabled); |
| 6073 | return isEnabled; |
| 6074 | } finally { |
| 6075 | Binder.restoreCallingIdentity(identity); |
| 6076 | } |
| 6077 | } |
| 6078 | |
| 6079 | /** |
Sooraj Sasindran | 4deb887 | 2020-10-30 13:17:53 -0700 | [diff] [blame] | 6080 | * get carrier bandwidth per primary and secondary carrier |
| 6081 | * @param subId subscription id of the sim card |
| 6082 | * @return CarrierBandwidth with bandwidth of both primary and secondary carrier.. |
| 6083 | */ |
| 6084 | @Override |
| 6085 | public CarrierBandwidth getCarrierBandwidth(int subId) { |
| 6086 | TelephonyPermissions |
| 6087 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6088 | mApp, subId, "isNRDualConnectivityEnabled"); |
| 6089 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 6090 | final long identity = Binder.clearCallingIdentity(); |
| 6091 | try { |
| 6092 | CarrierBandwidth carrierBandwidth = |
| 6093 | getPhoneFromSubId(subId).getCarrierBandwidth(); |
| 6094 | if (DBG) log("getCarrierBandwidth: " + carrierBandwidth); |
| 6095 | return carrierBandwidth; |
| 6096 | } finally { |
| 6097 | Binder.restoreCallingIdentity(identity); |
| 6098 | } |
| 6099 | } |
| 6100 | |
| 6101 | /** |
Sooraj Sasindran | c46dfbd | 2020-06-03 01:06:00 -0700 | [diff] [blame] | 6102 | * Get the effective allowed network types on the device. |
| 6103 | * This API will return an intersection of allowed network types for all reasons, |
| 6104 | * including the configuration done through setAllowedNetworkTypes |
| 6105 | * |
| 6106 | * @param subId the id of the subscription. |
| 6107 | * @return the allowed network types |
| 6108 | */ |
| 6109 | @Override |
| 6110 | public long getEffectiveAllowedNetworkTypes(int subId) { |
| 6111 | TelephonyPermissions |
| 6112 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6113 | mApp, subId, "getEffectiveAllowedNetworkTypes"); |
| 6114 | final long identity = Binder.clearCallingIdentity(); |
| 6115 | try { |
| 6116 | return getPhoneFromSubId(subId).getEffectiveAllowedNetworkTypes(); |
| 6117 | } finally { |
| 6118 | Binder.restoreCallingIdentity(identity); |
| 6119 | } |
| 6120 | } |
| 6121 | |
| 6122 | /** |
| 6123 | * Set the allowed network types of the device and |
| 6124 | * provide the reason triggering the allowed network change. |
| 6125 | * |
| 6126 | * @param subId the id of the subscription. |
| 6127 | * @param reason the reason the allowed network type change is taking place |
| 6128 | * @param allowedNetworkTypes the allowed network types. |
| 6129 | * @return true on success; false on any failure. |
| 6130 | */ |
| 6131 | @Override |
| 6132 | public boolean setAllowedNetworkTypesForReason(int subId, |
| 6133 | @TelephonyManager.AllowedNetworkTypesReason int reason, long allowedNetworkTypes) { |
| 6134 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6135 | mApp, subId, "setAllowedNetworkTypesForReason"); |
| 6136 | final long identity = Binder.clearCallingIdentity(); |
| 6137 | try { |
| 6138 | getPhoneFromSubId(subId).setAllowedNetworkTypes(reason, allowedNetworkTypes); |
| 6139 | int preferredNetworkMode = Settings.Global.getInt(mApp.getContentResolver(), |
| 6140 | Settings.Global.PREFERRED_NETWORK_MODE + subId, |
| 6141 | RILConstants.PREFERRED_NETWORK_MODE); |
| 6142 | return setPreferredNetworkType(subId, preferredNetworkMode); |
| 6143 | } finally { |
| 6144 | Binder.restoreCallingIdentity(identity); |
| 6145 | } |
| 6146 | } |
| 6147 | |
| 6148 | /** |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6149 | * Check whether DUN APN is required for tethering with subId. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6150 | * |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6151 | * @param subId the id of the subscription to require tethering. |
Amit Mahajan | fe58cdf | 2017-07-11 12:01:53 -0700 | [diff] [blame] | 6152 | * @return {@code true} if DUN APN is required for tethering. |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6153 | * @hide |
| 6154 | */ |
| 6155 | @Override |
SongFerngWang | f08d812 | 2019-11-15 14:58:44 +0800 | [diff] [blame] | 6156 | public boolean isTetheringApnRequiredForSubscriber(int subId) { |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6157 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6158 | final long identity = Binder.clearCallingIdentity(); |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6159 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6160 | try { |
Miao | a84611c | 2019-03-15 09:21:10 +0800 | [diff] [blame] | 6161 | if (phone != null) { |
| 6162 | return phone.hasMatchedTetherApnSetting(); |
| 6163 | } else { |
| 6164 | return false; |
| 6165 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6166 | } finally { |
| 6167 | Binder.restoreCallingIdentity(identity); |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6168 | } |
Junda Liu | 475951f | 2014-11-07 16:45:03 -0800 | [diff] [blame] | 6169 | } |
| 6170 | |
| 6171 | /** |
Shuo Qian | cd19c46 | 2020-01-16 20:51:11 -0800 | [diff] [blame] | 6172 | * Enable or disable always reporting signal strength changes from radio. |
| 6173 | * |
| 6174 | * @param isEnable {@code true} for enabling; {@code false} for disabling. |
| 6175 | */ |
| 6176 | @Override |
| 6177 | public void setAlwaysReportSignalStrength(int subId, boolean isEnable) { |
| 6178 | enforceModifyPermission(); |
| 6179 | enforceSystemCaller(); |
| 6180 | |
| 6181 | final long identity = Binder.clearCallingIdentity(); |
| 6182 | final Phone phone = getPhone(subId); |
| 6183 | try { |
| 6184 | if (phone != null) { |
| 6185 | if (DBG) { |
| 6186 | log("setAlwaysReportSignalStrength: subId=" + subId |
| 6187 | + " isEnable=" + isEnable); |
| 6188 | } |
| 6189 | phone.setAlwaysReportSignalStrength(isEnable); |
| 6190 | } else { |
| 6191 | loge("setAlwaysReportSignalStrength: no phone found for subId=" |
| 6192 | + subId); |
| 6193 | } |
| 6194 | } finally { |
| 6195 | Binder.restoreCallingIdentity(identity); |
| 6196 | } |
| 6197 | } |
| 6198 | |
| 6199 | /** |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6200 | * Get the user enabled state of Mobile Data. |
| 6201 | * |
| 6202 | * TODO: remove and use isUserDataEnabled. |
| 6203 | * This can't be removed now because some vendor codes |
| 6204 | * calls through ITelephony directly while they should |
| 6205 | * use TelephonyManager. |
| 6206 | * |
| 6207 | * @return true on enabled |
| 6208 | */ |
| 6209 | @Override |
| 6210 | public boolean getDataEnabled(int subId) { |
| 6211 | return isUserDataEnabled(subId); |
| 6212 | } |
| 6213 | |
| 6214 | /** |
| 6215 | * Get whether mobile data is enabled per user setting. |
| 6216 | * |
| 6217 | * There are other factors deciding whether mobile data is actually enabled, but they are |
| 6218 | * not considered here. See {@link #isDataEnabled(int)} for more details. |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6219 | * |
Jeff Davidson | a192071 | 2016-11-18 17:05:56 -0800 | [diff] [blame] | 6220 | * Accepts either ACCESS_NETWORK_STATE, MODIFY_PHONE_STATE or carrier privileges. |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6221 | * |
| 6222 | * @return {@code true} if data is enabled else {@code false} |
| 6223 | */ |
| 6224 | @Override |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6225 | public boolean isUserDataEnabled(int subId) { |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6226 | try { |
| 6227 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6228 | null); |
| 6229 | } catch (Exception e) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6230 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 6231 | mApp, subId, "isUserDataEnabled"); |
Robert Greenwalt | 646120a | 2014-05-23 11:54:03 -0700 | [diff] [blame] | 6232 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6233 | |
| 6234 | final long identity = Binder.clearCallingIdentity(); |
| 6235 | try { |
| 6236 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6237 | if (DBG) log("isUserDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6238 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6239 | if (phone != null) { |
| 6240 | boolean retVal = phone.isUserDataEnabled(); |
| 6241 | if (DBG) log("isUserDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6242 | return retVal; |
| 6243 | } else { |
| 6244 | if (DBG) loge("isUserDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6245 | return false; |
| 6246 | } |
| 6247 | } finally { |
| 6248 | Binder.restoreCallingIdentity(identity); |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6249 | } |
| 6250 | } |
| 6251 | |
| 6252 | /** |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6253 | * Checks if the device is capable of mobile data by considering whether whether the |
| 6254 | * user has enabled mobile data, whether the carrier has enabled mobile data, and |
| 6255 | * whether the network policy allows data connections. |
Malcolm Chen | 964682d | 2017-11-28 16:20:07 -0800 | [diff] [blame] | 6256 | * |
Shuo Qian | 8ee4e88 | 2020-01-08 14:30:06 -0800 | [diff] [blame] | 6257 | * @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] | 6258 | */ |
| 6259 | @Override |
| 6260 | public boolean isDataEnabled(int subId) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6261 | try { |
| 6262 | try { |
| 6263 | mApp.enforceCallingOrSelfPermission( |
| 6264 | android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6265 | null); |
| 6266 | } catch (Exception e) { |
| 6267 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
| 6268 | "isDataEnabled"); |
| 6269 | } |
| 6270 | } catch (Exception e) { |
| 6271 | enforceReadPrivilegedPermission("isDataEnabled"); |
| 6272 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6273 | |
| 6274 | final long identity = Binder.clearCallingIdentity(); |
| 6275 | try { |
| 6276 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6277 | if (DBG) log("isDataEnabled: subId=" + subId + " phoneId=" + phoneId); |
| 6278 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6279 | if (phone != null) { |
Jack Yu | d79fba2 | 2018-12-13 11:51:28 -0800 | [diff] [blame] | 6280 | boolean retVal = phone.getDataEnabledSettings().isDataEnabled(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6281 | if (DBG) log("isDataEnabled: subId=" + subId + " retVal=" + retVal); |
| 6282 | return retVal; |
| 6283 | } else { |
| 6284 | if (DBG) loge("isDataEnabled: no phone subId=" + subId + " retVal=false"); |
| 6285 | return false; |
| 6286 | } |
| 6287 | } finally { |
| 6288 | Binder.restoreCallingIdentity(identity); |
Wink Saville | e7353bb | 2014-12-05 14:21:41 -0800 | [diff] [blame] | 6289 | } |
Robert Greenwalt | ed86e58 | 2014-05-21 20:03:20 -0700 | [diff] [blame] | 6290 | } |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6291 | |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6292 | /** |
| 6293 | * Check if data is enabled for a specific reason |
| 6294 | * @param subId Subscription index |
| 6295 | * @param reason the reason the data enable change is taking place |
| 6296 | * @return {@code true} if the overall data is enabled; {@code false} if not. |
| 6297 | */ |
| 6298 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6299 | public boolean isDataEnabledForReason(int subId, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6300 | @TelephonyManager.DataEnabledReason int reason) { |
| 6301 | try { |
| 6302 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 6303 | null); |
| 6304 | } catch (Exception e) { |
| 6305 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PHONE_STATE, |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6306 | "isDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6307 | } |
| 6308 | |
| 6309 | |
| 6310 | final long identity = Binder.clearCallingIdentity(); |
| 6311 | try { |
| 6312 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 6313 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6314 | log("isDataEnabledForReason: subId=" + subId + " phoneId=" + phoneId |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6315 | + " reason=" + reason); |
| 6316 | } |
| 6317 | Phone phone = PhoneFactory.getPhone(phoneId); |
| 6318 | if (phone != null) { |
| 6319 | boolean retVal; |
| 6320 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER) { |
| 6321 | retVal = phone.isUserDataEnabled(); |
| 6322 | } else { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6323 | retVal = phone.getDataEnabledSettings().isDataEnabledForReason(reason); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6324 | } |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6325 | if (DBG) log("isDataEnabledForReason: retVal=" + retVal); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6326 | return retVal; |
| 6327 | } else { |
| 6328 | if (DBG) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 6329 | loge("isDataEnabledForReason: no phone subId=" |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 6330 | + subId + " retVal=false"); |
| 6331 | } |
| 6332 | return false; |
| 6333 | } |
| 6334 | } finally { |
| 6335 | Binder.restoreCallingIdentity(identity); |
| 6336 | } |
| 6337 | } |
| 6338 | |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6339 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, int uid, |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6340 | Phone phone) { |
Hall Liu | 54a2a0c | 2020-07-13 12:13:03 -0700 | [diff] [blame] | 6341 | if (uid == Process.SYSTEM_UID || uid == Process.PHONE_UID) { |
| 6342 | // Skip the check if it's one of these special uids |
| 6343 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6344 | } |
| 6345 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6346 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6347 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6348 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6349 | || subController == null) return privilegeFromSim; |
| 6350 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6351 | PackageManager pkgMgr = phone.getContext().getPackageManager(); |
| 6352 | String[] packages = pkgMgr.getPackagesForUid(uid); |
| 6353 | |
| 6354 | final long identity = Binder.clearCallingIdentity(); |
| 6355 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6356 | int subId = phone.getSubId(); |
| 6357 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6358 | // A test override is in place for the privileges for this subId, so don't try to |
| 6359 | // read the subscription privileges. |
| 6360 | return privilegeFromSim; |
| 6361 | } |
| 6362 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6363 | SubscriptionManager subManager = (SubscriptionManager) |
| 6364 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6365 | for (String pkg : packages) { |
| 6366 | if (subManager.canManageSubscription(subInfo, pkg)) { |
| 6367 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS; |
| 6368 | } |
| 6369 | } |
| 6370 | return privilegeFromSim; |
| 6371 | } finally { |
| 6372 | Binder.restoreCallingIdentity(identity); |
| 6373 | } |
| 6374 | } |
| 6375 | |
| 6376 | private int getCarrierPrivilegeStatusFromCarrierConfigRules(int privilegeFromSim, Phone phone, |
| 6377 | String pkgName) { |
| 6378 | //load access rules from carrier configs, and check those as well: b/139133814 |
| 6379 | SubscriptionController subController = SubscriptionController.getInstance(); |
| 6380 | if (privilegeFromSim == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS |
| 6381 | || subController == null) return privilegeFromSim; |
| 6382 | |
| 6383 | final long identity = Binder.clearCallingIdentity(); |
| 6384 | try { |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 6385 | int subId = phone.getSubId(); |
| 6386 | if (mCarrierPrivilegeTestOverrideSubIds.contains(subId)) { |
| 6387 | // A test override is in place for the privileges for this subId, so don't try to |
| 6388 | // read the subscription privileges. |
| 6389 | return privilegeFromSim; |
| 6390 | } |
| 6391 | SubscriptionInfo subInfo = subController.getSubscriptionInfo(subId); |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6392 | SubscriptionManager subManager = (SubscriptionManager) |
| 6393 | phone.getContext().getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE); |
| 6394 | return subManager.canManageSubscription(subInfo, pkgName) |
| 6395 | ? TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS : privilegeFromSim; |
| 6396 | } finally { |
| 6397 | Binder.restoreCallingIdentity(identity); |
| 6398 | } |
| 6399 | } |
| 6400 | |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6401 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6402 | public int getCarrierPrivilegeStatus(int subId) { |
| 6403 | final Phone phone = getPhone(subId); |
| 6404 | if (phone == null) { |
| 6405 | loge("getCarrierPrivilegeStatus: Invalid subId"); |
| 6406 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6407 | } |
| 6408 | UiccCard card = UiccController.getInstance().getUiccCard(phone.getPhoneId()); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6409 | if (card == null) { |
Shishir Agrawal | 5e5becd | 2014-11-18 11:38:23 -0800 | [diff] [blame] | 6410 | loge("getCarrierPrivilegeStatus: No UICC"); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6411 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6412 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6413 | |
| 6414 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6415 | card.getCarrierPrivilegeStatusForCurrentTransaction( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6416 | phone.getContext().getPackageManager()), Binder.getCallingUid(), phone); |
Shishir Agrawal | 60f9c95 | 2014-06-23 12:00:43 -0700 | [diff] [blame] | 6417 | } |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6418 | |
| 6419 | @Override |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6420 | public int getCarrierPrivilegeStatusForUid(int subId, int uid) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6421 | enforceReadPrivilegedPermission("getCarrierPrivilegeStatusForUid"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6422 | final Phone phone = getPhone(subId); |
| 6423 | if (phone == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6424 | loge("getCarrierPrivilegeStatusForUid: Invalid subId"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6425 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
| 6426 | } |
| 6427 | UiccProfile profile = |
| 6428 | UiccController.getInstance().getUiccProfileForPhone(phone.getPhoneId()); |
| 6429 | if (profile == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6430 | loge("getCarrierPrivilegeStatusForUid: No UICC"); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6431 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6432 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6433 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6434 | profile.getCarrierPrivilegeStatusForUid( |
Malcolm Chen | df0b4cc | 2020-02-24 15:12:43 -0800 | [diff] [blame] | 6435 | phone.getContext().getPackageManager(), uid), uid, phone); |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6436 | } |
| 6437 | |
| 6438 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6439 | public int checkCarrierPrivilegesForPackage(int subId, String pkgName) { |
| 6440 | if (TextUtils.isEmpty(pkgName)) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6441 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6442 | } |
| 6443 | |
| 6444 | int phoneId = SubscriptionManager.getPhoneId(subId); |
| 6445 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6446 | if (card == null) { |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6447 | loge("checkCarrierPrivilegesForPackage: No UICC on subId " + subId); |
Shishir Agrawal | eb8771e | 2014-07-22 11:24:08 -0700 | [diff] [blame] | 6448 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6449 | } |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6450 | return getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6451 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6452 | getPhone(phoneId), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6453 | } |
| 6454 | |
| 6455 | @Override |
| 6456 | public int checkCarrierPrivilegesForPackageAnyPhone(String pkgName) { |
Junda Liu | 317d70b | 2016-03-08 09:33:53 -0800 | [diff] [blame] | 6457 | if (TextUtils.isEmpty(pkgName)) |
| 6458 | return TelephonyManager.CARRIER_PRIVILEGE_STATUS_NO_ACCESS; |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6459 | int result = TelephonyManager.CARRIER_PRIVILEGE_STATUS_RULES_NOT_LOADED; |
| 6460 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6461 | UiccCard card = UiccController.getInstance().getUiccCard(i); |
| 6462 | if (card == null) { |
Jonathan Basseri | 7d320df | 2015-06-16 12:17:08 -0700 | [diff] [blame] | 6463 | // No UICC in that slot. |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6464 | continue; |
| 6465 | } |
| 6466 | |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6467 | result = getCarrierPrivilegeStatusFromCarrierConfigRules( |
| 6468 | card.getCarrierPrivilegeStatus(mApp.getPackageManager(), pkgName), |
| 6469 | getPhone(i), pkgName); |
Zach Johnson | 50ecba3 | 2015-05-19 00:24:21 -0700 | [diff] [blame] | 6470 | if (result == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 6471 | break; |
| 6472 | } |
| 6473 | } |
| 6474 | |
| 6475 | return result; |
Junda Liu | 2934034 | 2014-07-10 15:23:27 -0700 | [diff] [blame] | 6476 | } |
Derek Tan | 89e89d4 | 2014-07-08 17:00:10 -0700 | [diff] [blame] | 6477 | |
| 6478 | @Override |
Junda Liu | e64de78 | 2015-04-16 17:19:16 -0700 | [diff] [blame] | 6479 | public List<String> getCarrierPackageNamesForIntentAndPhone(Intent intent, int phoneId) { |
| 6480 | if (!SubscriptionManager.isValidPhoneId(phoneId)) { |
| 6481 | loge("phoneId " + phoneId + " is not valid."); |
| 6482 | return null; |
| 6483 | } |
| 6484 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6485 | if (card == null) { |
Taesu Lee | f8fbed9 | 2019-10-07 18:47:02 +0900 | [diff] [blame] | 6486 | loge("getCarrierPackageNamesForIntentAndPhone: No UICC"); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6487 | return null ; |
| 6488 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6489 | return card.getCarrierPackageNamesForIntent(mApp.getPackageManager(), intent); |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6490 | } |
| 6491 | |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6492 | @Override |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6493 | public List<String> getPackagesWithCarrierPrivileges(int phoneId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6494 | PackageManager pm = mApp.getPackageManager(); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6495 | List<String> privilegedPackages = new ArrayList<>(); |
| 6496 | List<PackageInfo> packages = null; |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6497 | UiccCard card = UiccController.getInstance().getUiccCard(phoneId); |
| 6498 | // has UICC in that slot. |
| 6499 | if (card != null) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6500 | if (card.hasCarrierPrivilegeRules()) { |
| 6501 | if (packages == null) { |
| 6502 | // Only check packages in user 0 for now |
| 6503 | packages = pm.getInstalledPackagesAsUser( |
Nazanin Bakhshi | 5d0636e | 2019-08-19 16:29:37 -0700 | [diff] [blame] | 6504 | PackageManager.MATCH_DISABLED_COMPONENTS |
| 6505 | | PackageManager.MATCH_DISABLED_UNTIL_USED_COMPONENTS |
Cheonho Park | 17089c6 | 2019-08-01 15:23:12 +0900 | [diff] [blame] | 6506 | | PackageManager.GET_SIGNING_CERTIFICATES, |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6507 | UserHandle.SYSTEM.getIdentifier()); |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6508 | } |
| 6509 | for (int p = packages.size() - 1; p >= 0; p--) { |
| 6510 | PackageInfo pkgInfo = packages.get(p); |
| 6511 | if (pkgInfo != null && pkgInfo.packageName != null |
| 6512 | && card.getCarrierPrivilegeStatus(pkgInfo) |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6513 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Amith Yamasani | 6e11887 | 2016-02-19 12:53:51 -0800 | [diff] [blame] | 6514 | privilegedPackages.add(pkgInfo.packageName); |
| 6515 | } |
| 6516 | } |
| 6517 | } |
| 6518 | } |
| 6519 | return privilegedPackages; |
| 6520 | } |
| 6521 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6522 | @Override |
| 6523 | public List<String> getPackagesWithCarrierPrivilegesForAllPhones() { |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6524 | enforceReadPrivilegedPermission("getPackagesWithCarrierPrivilegesForAllPhones"); |
| 6525 | |
| 6526 | final long identity = Binder.clearCallingIdentity(); |
| 6527 | |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6528 | List<String> privilegedPackages = new ArrayList<>(); |
Shuo Qian | 067a06d | 2019-12-03 23:40:18 +0000 | [diff] [blame] | 6529 | try { |
| 6530 | for (int i = 0; i < TelephonyManager.getDefault().getPhoneCount(); i++) { |
| 6531 | privilegedPackages.addAll(getPackagesWithCarrierPrivileges(i)); |
| 6532 | } |
| 6533 | } finally { |
| 6534 | Binder.restoreCallingIdentity(identity); |
chen xu | f7e9fe8 | 2019-05-09 19:31:02 -0700 | [diff] [blame] | 6535 | } |
| 6536 | return privilegedPackages; |
| 6537 | } |
| 6538 | |
Wink Saville | b564aae | 2014-10-23 10:18:09 -0700 | [diff] [blame] | 6539 | private String getIccId(int subId) { |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6540 | final Phone phone = getPhone(subId); |
| 6541 | UiccCard card = phone == null ? null : phone.getUiccCard(); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6542 | if (card == null) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6543 | return null; |
| 6544 | } |
| 6545 | String iccId = card.getIccId(); |
| 6546 | if (TextUtils.isEmpty(iccId)) { |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6547 | return null; |
| 6548 | } |
| 6549 | return iccId; |
| 6550 | } |
| 6551 | |
Shishir Agrawal | eb6439a | 2014-07-21 13:19:38 -0700 | [diff] [blame] | 6552 | @Override |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6553 | public void setCallComposerStatus(int subId, int status) { |
| 6554 | enforceModifyPermission(); |
| 6555 | |
| 6556 | final long identity = Binder.clearCallingIdentity(); |
| 6557 | try { |
| 6558 | Phone phone = getPhone(subId); |
| 6559 | if (phone != null) { |
| 6560 | Phone defaultPhone = phone.getImsPhone(); |
| 6561 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 6562 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 6563 | imsPhone.setCallComposerStatus(status); |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6564 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 6565 | .updateImsServiceConfig(); |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6566 | } |
| 6567 | } |
Shuo Qian | 284ae75 | 2020-12-22 19:10:14 -0800 | [diff] [blame] | 6568 | } catch (ImsException e) { |
| 6569 | throw new ServiceSpecificException(e.getCode()); |
| 6570 | } finally { |
Shuo Qian | e4e1167 | 2020-12-15 22:15:33 -0800 | [diff] [blame] | 6571 | Binder.restoreCallingIdentity(identity); |
| 6572 | } |
| 6573 | } |
| 6574 | |
| 6575 | @Override |
| 6576 | public int getCallComposerStatus(int subId) { |
| 6577 | enforceReadPrivilegedPermission("getCallComposerStatus"); |
| 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 | return imsPhone.getCallComposerStatus(); |
| 6587 | } |
| 6588 | } |
| 6589 | } finally { |
| 6590 | Binder.restoreCallingIdentity(identity); |
| 6591 | } |
| 6592 | return TelephonyManager.CALL_COMPOSER_STATUS_OFF; |
| 6593 | } |
| 6594 | |
| 6595 | @Override |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6596 | public boolean setLine1NumberForDisplayForSubscriber(int subId, String alphaTag, |
| 6597 | String number) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6598 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6599 | subId, "setLine1NumberForDisplayForSubscriber"); |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6600 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6601 | final long identity = Binder.clearCallingIdentity(); |
| 6602 | try { |
| 6603 | final String iccId = getIccId(subId); |
| 6604 | final Phone phone = getPhone(subId); |
| 6605 | if (phone == null) { |
| 6606 | return false; |
| 6607 | } |
| 6608 | final String subscriberId = phone.getSubscriberId(); |
| 6609 | |
| 6610 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6611 | Rlog.d(LOG_TAG, "Setting line number for ICC=" + iccId + ", subscriberId=" |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6612 | + subscriberId + " to " + number); |
| 6613 | } |
| 6614 | |
| 6615 | if (TextUtils.isEmpty(iccId)) { |
| 6616 | return false; |
| 6617 | } |
| 6618 | |
| 6619 | final SharedPreferences.Editor editor = mTelephonySharedPreferences.edit(); |
| 6620 | |
| 6621 | final String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6622 | if (alphaTag == null) { |
| 6623 | editor.remove(alphaTagPrefKey); |
| 6624 | } else { |
| 6625 | editor.putString(alphaTagPrefKey, alphaTag); |
| 6626 | } |
| 6627 | |
| 6628 | // Record both the line number and IMSI for this ICCID, since we need to |
| 6629 | // track all merged IMSIs based on line number |
| 6630 | final String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6631 | final String subscriberPrefKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6632 | if (number == null) { |
| 6633 | editor.remove(numberPrefKey); |
| 6634 | editor.remove(subscriberPrefKey); |
| 6635 | } else { |
| 6636 | editor.putString(numberPrefKey, number); |
| 6637 | editor.putString(subscriberPrefKey, subscriberId); |
| 6638 | } |
| 6639 | |
| 6640 | editor.commit(); |
| 6641 | return true; |
| 6642 | } finally { |
| 6643 | Binder.restoreCallingIdentity(identity); |
Sanket Padawe | 356d763 | 2015-06-22 14:03:32 -0700 | [diff] [blame] | 6644 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6645 | } |
| 6646 | |
| 6647 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6648 | public String getLine1NumberForDisplay(int subId, String callingPackage, |
| 6649 | String callingFeatureId) { |
Makoto Onuki | fee6934 | 2015-06-29 14:44:50 -0700 | [diff] [blame] | 6650 | // This is open to apps with WRITE_SMS. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6651 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneNumber( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6652 | mApp, subId, callingPackage, callingFeatureId, "getLine1NumberForDisplay")) { |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6653 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null due to permission"); |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6654 | return null; |
| 6655 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6656 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6657 | final long identity = Binder.clearCallingIdentity(); |
| 6658 | try { |
| 6659 | String iccId = getIccId(subId); |
| 6660 | if (iccId != null) { |
| 6661 | String numberPrefKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6662 | if (DBG_MERGE) { |
| 6663 | log("getLine1NumberForDisplay returning " |
| 6664 | + mTelephonySharedPreferences.getString(numberPrefKey, null)); |
| 6665 | } |
| 6666 | return mTelephonySharedPreferences.getString(numberPrefKey, null); |
Amit Mahajan | 9cf1151 | 2015-11-09 11:40:48 -0800 | [diff] [blame] | 6667 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6668 | if (DBG_MERGE) log("getLine1NumberForDisplay returning null as iccId is null"); |
| 6669 | return null; |
| 6670 | } finally { |
| 6671 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6672 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6673 | } |
| 6674 | |
| 6675 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6676 | public String getLine1AlphaTagForDisplay(int subId, String callingPackage, |
| 6677 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6678 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6679 | mApp, subId, callingPackage, callingFeatureId, "getLine1AlphaTagForDisplay")) { |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 6680 | return null; |
| 6681 | } |
Derek Tan | 97ebb42 | 2014-09-05 16:55:38 -0700 | [diff] [blame] | 6682 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6683 | final long identity = Binder.clearCallingIdentity(); |
| 6684 | try { |
| 6685 | String iccId = getIccId(subId); |
| 6686 | if (iccId != null) { |
| 6687 | String alphaTagPrefKey = PREF_CARRIERS_ALPHATAG_PREFIX + iccId; |
| 6688 | return mTelephonySharedPreferences.getString(alphaTagPrefKey, null); |
| 6689 | } |
| 6690 | return null; |
| 6691 | } finally { |
| 6692 | Binder.restoreCallingIdentity(identity); |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6693 | } |
Derek Tan | 7226c84 | 2014-07-02 17:42:23 -0700 | [diff] [blame] | 6694 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6695 | |
| 6696 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6697 | public String[] getMergedSubscriberIds(int subId, String callingPackage, |
| 6698 | String callingFeatureId) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6699 | // This API isn't public, so no need to provide a valid subscription ID - we're not worried |
| 6700 | // about carrier-privileged callers not having access. |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6701 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6702 | mApp, SubscriptionManager.INVALID_SUBSCRIPTION_ID, callingPackage, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6703 | callingFeatureId, "getMergedSubscriberIds")) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6704 | return null; |
| 6705 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6706 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6707 | // Clear calling identity, when calling TelephonyManager, because callerUid must be |
| 6708 | // the process, where TelephonyManager was instantiated. |
| 6709 | // Otherwise AppOps check will fail. |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6710 | final long identity = Binder.clearCallingIdentity(); |
| 6711 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 6712 | final Context context = mApp; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6713 | final TelephonyManager tele = TelephonyManager.from(context); |
| 6714 | final SubscriptionManager sub = SubscriptionManager.from(context); |
| 6715 | |
| 6716 | // Figure out what subscribers are currently active |
| 6717 | final ArraySet<String> activeSubscriberIds = new ArraySet<>(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6718 | |
Jordan Liu | b49b04b | 2019-05-06 14:45:15 -0700 | [diff] [blame] | 6719 | // Only consider subs which match the current subId |
| 6720 | // This logic can be simplified. See b/131189269 for progress. |
| 6721 | if (isActiveSubscription(subId)) { |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6722 | activeSubscriberIds.add(tele.getSubscriberId(subId)); |
| 6723 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6724 | |
| 6725 | // First pass, find a number override for an active subscriber |
| 6726 | String mergeNumber = null; |
| 6727 | final Map<String, ?> prefs = mTelephonySharedPreferences.getAll(); |
| 6728 | for (String key : prefs.keySet()) { |
| 6729 | if (key.startsWith(PREF_CARRIERS_SUBSCRIBER_PREFIX)) { |
| 6730 | final String subscriberId = (String) prefs.get(key); |
| 6731 | if (activeSubscriberIds.contains(subscriberId)) { |
| 6732 | final String iccId = key.substring( |
| 6733 | PREF_CARRIERS_SUBSCRIBER_PREFIX.length()); |
| 6734 | final String numberKey = PREF_CARRIERS_NUMBER_PREFIX + iccId; |
| 6735 | mergeNumber = (String) prefs.get(numberKey); |
| 6736 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6737 | Rlog.d(LOG_TAG, "Found line number " + mergeNumber |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6738 | + " for active subscriber " + subscriberId); |
| 6739 | } |
| 6740 | if (!TextUtils.isEmpty(mergeNumber)) { |
| 6741 | break; |
| 6742 | } |
| 6743 | } |
| 6744 | } |
| 6745 | } |
| 6746 | |
| 6747 | // Shortcut when no active merged subscribers |
| 6748 | if (TextUtils.isEmpty(mergeNumber)) { |
| 6749 | return null; |
| 6750 | } |
| 6751 | |
| 6752 | // Second pass, find all subscribers under that line override |
| 6753 | final ArraySet<String> result = new ArraySet<>(); |
| 6754 | for (String key : prefs.keySet()) { |
| 6755 | if (key.startsWith(PREF_CARRIERS_NUMBER_PREFIX)) { |
| 6756 | final String number = (String) prefs.get(key); |
| 6757 | if (mergeNumber.equals(number)) { |
| 6758 | final String iccId = key.substring(PREF_CARRIERS_NUMBER_PREFIX.length()); |
| 6759 | final String subscriberKey = PREF_CARRIERS_SUBSCRIBER_PREFIX + iccId; |
| 6760 | final String subscriberId = (String) prefs.get(subscriberKey); |
| 6761 | if (!TextUtils.isEmpty(subscriberId)) { |
| 6762 | result.add(subscriberId); |
| 6763 | } |
| 6764 | } |
| 6765 | } |
| 6766 | } |
| 6767 | |
| 6768 | final String[] resultArray = result.toArray(new String[result.size()]); |
| 6769 | Arrays.sort(resultArray); |
| 6770 | if (DBG_MERGE) { |
Amit Mahajan | b8f1320 | 2020-01-27 18:16:07 -0800 | [diff] [blame] | 6771 | Rlog.d(LOG_TAG, |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6772 | "Found subscribers " + Arrays.toString(resultArray) + " after merge"); |
| 6773 | } |
| 6774 | return resultArray; |
Fyodor Kupolov | 8e53b0b | 2015-06-17 13:17:50 -0700 | [diff] [blame] | 6775 | } finally { |
| 6776 | Binder.restoreCallingIdentity(identity); |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6777 | } |
Jeff Sharkey | 85190e6 | 2014-12-05 09:40:12 -0800 | [diff] [blame] | 6778 | } |
| 6779 | |
| 6780 | @Override |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6781 | public String[] getMergedImsisFromGroup(int subId, String callingPackage) { |
| 6782 | enforceReadPrivilegedPermission("getMergedImsisFromGroup"); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6783 | |
| 6784 | final long identity = Binder.clearCallingIdentity(); |
| 6785 | try { |
| 6786 | final TelephonyManager telephonyManager = mApp.getSystemService( |
| 6787 | TelephonyManager.class); |
| 6788 | String subscriberId = telephonyManager.getSubscriberId(subId); |
| 6789 | if (subscriberId == null) { |
| 6790 | if (DBG) { |
zoey chen | 3800347 | 2019-12-13 17:16:31 +0800 | [diff] [blame] | 6791 | log("getMergedImsisFromGroup can't find subscriberId for subId " |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6792 | + subId); |
| 6793 | } |
| 6794 | return null; |
| 6795 | } |
| 6796 | |
| 6797 | final SubscriptionInfo info = SubscriptionController.getInstance() |
| 6798 | .getSubscriptionInfo(subId); |
| 6799 | final ParcelUuid groupUuid = info.getGroupUuid(); |
| 6800 | // If it doesn't belong to any group, return just subscriberId of itself. |
| 6801 | if (groupUuid == null) { |
| 6802 | return new String[]{subscriberId}; |
| 6803 | } |
| 6804 | |
| 6805 | // Get all subscriberIds from the group. |
| 6806 | final List<String> mergedSubscriberIds = new ArrayList<>(); |
| 6807 | final List<SubscriptionInfo> groupInfos = SubscriptionController.getInstance() |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 6808 | .getSubscriptionsInGroup(groupUuid, mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 6809 | mApp.getAttributionTag()); |
Malcolm Chen | 6ca9737 | 2019-07-01 16:28:21 -0700 | [diff] [blame] | 6810 | for (SubscriptionInfo subInfo : groupInfos) { |
| 6811 | subscriberId = telephonyManager.getSubscriberId(subInfo.getSubscriptionId()); |
| 6812 | if (subscriberId != null) { |
| 6813 | mergedSubscriberIds.add(subscriberId); |
| 6814 | } |
| 6815 | } |
| 6816 | |
| 6817 | return mergedSubscriberIds.toArray(new String[mergedSubscriberIds.size()]); |
| 6818 | } finally { |
| 6819 | Binder.restoreCallingIdentity(identity); |
| 6820 | |
| 6821 | } |
| 6822 | } |
| 6823 | |
| 6824 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6825 | public boolean setOperatorBrandOverride(int subId, String brand) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6826 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege(mApp, |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 6827 | subId, "setOperatorBrandOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6828 | |
| 6829 | final long identity = Binder.clearCallingIdentity(); |
| 6830 | try { |
| 6831 | final Phone phone = getPhone(subId); |
| 6832 | return phone == null ? false : phone.setOperatorBrandOverride(brand); |
| 6833 | } finally { |
| 6834 | Binder.restoreCallingIdentity(identity); |
| 6835 | } |
Shishir Agrawal | b1ebf8c | 2014-07-17 16:32:41 -0700 | [diff] [blame] | 6836 | } |
Steven Liu | 4bf01bc | 2014-07-17 11:05:29 -0500 | [diff] [blame] | 6837 | |
| 6838 | @Override |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6839 | public boolean setRoamingOverride(int subId, List<String> gsmRoamingList, |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6840 | List<String> gsmNonRoamingList, List<String> cdmaRoamingList, |
| 6841 | List<String> cdmaNonRoamingList) { |
Shuo Qian | 2c0ae43 | 2019-12-05 11:40:37 -0800 | [diff] [blame] | 6842 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
| 6843 | mApp, subId, "setRoamingOverride"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6844 | |
| 6845 | final long identity = Binder.clearCallingIdentity(); |
| 6846 | try { |
| 6847 | final Phone phone = getPhone(subId); |
| 6848 | if (phone == null) { |
| 6849 | return false; |
| 6850 | } |
| 6851 | return phone.setRoamingOverride(gsmRoamingList, gsmNonRoamingList, cdmaRoamingList, |
| 6852 | cdmaNonRoamingList); |
| 6853 | } finally { |
| 6854 | Binder.restoreCallingIdentity(identity); |
Shishir Agrawal | c04d975 | 2016-02-19 10:41:00 -0800 | [diff] [blame] | 6855 | } |
Shishir Agrawal | 621a47c | 2014-12-01 10:25:09 -0800 | [diff] [blame] | 6856 | } |
| 6857 | |
| 6858 | @Override |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6859 | @Deprecated |
| 6860 | public int invokeOemRilRequestRaw(byte[] oemReq, byte[] oemResp) { |
| 6861 | enforceModifyPermission(); |
| 6862 | |
| 6863 | int returnValue = 0; |
| 6864 | try { |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 6865 | AsyncResult result = (AsyncResult) sendRequest(CMD_INVOKE_OEM_RIL_REQUEST_RAW, oemReq); |
Shuo Qian | 850e4d6a | 2018-04-25 21:02:08 +0000 | [diff] [blame] | 6866 | if(result.exception == null) { |
| 6867 | if (result.result != null) { |
| 6868 | byte[] responseData = (byte[])(result.result); |
| 6869 | if(responseData.length > oemResp.length) { |
| 6870 | Log.w(LOG_TAG, "Buffer to copy response too small: Response length is " + |
| 6871 | responseData.length + "bytes. Buffer Size is " + |
| 6872 | oemResp.length + "bytes."); |
| 6873 | } |
| 6874 | System.arraycopy(responseData, 0, oemResp, 0, responseData.length); |
| 6875 | returnValue = responseData.length; |
| 6876 | } |
| 6877 | } else { |
| 6878 | CommandException ex = (CommandException) result.exception; |
| 6879 | returnValue = ex.getCommandError().ordinal(); |
| 6880 | if(returnValue > 0) returnValue *= -1; |
| 6881 | } |
| 6882 | } catch (RuntimeException e) { |
| 6883 | Log.w(LOG_TAG, "sendOemRilRequestRaw: Runtime Exception"); |
| 6884 | returnValue = (CommandException.Error.GENERIC_FAILURE.ordinal()); |
| 6885 | if(returnValue > 0) returnValue *= -1; |
| 6886 | } |
| 6887 | |
| 6888 | return returnValue; |
| 6889 | } |
| 6890 | |
| 6891 | @Override |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6892 | public void setRadioCapability(RadioAccessFamily[] rafs) { |
| 6893 | try { |
| 6894 | ProxyController.getInstance().setRadioCapability(rafs); |
| 6895 | } catch (RuntimeException e) { |
| 6896 | Log.w(LOG_TAG, "setRadioCapability: Runtime Exception"); |
| 6897 | } |
| 6898 | } |
| 6899 | |
| 6900 | @Override |
Robert Greenwalt | 36b23af | 2015-07-06 17:59:14 -0700 | [diff] [blame] | 6901 | public int getRadioAccessFamily(int phoneId, String callingPackage) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6902 | Phone phone = PhoneFactory.getPhone(phoneId); |
Shuo Qian | dee5340 | 2020-05-29 14:08:15 -0700 | [diff] [blame] | 6903 | try { |
| 6904 | TelephonyPermissions |
| 6905 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6906 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6907 | } catch (SecurityException e) { |
| 6908 | EventLog.writeEvent(0x534e4554, "150857259", -1, "Missing Permission"); |
| 6909 | throw e; |
| 6910 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6911 | int raf = RadioAccessFamily.RAF_UNKNOWN; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6912 | if (phone == null) { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6913 | return raf; |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 6914 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6915 | final long identity = Binder.clearCallingIdentity(); |
| 6916 | try { |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6917 | TelephonyPermissions |
| 6918 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 6919 | mApp, phone.getSubId(), "getRadioAccessFamily"); |
| 6920 | raf = ProxyController.getInstance().getRadioAccessFamily(phoneId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 6921 | } finally { |
| 6922 | Binder.restoreCallingIdentity(identity); |
| 6923 | } |
chen xu | b97461a | 2018-10-26 14:17:57 -0700 | [diff] [blame] | 6924 | return raf; |
Wink Saville | 5d475dd | 2014-10-17 15:00:58 -0700 | [diff] [blame] | 6925 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 6926 | |
| 6927 | @Override |
Hall Liu | 82694d5 | 2020-12-11 18:22:04 -0800 | [diff] [blame^] | 6928 | public void uploadCallComposerPicture(int subscriptionId, String callingPackage, |
| 6929 | ParcelFileDescriptor fd, ResultReceiver callback) { |
| 6930 | try { |
| 6931 | if (!Objects.equals(mApp.getPackageManager().getPackageUid(callingPackage, 0), |
| 6932 | Binder.getCallingUid())) { |
| 6933 | throw new SecurityException("Package uid and package name do not match: " |
| 6934 | + "uid=" + Binder.getCallingUid() + ", packageName=" + callingPackage); |
| 6935 | } |
| 6936 | } catch (PackageManager.NameNotFoundException e) { |
| 6937 | throw new SecurityException("Package name invalid:" + callingPackage); |
| 6938 | } |
| 6939 | RoleManager rm = mApp.getSystemService(RoleManager.class); |
| 6940 | List<String> dialerRoleHolders = rm.getRoleHolders(RoleManager.ROLE_DIALER); |
| 6941 | if (!dialerRoleHolders.contains(callingPackage)) { |
| 6942 | throw new SecurityException("App must be the dialer role holder to" |
| 6943 | + " upload a call composer pic"); |
| 6944 | } |
| 6945 | |
| 6946 | Executors.newSingleThreadExecutor().execute(() -> { |
| 6947 | ByteArrayOutputStream output = new ByteArrayOutputStream( |
| 6948 | (int) TelephonyManager.getMaximumCallComposerPictureSize()); |
| 6949 | InputStream input = new ParcelFileDescriptor.AutoCloseInputStream(fd); |
| 6950 | boolean readUntilEnd = false; |
| 6951 | int totalBytesRead = 0; |
| 6952 | byte[] buffer = new byte[16 * 1024]; |
| 6953 | while (true) { |
| 6954 | int numRead; |
| 6955 | try { |
| 6956 | numRead = input.read(buffer); |
| 6957 | } catch (IOException e) { |
| 6958 | try { |
| 6959 | fd.checkError(); |
| 6960 | callback.send(TelephonyManager.CallComposerException.ERROR_INPUT_CLOSED, |
| 6961 | null); |
| 6962 | } catch (IOException e1) { |
| 6963 | // This means that the other side closed explicitly with an error. If this |
| 6964 | // happens, log and ignore. |
| 6965 | loge("Remote end of call composer picture pipe closed: " + e1); |
| 6966 | } |
| 6967 | break; |
| 6968 | } |
| 6969 | if (numRead == -1) { |
| 6970 | readUntilEnd = true; |
| 6971 | break; |
| 6972 | } |
| 6973 | totalBytesRead += numRead; |
| 6974 | if (totalBytesRead > TelephonyManager.getMaximumCallComposerPictureSize()) { |
| 6975 | loge("Too many bytes read for call composer picture: " + totalBytesRead); |
| 6976 | try { |
| 6977 | input.close(); |
| 6978 | } catch (IOException e) { |
| 6979 | // ignore |
| 6980 | } |
| 6981 | break; |
| 6982 | } |
| 6983 | output.write(buffer, 0, numRead); |
| 6984 | } |
| 6985 | // Generally, the remote end will close the file descriptors. The only case where we |
| 6986 | // close is above, where the picture size is too big. |
| 6987 | |
| 6988 | try { |
| 6989 | fd.checkError(); |
| 6990 | } catch (IOException e) { |
| 6991 | loge("Remote end for call composer closed with an error: " + e); |
| 6992 | return; |
| 6993 | } |
| 6994 | |
| 6995 | // TODO: pass along the bytes read to the carrier somehow |
| 6996 | |
| 6997 | ParcelUuid result = new ParcelUuid(UUID.randomUUID()); |
| 6998 | // TODO: cache this uuid that's been associated with the picture |
| 6999 | Bundle outputResult = new Bundle(); |
| 7000 | outputResult.putParcelable(TelephonyManager.KEY_CALL_COMPOSER_PICTURE_HANDLE, result); |
| 7001 | callback.send(-1, outputResult); |
| 7002 | }); |
| 7003 | } |
| 7004 | |
| 7005 | @Override |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7006 | public void enableVideoCalling(boolean enable) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7007 | final Phone defaultPhone = getDefaultPhone(); |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7008 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7009 | |
| 7010 | final long identity = Binder.clearCallingIdentity(); |
| 7011 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7012 | ImsManager.getInstance(defaultPhone.getContext(), |
| 7013 | defaultPhone.getPhoneId()).setVtSetting(enable); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7014 | } finally { |
| 7015 | Binder.restoreCallingIdentity(identity); |
| 7016 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7017 | } |
| 7018 | |
| 7019 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7020 | public boolean isVideoCallingEnabled(String callingPackage, String callingFeatureId) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7021 | final Phone defaultPhone = getDefaultPhone(); |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7022 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, defaultPhone.getSubId(), |
| 7023 | callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Amit Mahajan | 578e53d | 2018-03-20 16:18:38 +0000 | [diff] [blame] | 7024 | return false; |
| 7025 | } |
Svet Ganov | b320e18 | 2015-04-16 12:30:10 -0700 | [diff] [blame] | 7026 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7027 | final long identity = Binder.clearCallingIdentity(); |
| 7028 | try { |
| 7029 | // Check the user preference and the system-level IMS setting. Even if the user has |
| 7030 | // enabled video calling, if IMS is disabled we aren't able to support video calling. |
| 7031 | // In the long run, we may instead need to check if there exists a connection service |
| 7032 | // which can support video calling. |
| 7033 | ImsManager imsManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7034 | ImsManager.getInstance(defaultPhone.getContext(), defaultPhone.getPhoneId()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7035 | return imsManager.isVtEnabledByPlatform() |
| 7036 | && imsManager.isEnhanced4gLteModeSettingEnabledByUser() |
| 7037 | && imsManager.isVtEnabledByUser(); |
| 7038 | } finally { |
| 7039 | Binder.restoreCallingIdentity(identity); |
| 7040 | } |
Andrew Lee | df14ead | 2014-10-17 14:22:52 -0700 | [diff] [blame] | 7041 | } |
Libin.Tang@motorola.com | afe8264 | 2014-12-18 13:27:53 -0600 | [diff] [blame] | 7042 | |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7043 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7044 | public boolean canChangeDtmfToneLength(int subId, String callingPackage, |
| 7045 | String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7046 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7047 | mApp, subId, callingPackage, callingFeatureId, |
| 7048 | "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7049 | return false; |
| 7050 | } |
| 7051 | |
| 7052 | final long identity = Binder.clearCallingIdentity(); |
| 7053 | try { |
| 7054 | CarrierConfigManager configManager = |
| 7055 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7056 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7057 | .getBoolean(CarrierConfigManager.KEY_DTMF_TYPE_ENABLED_BOOL); |
| 7058 | } finally { |
| 7059 | Binder.restoreCallingIdentity(identity); |
| 7060 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7061 | } |
| 7062 | |
| 7063 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7064 | public boolean isWorldPhone(int subId, String callingPackage, String callingFeatureId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7065 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7066 | mApp, subId, callingPackage, callingFeatureId, "isVideoCallingEnabled")) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7067 | return false; |
| 7068 | } |
| 7069 | |
| 7070 | final long identity = Binder.clearCallingIdentity(); |
| 7071 | try { |
| 7072 | CarrierConfigManager configManager = |
| 7073 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7074 | return configManager.getConfigForSubId(subId) |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7075 | .getBoolean(CarrierConfigManager.KEY_WORLD_PHONE_BOOL); |
| 7076 | } finally { |
| 7077 | Binder.restoreCallingIdentity(identity); |
| 7078 | } |
Andrew Lee | a1239f2 | 2015-03-02 17:44:07 -0800 | [diff] [blame] | 7079 | } |
| 7080 | |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7081 | @Override |
| 7082 | public boolean isTtyModeSupported() { |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7083 | TelecomManager telecomManager = mApp.getSystemService(TelecomManager.class); |
Wooki Wu | 1f82f7a | 2016-02-15 15:59:58 +0800 | [diff] [blame] | 7084 | return telecomManager.isTtySupported(); |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7085 | } |
| 7086 | |
| 7087 | @Override |
| 7088 | public boolean isHearingAidCompatibilitySupported() { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7089 | final long identity = Binder.clearCallingIdentity(); |
| 7090 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7091 | return mApp.getResources().getBoolean(R.bool.hac_enabled); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7092 | } finally { |
| 7093 | Binder.restoreCallingIdentity(identity); |
| 7094 | } |
Andrew Lee | 9431b83 | 2015-03-09 18:46:45 -0700 | [diff] [blame] | 7095 | } |
| 7096 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7097 | /** |
| 7098 | * Determines whether the device currently supports RTT (Real-time text). Based both on carrier |
| 7099 | * support for the feature and device firmware support. |
| 7100 | * |
| 7101 | * @return {@code true} if the device and carrier both support RTT, {@code false} otherwise. |
| 7102 | */ |
| 7103 | @Override |
| 7104 | public boolean isRttSupported(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7105 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7106 | final Phone phone = getPhone(subscriptionId); |
| 7107 | if (phone == null) { |
| 7108 | loge("isRttSupported: no Phone found. Invalid subId:" + subscriptionId); |
| 7109 | return false; |
| 7110 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7111 | try { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7112 | boolean isCarrierSupported = mApp.getCarrierConfigForSubId(subscriptionId).getBoolean( |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7113 | CarrierConfigManager.KEY_RTT_SUPPORTED_BOOL); |
| 7114 | boolean isDeviceSupported = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7115 | phone.getContext().getResources().getBoolean(R.bool.config_support_rtt); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7116 | return isCarrierSupported && isDeviceSupported; |
| 7117 | } finally { |
| 7118 | Binder.restoreCallingIdentity(identity); |
| 7119 | } |
Hall Liu | 9818758 | 2018-01-22 19:15:32 -0800 | [diff] [blame] | 7120 | } |
| 7121 | |
Hall Liu | f666891 | 2018-10-31 17:05:23 -0700 | [diff] [blame] | 7122 | /** |
Hall Liu | f2daa02 | 2019-07-23 18:39:00 -0700 | [diff] [blame] | 7123 | * Determines whether the user has turned on RTT. If the carrier wants to ignore the user-set |
| 7124 | * RTT setting, will return true if the device and carrier both support RTT. |
| 7125 | * 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] | 7126 | */ |
| 7127 | public boolean isRttEnabled(int subscriptionId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7128 | final long identity = Binder.clearCallingIdentity(); |
| 7129 | try { |
Hall Liu | 5bab75c | 2019-12-11 23:58:20 +0000 | [diff] [blame] | 7130 | boolean isRttSupported = isRttSupported(subscriptionId); |
| 7131 | boolean isUserRttSettingOn = Settings.Secure.getInt( |
| 7132 | mApp.getContentResolver(), Settings.Secure.RTT_CALLING_MODE, 0) != 0; |
| 7133 | boolean shouldIgnoreUserRttSetting = mApp.getCarrierConfigForSubId(subscriptionId) |
| 7134 | .getBoolean(CarrierConfigManager.KEY_IGNORE_RTT_MODE_SETTING_BOOL); |
| 7135 | return isRttSupported && (isUserRttSettingOn || shouldIgnoreUserRttSetting); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7136 | } finally { |
| 7137 | Binder.restoreCallingIdentity(identity); |
| 7138 | } |
Hall Liu | 3ad5f01 | 2018-04-06 16:23:39 -0700 | [diff] [blame] | 7139 | } |
| 7140 | |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7141 | @Deprecated |
| 7142 | @Override |
| 7143 | public String getDeviceId(String callingPackage) { |
| 7144 | return getDeviceIdWithFeature(callingPackage, null); |
| 7145 | } |
| 7146 | |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7147 | /** |
| 7148 | * Returns the unique device ID of phone, for example, the IMEI for |
| 7149 | * GSM and the MEID for CDMA phones. Return null if device ID is not available. |
| 7150 | * |
| 7151 | * <p>Requires Permission: |
| 7152 | * {@link android.Manifest.permission#READ_PHONE_STATE READ_PHONE_STATE} |
| 7153 | */ |
| 7154 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7155 | public String getDeviceIdWithFeature(String callingPackage, String callingFeatureId) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7156 | final Phone phone = PhoneFactory.getPhone(0); |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7157 | if (phone == null) { |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7158 | return null; |
| 7159 | } |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7160 | int subId = phone.getSubId(); |
Michael Groover | 70af6dc | 2018-10-01 16:23:15 -0700 | [diff] [blame] | 7161 | if (!TelephonyPermissions.checkCallingOrSelfReadDeviceIdentifiers(mApp, subId, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7162 | callingPackage, callingFeatureId, "getDeviceId")) { |
Jeff Davidson | 913390f | 2018-02-23 17:11:49 -0800 | [diff] [blame] | 7163 | return null; |
| 7164 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7165 | |
| 7166 | final long identity = Binder.clearCallingIdentity(); |
| 7167 | try { |
| 7168 | return phone.getDeviceId(); |
| 7169 | } finally { |
| 7170 | Binder.restoreCallingIdentity(identity); |
| 7171 | } |
Sanket Padawe | 7310cc7 | 2015-01-14 09:53:20 -0800 | [diff] [blame] | 7172 | } |
| 7173 | |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7174 | /** |
| 7175 | * {@hide} |
| 7176 | * Returns the IMS Registration Status on a particular subid |
| 7177 | * |
| 7178 | * @param subId |
| 7179 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7180 | public boolean isImsRegistered(int subId) { |
Ping Sun | c67b7c2 | 2016-03-02 19:16:45 +0800 | [diff] [blame] | 7181 | Phone phone = getPhone(subId); |
| 7182 | if (phone != null) { |
| 7183 | return phone.isImsRegistered(); |
| 7184 | } else { |
| 7185 | return false; |
| 7186 | } |
| 7187 | } |
| 7188 | |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7189 | @Override |
| 7190 | public int getSubIdForPhoneAccount(PhoneAccount phoneAccount) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7191 | final long identity = Binder.clearCallingIdentity(); |
| 7192 | try { |
| 7193 | return PhoneUtils.getSubIdForPhoneAccount(phoneAccount); |
| 7194 | } finally { |
| 7195 | Binder.restoreCallingIdentity(identity); |
| 7196 | } |
Santos Cordon | 7a1885b | 2015-02-03 11:15:19 -0800 | [diff] [blame] | 7197 | } |
Nathan Harold | dcfc793 | 2015-03-18 10:01:20 -0700 | [diff] [blame] | 7198 | |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7199 | @Override |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7200 | public int getSubIdForPhoneAccountHandle( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7201 | PhoneAccountHandle phoneAccountHandle, String callingPackage, String callingFeatureId) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7202 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, getDefaultSubscription(), |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7203 | callingPackage, callingFeatureId, "getSubIdForPhoneAccountHandle")) { |
Shuo Qian | 6e6137d | 2019-10-30 16:33:31 -0700 | [diff] [blame] | 7204 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 7205 | } |
| 7206 | final long identity = Binder.clearCallingIdentity(); |
| 7207 | try { |
| 7208 | return PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle); |
| 7209 | } finally { |
| 7210 | Binder.restoreCallingIdentity(identity); |
| 7211 | } |
| 7212 | } |
| 7213 | |
| 7214 | @Override |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7215 | public @Nullable PhoneAccountHandle getPhoneAccountHandleForSubscriptionId(int subscriptionId) { |
duki.hong | fd96bde | 2020-07-22 17:32:19 +0900 | [diff] [blame] | 7216 | enforceReadPrivilegedPermission("getPhoneAccountHandleForSubscriptionId, " |
| 7217 | + "subscriptionId: " + subscriptionId); |
Tyler Gunn | f70ed16 | 2019-04-03 15:28:53 -0700 | [diff] [blame] | 7218 | final long identity = Binder.clearCallingIdentity(); |
| 7219 | try { |
| 7220 | Phone phone = getPhone(subscriptionId); |
| 7221 | if (phone == null) { |
| 7222 | return null; |
| 7223 | } |
| 7224 | return PhoneUtils.makePstnPhoneAccountHandle(phone); |
| 7225 | } finally { |
| 7226 | Binder.restoreCallingIdentity(identity); |
| 7227 | } |
| 7228 | } |
| 7229 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7230 | /** |
| 7231 | * @return the VoWiFi calling availability. |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7232 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7233 | public boolean isWifiCallingAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7234 | final long identity = Binder.clearCallingIdentity(); |
| 7235 | try { |
| 7236 | Phone phone = getPhone(subId); |
| 7237 | if (phone != null) { |
| 7238 | return phone.isWifiCallingEnabled(); |
| 7239 | } else { |
| 7240 | return false; |
| 7241 | } |
| 7242 | } finally { |
| 7243 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7244 | } |
Nathan Harold | c55097a | 2015-03-11 18:14:50 -0700 | [diff] [blame] | 7245 | } |
| 7246 | |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7247 | /** |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7248 | * @return the VT calling availability. |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7249 | */ |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7250 | public boolean isVideoTelephonyAvailable(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7251 | final long identity = Binder.clearCallingIdentity(); |
| 7252 | try { |
| 7253 | Phone phone = getPhone(subId); |
| 7254 | if (phone != null) { |
| 7255 | return phone.isVideoEnabled(); |
| 7256 | } else { |
| 7257 | return false; |
| 7258 | } |
| 7259 | } finally { |
| 7260 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7261 | } |
| 7262 | } |
| 7263 | |
| 7264 | /** |
| 7265 | * @return the IMS registration technology for the MMTEL feature. Valid return values are |
| 7266 | * defined in {@link ImsRegistrationImplBase}. |
| 7267 | */ |
| 7268 | public @ImsRegistrationImplBase.ImsRegistrationTech int getImsRegTechnologyForMmTel(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7269 | final long identity = Binder.clearCallingIdentity(); |
| 7270 | try { |
| 7271 | Phone phone = getPhone(subId); |
| 7272 | if (phone != null) { |
| 7273 | return phone.getImsRegistrationTech(); |
| 7274 | } else { |
| 7275 | return ImsRegistrationImplBase.REGISTRATION_TECH_NONE; |
| 7276 | } |
| 7277 | } finally { |
| 7278 | Binder.restoreCallingIdentity(identity); |
Brad Ebinger | 1f2b508 | 2018-02-08 16:11:32 -0800 | [diff] [blame] | 7279 | } |
Etan Cohen | 3b7a1bc | 2015-05-28 15:57:13 -0700 | [diff] [blame] | 7280 | } |
| 7281 | |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7282 | @Override |
| 7283 | public void factoryReset(int subId) { |
paulhu | 5a77360 | 2019-08-23 19:17:33 +0800 | [diff] [blame] | 7284 | enforceSettingsPermission(); |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7285 | if (mUserManager.hasUserRestriction(UserManager.DISALLOW_NETWORK_RESET)) { |
| 7286 | return; |
| 7287 | } |
| 7288 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7289 | final long identity = Binder.clearCallingIdentity(); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7290 | |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7291 | try { |
Stuart Scott | 981d858 | 2015-04-21 14:09:50 -0700 | [diff] [blame] | 7292 | if (SubscriptionManager.isUsableSubIdValue(subId) && !mUserManager.hasUserRestriction( |
| 7293 | UserManager.DISALLOW_CONFIG_MOBILE_NETWORKS)) { |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7294 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_USER, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7295 | getDefaultDataEnabled()); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7296 | setNetworkSelectionModeAutomatic(subId); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 7297 | setPreferredNetworkType(subId, getDefaultNetworkType(subId)); |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7298 | setDataRoamingEnabled(subId, getDefaultDataRoamingEnabled(subId)); |
| 7299 | CarrierInfoManager.deleteAllCarrierKeysForImsiEncryption(mApp); |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7300 | } |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7301 | // There has been issues when Sms raw table somehow stores orphan |
| 7302 | // fragments. They lead to garbled message when new fragments come |
| 7303 | // in and combined with those stale ones. In case this happens again, |
| 7304 | // user can reset all network settings which will clean up this table. |
| 7305 | cleanUpSmsRawTable(getDefaultPhone().getContext()); |
Brad Ebinger | bc7dd58 | 2019-10-17 17:03:22 -0700 | [diff] [blame] | 7306 | // Clean up IMS settings as well here. |
| 7307 | int slotId = getSlotIndex(subId); |
| 7308 | if (slotId > SubscriptionManager.INVALID_SIM_SLOT_INDEX) { |
| 7309 | ImsManager.getInstance(mApp, slotId).factoryReset(); |
| 7310 | } |
Naina Nalluri | d63128d | 2019-09-17 14:10:30 -0700 | [diff] [blame] | 7311 | |
| 7312 | // Erase modem config if erase modem on network setting is enabled. |
| 7313 | String configValue = DeviceConfig.getProperty(DeviceConfig.NAMESPACE_TELEPHONY, |
| 7314 | RESET_NETWORK_ERASE_MODEM_CONFIG_ENABLED); |
| 7315 | if (configValue != null && Boolean.parseBoolean(configValue)) { |
| 7316 | sendEraseModemConfig(getDefaultPhone()); |
| 7317 | } |
Svet Ganov | cc087f8 | 2015-05-12 20:35:54 -0700 | [diff] [blame] | 7318 | } finally { |
| 7319 | Binder.restoreCallingIdentity(identity); |
Stuart Scott | 8eef64f | 2015-04-08 15:13:54 -0700 | [diff] [blame] | 7320 | } |
| 7321 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7322 | |
Amit Mahajan | 7dbbd82 | 2019-03-13 17:33:47 -0700 | [diff] [blame] | 7323 | private void cleanUpSmsRawTable(Context context) { |
| 7324 | ContentResolver resolver = context.getContentResolver(); |
| 7325 | Uri uri = Uri.withAppendedPath(Telephony.Sms.CONTENT_URI, "raw/permanentDelete"); |
| 7326 | resolver.delete(uri, null, null); |
| 7327 | } |
| 7328 | |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7329 | @Override |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7330 | public String getSimLocaleForSubscriber(int subId) { |
| 7331 | enforceReadPrivilegedPermission("getSimLocaleForSubscriber, subId: " + subId); |
| 7332 | final Phone phone = getPhone(subId); |
| 7333 | if (phone == null) { |
| 7334 | log("getSimLocaleForSubscriber, invalid subId"); |
chen xu | 2bb91e4 | 2019-01-24 14:35:54 -0800 | [diff] [blame] | 7335 | return null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7336 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7337 | final long identity = Binder.clearCallingIdentity(); |
| 7338 | try { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7339 | final SubscriptionInfo info = mSubscriptionController.getActiveSubscriptionInfo(subId, |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7340 | phone.getContext().getOpPackageName(), phone.getContext().getAttributionTag()); |
chen xu | 6291c47 | 2019-02-04 12:55:53 -0800 | [diff] [blame] | 7341 | if (info == null) { |
| 7342 | log("getSimLocaleForSubscriber, inactive subId: " + subId); |
| 7343 | return null; |
| 7344 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7345 | // Try and fetch the locale from the carrier properties or from the SIM language |
| 7346 | // preferences (EF-PL and EF-LI)... |
| 7347 | final int mcc = info.getMcc(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7348 | String simLanguage = null; |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7349 | final Locale localeFromDefaultSim = phone.getLocaleFromSimAndCarrierPrefs(); |
| 7350 | if (localeFromDefaultSim != null) { |
| 7351 | if (!localeFromDefaultSim.getCountry().isEmpty()) { |
| 7352 | if (DBG) log("Using locale from subId: " + subId + " locale: " |
| 7353 | + localeFromDefaultSim); |
| 7354 | return localeFromDefaultSim.toLanguageTag(); |
| 7355 | } else { |
| 7356 | simLanguage = localeFromDefaultSim.getLanguage(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7357 | } |
| 7358 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7359 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7360 | // The SIM language preferences only store a language (e.g. fr = French), not an |
| 7361 | // exact locale (e.g. fr_FR = French/France). So, if the locale returned from |
| 7362 | // the SIM and carrier preferences does not include a country we add the country |
| 7363 | // determined from the SIM MCC to provide an exact locale. |
zoey chen | c730df8 | 2019-12-18 17:07:20 +0800 | [diff] [blame] | 7364 | final Locale mccLocale = LocaleUtils.getLocaleFromMcc(mApp, mcc, simLanguage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7365 | if (mccLocale != null) { |
chen xu | 5d3637b | 2019-01-21 23:31:38 -0800 | [diff] [blame] | 7366 | if (DBG) log("No locale from SIM, using mcc locale:" + mccLocale); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7367 | return mccLocale.toLanguageTag(); |
| 7368 | } |
| 7369 | |
| 7370 | if (DBG) log("No locale found - returning null"); |
| 7371 | return null; |
| 7372 | } finally { |
| 7373 | Binder.restoreCallingIdentity(identity); |
| 7374 | } |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7375 | } |
| 7376 | |
| 7377 | private List<SubscriptionInfo> getAllSubscriptionInfoList() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7378 | return mSubscriptionController.getAllSubInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7379 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7380 | } |
| 7381 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7382 | /** |
| 7383 | * NOTE: this method assumes permission checks are done and caller identity has been cleared. |
| 7384 | */ |
| 7385 | private List<SubscriptionInfo> getActiveSubscriptionInfoListPrivileged() { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7386 | return mSubscriptionController.getActiveSubscriptionInfoList(mApp.getOpPackageName(), |
Philip P. Moltmann | 8d34f0c | 2020-03-05 16:24:02 -0800 | [diff] [blame] | 7387 | mApp.getAttributionTag()); |
Narayan Kamath | 1c496c2 | 2015-04-16 14:40:19 +0100 | [diff] [blame] | 7388 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7389 | |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7390 | private final ModemActivityInfo mLastModemActivityInfo = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7391 | new ModemActivityInfo(0, 0, 0, new int[ModemActivityInfo.getNumTxPowerLevels()], 0); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7392 | |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7393 | /** |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7394 | * Responds to the ResultReceiver with the {@link android.telephony.ModemActivityInfo} object |
| 7395 | * representing the state of the modem. |
| 7396 | * |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7397 | * NOTE: The underlying implementation clears the modem state, so there should only ever be one |
| 7398 | * caller to it. Everyone should call this class to get cumulative data. |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7399 | * @hide |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7400 | */ |
| 7401 | @Override |
Adam Lesinski | 903a54c | 2016-04-11 14:49:52 -0700 | [diff] [blame] | 7402 | public void requestModemActivityInfo(ResultReceiver result) { |
| 7403 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7404 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7405 | |
| 7406 | final long identity = Binder.clearCallingIdentity(); |
| 7407 | try { |
Shuo Qian | 8f4750a | 2020-02-20 17:12:10 -0800 | [diff] [blame] | 7408 | sendRequestAsync(CMD_GET_MODEM_ACTIVITY_INFO, result, null, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7409 | } finally { |
| 7410 | Binder.restoreCallingIdentity(identity); |
Chenjie Yu | 1ba9725 | 2018-01-11 18:16:20 -0800 | [diff] [blame] | 7411 | } |
Prerepa Viswanadham | 7fcff69 | 2015-06-03 11:20:55 -0700 | [diff] [blame] | 7412 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7413 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7414 | // Checks that ModemActivityInfo is valid. Sleep time, Idle time, Rx time and Tx time should be |
| 7415 | // less than total activity duration. |
| 7416 | private boolean isModemActivityInfoValid(ModemActivityInfo info) { |
| 7417 | if (info == null) { |
| 7418 | return false; |
| 7419 | } |
| 7420 | int activityDurationMs = |
Hall Liu | 49656c0 | 2020-10-09 19:00:11 -0700 | [diff] [blame] | 7421 | (int) (info.getTimestampMillis() - mLastModemActivityInfo.getTimestampMillis()); |
| 7422 | int totalTxTimeMs = Arrays.stream(info.getTransmitTimeMillis()).sum(); |
| 7423 | |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7424 | return (info.isValid() |
| 7425 | && (info.getSleepTimeMillis() <= activityDurationMs) |
| 7426 | && (info.getIdleTimeMillis() <= activityDurationMs) |
Chen Xu | d78231e | 2019-09-10 18:49:52 -0700 | [diff] [blame] | 7427 | && (info.getReceiveTimeMillis() <= activityDurationMs) |
Siddharth Ray | b811406 | 2018-06-17 15:02:38 -0700 | [diff] [blame] | 7428 | && (totalTxTimeMs <= activityDurationMs)); |
| 7429 | } |
| 7430 | |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7431 | /** |
| 7432 | * {@hide} |
| 7433 | * Returns the service state information on specified subscription. |
| 7434 | */ |
| 7435 | @Override |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7436 | public ServiceState getServiceStateForSubscriber(int subId, String callingPackage, |
| 7437 | String callingFeatureId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7438 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7439 | mApp, subId, callingPackage, callingFeatureId, "getServiceStateForSubscriber")) { |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7440 | return null; |
| 7441 | } |
| 7442 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7443 | LocationAccessPolicy.LocationPermissionResult fineLocationResult = |
| 7444 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7445 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7446 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7447 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7448 | .setCallingPid(Binder.getCallingPid()) |
| 7449 | .setCallingUid(Binder.getCallingUid()) |
| 7450 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7451 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7452 | .setMinSdkVersionForFine(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7453 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
| 7454 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7455 | .build()); |
| 7456 | |
| 7457 | LocationAccessPolicy.LocationPermissionResult coarseLocationResult = |
| 7458 | LocationAccessPolicy.checkLocationPermission(mApp, |
| 7459 | new LocationAccessPolicy.LocationPermissionQuery.Builder() |
| 7460 | .setCallingPackage(callingPackage) |
Philip P. Moltmann | 3a2772a | 2019-10-04 08:15:00 -0700 | [diff] [blame] | 7461 | .setCallingFeatureId(callingFeatureId) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7462 | .setCallingPid(Binder.getCallingPid()) |
| 7463 | .setCallingUid(Binder.getCallingUid()) |
| 7464 | .setMethod("getServiceStateForSubscriber") |
Hall Liu | f18a0cf | 2019-04-17 13:37:11 -0700 | [diff] [blame] | 7465 | .setLogAsInfo(true) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7466 | .setMinSdkVersionForCoarse(Build.VERSION_CODES.Q) |
Hall Liu | c4a3e42 | 2020-05-26 17:18:03 -0700 | [diff] [blame] | 7467 | .setMinSdkVersionForFine(Integer.MAX_VALUE) |
| 7468 | .setMinSdkVersionForEnforcement(Build.VERSION_CODES.Q) |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7469 | .build()); |
| 7470 | // We don't care about hard or soft here -- all we need to know is how much info to scrub. |
| 7471 | boolean hasFinePermission = |
| 7472 | fineLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7473 | boolean hasCoarsePermission = |
| 7474 | coarseLocationResult == LocationAccessPolicy.LocationPermissionResult.ALLOWED; |
| 7475 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7476 | final Phone phone = getPhone(subId); |
| 7477 | if (phone == null) { |
| 7478 | return null; |
| 7479 | } |
| 7480 | |
Jordan Liu | 0f2bc44 | 2020-11-18 16:47:37 -0800 | [diff] [blame] | 7481 | final long identity = Binder.clearCallingIdentity(); |
| 7482 | |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7483 | boolean isCallingPackageDataService = phone.getDataServicePackages() |
| 7484 | .contains(callingPackage); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7485 | try { |
Jordan Liu | c437b19 | 2020-08-17 10:59:12 -0700 | [diff] [blame] | 7486 | // isActiveSubId requires READ_PHONE_STATE, which we already check for above |
| 7487 | if (!mSubscriptionController.isActiveSubId(subId, callingPackage, callingFeatureId)) { |
| 7488 | Rlog.d(LOG_TAG, |
| 7489 | "getServiceStateForSubscriber returning null for inactive subId=" + subId); |
| 7490 | return null; |
| 7491 | } |
| 7492 | |
Hall Liu | f19c44f | 2018-11-27 14:38:17 -0800 | [diff] [blame] | 7493 | ServiceState ss = phone.getServiceState(); |
| 7494 | |
| 7495 | // Scrub out the location info in ServiceState depending on what level of access |
| 7496 | // the caller has. |
Jack Yu | 479f40e | 2020-10-27 21:29:25 -0700 | [diff] [blame] | 7497 | if (hasFinePermission || isCallingPackageDataService) return ss; |
Malcolm Chen | 5052de6 | 2019-12-30 13:56:38 -0800 | [diff] [blame] | 7498 | if (hasCoarsePermission) return ss.createLocationInfoSanitizedCopy(false); |
| 7499 | return ss.createLocationInfoSanitizedCopy(true); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7500 | } finally { |
| 7501 | Binder.restoreCallingIdentity(identity); |
| 7502 | } |
Jack Yu | 85bd38a | 2015-11-09 11:34:32 -0800 | [diff] [blame] | 7503 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7504 | |
| 7505 | /** |
| 7506 | * Returns the URI for the per-account voicemail ringtone set in Phone settings. |
| 7507 | * |
| 7508 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7509 | * voicemail ringtone. |
| 7510 | * @return The URI for the ringtone to play when receiving a voicemail from a specific |
| 7511 | * PhoneAccount. |
| 7512 | */ |
| 7513 | @Override |
| 7514 | public Uri getVoicemailRingtoneUri(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7515 | final long identity = Binder.clearCallingIdentity(); |
| 7516 | try { |
| 7517 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7518 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7519 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7520 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7521 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7522 | return VoicemailNotificationSettingsUtil.getRingtoneUri(phone.getContext()); |
| 7523 | } finally { |
| 7524 | Binder.restoreCallingIdentity(identity); |
| 7525 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7526 | } |
| 7527 | |
| 7528 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7529 | * Sets the per-account voicemail ringtone. |
| 7530 | * |
| 7531 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7532 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7533 | * |
| 7534 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7535 | * voicemail ringtone. |
| 7536 | * @param uri The URI for the ringtone to play when receiving a voicemail from a specific |
| 7537 | * PhoneAccount. |
| 7538 | */ |
| 7539 | @Override |
| 7540 | public void setVoicemailRingtoneUri(String callingPackage, |
| 7541 | PhoneAccountHandle phoneAccountHandle, Uri uri) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7542 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7543 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7544 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7545 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7546 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7547 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7548 | "setVoicemailRingtoneUri"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7549 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7550 | |
| 7551 | final long identity = Binder.clearCallingIdentity(); |
| 7552 | try { |
| 7553 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7554 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7555 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7556 | } |
| 7557 | VoicemailNotificationSettingsUtil.setRingtoneUri(phone.getContext(), uri); |
| 7558 | } finally { |
| 7559 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7560 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7561 | } |
| 7562 | |
| 7563 | /** |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7564 | * Returns whether vibration is set for voicemail notification in Phone settings. |
| 7565 | * |
| 7566 | * @param accountHandle The handle for the {@link PhoneAccount} for which to retrieve the |
| 7567 | * voicemail vibration setting. |
| 7568 | * @return {@code true} if the vibration is set for this PhoneAccount, {@code false} otherwise. |
| 7569 | */ |
| 7570 | @Override |
| 7571 | public boolean isVoicemailVibrationEnabled(PhoneAccountHandle accountHandle) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7572 | final long identity = Binder.clearCallingIdentity(); |
| 7573 | try { |
| 7574 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(accountHandle); |
| 7575 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7576 | phone = getDefaultPhone(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7577 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7578 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7579 | return VoicemailNotificationSettingsUtil.isVibrationEnabled(phone.getContext()); |
| 7580 | } finally { |
| 7581 | Binder.restoreCallingIdentity(identity); |
| 7582 | } |
Nancy Chen | 31f9ba1 | 2016-01-06 11:42:12 -0800 | [diff] [blame] | 7583 | } |
| 7584 | |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7585 | /** |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7586 | * Sets the per-account voicemail vibration. |
| 7587 | * |
| 7588 | * <p>Requires that the calling app is the default dialer, or has carrier privileges, or |
| 7589 | * has permission {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 7590 | * |
| 7591 | * @param phoneAccountHandle The handle for the {@link PhoneAccount} for which to set the |
| 7592 | * voicemail vibration setting. |
| 7593 | * @param enabled Whether to enable or disable vibration for voicemail notifications from a |
| 7594 | * specific PhoneAccount. |
| 7595 | */ |
| 7596 | @Override |
| 7597 | public void setVoicemailVibrationEnabled(String callingPackage, |
| 7598 | PhoneAccountHandle phoneAccountHandle, boolean enabled) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7599 | final Phone defaultPhone = getDefaultPhone(); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7600 | mAppOps.checkPackage(Binder.getCallingUid(), callingPackage); |
Tyler Gunn | 5ddfdc9 | 2019-10-31 13:08:23 -0700 | [diff] [blame] | 7601 | TelecomManager tm = defaultPhone.getContext().getSystemService(TelecomManager.class); |
| 7602 | if (!TextUtils.equals(callingPackage, tm.getDefaultDialerPackage())) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7603 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7604 | mApp, PhoneUtils.getSubIdForPhoneAccountHandle(phoneAccountHandle), |
| 7605 | "setVoicemailVibrationEnabled"); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7606 | } |
| 7607 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7608 | final long identity = Binder.clearCallingIdentity(); |
| 7609 | try { |
| 7610 | Phone phone = PhoneUtils.getPhoneForPhoneAccountHandle(phoneAccountHandle); |
| 7611 | if (phone == null) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7612 | phone = defaultPhone; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7613 | } |
| 7614 | VoicemailNotificationSettingsUtil.setVibrationEnabled(phone.getContext(), enabled); |
| 7615 | } finally { |
| 7616 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7617 | } |
Ta-wei Yen | c33877d | 2017-01-23 18:11:21 -0800 | [diff] [blame] | 7618 | } |
| 7619 | |
| 7620 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7621 | * Make sure either called from same process as self (phone) or IPC caller has read privilege. |
| 7622 | * |
| 7623 | * @throws SecurityException if the caller does not have the required permission |
| 7624 | */ |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7625 | private void enforceReadPrivilegedPermission(String message) { |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7626 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.READ_PRIVILEGED_PHONE_STATE, |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7627 | message); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7628 | } |
| 7629 | |
| 7630 | /** |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7631 | * Make sure either called from same process as self (phone) or IPC caller has send SMS |
| 7632 | * permission. |
| 7633 | * |
| 7634 | * @throws SecurityException if the caller does not have the required permission |
| 7635 | */ |
| 7636 | private void enforceSendSmsPermission() { |
| 7637 | mApp.enforceCallingOrSelfPermission(permission.SEND_SMS, null); |
| 7638 | } |
| 7639 | |
| 7640 | /** |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7641 | * Make sure called from the package in charge of visual voicemail. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7642 | * |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7643 | * @throws SecurityException if the caller is not the visual voicemail package. |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7644 | */ |
Ta-wei Yen | 527a9c0 | 2017-01-06 15:29:25 -0800 | [diff] [blame] | 7645 | private void enforceVisualVoicemailPackage(String callingPackage, int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7646 | final long identity = Binder.clearCallingIdentity(); |
| 7647 | try { |
| 7648 | ComponentName componentName = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7649 | RemoteVvmTaskManager.getRemotePackage(mApp, subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7650 | if (componentName == null) { |
| 7651 | throw new SecurityException( |
| 7652 | "Caller not current active visual voicemail package[null]"); |
| 7653 | } |
| 7654 | String vvmPackage = componentName.getPackageName(); |
| 7655 | if (!callingPackage.equals(vvmPackage)) { |
| 7656 | throw new SecurityException("Caller not current active visual voicemail package[" |
| 7657 | + vvmPackage + "]"); |
| 7658 | } |
| 7659 | } finally { |
| 7660 | Binder.restoreCallingIdentity(identity); |
Ta-wei Yen | 30a69c8 | 2016-12-27 14:52:32 -0800 | [diff] [blame] | 7661 | } |
| 7662 | } |
| 7663 | |
| 7664 | /** |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7665 | * Return the application ID for the app type. |
| 7666 | * |
| 7667 | * @param subId the subscription ID that this request applies to. |
| 7668 | * @param appType the uicc app type. |
| 7669 | * @return Application ID for specificied app type, or null if no uicc. |
| 7670 | */ |
| 7671 | @Override |
| 7672 | public String getAidForAppType(int subId, int appType) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7673 | enforceReadPrivilegedPermission("getAidForAppType"); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7674 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7675 | |
| 7676 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7677 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7678 | if (phone == null) { |
| 7679 | return null; |
| 7680 | } |
| 7681 | String aid = null; |
| 7682 | try { |
| 7683 | aid = UiccController.getInstance().getUiccCard(phone.getPhoneId()) |
| 7684 | .getApplicationByType(appType).getAid(); |
| 7685 | } catch (Exception e) { |
| 7686 | Log.e(LOG_TAG, "Not getting aid. Exception ex=" + e); |
| 7687 | } |
| 7688 | return aid; |
| 7689 | } finally { |
| 7690 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7691 | } |
Youhan Wang | e64578a | 2016-05-02 15:32:42 -0700 | [diff] [blame] | 7692 | } |
| 7693 | |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7694 | /** |
| 7695 | * Return the Electronic Serial Number. |
| 7696 | * |
| 7697 | * @param subId the subscription ID that this request applies to. |
| 7698 | * @return ESN or null if error. |
| 7699 | */ |
| 7700 | @Override |
| 7701 | public String getEsn(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7702 | enforceReadPrivilegedPermission("getEsn"); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7703 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7704 | |
| 7705 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7706 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7707 | if (phone == null) { |
| 7708 | return null; |
| 7709 | } |
| 7710 | String esn = null; |
| 7711 | try { |
| 7712 | esn = phone.getEsn(); |
| 7713 | } catch (Exception e) { |
| 7714 | Log.e(LOG_TAG, "Not getting ESN. Exception ex=" + e); |
| 7715 | } |
| 7716 | return esn; |
| 7717 | } finally { |
| 7718 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7719 | } |
Youhan Wang | 4001d25 | 2016-05-11 10:29:41 -0700 | [diff] [blame] | 7720 | } |
| 7721 | |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7722 | /** |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7723 | * Return the Preferred Roaming List Version. |
| 7724 | * |
| 7725 | * @param subId the subscription ID that this request applies to. |
| 7726 | * @return PRLVersion or null if error. |
| 7727 | */ |
| 7728 | @Override |
| 7729 | public String getCdmaPrlVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7730 | enforceReadPrivilegedPermission("getCdmaPrlVersion"); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7731 | Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7732 | |
| 7733 | final long identity = Binder.clearCallingIdentity(); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7734 | try { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7735 | if (phone == null) { |
| 7736 | return null; |
| 7737 | } |
| 7738 | String cdmaPrlVersion = null; |
| 7739 | try { |
| 7740 | cdmaPrlVersion = phone.getCdmaPrlVersion(); |
| 7741 | } catch (Exception e) { |
| 7742 | Log.e(LOG_TAG, "Not getting PRLVersion", e); |
| 7743 | } |
| 7744 | return cdmaPrlVersion; |
| 7745 | } finally { |
| 7746 | Binder.restoreCallingIdentity(identity); |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7747 | } |
Youhan Wang | 66ad5d7 | 2016-07-18 17:56:58 -0700 | [diff] [blame] | 7748 | } |
| 7749 | |
| 7750 | /** |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7751 | * Get snapshot of Telephony histograms |
| 7752 | * @return List of Telephony histograms |
| 7753 | * @hide |
| 7754 | */ |
| 7755 | @Override |
| 7756 | public List<TelephonyHistogram> getTelephonyHistograms() { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7757 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 7758 | mApp, getDefaultSubscription(), "getTelephonyHistograms"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7759 | |
| 7760 | final long identity = Binder.clearCallingIdentity(); |
| 7761 | try { |
| 7762 | return RIL.getTelephonyRILTimingHistograms(); |
| 7763 | } finally { |
| 7764 | Binder.restoreCallingIdentity(identity); |
| 7765 | } |
Sanket Padawe | 99ef1e3 | 2016-05-18 16:12:33 -0700 | [diff] [blame] | 7766 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7767 | |
| 7768 | /** |
| 7769 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7770 | * Set the allowed carrier list and the excluded carrier list, indicating the priority between |
| 7771 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7772 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7773 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7774 | * @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] | 7775 | */ |
| 7776 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7777 | @TelephonyManager.SetCarrierRestrictionResult |
| 7778 | public int setAllowedCarriers(CarrierRestrictionRules carrierRestrictionRules) { |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7779 | enforceModifyPermission(); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7780 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7781 | |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7782 | if (carrierRestrictionRules == null) { |
| 7783 | throw new NullPointerException("carrier restriction cannot be null"); |
Meng Wang | 9b7c4e9 | 2017-02-17 11:41:27 -0800 | [diff] [blame] | 7784 | } |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7785 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7786 | final long identity = Binder.clearCallingIdentity(); |
| 7787 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7788 | return (int) sendRequest(CMD_SET_ALLOWED_CARRIERS, carrierRestrictionRules, |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7789 | workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7790 | } finally { |
| 7791 | Binder.restoreCallingIdentity(identity); |
| 7792 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7793 | } |
| 7794 | |
| 7795 | /** |
| 7796 | * {@hide} |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7797 | * Get the allowed carrier list and the excluded carrier list, including the priority between |
| 7798 | * the two lists. |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7799 | * Require system privileges. In the future we may add this to carrier APIs. |
| 7800 | * |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7801 | * @return {@link android.telephony.CarrierRestrictionRules} |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7802 | */ |
| 7803 | @Override |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7804 | public CarrierRestrictionRules getAllowedCarriers() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 7805 | enforceReadPrivilegedPermission("getAllowedCarriers"); |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 7806 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7807 | |
| 7808 | final long identity = Binder.clearCallingIdentity(); |
| 7809 | try { |
Michele Berionne | 482f820 | 2018-11-27 18:57:59 -0800 | [diff] [blame] | 7810 | Object response = sendRequest(CMD_GET_ALLOWED_CARRIERS, null, workSource); |
| 7811 | if (response instanceof CarrierRestrictionRules) { |
| 7812 | return (CarrierRestrictionRules) response; |
| 7813 | } |
| 7814 | // Response is an Exception of some kind, |
| 7815 | // which is signalled to the user as a NULL retval |
| 7816 | return null; |
| 7817 | } catch (Exception e) { |
| 7818 | Log.e(LOG_TAG, "getAllowedCarriers. Exception ex=" + e); |
| 7819 | return null; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7820 | } finally { |
| 7821 | Binder.restoreCallingIdentity(identity); |
| 7822 | } |
Meng Wang | 1a7c35a | 2016-05-05 20:56:15 -0700 | [diff] [blame] | 7823 | } |
| 7824 | |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7825 | /** |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7826 | * Action set from carrier signalling broadcast receivers to enable/disable radio |
| 7827 | * @param subId the subscription ID that this action applies to. |
| 7828 | * @param enabled control enable or disable radio. |
| 7829 | * {@hide} |
| 7830 | */ |
| 7831 | @Override |
| 7832 | public void carrierActionSetRadioEnabled(int subId, boolean enabled) { |
| 7833 | enforceModifyPermission(); |
| 7834 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7835 | |
| 7836 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7837 | if (phone == null) { |
| 7838 | loge("carrierAction: SetRadioEnabled fails with invalid sibId: " + subId); |
| 7839 | return; |
| 7840 | } |
| 7841 | try { |
| 7842 | phone.carrierActionSetRadioEnabled(enabled); |
| 7843 | } catch (Exception e) { |
| 7844 | Log.e(LOG_TAG, "carrierAction: SetRadioEnabled fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7845 | } finally { |
| 7846 | Binder.restoreCallingIdentity(identity); |
fionaxu | 59545b4 | 2016-05-25 15:53:37 -0700 | [diff] [blame] | 7847 | } |
| 7848 | } |
| 7849 | |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7850 | /** |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7851 | * Action set from carrier signalling broadcast receivers to start/stop reporting the default |
| 7852 | * network status based on which carrier apps could apply actions accordingly, |
| 7853 | * enable/disable default url handler for example. |
| 7854 | * |
| 7855 | * @param subId the subscription ID that this action applies to. |
| 7856 | * @param report control start/stop reporting the default network status. |
| 7857 | * {@hide} |
| 7858 | */ |
| 7859 | @Override |
| 7860 | public void carrierActionReportDefaultNetworkStatus(int subId, boolean report) { |
| 7861 | enforceModifyPermission(); |
| 7862 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7863 | |
| 7864 | final long identity = Binder.clearCallingIdentity(); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7865 | if (phone == null) { |
| 7866 | loge("carrierAction: ReportDefaultNetworkStatus fails with invalid sibId: " + subId); |
| 7867 | return; |
| 7868 | } |
| 7869 | try { |
| 7870 | phone.carrierActionReportDefaultNetworkStatus(report); |
| 7871 | } catch (Exception e) { |
| 7872 | Log.e(LOG_TAG, "carrierAction: ReportDefaultNetworkStatus fails. Exception ex=" + e); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7873 | } finally { |
| 7874 | Binder.restoreCallingIdentity(identity); |
fionaxu | 8da9cb1 | 2017-05-23 15:02:46 -0700 | [diff] [blame] | 7875 | } |
| 7876 | } |
| 7877 | |
| 7878 | /** |
fionaxu | d962228 | 2017-07-17 17:51:30 -0700 | [diff] [blame] | 7879 | * Action set from carrier signalling broadcast receivers to reset all carrier actions |
| 7880 | * @param subId the subscription ID that this action applies to. |
| 7881 | * {@hide} |
| 7882 | */ |
| 7883 | @Override |
| 7884 | public void carrierActionResetAll(int subId) { |
| 7885 | enforceModifyPermission(); |
| 7886 | final Phone phone = getPhone(subId); |
| 7887 | if (phone == null) { |
| 7888 | loge("carrierAction: ResetAll fails with invalid sibId: " + subId); |
| 7889 | return; |
| 7890 | } |
| 7891 | try { |
| 7892 | phone.carrierActionResetAll(); |
| 7893 | } catch (Exception e) { |
| 7894 | Log.e(LOG_TAG, "carrierAction: ResetAll fails. Exception ex=" + e); |
| 7895 | } |
| 7896 | } |
| 7897 | |
| 7898 | /** |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7899 | * Called when "adb shell dumpsys phone" is invoked. Dump is also automatically invoked when a |
| 7900 | * bug report is being generated. |
| 7901 | */ |
| 7902 | @Override |
Ta-wei Yen | 99282e0 | 2016-06-21 18:19:35 -0700 | [diff] [blame] | 7903 | protected void dump(FileDescriptor fd, PrintWriter writer, String[] args) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7904 | if (mApp.checkCallingOrSelfPermission(android.Manifest.permission.DUMP) |
| 7905 | != PackageManager.PERMISSION_GRANTED) { |
dcashman | 22b950d | 2016-06-27 11:39:02 -0700 | [diff] [blame] | 7906 | writer.println("Permission Denial: can't dump Phone from pid=" |
| 7907 | + Binder.getCallingPid() |
| 7908 | + ", uid=" + Binder.getCallingUid() |
| 7909 | + "without permission " |
| 7910 | + android.Manifest.permission.DUMP); |
| 7911 | return; |
| 7912 | } |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7913 | DumpsysHandler.dump(mApp, fd, writer, args); |
Ta-wei Yen | c236d6b | 2016-06-21 13:33:12 -0700 | [diff] [blame] | 7914 | } |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7915 | |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7916 | @Override |
Hall Liu | a1548bd | 2019-12-24 14:14:12 -0800 | [diff] [blame] | 7917 | public int handleShellCommand(@NonNull ParcelFileDescriptor in, |
| 7918 | @NonNull ParcelFileDescriptor out, @NonNull ParcelFileDescriptor err, |
| 7919 | @NonNull String[] args) { |
| 7920 | return new TelephonyShellCommand(this, getDefaultPhone().getContext()).exec( |
| 7921 | this, in.getFileDescriptor(), out.getFileDescriptor(), |
| 7922 | err.getFileDescriptor(), args); |
Brad Ebinger | dac2f00 | 2018-04-03 15:17:52 -0700 | [diff] [blame] | 7923 | } |
| 7924 | |
Jack Yu | eb89b24 | 2016-06-22 13:27:47 -0700 | [diff] [blame] | 7925 | /** |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7926 | * Policy control of data connection with reason {@@TelephonyManager.DataEnabledReason} |
Greg Kaiser | 17f4175 | 2020-05-05 16:47:47 +0000 | [diff] [blame] | 7927 | * @param subId Subscription index |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7928 | * @param reason the reason the data enable change is taking place |
| 7929 | * @param enabled True if enabling the data, otherwise disabling. |
| 7930 | * @hide |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7931 | */ |
| 7932 | @Override |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7933 | public void setDataEnabledForReason(int subId, @TelephonyManager.DataEnabledReason int reason, |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7934 | boolean enabled) { |
| 7935 | if (reason == TelephonyManager.DATA_ENABLED_REASON_USER |
| 7936 | || reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7937 | try { |
| 7938 | TelephonyPermissions.enforceCallingOrSelfCarrierPrivilege( |
Sooraj Sasindran | 95c07a9 | 2020-07-15 01:35:24 -0700 | [diff] [blame] | 7939 | mApp, subId, "setDataEnabledForReason"); |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7940 | } catch (SecurityException se) { |
| 7941 | enforceModifyPermission(); |
| 7942 | } |
| 7943 | } else { |
| 7944 | enforceModifyPermission(); |
| 7945 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7946 | |
| 7947 | final long identity = Binder.clearCallingIdentity(); |
| 7948 | try { |
| 7949 | Phone phone = getPhone(subId); |
| 7950 | if (phone != null) { |
Sooraj Sasindran | af1b513 | 2020-05-05 21:06:20 +0000 | [diff] [blame] | 7951 | if (reason == TelephonyManager.DATA_ENABLED_REASON_CARRIER) { |
| 7952 | phone.carrierActionSetMeteredApnsEnabled(enabled); |
| 7953 | } else { |
| 7954 | phone.getDataEnabledSettings().setDataEnabled(reason, enabled); |
| 7955 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7956 | } |
| 7957 | } finally { |
| 7958 | Binder.restoreCallingIdentity(identity); |
Jack Yu | 75ab295 | 2016-07-08 14:29:33 -0700 | [diff] [blame] | 7959 | } |
| 7960 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7961 | |
| 7962 | /** |
| 7963 | * Get Client request stats |
| 7964 | * @return List of Client Request Stats |
| 7965 | * @hide |
| 7966 | */ |
| 7967 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7968 | public List<ClientRequestStats> getClientRequestStats(String callingPackage, |
| 7969 | String callingFeatureId, int subId) { |
Jeff Davidson | 7e17e31 | 2018-02-13 18:17:36 -0800 | [diff] [blame] | 7970 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 7971 | mApp, subId, callingPackage, callingFeatureId, "getClientRequestStats")) { |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7972 | return null; |
| 7973 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7974 | Phone phone = getPhone(subId); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7975 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 7976 | final long identity = Binder.clearCallingIdentity(); |
| 7977 | try { |
| 7978 | if (phone != null) { |
| 7979 | return phone.getClientRequestStats(); |
| 7980 | } |
| 7981 | |
| 7982 | return null; |
| 7983 | } finally { |
| 7984 | Binder.restoreCallingIdentity(identity); |
| 7985 | } |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7986 | } |
| 7987 | |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7988 | private WorkSource getWorkSource(int uid) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 7989 | String packageName = mApp.getPackageManager().getNameForUid(uid); |
Narayan Kamath | f04b5a1 | 2018-01-09 11:47:15 +0000 | [diff] [blame] | 7990 | return new WorkSource(uid, packageName); |
Sooraj Sasindran | 9a90931 | 2016-07-18 11:57:25 -0700 | [diff] [blame] | 7991 | } |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7992 | |
| 7993 | /** |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7994 | * Set SIM card power state. |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 7995 | * |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 7996 | * @param slotIndex SIM slot id. |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 7997 | * @param state State of SIM (power down, power up, pass through) |
| 7998 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 7999 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8000 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8001 | * |
| 8002 | **/ |
| 8003 | @Override |
Grace Chen | 7099007 | 2017-03-24 17:21:30 -0700 | [diff] [blame] | 8004 | public void setSimPowerStateForSlot(int slotIndex, int state) { |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8005 | enforceModifyPermission(); |
Sanket Padawe | 13bac7b | 2017-03-20 15:04:47 -0700 | [diff] [blame] | 8006 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8007 | |
vagdevi | af9a5b9 | 2018-08-15 16:01:53 -0700 | [diff] [blame] | 8008 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8009 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8010 | final long identity = Binder.clearCallingIdentity(); |
| 8011 | try { |
| 8012 | if (phone != null) { |
Jordan Liu | 109698e | 2020-11-24 14:50:34 -0800 | [diff] [blame] | 8013 | phone.setSimPowerState(state, null, workSource); |
| 8014 | } |
| 8015 | } finally { |
| 8016 | Binder.restoreCallingIdentity(identity); |
| 8017 | } |
| 8018 | } |
| 8019 | |
| 8020 | /** |
| 8021 | * Set SIM card power state. |
| 8022 | * |
| 8023 | * @param slotIndex SIM slot id. |
| 8024 | * @param state State of SIM (power down, power up, pass through) |
| 8025 | * @param callback callback to trigger after success or failure |
| 8026 | * - {@link android.telephony.TelephonyManager#CARD_POWER_DOWN} |
| 8027 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP} |
| 8028 | * - {@link android.telephony.TelephonyManager#CARD_POWER_UP_PASS_THROUGH} |
| 8029 | * |
| 8030 | **/ |
| 8031 | @Override |
| 8032 | public void setSimPowerStateForSlotWithCallback(int slotIndex, int state, |
| 8033 | IIntegerConsumer callback) { |
| 8034 | enforceModifyPermission(); |
| 8035 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8036 | |
| 8037 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 8038 | |
| 8039 | final long identity = Binder.clearCallingIdentity(); |
| 8040 | try { |
| 8041 | if (phone != null) { |
| 8042 | Pair<Integer, IIntegerConsumer> arguments = Pair.create(state, callback); |
| 8043 | sendRequestAsync(CMD_SET_SIM_POWER, arguments, phone, workSource); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8044 | } |
| 8045 | } finally { |
| 8046 | Binder.restoreCallingIdentity(identity); |
Jack Yu | eb4124c | 2017-02-16 15:32:43 -0800 | [diff] [blame] | 8047 | } |
| 8048 | } |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8049 | |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8050 | private boolean isUssdApiAllowed(int subId) { |
| 8051 | CarrierConfigManager configManager = |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8052 | (CarrierConfigManager) mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Tyler Gunn | 65d45c2 | 2017-06-05 11:22:26 -0700 | [diff] [blame] | 8053 | if (configManager == null) { |
| 8054 | return false; |
| 8055 | } |
| 8056 | PersistableBundle pb = configManager.getConfigForSubId(subId); |
| 8057 | if (pb == null) { |
| 8058 | return false; |
| 8059 | } |
| 8060 | return pb.getBoolean( |
| 8061 | CarrierConfigManager.KEY_ALLOW_USSD_REQUESTS_VIA_TELEPHONY_MANAGER_BOOL); |
| 8062 | } |
| 8063 | |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8064 | /** |
| 8065 | * Check if phone is in emergency callback mode |
| 8066 | * @return true if phone is in emergency callback mode |
| 8067 | * @param subId sub id |
| 8068 | */ |
goneil | 9c5f487 | 2017-12-05 14:07:56 -0800 | [diff] [blame] | 8069 | @Override |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8070 | public boolean getEmergencyCallbackMode(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8071 | enforceReadPrivilegedPermission("getEmergencyCallbackMode"); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8072 | final Phone phone = getPhone(subId); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8073 | |
| 8074 | final long identity = Binder.clearCallingIdentity(); |
| 8075 | try { |
| 8076 | if (phone != null) { |
| 8077 | return phone.isInEcm(); |
| 8078 | } else { |
| 8079 | return false; |
| 8080 | } |
| 8081 | } finally { |
| 8082 | Binder.restoreCallingIdentity(identity); |
Shuo Qian | dd21031 | 2017-04-12 22:11:33 +0000 | [diff] [blame] | 8083 | } |
| 8084 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8085 | |
| 8086 | /** |
| 8087 | * Get the current signal strength information for the given subscription. |
| 8088 | * Because this information is not updated when the device is in a low power state |
| 8089 | * it should not be relied-upon to be current. |
| 8090 | * @param subId Subscription index |
| 8091 | * @return the most recent cached signal strength info from the modem |
| 8092 | */ |
| 8093 | @Override |
| 8094 | public SignalStrength getSignalStrength(int subId) { |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8095 | final long identity = Binder.clearCallingIdentity(); |
| 8096 | try { |
| 8097 | Phone p = getPhone(subId); |
| 8098 | if (p == null) { |
| 8099 | return null; |
| 8100 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8101 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8102 | return p.getSignalStrength(); |
| 8103 | } finally { |
| 8104 | Binder.restoreCallingIdentity(identity); |
| 8105 | } |
Nathan Harold | 46b42aa | 2017-03-10 19:38:22 -0800 | [diff] [blame] | 8106 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8107 | |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8108 | /** |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8109 | * Get the current modem radio state for the given slot. |
| 8110 | * @param slotIndex slot index. |
| 8111 | * @param callingPackage the name of the package making the call. |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8112 | * @param callingFeatureId The feature in the package. |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8113 | * @return the current radio power state from the modem |
| 8114 | */ |
| 8115 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8116 | public int getRadioPowerState(int slotIndex, String callingPackage, String callingFeatureId) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8117 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8118 | if (phone != null) { |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8119 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, phone.getSubId(), |
| 8120 | callingPackage, callingFeatureId, "getRadioPowerState")) { |
Chen Xu | f792fd6 | 2018-10-17 17:54:36 +0000 | [diff] [blame] | 8121 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8122 | } |
| 8123 | |
| 8124 | final long identity = Binder.clearCallingIdentity(); |
| 8125 | try { |
| 8126 | return phone.getRadioPowerState(); |
| 8127 | } finally { |
| 8128 | Binder.restoreCallingIdentity(identity); |
| 8129 | } |
| 8130 | } |
| 8131 | return TelephonyManager.RADIO_POWER_UNAVAILABLE; |
| 8132 | } |
| 8133 | |
| 8134 | /** |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8135 | * Checks if data roaming is enabled on the subscription with id {@code subId}. |
| 8136 | * |
| 8137 | * <p>Requires one of the following permissions: |
| 8138 | * {@link android.Manifest.permission#ACCESS_NETWORK_STATE}, |
| 8139 | * {@link android.Manifest.permission#READ_PHONE_STATE} or that the calling app has carrier |
| 8140 | * privileges. |
| 8141 | * |
| 8142 | * @param subId subscription id |
| 8143 | * @return {@code true} if data roaming is enabled on this subscription, otherwise return |
| 8144 | * {@code false}. |
| 8145 | */ |
| 8146 | @Override |
| 8147 | public boolean isDataRoamingEnabled(int subId) { |
Shuo Qian | 093013d | 2020-08-13 15:42:55 -0700 | [diff] [blame] | 8148 | try { |
| 8149 | mApp.enforceCallingOrSelfPermission(android.Manifest.permission.ACCESS_NETWORK_STATE, |
| 8150 | null); |
| 8151 | } catch (Exception e) { |
| 8152 | TelephonyPermissions.enforeceCallingOrSelfReadPhoneStatePermissionOrCarrierPrivilege( |
| 8153 | mApp, subId, "isDataRoamingEnabled"); |
| 8154 | } |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8155 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8156 | boolean isEnabled = false; |
| 8157 | final long identity = Binder.clearCallingIdentity(); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8158 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8159 | Phone phone = getPhone(subId); |
| 8160 | isEnabled = phone != null ? phone.getDataRoamingEnabled() : false; |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8161 | } finally { |
| 8162 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8163 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8164 | return isEnabled; |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8165 | } |
| 8166 | |
| 8167 | |
| 8168 | /** |
| 8169 | * Enables/Disables the data roaming on the subscription with id {@code subId}. |
| 8170 | * |
| 8171 | * <p> Requires permission: |
| 8172 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE} or that the calling app has carrier |
| 8173 | * privileges. |
| 8174 | * |
| 8175 | * @param subId subscription id |
| 8176 | * @param isEnabled {@code true} means enable, {@code false} means disable. |
| 8177 | */ |
| 8178 | @Override |
| 8179 | public void setDataRoamingEnabled(int subId, boolean isEnabled) { |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8180 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8181 | mApp, subId, "setDataRoamingEnabled"); |
| 8182 | |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8183 | final long identity = Binder.clearCallingIdentity(); |
| 8184 | try { |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8185 | Phone phone = getPhone(subId); |
| 8186 | if (phone != null) { |
| 8187 | phone.setDataRoamingEnabled(isEnabled); |
| 8188 | } |
| 8189 | } finally { |
| 8190 | Binder.restoreCallingIdentity(identity); |
Pengquan Meng | 77b7f13 | 2018-08-22 14:49:57 -0700 | [diff] [blame] | 8191 | } |
| 8192 | } |
| 8193 | |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8194 | @Override |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8195 | public boolean isManualNetworkSelectionAllowed(int subId) { |
tom hsu | c91afc7 | 2020-01-06 23:46:07 +0800 | [diff] [blame] | 8196 | TelephonyPermissions |
| 8197 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | 44e66f1 | 2019-04-01 10:48:20 -0700 | [diff] [blame] | 8198 | mApp, subId, "isManualNetworkSelectionAllowed"); |
| 8199 | |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8200 | boolean isAllowed = true; |
| 8201 | final long identity = Binder.clearCallingIdentity(); |
| 8202 | try { |
Pengquan Meng | 6884a2c | 2018-10-03 12:19:13 -0700 | [diff] [blame] | 8203 | Phone phone = getPhone(subId); |
| 8204 | if (phone != null) { |
| 8205 | isAllowed = phone.isCspPlmnEnabled(); |
| 8206 | } |
| 8207 | } finally { |
| 8208 | Binder.restoreCallingIdentity(identity); |
| 8209 | } |
| 8210 | return isAllowed; |
| 8211 | } |
| 8212 | |
| 8213 | @Override |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8214 | public List<UiccCardInfo> getUiccCardsInfo(String callingPackage) { |
Jordan Liu | 4cda455 | 2020-03-23 11:55:07 -0700 | [diff] [blame] | 8215 | // Verify that tha callingPackage belongs to the calling UID |
| 8216 | mApp.getSystemService(AppOpsManager.class) |
| 8217 | .checkPackage(Binder.getCallingUid(), callingPackage); |
| 8218 | |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8219 | boolean hasReadPermission = false; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8220 | try { |
| 8221 | enforceReadPrivilegedPermission("getUiccCardsInfo"); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8222 | hasReadPermission = true; |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8223 | } catch (SecurityException e) { |
| 8224 | // even without READ_PRIVILEGED_PHONE_STATE, we allow the call to continue if the caller |
| 8225 | // has carrier privileges on an active UICC |
| 8226 | if (checkCarrierPrivilegesForPackageAnyPhone(callingPackage) |
| 8227 | != TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8228 | throw new SecurityException("Caller does not have permission."); |
Jordan Liu | c65bc95 | 2019-02-12 17:54:02 -0800 | [diff] [blame] | 8229 | } |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8230 | } |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8231 | |
| 8232 | final long identity = Binder.clearCallingIdentity(); |
| 8233 | try { |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8234 | UiccController uiccController = UiccController.getInstance(); |
| 8235 | ArrayList<UiccCardInfo> cardInfos = uiccController.getAllUiccCardInfos(); |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8236 | if (hasReadPermission) { |
| 8237 | return cardInfos; |
Jordan Liu | 75f43ea | 2019-01-17 16:56:37 -0800 | [diff] [blame] | 8238 | } |
Jordan Liu | 1e142fc | 2019-04-22 15:10:43 -0700 | [diff] [blame] | 8239 | |
| 8240 | // Remove private info if the caller doesn't have access |
| 8241 | ArrayList<UiccCardInfo> filteredInfos = new ArrayList<>(); |
| 8242 | for (UiccCardInfo cardInfo : cardInfos) { |
| 8243 | // For an inactive eUICC, the UiccCard will be null even though the UiccCardInfo |
| 8244 | // is available |
| 8245 | UiccCard card = uiccController.getUiccCardForSlot(cardInfo.getSlotIndex()); |
| 8246 | if (card == null || card.getUiccProfile() == null) { |
| 8247 | // assume no access if the card or profile is unavailable |
| 8248 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8249 | continue; |
| 8250 | } |
| 8251 | UiccProfile profile = card.getUiccProfile(); |
| 8252 | if (profile.getCarrierPrivilegeStatus(mApp.getPackageManager(), callingPackage) |
| 8253 | == TelephonyManager.CARRIER_PRIVILEGE_STATUS_HAS_ACCESS) { |
| 8254 | filteredInfos.add(cardInfo); |
| 8255 | } else { |
| 8256 | filteredInfos.add(cardInfo.getUnprivileged()); |
| 8257 | } |
| 8258 | } |
| 8259 | return filteredInfos; |
Jordan Liu | 5aa0700 | 2018-12-18 15:44:48 -0800 | [diff] [blame] | 8260 | } finally { |
| 8261 | Binder.restoreCallingIdentity(identity); |
| 8262 | } |
| 8263 | } |
| 8264 | |
| 8265 | @Override |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8266 | public UiccSlotInfo[] getUiccSlotsInfo() { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8267 | enforceReadPrivilegedPermission("getUiccSlotsInfo"); |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8268 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8269 | final long identity = Binder.clearCallingIdentity(); |
| 8270 | try { |
| 8271 | UiccSlot[] slots = UiccController.getInstance().getUiccSlots(); |
| 8272 | if (slots == null) { |
| 8273 | Rlog.i(LOG_TAG, "slots is null."); |
| 8274 | return null; |
| 8275 | } |
| 8276 | |
| 8277 | UiccSlotInfo[] infos = new UiccSlotInfo[slots.length]; |
| 8278 | for (int i = 0; i < slots.length; i++) { |
| 8279 | UiccSlot slot = slots[i]; |
| 8280 | if (slot == null) { |
| 8281 | continue; |
| 8282 | } |
| 8283 | |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8284 | String cardId; |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8285 | UiccCard card = slot.getUiccCard(); |
| 8286 | if (card != null) { |
| 8287 | cardId = card.getCardId(); |
Jordan Liu | 7be7e65 | 2019-05-06 18:55:02 +0000 | [diff] [blame] | 8288 | } else { |
Jordan Liu | 01bd00d | 2019-09-12 16:19:43 -0700 | [diff] [blame] | 8289 | cardId = slot.getEid(); |
| 8290 | if (TextUtils.isEmpty(cardId)) { |
| 8291 | cardId = slot.getIccId(); |
| 8292 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8293 | } |
| 8294 | |
Jordan Liu | 857451f | 2019-05-09 16:35:35 -0700 | [diff] [blame] | 8295 | if (cardId != null) { |
| 8296 | // if cardId is an ICCID, strip off trailing Fs before exposing to user |
| 8297 | // if cardId is an EID, it's all digits so this is fine |
| 8298 | cardId = IccUtils.stripTrailingFs(cardId); |
| 8299 | } |
| 8300 | |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8301 | int cardState = 0; |
| 8302 | switch (slot.getCardState()) { |
| 8303 | case CARDSTATE_ABSENT: |
| 8304 | cardState = UiccSlotInfo.CARD_STATE_INFO_ABSENT; |
| 8305 | break; |
| 8306 | case CARDSTATE_PRESENT: |
| 8307 | cardState = UiccSlotInfo.CARD_STATE_INFO_PRESENT; |
| 8308 | break; |
| 8309 | case CARDSTATE_ERROR: |
| 8310 | cardState = UiccSlotInfo.CARD_STATE_INFO_ERROR; |
| 8311 | break; |
| 8312 | case CARDSTATE_RESTRICTED: |
| 8313 | cardState = UiccSlotInfo.CARD_STATE_INFO_RESTRICTED; |
| 8314 | break; |
| 8315 | default: |
| 8316 | break; |
| 8317 | |
| 8318 | } |
| 8319 | |
| 8320 | infos[i] = new UiccSlotInfo( |
| 8321 | slot.isActive(), |
| 8322 | slot.isEuicc(), |
| 8323 | cardId, |
| 8324 | cardState, |
| 8325 | slot.getPhoneId(), |
Jordan Liu | a261958 | 2019-02-14 12:56:40 -0800 | [diff] [blame] | 8326 | slot.isExtendedApduSupported(), |
| 8327 | slot.isRemovable()); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8328 | } |
| 8329 | return infos; |
| 8330 | } finally { |
| 8331 | Binder.restoreCallingIdentity(identity); |
Holly Jiuyu Sun | 1d957c5 | 2018-04-04 13:52:42 -0700 | [diff] [blame] | 8332 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8333 | } |
| 8334 | |
| 8335 | @Override |
| 8336 | public boolean switchSlots(int[] physicalSlots) { |
| 8337 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8338 | |
| 8339 | final long identity = Binder.clearCallingIdentity(); |
| 8340 | try { |
| 8341 | return (Boolean) sendRequest(CMD_SWITCH_SLOTS, physicalSlots); |
| 8342 | } finally { |
| 8343 | Binder.restoreCallingIdentity(identity); |
| 8344 | } |
Holly Jiuyu Sun | 01c47ad | 2018-01-24 17:56:33 +0000 | [diff] [blame] | 8345 | } |
Jack Yu | 4c98804 | 2018-02-27 15:30:01 -0800 | [diff] [blame] | 8346 | |
| 8347 | @Override |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8348 | public int getCardIdForDefaultEuicc(int subId, String callingPackage) { |
Jordan Liu | 7de49fa | 2018-12-06 14:48:49 -0800 | [diff] [blame] | 8349 | final long identity = Binder.clearCallingIdentity(); |
| 8350 | try { |
| 8351 | return UiccController.getInstance().getCardIdForDefaultEuicc(); |
| 8352 | } finally { |
| 8353 | Binder.restoreCallingIdentity(identity); |
| 8354 | } |
| 8355 | } |
| 8356 | |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8357 | /** |
goneil | 47ffb6e | 2018-04-06 15:40:58 -0700 | [diff] [blame] | 8358 | * A test API to reload the UICC profile. |
| 8359 | * |
| 8360 | * <p>Requires that the calling app has permission |
| 8361 | * {@link android.Manifest.permission#MODIFY_PHONE_STATE MODIFY_PHONE_STATE}. |
| 8362 | * @hide |
| 8363 | */ |
| 8364 | @Override |
| 8365 | public void refreshUiccProfile(int subId) { |
| 8366 | enforceModifyPermission(); |
| 8367 | |
| 8368 | final long identity = Binder.clearCallingIdentity(); |
| 8369 | try { |
| 8370 | Phone phone = getPhone(subId); |
| 8371 | if (phone == null) { |
| 8372 | return; |
| 8373 | } |
| 8374 | UiccCard uiccCard = phone.getUiccCard(); |
| 8375 | if (uiccCard == null) { |
| 8376 | return; |
| 8377 | } |
| 8378 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8379 | if (uiccProfile == null) { |
| 8380 | return; |
| 8381 | } |
| 8382 | uiccProfile.refresh(); |
| 8383 | } finally { |
| 8384 | Binder.restoreCallingIdentity(identity); |
| 8385 | } |
| 8386 | } |
| 8387 | |
| 8388 | /** |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8389 | * Returns false if the mobile data is disabled by default, otherwise return true. |
| 8390 | */ |
| 8391 | private boolean getDefaultDataEnabled() { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8392 | return TelephonyProperties.mobile_data().orElse(true); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8393 | } |
| 8394 | |
| 8395 | /** |
| 8396 | * Returns true if the data roaming is enabled by default, i.e the system property |
| 8397 | * of {@link #DEFAULT_DATA_ROAMING_PROPERTY_NAME} is true or the config of |
| 8398 | * {@link CarrierConfigManager#KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL} is true. |
| 8399 | */ |
| 8400 | private boolean getDefaultDataRoamingEnabled(int subId) { |
| 8401 | final CarrierConfigManager configMgr = (CarrierConfigManager) |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8402 | mApp.getSystemService(Context.CARRIER_CONFIG_SERVICE); |
Shuo Qian | 1d84a0e | 2020-07-15 12:36:44 -0700 | [diff] [blame] | 8403 | boolean isDataRoamingEnabled = TelephonyProperties.data_roaming().orElse(false); |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8404 | isDataRoamingEnabled |= configMgr.getConfigForSubId(subId).getBoolean( |
| 8405 | CarrierConfigManager.KEY_CARRIER_DEFAULT_DATA_ROAMING_ENABLED_BOOL); |
| 8406 | return isDataRoamingEnabled; |
| 8407 | } |
| 8408 | |
| 8409 | /** |
| 8410 | * Returns the default network type for the given {@code subId}, if the default network type is |
| 8411 | * not set, return {@link Phone#PREFERRED_NT_MODE}. |
| 8412 | */ |
| 8413 | private int getDefaultNetworkType(int subId) { |
Inseob Kim | 14bb3d0 | 2018-12-13 17:11:34 +0900 | [diff] [blame] | 8414 | List<Integer> list = TelephonyProperties.default_network(); |
| 8415 | int phoneId = mSubscriptionController.getPhoneId(subId); |
| 8416 | if (phoneId >= 0 && phoneId < list.size() && list.get(phoneId) != null) { |
| 8417 | return list.get(phoneId); |
| 8418 | } |
| 8419 | return Phone.PREFERRED_NT_MODE; |
Pengquan Meng | 85728fb | 2018-03-12 16:31:21 -0700 | [diff] [blame] | 8420 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8421 | |
| 8422 | @Override |
| 8423 | public void setCarrierTestOverride(int subId, String mccmnc, String imsi, String iccid, String |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8424 | gid1, String gid2, String plmn, String spn, String carrierPrivilegeRules, String apn) { |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8425 | enforceModifyPermission(); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8426 | |
| 8427 | final long identity = Binder.clearCallingIdentity(); |
| 8428 | try { |
| 8429 | final Phone phone = getPhone(subId); |
| 8430 | if (phone == null) { |
| 8431 | loge("setCarrierTestOverride fails with invalid subId: " + subId); |
| 8432 | return; |
| 8433 | } |
chen xu | eaba88a | 2019-03-15 13:15:10 -0700 | [diff] [blame] | 8434 | phone.setCarrierTestOverride(mccmnc, imsi, iccid, gid1, gid2, plmn, spn, |
| 8435 | carrierPrivilegeRules, apn); |
Jeff Davidson | 8ab02b2 | 2020-03-28 12:24:40 -0700 | [diff] [blame] | 8436 | if (carrierPrivilegeRules == null) { |
| 8437 | mCarrierPrivilegeTestOverrideSubIds.remove(subId); |
| 8438 | } else { |
| 8439 | mCarrierPrivilegeTestOverrideSubIds.add(subId); |
| 8440 | } |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8441 | } finally { |
| 8442 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8443 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8444 | } |
| 8445 | |
| 8446 | @Override |
| 8447 | public int getCarrierIdListVersion(int subId) { |
Brad Ebinger | 35c841c | 2018-10-01 10:40:55 -0700 | [diff] [blame] | 8448 | enforceReadPrivilegedPermission("getCarrierIdListVersion"); |
Malcolm Chen | aa4a853 | 2018-02-28 15:00:40 -0800 | [diff] [blame] | 8449 | |
| 8450 | final long identity = Binder.clearCallingIdentity(); |
| 8451 | try { |
| 8452 | final Phone phone = getPhone(subId); |
| 8453 | if (phone == null) { |
| 8454 | loge("getCarrierIdListVersion fails with invalid subId: " + subId); |
| 8455 | return TelephonyManager.UNKNOWN_CARRIER_ID_LIST_VERSION; |
| 8456 | } |
| 8457 | return phone.getCarrierIdListVersion(); |
| 8458 | } finally { |
| 8459 | Binder.restoreCallingIdentity(identity); |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8460 | } |
fionaxu | a13278b | 2018-03-21 00:08:13 -0700 | [diff] [blame] | 8461 | } |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8462 | |
| 8463 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8464 | public int getNumberOfModemsWithSimultaneousDataConnections(int subId, String callingPackage, |
| 8465 | String callingFeatureId) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8466 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8467 | mApp, subId, callingPackage, callingFeatureId, |
| 8468 | "getNumberOfModemsWithSimultaneousDataConnections")) { |
Malcolm Chen | 2c63d40 | 2018-08-14 16:00:53 -0700 | [diff] [blame] | 8469 | return -1; |
| 8470 | } |
| 8471 | |
| 8472 | final long identity = Binder.clearCallingIdentity(); |
| 8473 | try { |
| 8474 | return mPhoneConfigurationManager.getNumberOfModemsWithSimultaneousDataConnections(); |
| 8475 | } finally { |
| 8476 | Binder.restoreCallingIdentity(identity); |
| 8477 | } |
| 8478 | } |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8479 | |
| 8480 | @Override |
| 8481 | public int getCdmaRoamingMode(int subId) { |
zoey chen | 7e6d4e5 | 2019-12-17 18:18:59 +0800 | [diff] [blame] | 8482 | TelephonyPermissions |
| 8483 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8484 | mApp, subId, "getCdmaRoamingMode"); |
| 8485 | |
| 8486 | final long identity = Binder.clearCallingIdentity(); |
| 8487 | try { |
| 8488 | return (int) sendRequest(CMD_GET_CDMA_ROAMING_MODE, null /* argument */, subId); |
| 8489 | } finally { |
| 8490 | Binder.restoreCallingIdentity(identity); |
| 8491 | } |
| 8492 | } |
| 8493 | |
| 8494 | @Override |
| 8495 | public boolean setCdmaRoamingMode(int subId, int mode) { |
| 8496 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8497 | mApp, subId, "setCdmaRoamingMode"); |
| 8498 | |
| 8499 | final long identity = Binder.clearCallingIdentity(); |
| 8500 | try { |
| 8501 | return (boolean) sendRequest(CMD_SET_CDMA_ROAMING_MODE, mode, subId); |
| 8502 | } finally { |
| 8503 | Binder.restoreCallingIdentity(identity); |
| 8504 | } |
| 8505 | } |
| 8506 | |
| 8507 | @Override |
Sarah Chin | baab143 | 2020-10-28 13:46:24 -0700 | [diff] [blame] | 8508 | public int getCdmaSubscriptionMode(int subId) { |
| 8509 | TelephonyPermissions |
| 8510 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 8511 | mApp, subId, "getCdmaSubscriptionMode"); |
| 8512 | |
| 8513 | final long identity = Binder.clearCallingIdentity(); |
| 8514 | try { |
| 8515 | return (int) sendRequest(CMD_GET_CDMA_SUBSCRIPTION_MODE, null /* argument */, subId); |
| 8516 | } finally { |
| 8517 | Binder.restoreCallingIdentity(identity); |
| 8518 | } |
| 8519 | } |
| 8520 | |
| 8521 | @Override |
Pengquan Meng | a1bb627 | 2018-09-06 09:59:22 -0700 | [diff] [blame] | 8522 | public boolean setCdmaSubscriptionMode(int subId, int mode) { |
| 8523 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8524 | mApp, subId, "setCdmaSubscriptionMode"); |
| 8525 | |
| 8526 | final long identity = Binder.clearCallingIdentity(); |
| 8527 | try { |
| 8528 | return (boolean) sendRequest(CMD_SET_CDMA_SUBSCRIPTION_MODE, mode, subId); |
| 8529 | } finally { |
| 8530 | Binder.restoreCallingIdentity(identity); |
| 8531 | } |
| 8532 | } |
Makoto Onuki | da3bf79 | 2018-09-18 16:06:29 -0700 | [diff] [blame] | 8533 | |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8534 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8535 | public Map<Integer, List<EmergencyNumber>> getEmergencyNumberList( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8536 | String callingPackage, String callingFeatureId) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8537 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8538 | mApp, getDefaultSubscription(), callingPackage, callingFeatureId, |
| 8539 | "getEmergencyNumberList")) { |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8540 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8541 | } |
| 8542 | final long identity = Binder.clearCallingIdentity(); |
| 8543 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8544 | Map<Integer, List<EmergencyNumber>> emergencyNumberListInternal = new HashMap<>(); |
| 8545 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8546 | if (phone.getEmergencyNumberTracker() != null |
| 8547 | && phone.getEmergencyNumberTracker().getEmergencyNumberList() != null) { |
| 8548 | emergencyNumberListInternal.put( |
| 8549 | phone.getSubId(), |
| 8550 | phone.getEmergencyNumberTracker().getEmergencyNumberList()); |
| 8551 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8552 | } |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8553 | return emergencyNumberListInternal; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8554 | } finally { |
| 8555 | Binder.restoreCallingIdentity(identity); |
| 8556 | } |
sqian | c5eccab | 2018-10-19 18:46:41 -0700 | [diff] [blame] | 8557 | } |
| 8558 | |
| 8559 | @Override |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8560 | public boolean isEmergencyNumber(String number, boolean exactMatch) { |
Nazanin Bakhshi | f782e56 | 2018-12-11 15:15:39 -0800 | [diff] [blame] | 8561 | final Phone defaultPhone = getDefaultPhone(); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8562 | if (!exactMatch) { |
| 8563 | TelephonyPermissions |
| 8564 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
sqian | 8c68542 | 2019-02-22 15:55:18 -0800 | [diff] [blame] | 8565 | mApp, defaultPhone.getSubId(), "isEmergencyNumber(Potential)"); |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8566 | } |
| 8567 | final long identity = Binder.clearCallingIdentity(); |
| 8568 | try { |
sqian | 854d44b | 2018-12-12 16:48:18 -0800 | [diff] [blame] | 8569 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8570 | if (phone.getEmergencyNumberTracker() != null |
Taesu Lee | e050c00 | 2020-10-13 17:19:35 +0900 | [diff] [blame] | 8571 | && phone.getEmergencyNumberTracker() |
| 8572 | .isEmergencyNumber(number, exactMatch)) { |
| 8573 | return true; |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8574 | } |
sqian | 11b7a0e | 2018-12-05 18:48:28 -0800 | [diff] [blame] | 8575 | } |
| 8576 | return false; |
| 8577 | } finally { |
| 8578 | Binder.restoreCallingIdentity(identity); |
| 8579 | } |
| 8580 | } |
| 8581 | |
sqian | f4ca7ed | 2019-01-15 18:32:07 -0800 | [diff] [blame] | 8582 | /** |
| 8583 | * Update emergency number list for test mode. |
| 8584 | */ |
| 8585 | @Override |
| 8586 | public void updateEmergencyNumberListTestMode(int action, EmergencyNumber num) { |
| 8587 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8588 | "updateEmergencyNumberListTestMode"); |
| 8589 | |
| 8590 | final long identity = Binder.clearCallingIdentity(); |
| 8591 | try { |
| 8592 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8593 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8594 | if (tracker != null) { |
| 8595 | tracker.executeEmergencyNumberTestModeCommand(action, num); |
| 8596 | } |
| 8597 | } |
| 8598 | } finally { |
| 8599 | Binder.restoreCallingIdentity(identity); |
| 8600 | } |
| 8601 | } |
| 8602 | |
| 8603 | /** |
| 8604 | * Get the full emergency number list for test mode. |
| 8605 | */ |
| 8606 | @Override |
| 8607 | public List<String> getEmergencyNumberListTestMode() { |
| 8608 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 8609 | "getEmergencyNumberListTestMode"); |
| 8610 | |
| 8611 | final long identity = Binder.clearCallingIdentity(); |
| 8612 | try { |
| 8613 | Set<String> emergencyNumbers = new HashSet<>(); |
| 8614 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8615 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8616 | if (tracker != null) { |
| 8617 | for (EmergencyNumber num : tracker.getEmergencyNumberList()) { |
| 8618 | emergencyNumbers.add(num.getNumber()); |
| 8619 | } |
| 8620 | } |
| 8621 | } |
| 8622 | return new ArrayList<>(emergencyNumbers); |
| 8623 | } finally { |
| 8624 | Binder.restoreCallingIdentity(identity); |
| 8625 | } |
| 8626 | } |
| 8627 | |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8628 | @Override |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8629 | public int getEmergencyNumberDbVersion(int subId) { |
| 8630 | enforceReadPrivilegedPermission("getEmergencyNumberDbVersion"); |
| 8631 | |
| 8632 | final long identity = Binder.clearCallingIdentity(); |
| 8633 | try { |
| 8634 | final Phone phone = getPhone(subId); |
| 8635 | if (phone == null) { |
| 8636 | loge("getEmergencyNumberDbVersion fails with invalid subId: " + subId); |
| 8637 | return TelephonyManager.INVALID_EMERGENCY_NUMBER_DB_VERSION; |
| 8638 | } |
| 8639 | return phone.getEmergencyNumberDbVersion(); |
| 8640 | } finally { |
| 8641 | Binder.restoreCallingIdentity(identity); |
| 8642 | } |
| 8643 | } |
| 8644 | |
| 8645 | @Override |
| 8646 | public void notifyOtaEmergencyNumberDbInstalled() { |
| 8647 | enforceModifyPermission(); |
| 8648 | |
| 8649 | final long identity = Binder.clearCallingIdentity(); |
| 8650 | try { |
| 8651 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8652 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8653 | if (tracker != null) { |
| 8654 | tracker.updateOtaEmergencyNumberDatabase(); |
| 8655 | } |
| 8656 | } |
| 8657 | } finally { |
| 8658 | Binder.restoreCallingIdentity(identity); |
| 8659 | } |
| 8660 | } |
| 8661 | |
| 8662 | @Override |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8663 | public void updateOtaEmergencyNumberDbFilePath(ParcelFileDescriptor otaParcelFileDescriptor) { |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8664 | enforceActiveEmergencySessionPermission(); |
| 8665 | |
| 8666 | final long identity = Binder.clearCallingIdentity(); |
| 8667 | try { |
| 8668 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8669 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8670 | if (tracker != null) { |
Shuo Qian | c373f11 | 2020-03-05 17:55:34 -0800 | [diff] [blame] | 8671 | tracker.updateOtaEmergencyNumberDbFilePath(otaParcelFileDescriptor); |
| 8672 | } |
| 8673 | } |
| 8674 | } finally { |
| 8675 | Binder.restoreCallingIdentity(identity); |
| 8676 | } |
| 8677 | } |
| 8678 | |
| 8679 | @Override |
| 8680 | public void resetOtaEmergencyNumberDbFilePath() { |
| 8681 | enforceActiveEmergencySessionPermission(); |
| 8682 | |
| 8683 | final long identity = Binder.clearCallingIdentity(); |
| 8684 | try { |
| 8685 | for (Phone phone: PhoneFactory.getPhones()) { |
| 8686 | EmergencyNumberTracker tracker = phone.getEmergencyNumberTracker(); |
| 8687 | if (tracker != null) { |
| 8688 | tracker.resetOtaEmergencyNumberDbFilePath(); |
Shuo Qian | 3b6ee77 | 2019-11-13 17:43:31 -0800 | [diff] [blame] | 8689 | } |
| 8690 | } |
| 8691 | } finally { |
| 8692 | Binder.restoreCallingIdentity(identity); |
| 8693 | } |
| 8694 | } |
| 8695 | |
| 8696 | @Override |
chen xu | d6b45bd | 2018-10-30 22:27:10 -0700 | [diff] [blame] | 8697 | public List<String> getCertsFromCarrierPrivilegeAccessRules(int subId) { |
| 8698 | enforceReadPrivilegedPermission("getCertsFromCarrierPrivilegeAccessRules"); |
| 8699 | Phone phone = getPhone(subId); |
| 8700 | if (phone == null) { |
| 8701 | return null; |
| 8702 | } |
| 8703 | final long identity = Binder.clearCallingIdentity(); |
| 8704 | try { |
| 8705 | UiccProfile profile = UiccController.getInstance() |
| 8706 | .getUiccProfileForPhone(phone.getPhoneId()); |
| 8707 | if (profile != null) { |
| 8708 | return profile.getCertsFromCarrierPrivilegeAccessRules(); |
| 8709 | } |
| 8710 | } finally { |
| 8711 | Binder.restoreCallingIdentity(identity); |
| 8712 | } |
| 8713 | return null; |
| 8714 | } |
Malcolm Chen | 8e4ed91 | 2019-01-15 20:22:16 -0800 | [diff] [blame] | 8715 | |
| 8716 | /** |
| 8717 | * Enable or disable a modem stack. |
| 8718 | */ |
| 8719 | @Override |
| 8720 | public boolean enableModemForSlot(int slotIndex, boolean enable) { |
| 8721 | enforceModifyPermission(); |
| 8722 | |
| 8723 | final long identity = Binder.clearCallingIdentity(); |
| 8724 | try { |
| 8725 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8726 | if (phone == null) { |
| 8727 | return false; |
| 8728 | } else { |
| 8729 | return (Boolean) sendRequest(CMD_REQUEST_ENABLE_MODEM, enable, phone, null); |
| 8730 | } |
| 8731 | } finally { |
| 8732 | Binder.restoreCallingIdentity(identity); |
| 8733 | } |
| 8734 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8735 | |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8736 | /** |
| 8737 | * Whether a modem stack is enabled or not. |
| 8738 | */ |
| 8739 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8740 | public boolean isModemEnabledForSlot(int slotIndex, String callingPackage, |
| 8741 | String callingFeatureId) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8742 | Phone phone = PhoneFactory.getPhone(slotIndex); |
| 8743 | if (phone == null) return false; |
| 8744 | |
| 8745 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8746 | mApp, phone.getSubId(), callingPackage, callingFeatureId, |
| 8747 | "isModemEnabledForSlot")) { |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8748 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 8749 | } |
| 8750 | |
| 8751 | final long identity = Binder.clearCallingIdentity(); |
| 8752 | try { |
Nazanin Bakhshi | f71371d | 2019-04-29 17:29:44 -0700 | [diff] [blame] | 8753 | try { |
| 8754 | return mPhoneConfigurationManager.getPhoneStatusFromCache(phone.getPhoneId()); |
| 8755 | } catch (NoSuchElementException ex) { |
| 8756 | return (Boolean) sendRequest(CMD_GET_MODEM_STATUS, null, phone, null); |
| 8757 | } |
Malcolm Chen | 4bcd982 | 2019-03-27 18:34:05 -0700 | [diff] [blame] | 8758 | } finally { |
| 8759 | Binder.restoreCallingIdentity(identity); |
| 8760 | } |
| 8761 | } |
| 8762 | |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8763 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8764 | public void setMultiSimCarrierRestriction(boolean isMultiSimCarrierRestricted) { |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8765 | enforceModifyPermission(); |
| 8766 | |
| 8767 | final long identity = Binder.clearCallingIdentity(); |
| 8768 | try { |
| 8769 | mTelephonySharedPreferences.edit() |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8770 | .putBoolean(PREF_MULTI_SIM_RESTRICTED, isMultiSimCarrierRestricted) |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8771 | .commit(); |
| 8772 | } finally { |
| 8773 | Binder.restoreCallingIdentity(identity); |
| 8774 | } |
| 8775 | } |
| 8776 | |
| 8777 | @Override |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8778 | @TelephonyManager.IsMultiSimSupportedResult |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8779 | public int isMultiSimSupported(String callingPackage, String callingFeatureId) { |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8780 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState(mApp, |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8781 | getDefaultPhone().getSubId(), callingPackage, callingFeatureId, |
| 8782 | "isMultiSimSupported")) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8783 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 4245e95 | 2019-02-04 11:36:23 -0800 | [diff] [blame] | 8784 | } |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8785 | |
| 8786 | final long identity = Binder.clearCallingIdentity(); |
| 8787 | try { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8788 | return isMultiSimSupportedInternal(); |
Michele | cea4cf2 | 2018-12-21 15:00:11 -0800 | [diff] [blame] | 8789 | } finally { |
| 8790 | Binder.restoreCallingIdentity(identity); |
| 8791 | } |
| 8792 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8793 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8794 | @TelephonyManager.IsMultiSimSupportedResult |
| 8795 | private int isMultiSimSupportedInternal() { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8796 | // If the device has less than 2 SIM cards, indicate that multisim is restricted. |
| 8797 | int numPhysicalSlots = UiccController.getInstance().getUiccSlots().length; |
| 8798 | if (numPhysicalSlots < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8799 | loge("isMultiSimSupportedInternal: requires at least 2 cards"); |
| 8800 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8801 | } |
| 8802 | // Check if the hardware supports multisim functionality. If usage of multisim is not |
| 8803 | // supported by the modem, indicate that it is restricted. |
| 8804 | PhoneCapability staticCapability = |
| 8805 | mPhoneConfigurationManager.getStaticPhoneCapability(); |
| 8806 | if (staticCapability == null) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8807 | loge("isMultiSimSupportedInternal: no static configuration available"); |
| 8808 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8809 | } |
Sarah Chin | 7caee49 | 2020-02-18 20:49:02 +0000 | [diff] [blame] | 8810 | if (staticCapability.logicalModemList.size() < 2) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8811 | loge("isMultiSimSupportedInternal: maximum number of modem is < 2"); |
| 8812 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_HARDWARE; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8813 | } |
| 8814 | // Check if support of multiple SIMs is restricted by carrier |
| 8815 | if (mTelephonySharedPreferences.getBoolean(PREF_MULTI_SIM_RESTRICTED, false)) { |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8816 | return TelephonyManager.MULTISIM_NOT_SUPPORTED_BY_CARRIER; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8817 | } |
| 8818 | |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8819 | return TelephonyManager.MULTISIM_ALLOWED; |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8820 | } |
| 8821 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8822 | /** |
| 8823 | * Switch configs to enable multi-sim or switch back to single-sim |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8824 | * Note: Switch from multi-sim to single-sim is only possible with MODIFY_PHONE_STATE |
| 8825 | * permission, but the other way around is possible with either MODIFY_PHONE_STATE |
| 8826 | * or carrier privileges |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8827 | * @param numOfSims number of active sims we want to switch to |
| 8828 | */ |
| 8829 | @Override |
| 8830 | public void switchMultiSimConfig(int numOfSims) { |
Nazanin Bakhshi | 1731878 | 2019-03-01 11:56:08 -0800 | [diff] [blame] | 8831 | if (numOfSims == 1) { |
| 8832 | enforceModifyPermission(); |
| 8833 | } else { |
| 8834 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 8835 | mApp, SubscriptionManager.DEFAULT_SUBSCRIPTION_ID, "switchMultiSimConfig"); |
| 8836 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8837 | final long identity = Binder.clearCallingIdentity(); |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8838 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8839 | try { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8840 | //only proceed if multi-sim is not restricted |
Michele | 0ea7d78 | 2019-03-19 14:58:42 -0700 | [diff] [blame] | 8841 | if (isMultiSimSupportedInternal() != TelephonyManager.MULTISIM_ALLOWED) { |
Michele | 30b57b2 | 2019-03-01 12:01:14 -0800 | [diff] [blame] | 8842 | loge("switchMultiSimConfig not possible. It is restricted or not supported."); |
| 8843 | return; |
| 8844 | } |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8845 | mPhoneConfigurationManager.switchMultiSimConfig(numOfSims); |
| 8846 | } finally { |
| 8847 | Binder.restoreCallingIdentity(identity); |
| 8848 | } |
| 8849 | } |
| 8850 | |
Hyungjun Park | bb07fde | 2019-01-10 15:28:51 +0900 | [diff] [blame] | 8851 | @Override |
| 8852 | public boolean isApplicationOnUicc(int subId, int appType) { |
| 8853 | enforceReadPrivilegedPermission("isApplicationOnUicc"); |
| 8854 | Phone phone = getPhone(subId); |
| 8855 | if (phone == null) { |
| 8856 | return false; |
| 8857 | } |
| 8858 | final long identity = Binder.clearCallingIdentity(); |
| 8859 | try { |
| 8860 | UiccCard uiccCard = phone.getUiccCard(); |
| 8861 | if (uiccCard == null) { |
| 8862 | return false; |
| 8863 | } |
| 8864 | UiccProfile uiccProfile = uiccCard.getUiccProfile(); |
| 8865 | if (uiccProfile == null) { |
| 8866 | return false; |
| 8867 | } |
| 8868 | if (TelephonyManager.APPTYPE_SIM <= appType |
| 8869 | && appType <= TelephonyManager.APPTYPE_ISIM) { |
| 8870 | return uiccProfile.isApplicationOnIcc(AppType.values()[appType]); |
| 8871 | } |
| 8872 | return false; |
| 8873 | } finally { |
| 8874 | Binder.restoreCallingIdentity(identity); |
| 8875 | } |
| 8876 | } |
| 8877 | |
Nazanin Bakhshi | 628473f | 2019-01-29 17:37:52 -0800 | [diff] [blame] | 8878 | /** |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8879 | * Get whether making changes to modem configurations will trigger reboot. |
| 8880 | * Return value defaults to true. |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8881 | */ |
| 8882 | @Override |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8883 | public boolean doesSwitchMultiSimConfigTriggerReboot(int subId, String callingPackage, |
| 8884 | String callingFeatureId) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8885 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
Philip P. Moltmann | 700a959 | 2019-10-03 11:53:50 -0700 | [diff] [blame] | 8886 | mApp, subId, callingPackage, callingFeatureId, |
| 8887 | "doesSwitchMultiSimConfigTriggerReboot")) { |
chen xu | b4baa77 | 2019-04-03 10:23:41 -0700 | [diff] [blame] | 8888 | return false; |
| 8889 | } |
Nazanin Bakhshi | 5fe5ef2 | 2019-01-30 10:52:09 -0800 | [diff] [blame] | 8890 | final long identity = Binder.clearCallingIdentity(); |
| 8891 | try { |
| 8892 | return mPhoneConfigurationManager.isRebootRequiredForModemConfigChange(); |
| 8893 | } finally { |
| 8894 | Binder.restoreCallingIdentity(identity); |
| 8895 | } |
| 8896 | } |
| 8897 | |
Nathan Harold | 29f5f05 | 2019-02-15 13:41:57 -0800 | [diff] [blame] | 8898 | private void updateModemStateMetrics() { |
| 8899 | TelephonyMetrics metrics = TelephonyMetrics.getInstance(); |
| 8900 | // TODO: check the state for each modem if the api is ready. |
| 8901 | metrics.updateEnabledModemBitmap((1 << TelephonyManager.from(mApp).getPhoneCount()) - 1); |
| 8902 | } |
| 8903 | |
Pengquan Meng | 3889a57 | 2019-01-23 11:16:29 -0800 | [diff] [blame] | 8904 | @Override |
| 8905 | public int[] getSlotsMapping() { |
| 8906 | enforceReadPrivilegedPermission("getSlotsMapping"); |
| 8907 | |
| 8908 | final long identity = Binder.clearCallingIdentity(); |
| 8909 | try { |
| 8910 | int phoneCount = TelephonyManager.getDefault().getPhoneCount(); |
| 8911 | // All logical slots should have a mapping to a physical slot. |
| 8912 | int[] logicalSlotsMapping = new int[phoneCount]; |
| 8913 | UiccSlotInfo[] slotInfos = getUiccSlotsInfo(); |
| 8914 | for (int i = 0; i < slotInfos.length; i++) { |
| 8915 | if (SubscriptionManager.isValidPhoneId(slotInfos[i].getLogicalSlotIdx())) { |
| 8916 | logicalSlotsMapping[slotInfos[i].getLogicalSlotIdx()] = i; |
| 8917 | } |
| 8918 | } |
| 8919 | return logicalSlotsMapping; |
| 8920 | } finally { |
| 8921 | Binder.restoreCallingIdentity(identity); |
| 8922 | } |
| 8923 | } |
Nathan Harold | 48d6fd5 | 2019-02-06 19:01:40 -0800 | [diff] [blame] | 8924 | |
| 8925 | /** |
| 8926 | * Get the IRadio HAL Version |
| 8927 | */ |
| 8928 | @Override |
| 8929 | public int getRadioHalVersion() { |
| 8930 | Phone phone = getDefaultPhone(); |
| 8931 | if (phone == null) return -1; |
| 8932 | HalVersion hv = phone.getHalVersion(); |
| 8933 | if (hv.equals(HalVersion.UNKNOWN)) return -1; |
| 8934 | return hv.major * 100 + hv.minor; |
| 8935 | } |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8936 | |
| 8937 | /** |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 8938 | * Get the current calling package name. |
| 8939 | * @return the current calling package name |
| 8940 | */ |
| 8941 | @Override |
| 8942 | public String getCurrentPackageName() { |
| 8943 | return mApp.getPackageManager().getPackagesForUid(Binder.getCallingUid())[0]; |
| 8944 | } |
| 8945 | |
| 8946 | /** |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8947 | * Return whether data is enabled for certain APN type. This will tell if framework will accept |
| 8948 | * corresponding network requests on a subId. |
| 8949 | * |
| 8950 | * Data is enabled if: |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8951 | * 1) user data is turned on, or |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8952 | * 2) APN is un-metered for this subscription, or |
| 8953 | * 3) APN type is whitelisted. E.g. MMS is whitelisted if |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 8954 | * {@link TelephonyManager#MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED} is enabled. |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8955 | * |
| 8956 | * @return whether data is allowed for a apn type. |
| 8957 | * |
| 8958 | * @hide |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8959 | */ |
| 8960 | @Override |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8961 | public boolean isDataEnabledForApn(int apnType, int subId, String callingPackage) { |
Amit Mahajan | 5d4e192 | 2019-10-07 16:20:43 -0700 | [diff] [blame] | 8962 | enforceReadPrivilegedPermission("Needs READ_PRIVILEGED_PHONE_STATE for " |
| 8963 | + "isDataEnabledForApn"); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8964 | |
| 8965 | // Now that all security checks passes, perform the operation as ourselves. |
| 8966 | final long identity = Binder.clearCallingIdentity(); |
| 8967 | try { |
| 8968 | Phone phone = getPhone(subId); |
| 8969 | if (phone == null) return false; |
| 8970 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8971 | boolean isMetered = ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8972 | return !isMetered || phone.getDataEnabledSettings().isDataEnabled(apnType); |
| 8973 | } finally { |
| 8974 | Binder.restoreCallingIdentity(identity); |
| 8975 | } |
| 8976 | } |
| 8977 | |
| 8978 | @Override |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8979 | public boolean isApnMetered(@ApnType int apnType, int subId) { |
Malcolm Chen | e5ad579 | 2019-04-18 13:51:02 -0700 | [diff] [blame] | 8980 | enforceReadPrivilegedPermission("isApnMetered"); |
| 8981 | |
| 8982 | // Now that all security checks passes, perform the operation as ourselves. |
| 8983 | final long identity = Binder.clearCallingIdentity(); |
| 8984 | try { |
| 8985 | Phone phone = getPhone(subId); |
| 8986 | if (phone == null) return true; // By default return true. |
| 8987 | |
Jack Yu | 41407ee | 2019-05-13 16:54:09 -0700 | [diff] [blame] | 8988 | return ApnSettingUtils.isMeteredApnType(apnType, phone); |
Malcolm Chen | dc8c10e | 2019-04-10 18:25:07 -0700 | [diff] [blame] | 8989 | } finally { |
| 8990 | Binder.restoreCallingIdentity(identity); |
| 8991 | } |
| 8992 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 8993 | |
| 8994 | @Override |
Hall Liu | 73f5d36 | 2020-01-20 13:42:00 -0800 | [diff] [blame] | 8995 | public void setSystemSelectionChannels(List<RadioAccessSpecifier> specifiers, |
| 8996 | int subscriptionId, IBooleanConsumer resultCallback) { |
| 8997 | enforceModifyPermission(); |
| 8998 | long token = Binder.clearCallingIdentity(); |
| 8999 | try { |
| 9000 | Phone phone = getPhone(subscriptionId); |
| 9001 | if (phone == null) { |
| 9002 | try { |
| 9003 | if (resultCallback != null) { |
| 9004 | resultCallback.accept(false); |
| 9005 | } |
| 9006 | } catch (RemoteException e) { |
| 9007 | // ignore |
| 9008 | } |
| 9009 | return; |
| 9010 | } |
| 9011 | Pair<List<RadioAccessSpecifier>, Consumer<Boolean>> argument = |
| 9012 | Pair.create(specifiers, (x) -> { |
| 9013 | try { |
| 9014 | if (resultCallback != null) { |
| 9015 | resultCallback.accept(x); |
| 9016 | } |
| 9017 | } catch (RemoteException e) { |
| 9018 | // ignore |
| 9019 | } |
| 9020 | }); |
| 9021 | sendRequestAsync(CMD_SET_SYSTEM_SELECTION_CHANNELS, argument, phone, null); |
| 9022 | } finally { |
| 9023 | Binder.restoreCallingIdentity(token); |
| 9024 | } |
| 9025 | } |
| 9026 | |
| 9027 | @Override |
Sarah Chin | 679c08a | 2020-11-18 13:39:35 -0800 | [diff] [blame] | 9028 | public List<RadioAccessSpecifier> getSystemSelectionChannels(int subId) { |
| 9029 | TelephonyPermissions |
| 9030 | .enforeceCallingOrSelfReadPrivilegedPhoneStatePermissionOrCarrierPrivilege( |
| 9031 | mApp, subId, "getSystemSelectionChannels"); |
| 9032 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9033 | final long identity = Binder.clearCallingIdentity(); |
| 9034 | try { |
| 9035 | List<RadioAccessSpecifier> specifiers = |
| 9036 | (List<RadioAccessSpecifier>) sendRequest(CMD_GET_SYSTEM_SELECTION_CHANNELS, |
| 9037 | null, subId, workSource); |
| 9038 | if (DBG) log("getSystemSelectionChannels: " + specifiers); |
| 9039 | return specifiers; |
| 9040 | } finally { |
| 9041 | Binder.restoreCallingIdentity(identity); |
| 9042 | } |
| 9043 | } |
| 9044 | |
| 9045 | @Override |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9046 | public boolean isMvnoMatched(int subId, int mvnoType, @NonNull String mvnoMatchData) { |
changbetty | ca3d40d | 2020-03-03 16:27:31 +0800 | [diff] [blame] | 9047 | enforceReadPrivilegedPermission("isMvnoMatched"); |
changbetty | 7157e9e | 2019-12-06 18:16:37 +0800 | [diff] [blame] | 9048 | IccRecords iccRecords = UiccController.getInstance().getIccRecords( |
| 9049 | SubscriptionManager.getPhoneId(subId), UiccController.APP_FAM_3GPP); |
| 9050 | if (iccRecords == null) { |
| 9051 | Log.d(LOG_TAG, "isMvnoMatched# IccRecords is null"); |
| 9052 | return false; |
| 9053 | } |
| 9054 | return ApnSettingUtils.mvnoMatches(iccRecords, mvnoType, mvnoMatchData); |
| 9055 | } |
| 9056 | |
| 9057 | @Override |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9058 | public void enqueueSmsPickResult(String callingPackage, String callingAttributionTag, |
| 9059 | IIntegerConsumer pendingSubIdResult) { |
Shuo Qian | da2d6ec | 2020-01-14 15:18:28 -0800 | [diff] [blame] | 9060 | if (callingPackage == null) { |
| 9061 | callingPackage = getCurrentPackageName(); |
| 9062 | } |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9063 | SmsPermissions permissions = new SmsPermissions(getDefaultPhone(), mApp, |
| 9064 | (AppOpsManager) mApp.getSystemService(Context.APP_OPS_SERVICE)); |
Philip P. Moltmann | d02b737 | 2020-03-18 17:06:12 -0700 | [diff] [blame] | 9065 | if (!permissions.checkCallingCanSendSms(callingPackage, callingAttributionTag, |
| 9066 | "Sending message")) { |
Brad Ebinger | a63db5f | 2019-04-23 16:31:13 -0700 | [diff] [blame] | 9067 | throw new SecurityException("Requires SEND_SMS permission to perform this operation"); |
| 9068 | } |
| 9069 | PickSmsSubscriptionActivity.addPendingResult(pendingSubIdResult); |
| 9070 | Intent intent = new Intent(); |
| 9071 | intent.setClass(mApp, PickSmsSubscriptionActivity.class); |
| 9072 | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| 9073 | // Bring up choose default SMS subscription dialog right now |
| 9074 | intent.putExtra(PickSmsSubscriptionActivity.DIALOG_TYPE_KEY, |
| 9075 | PickSmsSubscriptionActivity.SMS_PICK_FOR_MESSAGE); |
| 9076 | mApp.startActivity(intent); |
| 9077 | } |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9078 | |
| 9079 | @Override |
| 9080 | public String getMmsUAProfUrl(int subId) { |
| 9081 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9082 | final long identity = Binder.clearCallingIdentity(); |
| 9083 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9084 | String carrierUAProfUrl = mApp.getCarrierConfigForSubId(subId).getString( |
| 9085 | CarrierConfigManager.KEY_MMS_UA_PROF_URL_STRING); |
| 9086 | if (!TextUtils.isEmpty(carrierUAProfUrl)) { |
| 9087 | return carrierUAProfUrl; |
| 9088 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9089 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9090 | .getString(com.android.internal.R.string.config_mms_user_agent_profile_url); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9091 | } finally { |
| 9092 | Binder.restoreCallingIdentity(identity); |
| 9093 | } |
| 9094 | } |
| 9095 | |
| 9096 | @Override |
| 9097 | public String getMmsUserAgent(int subId) { |
| 9098 | //TODO investigate if this API should require proper permission check in R b/133791609 |
| 9099 | final long identity = Binder.clearCallingIdentity(); |
| 9100 | try { |
Guoqiang.Qiu | 171383d | 2020-07-13 09:38:32 +0800 | [diff] [blame] | 9101 | String carrierUserAgent = mApp.getCarrierConfigForSubId(subId).getString( |
| 9102 | CarrierConfigManager.KEY_MMS_USER_AGENT_STRING); |
| 9103 | if (!TextUtils.isEmpty(carrierUserAgent)) { |
| 9104 | return carrierUserAgent; |
| 9105 | } |
Daniel Bright | ebb4eb7 | 2020-02-18 15:16:33 -0800 | [diff] [blame] | 9106 | return SubscriptionManager.getResourcesForSubId(getDefaultPhone().getContext(), subId) |
| 9107 | .getString(com.android.internal.R.string.config_mms_user_agent); |
chen xu | d5ca2d5 | 2019-05-28 15:20:57 -0700 | [diff] [blame] | 9108 | } finally { |
| 9109 | Binder.restoreCallingIdentity(identity); |
| 9110 | } |
| 9111 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9112 | |
| 9113 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9114 | public boolean isMobileDataPolicyEnabled(int subscriptionId, int policy) { |
| 9115 | enforceReadPrivilegedPermission("isMobileDataPolicyEnabled"); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9116 | |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9117 | final long identity = Binder.clearCallingIdentity(); |
| 9118 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9119 | Phone phone = getPhone(subscriptionId); |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9120 | if (phone == null) return false; |
| 9121 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9122 | switch (policy) { |
| 9123 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9124 | return phone.getDataEnabledSettings().isDataAllowedInVoiceCall(); |
| 9125 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9126 | return phone.getDataEnabledSettings().isMmsAlwaysAllowed(); |
| 9127 | default: |
| 9128 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9129 | } |
Jack Yu | b07d497 | 2019-05-28 16:12:25 -0700 | [diff] [blame] | 9130 | } finally { |
| 9131 | Binder.restoreCallingIdentity(identity); |
| 9132 | } |
| 9133 | } |
| 9134 | |
| 9135 | @Override |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9136 | public void setMobileDataPolicyEnabledStatus(int subscriptionId, int policy, |
| 9137 | boolean enabled) { |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9138 | enforceModifyPermission(); |
| 9139 | |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9140 | final long identity = Binder.clearCallingIdentity(); |
| 9141 | try { |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9142 | Phone phone = getPhone(subscriptionId); |
| 9143 | if (phone == null) return; |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9144 | |
Hall Liu | a62f5da | 2020-09-25 10:42:19 -0700 | [diff] [blame] | 9145 | switch (policy) { |
| 9146 | case TelephonyManager.MOBILE_DATA_POLICY_DATA_ON_NON_DEFAULT_DURING_VOICE_CALL: |
| 9147 | phone.getDataEnabledSettings().setAllowDataDuringVoiceCall(enabled); |
| 9148 | break; |
| 9149 | case TelephonyManager.MOBILE_DATA_POLICY_MMS_ALWAYS_ALLOWED: |
| 9150 | phone.getDataEnabledSettings().setAlwaysAllowMmsData(enabled); |
| 9151 | break; |
| 9152 | default: |
| 9153 | throw new IllegalArgumentException(policy + " is not a valid policy"); |
| 9154 | } |
changbetty | d5c246e | 2019-12-24 15:40:37 +0800 | [diff] [blame] | 9155 | } finally { |
| 9156 | Binder.restoreCallingIdentity(identity); |
| 9157 | } |
| 9158 | } |
| 9159 | |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9160 | /** |
Hall Liu | 746e03c | 2020-09-25 11:13:49 -0700 | [diff] [blame] | 9161 | * Updates whether conference event package handling is enabled. |
Tyler Gunn | 7bcdc74 | 2019-10-04 15:56:59 -0700 | [diff] [blame] | 9162 | * @param isCepEnabled {@code true} if CEP handling is enabled (default), or {@code false} |
| 9163 | * otherwise. |
| 9164 | */ |
| 9165 | @Override |
| 9166 | public void setCepEnabled(boolean isCepEnabled) { |
| 9167 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), "setCepEnabled"); |
| 9168 | |
| 9169 | final long identity = Binder.clearCallingIdentity(); |
| 9170 | try { |
| 9171 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled); |
| 9172 | for (Phone phone : PhoneFactory.getPhones()) { |
| 9173 | Phone defaultPhone = phone.getImsPhone(); |
| 9174 | if (defaultPhone != null && defaultPhone.getPhoneType() == PHONE_TYPE_IMS) { |
| 9175 | ImsPhone imsPhone = (ImsPhone) defaultPhone; |
| 9176 | ImsPhoneCallTracker imsPhoneCallTracker = |
| 9177 | (ImsPhoneCallTracker) imsPhone.getCallTracker(); |
| 9178 | imsPhoneCallTracker.setConferenceEventPackageEnabled(isCepEnabled); |
| 9179 | Rlog.i(LOG_TAG, "setCepEnabled isCepEnabled=" + isCepEnabled + ", for imsPhone " |
| 9180 | + imsPhone.getMsisdn()); |
| 9181 | } |
| 9182 | } |
| 9183 | } finally { |
| 9184 | Binder.restoreCallingIdentity(identity); |
| 9185 | } |
| 9186 | } |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9187 | |
| 9188 | /** |
| 9189 | * Notify that an RCS autoconfiguration XML file has been received for provisioning. |
| 9190 | * |
| 9191 | * @param config The XML file to be read. ASCII/UTF8 encoded text if not compressed. |
| 9192 | * @param isCompressed The XML file is compressed in gzip format and must be decompressed |
| 9193 | * before being read. |
| 9194 | */ |
| 9195 | @Override |
| 9196 | public void notifyRcsAutoConfigurationReceived(int subId, @NonNull byte[] config, boolean |
| 9197 | isCompressed) { |
| 9198 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9199 | mApp, subId, "notifyRcsAutoConfigurationReceived"); |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9200 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9201 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9202 | } |
| 9203 | if (!isImsAvailableOnDevice()) { |
| 9204 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9205 | "IMS not available on device."); |
| 9206 | } |
| 9207 | |
| 9208 | final long identity = Binder.clearCallingIdentity(); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9209 | try { |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9210 | RcsProvisioningMonitor.getInstance().updateConfig(subId, config, isCompressed); |
| 9211 | } finally { |
| 9212 | Binder.restoreCallingIdentity(identity); |
allenwtsu | 46dcc57 | 2020-01-08 18:24:03 +0800 | [diff] [blame] | 9213 | } |
| 9214 | } |
zoey chen | e02881a | 2019-12-30 16:11:23 +0800 | [diff] [blame] | 9215 | |
| 9216 | @Override |
| 9217 | public boolean isIccLockEnabled(int subId) { |
| 9218 | enforceReadPrivilegedPermission("isIccLockEnabled"); |
| 9219 | |
| 9220 | // Now that all security checks passes, perform the operation as ourselves. |
| 9221 | final long identity = Binder.clearCallingIdentity(); |
| 9222 | try { |
| 9223 | Phone phone = getPhone(subId); |
| 9224 | if (phone != null && phone.getIccCard() != null) { |
| 9225 | return phone.getIccCard().getIccLockEnabled(); |
| 9226 | } else { |
| 9227 | return false; |
| 9228 | } |
| 9229 | } finally { |
| 9230 | Binder.restoreCallingIdentity(identity); |
| 9231 | } |
| 9232 | } |
| 9233 | |
| 9234 | /** |
| 9235 | * Set the ICC pin lock enabled or disabled. |
| 9236 | * |
| 9237 | * @return an integer representing the status of IccLock enabled or disabled in the following |
| 9238 | * three cases: |
| 9239 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if enabled or disabled IccLock |
| 9240 | * successfully. |
| 9241 | * - Positive number and zero for remaining password attempts. |
| 9242 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9243 | * |
| 9244 | */ |
| 9245 | @Override |
| 9246 | public int setIccLockEnabled(int subId, boolean enabled, String password) { |
| 9247 | enforceModifyPermission(); |
| 9248 | |
| 9249 | Phone phone = getPhone(subId); |
| 9250 | if (phone == null) { |
| 9251 | return 0; |
| 9252 | } |
| 9253 | // Now that all security checks passes, perform the operation as ourselves. |
| 9254 | final long identity = Binder.clearCallingIdentity(); |
| 9255 | try { |
| 9256 | int attemptsRemaining = (int) sendRequest(CMD_SET_ICC_LOCK_ENABLED, |
| 9257 | new Pair<Boolean, String>(enabled, password), phone, null); |
| 9258 | return attemptsRemaining; |
| 9259 | |
| 9260 | } catch (Exception e) { |
| 9261 | Log.e(LOG_TAG, "setIccLockEnabled. Exception e =" + e); |
| 9262 | } finally { |
| 9263 | Binder.restoreCallingIdentity(identity); |
| 9264 | } |
| 9265 | return 0; |
| 9266 | } |
| 9267 | |
| 9268 | /** |
| 9269 | * Change the ICC password used in ICC pin lock. |
| 9270 | * |
| 9271 | * @return an integer representing the status of IccLock changed in the following three cases: |
| 9272 | * - {@link TelephonyManager#CHANGE_ICC_LOCK_SUCCESS} if changed IccLock successfully. |
| 9273 | * - Positive number and zero for remaining password attempts. |
| 9274 | * - Negative number for other failure cases (such like enabling/disabling PIN failed). |
| 9275 | * |
| 9276 | */ |
| 9277 | @Override |
| 9278 | public int changeIccLockPassword(int subId, String oldPassword, String newPassword) { |
| 9279 | enforceModifyPermission(); |
| 9280 | |
| 9281 | Phone phone = getPhone(subId); |
| 9282 | if (phone == null) { |
| 9283 | return 0; |
| 9284 | } |
| 9285 | // Now that all security checks passes, perform the operation as ourselves. |
| 9286 | final long identity = Binder.clearCallingIdentity(); |
| 9287 | try { |
| 9288 | int attemptsRemaining = (int) sendRequest(CMD_CHANGE_ICC_LOCK_PASSWORD, |
| 9289 | new Pair<String, String>(oldPassword, newPassword), phone, null); |
| 9290 | return attemptsRemaining; |
| 9291 | |
| 9292 | } catch (Exception e) { |
| 9293 | Log.e(LOG_TAG, "changeIccLockPassword. Exception e =" + e); |
| 9294 | } finally { |
| 9295 | Binder.restoreCallingIdentity(identity); |
| 9296 | } |
| 9297 | return 0; |
| 9298 | } |
Peter Wang | dafb9ac | 2020-01-15 14:13:38 -0800 | [diff] [blame] | 9299 | |
| 9300 | /** |
| 9301 | * Request for receiving user activity notification |
| 9302 | */ |
| 9303 | @Override |
| 9304 | public void requestUserActivityNotification() { |
| 9305 | if (!mNotifyUserActivity.get() |
| 9306 | && !mMainThreadHandler.hasMessages(MSG_NOTIFY_USER_ACTIVITY)) { |
| 9307 | mNotifyUserActivity.set(true); |
| 9308 | } |
| 9309 | } |
| 9310 | |
| 9311 | /** |
| 9312 | * Called when userActivity is signalled in the power manager. |
| 9313 | * This is safe to call from any thread, with any window manager locks held or not. |
| 9314 | */ |
| 9315 | @Override |
| 9316 | public void userActivity() { |
| 9317 | // *************************************** |
| 9318 | // * Inherited from PhoneWindowManager * |
| 9319 | // *************************************** |
| 9320 | // THIS IS CALLED FROM DEEP IN THE POWER MANAGER |
| 9321 | // WITH ITS LOCKS HELD. |
| 9322 | // |
| 9323 | // This code must be VERY careful about the locks |
| 9324 | // it acquires. |
| 9325 | // In fact, the current code acquires way too many, |
| 9326 | // and probably has lurking deadlocks. |
| 9327 | |
| 9328 | if (Binder.getCallingUid() != Process.SYSTEM_UID) { |
| 9329 | throw new SecurityException("Only the OS may call notifyUserActivity()"); |
| 9330 | } |
| 9331 | |
| 9332 | if (mNotifyUserActivity.getAndSet(false)) { |
| 9333 | mMainThreadHandler.sendEmptyMessageDelayed(MSG_NOTIFY_USER_ACTIVITY, |
| 9334 | USER_ACTIVITY_NOTIFICATION_DELAY); |
| 9335 | } |
| 9336 | } |
Malcolm Chen | 4639c56 | 2020-04-13 11:59:40 -0700 | [diff] [blame] | 9337 | |
| 9338 | @Override |
| 9339 | public boolean canConnectTo5GInDsdsMode() { |
| 9340 | return mApp.getResources().getBoolean(R.bool.config_5g_connection_in_dsds_mode); |
| 9341 | } |
Jack Yu | d10cdd4 | 2020-09-28 20:28:01 -0700 | [diff] [blame] | 9342 | |
| 9343 | @Override |
| 9344 | public @NonNull List<String> getEquivalentHomePlmns(int subId, String callingPackage, |
| 9345 | String callingFeatureId) { |
| 9346 | if (!TelephonyPermissions.checkCallingOrSelfReadPhoneState( |
| 9347 | mApp, subId, callingPackage, callingFeatureId, "getEquivalentHomePlmns")) { |
| 9348 | throw new SecurityException("Requires READ_PHONE_STATE permission."); |
| 9349 | } |
| 9350 | |
| 9351 | Phone phone = getPhone(subId); |
| 9352 | if (phone == null) { |
| 9353 | throw new RuntimeException("phone is not available"); |
| 9354 | } |
| 9355 | // Now that all security checks passes, perform the operation as ourselves. |
| 9356 | final long identity = Binder.clearCallingIdentity(); |
| 9357 | try { |
| 9358 | return phone.getEquivalentHomePlmns(); |
| 9359 | } finally { |
| 9360 | Binder.restoreCallingIdentity(identity); |
| 9361 | } |
| 9362 | } |
Daniel Bright | 59e6731 | 2020-11-13 11:49:37 -0800 | [diff] [blame] | 9363 | |
| 9364 | @Override |
| 9365 | public boolean isRadioInterfaceCapabilitySupported( |
| 9366 | @NonNull @TelephonyManager.RadioInterfaceCapability String capability) { |
| 9367 | RadioInterfaceCapabilities radioInterfaceCapabilities = |
| 9368 | mPhoneConfigurationManager.getRadioInterfaceCapabilities(); |
| 9369 | if (radioInterfaceCapabilities == null) { |
| 9370 | throw new RuntimeException("radio interface capabilities are not available"); |
| 9371 | } else { |
| 9372 | return radioInterfaceCapabilities.isSupported(capability); |
| 9373 | } |
| 9374 | } |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9375 | |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9376 | @Override |
| 9377 | public void bootstrapAuthenticationRequest(int subId, int appType, Uri nafUrl, |
| 9378 | UaSecurityProtocolIdentifier securityProtocol, |
| 9379 | boolean forceBootStrapping, IBootstrapAuthenticationCallback callback) |
| 9380 | throws RemoteException { |
| 9381 | enforceModifyPermission(); |
| 9382 | if (DBG) { |
| 9383 | log("bootstrapAuthenticationRequest, subId:" + subId + ", appType:" |
| 9384 | + appType + ", NAF:" + nafUrl + ", sp:" + securityProtocol |
| 9385 | + ", forceBootStrapping:" + forceBootStrapping + ", callback:" + callback); |
| 9386 | } |
| 9387 | |
| 9388 | if (!SubscriptionManager.isValidSubscriptionId(subId) |
| 9389 | || appType < TelephonyManager.APPTYPE_UNKNOWN |
| 9390 | || appType > TelephonyManager.APPTYPE_ISIM |
| 9391 | || nafUrl == null || securityProtocol == null || callback == null) { |
| 9392 | Log.d(LOG_TAG, "bootstrapAuthenticationRequest failed due to invalid parameters"); |
| 9393 | if (callback != null) { |
| 9394 | try { |
| 9395 | callback.onAuthenticationFailure( |
| 9396 | 0, TelephonyManager.GBA_FAILURE_REASON_FEATURE_NOT_SUPPORTED); |
| 9397 | } catch (RemoteException exception) { |
| 9398 | log("Fail to notify onAuthenticationFailure due to " + exception); |
| 9399 | } |
| 9400 | return; |
| 9401 | } |
| 9402 | } |
| 9403 | |
| 9404 | final long token = Binder.clearCallingIdentity(); |
| 9405 | try { |
| 9406 | getGbaManager(subId).bootstrapAuthenticationRequest( |
| 9407 | new GbaAuthRequest(subId, appType, nafUrl, securityProtocol.toByteArray(), |
| 9408 | forceBootStrapping, callback)); |
| 9409 | } finally { |
| 9410 | Binder.restoreCallingIdentity(token); |
| 9411 | } |
| 9412 | } |
| 9413 | |
Jack Nudelman | b0b8764 | 2020-11-12 15:04:39 -0800 | [diff] [blame] | 9414 | /** |
| 9415 | * Attempts to set the radio power state for thermal reason. This does not guarantee that the |
| 9416 | * requested radio power state will actually be set. See {@link |
| 9417 | * PhoneInternalInterface#setRadioPowerForReason} for more details. |
| 9418 | * |
| 9419 | * @param subId the subscription ID of the phone requesting to set the radio power state. |
| 9420 | * @param enable {@code true} if trying to turn radio on. |
| 9421 | * @return {@code true} if phone setRadioPowerForReason was called. Otherwise, returns {@code |
| 9422 | * false}. |
| 9423 | */ |
| 9424 | private boolean setRadioPowerForThermal(int subId, boolean enable) { |
| 9425 | Phone phone = getPhone(subId); |
| 9426 | if (phone != null) { |
| 9427 | phone.setRadioPowerForReason(enable, Phone.RADIO_POWER_REASON_THERMAL); |
| 9428 | return true; |
| 9429 | } |
| 9430 | return false; |
| 9431 | } |
| 9432 | |
| 9433 | private int handleDataThrottlingRequest(int subId, |
| 9434 | DataThrottlingRequest dataThrottlingRequest) { |
| 9435 | // Ensure that radio is on. If not able to power on due to phone being unavailable, return |
| 9436 | // THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9437 | if (!setRadioPowerForThermal(subId, true)) { |
| 9438 | return TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9439 | } |
| 9440 | |
| 9441 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, true); |
| 9442 | |
| 9443 | int thermalMitigationResult = |
| 9444 | (int) sendRequest(CMD_SET_DATA_THROTTLING, dataThrottlingRequest, subId); |
| 9445 | if (thermalMitigationResult == SET_DATA_THROTTLING_MODEM_THREW_INVALID_PARAMS) { |
| 9446 | throw new IllegalArgumentException("modem returned INVALID_ARGUMENTS"); |
| 9447 | } |
| 9448 | return thermalMitigationResult; |
| 9449 | } |
| 9450 | |
| 9451 | /** |
| 9452 | * Thermal mitigation request to control functionalities at modem. |
| 9453 | * |
| 9454 | * @param subId the id of the subscription. |
| 9455 | * @param thermalMitigationRequest holds all necessary information to be passed down to modem. |
| 9456 | * |
| 9457 | * @return thermalMitigationResult enum as defined in android.telephony.Annotation. |
| 9458 | */ |
| 9459 | @Override |
| 9460 | @ThermalMitigationResult |
| 9461 | public int sendThermalMitigationRequest( |
| 9462 | int subId, |
| 9463 | ThermalMitigationRequest thermalMitigationRequest) throws IllegalArgumentException { |
| 9464 | enforceModifyPermission(); |
| 9465 | |
| 9466 | WorkSource workSource = getWorkSource(Binder.getCallingUid()); |
| 9467 | final long identity = Binder.clearCallingIdentity(); |
| 9468 | |
| 9469 | int thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_UNKNOWN_ERROR; |
| 9470 | try { |
| 9471 | int thermalMitigationAction = thermalMitigationRequest.getThermalMitigationAction(); |
| 9472 | switch (thermalMitigationAction) { |
| 9473 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_DATA_THROTTLING: |
| 9474 | thermalMitigationResult = |
| 9475 | handleDataThrottlingRequest(subId, |
| 9476 | thermalMitigationRequest.getDataThrottlingRequest()); |
| 9477 | break; |
| 9478 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY: |
| 9479 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9480 | throw new IllegalArgumentException("dataThrottlingRequest must be null for " |
| 9481 | + "ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_VOICE_ONLY"); |
| 9482 | } |
| 9483 | |
| 9484 | // Ensure that radio is on. If not able to power on due to phone being |
| 9485 | // unavailable, return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9486 | if (!setRadioPowerForThermal(subId, true)) { |
| 9487 | thermalMitigationResult = |
| 9488 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9489 | break; |
| 9490 | } |
| 9491 | |
| 9492 | setDataEnabledForReason(subId, TelephonyManager.DATA_ENABLED_REASON_THERMAL, |
| 9493 | false); |
| 9494 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9495 | break; |
| 9496 | case ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF: |
| 9497 | if (thermalMitigationRequest.getDataThrottlingRequest() != null) { |
| 9498 | throw new IllegalArgumentException("dataThrottlingRequest must be null for" |
| 9499 | + " ThermalMitigationRequest.THERMAL_MITIGATION_ACTION_RADIO_OFF"); |
| 9500 | } |
| 9501 | |
| 9502 | TelecomAccountRegistry registry = TelecomAccountRegistry.getInstance(null); |
| 9503 | if (registry != null) { |
| 9504 | TelephonyConnectionService service = |
| 9505 | registry.getTelephonyConnectionService(); |
| 9506 | Phone phone = getPhone(subId); |
| 9507 | if (phone == null) { |
| 9508 | thermalMitigationResult = |
| 9509 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9510 | break; |
| 9511 | } |
| 9512 | |
| 9513 | if (PhoneConstantConversions.convertCallState(phone.getState()) |
| 9514 | != TelephonyManager.CALL_STATE_IDLE |
| 9515 | || phone.isInEmergencySmsMode() || phone.isInEcm() |
| 9516 | || (service != null && service.isEmergencyCallPending())) { |
| 9517 | String errorMessage = "Phone state is not valid. call state = " |
| 9518 | + PhoneConstantConversions.convertCallState(phone.getState()) |
| 9519 | + " isInEmergencySmsMode = " + phone.isInEmergencySmsMode() |
| 9520 | + " isInEmergencyCallbackMode = " + phone.isInEcm(); |
| 9521 | errorMessage += service == null |
| 9522 | ? " TelephonyConnectionService is null" |
| 9523 | : " isEmergencyCallPending = " |
| 9524 | + service.isEmergencyCallPending(); |
| 9525 | Log.e(LOG_TAG, errorMessage); |
| 9526 | thermalMitigationResult = |
| 9527 | TelephonyManager.THERMAL_MITIGATION_RESULT_INVALID_STATE; |
| 9528 | break; |
| 9529 | } |
| 9530 | } else { |
| 9531 | thermalMitigationResult = |
| 9532 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9533 | break; |
| 9534 | } |
| 9535 | |
| 9536 | // Turn radio off. If not able to power off due to phone being unavailable, |
| 9537 | // return THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE. |
| 9538 | if (!setRadioPowerForThermal(subId, false)) { |
| 9539 | thermalMitigationResult = |
| 9540 | TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_NOT_AVAILABLE; |
| 9541 | break; |
| 9542 | } |
| 9543 | thermalMitigationResult = |
| 9544 | TelephonyManager.THERMAL_MITIGATION_RESULT_SUCCESS; |
| 9545 | break; |
| 9546 | default: |
| 9547 | throw new IllegalArgumentException("the requested thermalMitigationAction does " |
| 9548 | + "not exist. Requested action: " + thermalMitigationAction); |
| 9549 | } |
| 9550 | } catch (IllegalArgumentException e) { |
| 9551 | throw e; |
| 9552 | } catch (Exception e) { |
| 9553 | Log.e(LOG_TAG, "thermalMitigationRequest. Exception e =" + e); |
| 9554 | thermalMitigationResult = TelephonyManager.THERMAL_MITIGATION_RESULT_MODEM_ERROR; |
| 9555 | } finally { |
| 9556 | Binder.restoreCallingIdentity(identity); |
| 9557 | } |
| 9558 | |
| 9559 | if (DBG) { |
| 9560 | log("thermalMitigationRequest returning with thermalMitigationResult: " |
| 9561 | + thermalMitigationResult); |
| 9562 | } |
| 9563 | |
| 9564 | return thermalMitigationResult; |
| 9565 | } |
Hui Wang | 641e81c | 2020-10-12 12:14:23 -0700 | [diff] [blame] | 9566 | |
| 9567 | /** |
| 9568 | * Set the GbaService Package Name that Telephony will bind to. |
| 9569 | * |
| 9570 | * @param subId The sim that the GbaService is associated with. |
| 9571 | * @param packageName The name of the package to be replaced with. |
| 9572 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9573 | */ |
| 9574 | @Override |
| 9575 | public boolean setBoundGbaServiceOverride(int subId, String packageName) { |
| 9576 | enforceModifyPermission(); |
| 9577 | |
| 9578 | final long identity = Binder.clearCallingIdentity(); |
| 9579 | try { |
| 9580 | return getGbaManager(subId).overrideServicePackage(packageName); |
| 9581 | } finally { |
| 9582 | Binder.restoreCallingIdentity(identity); |
| 9583 | } |
| 9584 | } |
| 9585 | |
| 9586 | /** |
| 9587 | * Return the package name of the currently bound GbaService. |
| 9588 | * |
| 9589 | * @param subId The sim that the GbaService is associated with. |
| 9590 | * @return the package name of the GbaService configuration, null if GBA is not supported. |
| 9591 | */ |
| 9592 | @Override |
| 9593 | public String getBoundGbaService(int subId) { |
| 9594 | enforceReadPrivilegedPermission("getBoundGbaServicePackage"); |
| 9595 | |
| 9596 | final long identity = Binder.clearCallingIdentity(); |
| 9597 | try { |
| 9598 | return getGbaManager(subId).getServicePackage(); |
| 9599 | } finally { |
| 9600 | Binder.restoreCallingIdentity(identity); |
| 9601 | } |
| 9602 | } |
| 9603 | |
| 9604 | /** |
| 9605 | * Set the release time for telephony to unbind GbaService. |
| 9606 | * |
| 9607 | * @param subId The sim that the GbaService is associated with. |
| 9608 | * @param interval The release time to unbind GbaService by millisecond. |
| 9609 | * @return true if setting the GbaService to bind to succeeded, false if it did not. |
| 9610 | */ |
| 9611 | @Override |
| 9612 | public boolean setGbaReleaseTimeOverride(int subId, int interval) { |
| 9613 | enforceModifyPermission(); |
| 9614 | |
| 9615 | final long identity = Binder.clearCallingIdentity(); |
| 9616 | try { |
| 9617 | return getGbaManager(subId).overrideReleaseTime(interval); |
| 9618 | } finally { |
| 9619 | Binder.restoreCallingIdentity(identity); |
| 9620 | } |
| 9621 | } |
| 9622 | |
| 9623 | /** |
| 9624 | * Return the release time for telephony to unbind GbaService. |
| 9625 | * |
| 9626 | * @param subId The sim that the GbaService is associated with. |
| 9627 | * @return The release time to unbind GbaService by millisecond. |
| 9628 | */ |
| 9629 | @Override |
| 9630 | public int getGbaReleaseTime(int subId) { |
| 9631 | enforceReadPrivilegedPermission("getGbaReleaseTime"); |
| 9632 | |
| 9633 | final long identity = Binder.clearCallingIdentity(); |
| 9634 | try { |
| 9635 | return getGbaManager(subId).getReleaseTime(); |
| 9636 | } finally { |
| 9637 | Binder.restoreCallingIdentity(identity); |
| 9638 | } |
| 9639 | } |
| 9640 | |
| 9641 | private GbaManager getGbaManager(int subId) { |
| 9642 | GbaManager instance = GbaManager.getInstance(subId); |
| 9643 | if (instance == null) { |
| 9644 | String packageName = mApp.getResources().getString(R.string.config_gba_package); |
| 9645 | int releaseTime = mApp.getResources().getInteger(R.integer.config_gba_release_time); |
| 9646 | instance = GbaManager.make(mApp, subId, packageName, releaseTime); |
| 9647 | } |
| 9648 | return instance; |
| 9649 | } |
Hui Wang | 761a668 | 2020-10-31 05:12:53 +0000 | [diff] [blame] | 9650 | |
| 9651 | /** |
| 9652 | * indicate whether the device and the carrier can support |
| 9653 | * RCS VoLTE single registration. |
| 9654 | */ |
| 9655 | @Override |
| 9656 | public boolean isRcsVolteSingleRegistrationCapable(int subId) { |
| 9657 | enforceReadPrivilegedPermission("isRcsVolteSingleRegistrationCapable"); |
| 9658 | |
| 9659 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9660 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9661 | } |
| 9662 | |
| 9663 | final long identity = Binder.clearCallingIdentity(); |
| 9664 | try { |
| 9665 | RcsProvisioningMonitor rpm = RcsProvisioningMonitor.getInstance(); |
| 9666 | if (rpm != null) { |
| 9667 | return rpm.isRcsVolteSingleRegistrationEnabled(subId); |
| 9668 | } |
| 9669 | return false; |
| 9670 | } finally { |
| 9671 | Binder.restoreCallingIdentity(identity); |
| 9672 | } |
| 9673 | } |
| 9674 | |
| 9675 | /** |
| 9676 | * Register RCS provisioning callback. |
| 9677 | */ |
| 9678 | @Override |
| 9679 | public void registerRcsProvisioningChangedCallback(int subId, |
| 9680 | IRcsConfigCallback callback) { |
| 9681 | enforceReadPrivilegedPermission("registerRcsProvisioningChangedCallback"); |
| 9682 | |
| 9683 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9684 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9685 | } |
| 9686 | if (!isImsAvailableOnDevice()) { |
| 9687 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9688 | "IMS not available on device."); |
| 9689 | } |
| 9690 | |
| 9691 | final long identity = Binder.clearCallingIdentity(); |
| 9692 | try { |
| 9693 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 9694 | .addRcsProvisioningCallbackForSubscription(callback, subId); |
| 9695 | } catch (ImsException e) { |
| 9696 | throw new ServiceSpecificException(e.getCode()); |
| 9697 | } finally { |
| 9698 | Binder.restoreCallingIdentity(identity); |
| 9699 | } |
| 9700 | } |
| 9701 | |
| 9702 | /** |
| 9703 | * Unregister RCS provisioning callback. |
| 9704 | */ |
| 9705 | @Override |
| 9706 | public void unregisterRcsProvisioningChangedCallback(int subId, |
| 9707 | IRcsConfigCallback callback) { |
| 9708 | enforceReadPrivilegedPermission("unregisterRcsProvisioningChangedCallback"); |
| 9709 | |
| 9710 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9711 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9712 | } |
| 9713 | if (!isImsAvailableOnDevice()) { |
| 9714 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9715 | "IMS not available on device."); |
| 9716 | } |
| 9717 | |
| 9718 | final long identity = Binder.clearCallingIdentity(); |
| 9719 | try { |
| 9720 | ImsManager.getInstance(mApp, getSlotIndexOrException(subId)) |
| 9721 | .removeRcsProvisioningCallbackForSubscription(callback, subId); |
| 9722 | } catch (ImsException e) { |
| 9723 | Log.i(LOG_TAG, "unregisterRcsProvisioningChangedCallback: " + subId |
| 9724 | + "is inactive, ignoring unregister."); |
| 9725 | } finally { |
| 9726 | Binder.restoreCallingIdentity(identity); |
| 9727 | } |
| 9728 | } |
| 9729 | |
| 9730 | /** |
| 9731 | * trigger RCS reconfiguration. |
| 9732 | */ |
| 9733 | public void triggerRcsReconfiguration(int subId) { |
| 9734 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9735 | mApp, subId, "triggerRcsReconfiguration"); |
| 9736 | |
| 9737 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9738 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9739 | } |
| 9740 | if (!isImsAvailableOnDevice()) { |
| 9741 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9742 | "IMS not available on device."); |
| 9743 | } |
| 9744 | |
| 9745 | final long identity = Binder.clearCallingIdentity(); |
| 9746 | try { |
| 9747 | RcsProvisioningMonitor.getInstance().requestReconfig(subId); |
| 9748 | } finally { |
| 9749 | Binder.restoreCallingIdentity(identity); |
| 9750 | } |
| 9751 | } |
| 9752 | |
| 9753 | /** |
| 9754 | * Provide the client configuration parameters of the RCS application. |
| 9755 | */ |
| 9756 | public void setRcsClientConfiguration(int subId, RcsClientConfiguration rcc) { |
| 9757 | TelephonyPermissions.enforceCallingOrSelfModifyPermissionOrCarrierPrivilege( |
| 9758 | mApp, subId, "setRcsClientConfiguration"); |
| 9759 | |
| 9760 | if (!SubscriptionManager.isValidSubscriptionId(subId)) { |
| 9761 | throw new IllegalArgumentException("Invalid Subscription ID: " + subId); |
| 9762 | } |
| 9763 | if (!isImsAvailableOnDevice()) { |
| 9764 | throw new ServiceSpecificException(ImsException.CODE_ERROR_UNSUPPORTED_OPERATION, |
| 9765 | "IMS not available on device."); |
| 9766 | } |
| 9767 | |
| 9768 | final long identity = Binder.clearCallingIdentity(); |
| 9769 | |
| 9770 | try { |
| 9771 | IImsConfig configBinder = getImsConfig(getSlotIndex(subId), ImsFeature.FEATURE_RCS); |
| 9772 | if (configBinder == null) { |
| 9773 | Rlog.e(LOG_TAG, "null result for setRcsClientConfiguration"); |
| 9774 | } else { |
| 9775 | configBinder.setRcsClientConfiguration(rcc); |
| 9776 | } |
| 9777 | } catch (RemoteException e) { |
| 9778 | Rlog.e(LOG_TAG, "fail to setRcsClientConfiguration " + e.getMessage()); |
| 9779 | } finally { |
| 9780 | Binder.restoreCallingIdentity(identity); |
| 9781 | } |
| 9782 | } |
| 9783 | |
| 9784 | /** |
| 9785 | * Overrides the config of RCS VoLTE single registration enabled for the device. |
| 9786 | */ |
| 9787 | @Override |
| 9788 | public void setDeviceSingleRegistrationEnabledOverride(String enabledStr) { |
| 9789 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9790 | "setDeviceSingleRegistrationEnabledOverride"); |
| 9791 | enforceModifyPermission(); |
| 9792 | |
| 9793 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9794 | : Boolean.parseBoolean(enabledStr); |
| 9795 | RcsProvisioningMonitor.getInstance().overrideDeviceSingleRegistrationEnabled(enabled); |
| 9796 | } |
| 9797 | |
| 9798 | /** |
| 9799 | * Gets the config of RCS VoLTE single registration enabled for the device. |
| 9800 | */ |
| 9801 | @Override |
| 9802 | public boolean getDeviceSingleRegistrationEnabled() { |
| 9803 | enforceReadPrivilegedPermission("getDeviceSingleRegistrationEnabled"); |
| 9804 | return RcsProvisioningMonitor.getInstance().getDeviceSingleRegistrationEnabled(); |
| 9805 | } |
| 9806 | |
| 9807 | /** |
| 9808 | * Overrides the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9809 | */ |
| 9810 | @Override |
| 9811 | public boolean setCarrierSingleRegistrationEnabledOverride(int subId, String enabledStr) { |
| 9812 | TelephonyPermissions.enforceShellOnly(Binder.getCallingUid(), |
| 9813 | "setCarrierSingleRegistrationEnabledOverride"); |
| 9814 | enforceModifyPermission(); |
| 9815 | |
| 9816 | Boolean enabled = "NULL".equalsIgnoreCase(enabledStr) ? null |
| 9817 | : Boolean.parseBoolean(enabledStr); |
| 9818 | return RcsProvisioningMonitor.getInstance().overrideCarrierSingleRegistrationEnabled( |
| 9819 | subId, enabled); |
| 9820 | } |
| 9821 | |
| 9822 | /** |
| 9823 | * Gets the config of RCS VoLTE single registration enabled for the carrier/subscription. |
| 9824 | */ |
| 9825 | @Override |
| 9826 | public boolean getCarrierSingleRegistrationEnabled(int subId) { |
| 9827 | enforceReadPrivilegedPermission("getCarrierSingleRegistrationEnabled"); |
| 9828 | return RcsProvisioningMonitor.getInstance().getCarrierSingleRegistrationEnabled(subId); |
| 9829 | } |
Chiachang Wang | d6d3477 | 2020-12-22 11:38:27 +0800 | [diff] [blame] | 9830 | |
| 9831 | /** |
| 9832 | * Get the mobile provisioning url that is used to launch a browser to allow users to manage |
| 9833 | * their mobile plan. |
| 9834 | */ |
| 9835 | @Override |
| 9836 | public String getMobileProvisioningUrl() { |
| 9837 | enforceReadPrivilegedPermission("getMobileProvisioningUrl"); |
| 9838 | final long identity = Binder.clearCallingIdentity(); |
| 9839 | try { |
| 9840 | return getDefaultPhone().getMobileProvisioningUrl(); |
| 9841 | } finally { |
| 9842 | Binder.restoreCallingIdentity(identity); |
| 9843 | } |
| 9844 | } |
Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 9845 | } |