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