1 /* 2 * Copyright (C) 2021 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 static com.google.common.truth.Truth.assertWithMessage; 20 21 import android.net.Uri; 22 23 import com.android.internal.annotations.VisibleForTesting; 24 import com.android.systemui.plugins.FalsingManager; 25 26 import java.io.PrintWriter; 27 import java.util.ArrayList; 28 import java.util.List; 29 30 /** 31 * Simple Fake for testing where {@link FalsingManager} is required. 32 */ 33 public class FalsingManagerFake implements FalsingManager { 34 private boolean mIsFalseTouch; 35 private boolean mIsSimpleTap; 36 private boolean mIsFalseDoubleTap; 37 private boolean mIsUnlockingDisabled; 38 private boolean mIsClassifierEnabled; 39 private boolean mShouldEnforceBouncer; 40 private boolean mIsReportingEnabled; 41 private boolean mIsFalseRobustTap; 42 private boolean mIsFalseLongTap; 43 private boolean mDestroyed; 44 private boolean mIsProximityNear; 45 46 private final List<FalsingBeliefListener> mFalsingBeliefListeners = new ArrayList<>(); 47 private final List<FalsingTapListener> mTapListeners = new ArrayList<>(); 48 49 @Override onSuccessfulUnlock()50 public void onSuccessfulUnlock() { 51 52 } 53 54 @VisibleForTesting setIsUnlockingDisabled(boolean isUnlockingDisabled)55 public void setIsUnlockingDisabled(boolean isUnlockingDisabled) { 56 mIsUnlockingDisabled = isUnlockingDisabled; 57 } 58 59 @Override isUnlockingDisabled()60 public boolean isUnlockingDisabled() { 61 return mIsUnlockingDisabled; 62 } 63 64 @VisibleForTesting setIsFalseTouch(boolean isFalseTouch)65 public void setIsFalseTouch(boolean isFalseTouch) { 66 mIsFalseTouch = isFalseTouch; 67 } 68 69 @Override isFalseTouch(@lassifier.InteractionType int interactionType)70 public boolean isFalseTouch(@Classifier.InteractionType int interactionType) { 71 checkDestroyed(); 72 return mIsFalseTouch; 73 } 74 setFalseTap(boolean falseRobustTap)75 public void setFalseTap(boolean falseRobustTap) { 76 mIsFalseRobustTap = falseRobustTap; 77 } 78 setSimpleTap(boolean isSimpleTape)79 public void setSimpleTap(boolean isSimpleTape) { 80 mIsSimpleTap = isSimpleTape; 81 } 82 setFalseDoubleTap(boolean falseDoubleTap)83 public void setFalseDoubleTap(boolean falseDoubleTap) { 84 mIsFalseDoubleTap = falseDoubleTap; 85 } 86 setIsProximityNear(boolean proxNear)87 public void setIsProximityNear(boolean proxNear) { 88 mIsProximityNear = proxNear; 89 } 90 setFalseLongTap(boolean falseLongTap)91 public void setFalseLongTap(boolean falseLongTap) { 92 mIsFalseLongTap = falseLongTap; 93 } 94 95 @Override isSimpleTap()96 public boolean isSimpleTap() { 97 checkDestroyed(); 98 return mIsSimpleTap; 99 } 100 101 @Override isFalseTap(@enalty int penalty)102 public boolean isFalseTap(@Penalty int penalty) { 103 checkDestroyed(); 104 return mIsFalseRobustTap; 105 } 106 107 @Override isFalseLongTap(int penalty)108 public boolean isFalseLongTap(int penalty) { 109 checkDestroyed(); 110 return mIsFalseLongTap; 111 } 112 113 @Override isFalseDoubleTap()114 public boolean isFalseDoubleTap() { 115 checkDestroyed(); 116 return mIsFalseDoubleTap; 117 } 118 119 @Override isProximityNear()120 public boolean isProximityNear() { 121 return mIsProximityNear; 122 } 123 124 @VisibleForTesting setIsClassifierEnabled(boolean isClassifierEnabled)125 public void setIsClassifierEnabled(boolean isClassifierEnabled) { 126 mIsClassifierEnabled = isClassifierEnabled; 127 } 128 129 @Override isClassifierEnabled()130 public boolean isClassifierEnabled() { 131 return mIsClassifierEnabled; 132 } 133 134 @Override shouldEnforceBouncer()135 public boolean shouldEnforceBouncer() { 136 return mShouldEnforceBouncer; 137 } 138 139 @Override reportRejectedTouch()140 public Uri reportRejectedTouch() { 141 return null; 142 } 143 144 @VisibleForTesting setIsReportingEnabled(boolean isReportingEnabled)145 public void setIsReportingEnabled(boolean isReportingEnabled) { 146 mIsReportingEnabled = isReportingEnabled; 147 } 148 149 @Override isReportingEnabled()150 public boolean isReportingEnabled() { 151 return mIsReportingEnabled; 152 } 153 154 @Override dump(PrintWriter pw, String[] args)155 public void dump(PrintWriter pw, String[] args) { 156 } 157 158 @Override cleanupInternal()159 public void cleanupInternal() { 160 mDestroyed = true; 161 } 162 checkDestroyed()163 private void checkDestroyed() { 164 assertWithMessage("FakeFasingManager has been destroyed") 165 .that(mDestroyed).isFalse(); 166 } 167 168 @Override onProximityEvent(ProximityEvent proximityEvent)169 public void onProximityEvent(ProximityEvent proximityEvent) { 170 171 } 172 173 @Override addFalsingBeliefListener(FalsingBeliefListener listener)174 public void addFalsingBeliefListener(FalsingBeliefListener listener) { 175 mFalsingBeliefListeners.add(listener); 176 } 177 178 @Override removeFalsingBeliefListener(FalsingBeliefListener listener)179 public void removeFalsingBeliefListener(FalsingBeliefListener listener) { 180 mFalsingBeliefListeners.remove(listener); 181 } 182 183 @Override addTapListener(FalsingTapListener falsingTapListener)184 public void addTapListener(FalsingTapListener falsingTapListener) { 185 mTapListeners.add(falsingTapListener); 186 } 187 188 @Override removeTapListener(FalsingTapListener falsingTapListener)189 public void removeTapListener(FalsingTapListener falsingTapListener) { 190 mTapListeners.remove(falsingTapListener); 191 } 192 getTapListeners()193 public List<FalsingTapListener> getTapListeners() { 194 return mTapListeners; 195 } 196 } 197