1 /* 2 * Copyright (C) 2019 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.systemui.classifier; 18 19 import android.content.Context; 20 import android.net.Uri; 21 import android.provider.DeviceConfig; 22 23 import androidx.annotation.NonNull; 24 25 import com.android.systemui.Dumpable; 26 import com.android.systemui.dagger.SysUISingleton; 27 import com.android.systemui.dagger.qualifiers.Main; 28 import com.android.systemui.dump.DumpManager; 29 import com.android.systemui.plugins.FalsingManager; 30 import com.android.systemui.plugins.FalsingPlugin; 31 import com.android.systemui.plugins.PluginListener; 32 import com.android.systemui.plugins.PluginManager; 33 import com.android.systemui.util.DeviceConfigProxy; 34 35 import java.io.PrintWriter; 36 import java.util.concurrent.Executor; 37 38 import javax.inject.Inject; 39 import javax.inject.Provider; 40 41 /** 42 * Simple passthrough implementation of {@link FalsingManager} allowing plugins to swap in. 43 * 44 * {@link BrightLineFalsingManager} is used when a Plugin is not loaded. 45 */ 46 @SysUISingleton 47 public class FalsingManagerProxy implements FalsingManager, Dumpable { 48 49 private static final String DUMPABLE_TAG = "FalsingManager"; 50 public static final String FALSING_REMAIN_LOCKED = "falsing_failure_after_attempts"; 51 public static final String FALSING_SUCCESS = "falsing_success_after_attempts"; 52 53 private final PluginManager mPluginManager; 54 private final DeviceConfigProxy mDeviceConfig; 55 private final Provider<BrightLineFalsingManager> mBrightLineFalsingManagerProvider; 56 private final DumpManager mDumpManager; 57 final PluginListener<FalsingPlugin> mPluginListener; 58 59 private FalsingManager mInternalFalsingManager; 60 61 private final DeviceConfig.OnPropertiesChangedListener mDeviceConfigListener = 62 properties -> onDeviceConfigPropertiesChanged(properties.getNamespace()); 63 64 @Inject FalsingManagerProxy(PluginManager pluginManager, @Main Executor executor, DeviceConfigProxy deviceConfig, DumpManager dumpManager, Provider<BrightLineFalsingManager> brightLineFalsingManagerProvider)65 FalsingManagerProxy(PluginManager pluginManager, @Main Executor executor, 66 DeviceConfigProxy deviceConfig, DumpManager dumpManager, 67 Provider<BrightLineFalsingManager> brightLineFalsingManagerProvider) { 68 mPluginManager = pluginManager; 69 mDumpManager = dumpManager; 70 mDeviceConfig = deviceConfig; 71 mBrightLineFalsingManagerProvider = brightLineFalsingManagerProvider; 72 setupFalsingManager(); 73 mDeviceConfig.addOnPropertiesChangedListener( 74 DeviceConfig.NAMESPACE_SYSTEMUI, executor, mDeviceConfigListener 75 ); 76 77 mPluginListener = new PluginListener<FalsingPlugin>() { 78 public void onPluginConnected(FalsingPlugin plugin, Context context) { 79 FalsingManager pluginFalsingManager = plugin.getFalsingManager(context); 80 if (pluginFalsingManager != null) { 81 mInternalFalsingManager.cleanupInternal(); 82 mInternalFalsingManager = pluginFalsingManager; 83 } 84 } 85 86 public void onPluginDisconnected(FalsingPlugin plugin) { 87 setupFalsingManager(); 88 } 89 }; 90 91 mPluginManager.addPluginListener(mPluginListener, FalsingPlugin.class); 92 93 mDumpManager.registerDumpable(DUMPABLE_TAG, this); 94 } 95 onDeviceConfigPropertiesChanged(String namespace)96 private void onDeviceConfigPropertiesChanged(String namespace) { 97 if (!DeviceConfig.NAMESPACE_SYSTEMUI.equals(namespace)) { 98 return; 99 } 100 101 setupFalsingManager(); 102 } 103 104 /** 105 * Setup the FalsingManager implementation. 106 * 107 * If multiple implementations are available, this is where the choice is made. 108 */ setupFalsingManager()109 private void setupFalsingManager() { 110 if (mInternalFalsingManager != null) { 111 mInternalFalsingManager.cleanupInternal(); 112 } 113 mInternalFalsingManager = mBrightLineFalsingManagerProvider.get(); 114 } 115 116 @Override onSuccessfulUnlock()117 public void onSuccessfulUnlock() { 118 mInternalFalsingManager.onSuccessfulUnlock(); 119 } 120 121 @Override isUnlockingDisabled()122 public boolean isUnlockingDisabled() { 123 return mInternalFalsingManager.isUnlockingDisabled(); 124 } 125 126 @Override isFalseTouch(@lassifier.InteractionType int interactionType)127 public boolean isFalseTouch(@Classifier.InteractionType int interactionType) { 128 return mInternalFalsingManager.isFalseTouch(interactionType); 129 } 130 131 @Override isSimpleTap()132 public boolean isSimpleTap() { 133 return mInternalFalsingManager.isSimpleTap(); 134 } 135 136 @Override isFalseTap(@enalty int penalty)137 public boolean isFalseTap(@Penalty int penalty) { 138 return mInternalFalsingManager.isFalseTap(penalty); 139 } 140 141 @Override isFalseLongTap(int penalty)142 public boolean isFalseLongTap(int penalty) { 143 return mInternalFalsingManager.isFalseLongTap(penalty); 144 } 145 146 @Override isFalseDoubleTap()147 public boolean isFalseDoubleTap() { 148 return mInternalFalsingManager.isFalseDoubleTap(); 149 } 150 151 @Override isProximityNear()152 public boolean isProximityNear() { 153 return mInternalFalsingManager.isProximityNear(); 154 } 155 156 @Override isClassifierEnabled()157 public boolean isClassifierEnabled() { 158 return mInternalFalsingManager.isClassifierEnabled(); 159 } 160 161 @Override shouldEnforceBouncer()162 public boolean shouldEnforceBouncer() { 163 return mInternalFalsingManager.shouldEnforceBouncer(); 164 } 165 166 @Override reportRejectedTouch()167 public Uri reportRejectedTouch() { 168 return mInternalFalsingManager.reportRejectedTouch(); 169 } 170 171 @Override isReportingEnabled()172 public boolean isReportingEnabled() { 173 return mInternalFalsingManager.isReportingEnabled(); 174 } 175 176 @Override addFalsingBeliefListener(FalsingBeliefListener listener)177 public void addFalsingBeliefListener(FalsingBeliefListener listener) { 178 mInternalFalsingManager.addFalsingBeliefListener(listener); 179 } 180 181 @Override removeFalsingBeliefListener(FalsingBeliefListener listener)182 public void removeFalsingBeliefListener(FalsingBeliefListener listener) { 183 mInternalFalsingManager.removeFalsingBeliefListener(listener); 184 } 185 186 @Override addTapListener(FalsingTapListener listener)187 public void addTapListener(FalsingTapListener listener) { 188 mInternalFalsingManager.addTapListener(listener); 189 } 190 191 @Override removeTapListener(FalsingTapListener listener)192 public void removeTapListener(FalsingTapListener listener) { 193 mInternalFalsingManager.removeTapListener(listener); 194 } 195 196 @Override onProximityEvent(ProximityEvent proximityEvent)197 public void onProximityEvent(ProximityEvent proximityEvent) { 198 mInternalFalsingManager.onProximityEvent(proximityEvent); 199 } 200 201 @Override dump(@onNull PrintWriter pw, @NonNull String[] args)202 public void dump(@NonNull PrintWriter pw, @NonNull String[] args) { 203 mInternalFalsingManager.dump(pw, args); 204 } 205 206 @Override cleanupInternal()207 public void cleanupInternal() { 208 mDeviceConfig.removeOnPropertiesChangedListener(mDeviceConfigListener); 209 mPluginManager.removePluginListener(mPluginListener); 210 mDumpManager.unregisterDumpable(DUMPABLE_TAG); 211 mInternalFalsingManager.cleanupInternal(); 212 } 213 } 214