blob: 685e7c534b660e705945dbffb2fdfdfaa77f7a3b [file] [log] [blame]
Dave Mankoff07fb7b72019-06-10 16:36:19 -04001/*
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
17package com.android.systemui.classifier.brightline;
18
19import android.hardware.SensorEvent;
20import android.view.MotionEvent;
21
22import com.android.systemui.classifier.Classifier;
23
24import java.util.List;
25
26/**
27 * Base class for rules that determine False touches.
28 */
29abstract class FalsingClassifier {
30 private final FalsingDataProvider mDataProvider;
31
32 FalsingClassifier(FalsingDataProvider dataProvider) {
33 this.mDataProvider = dataProvider;
34 }
35
36 List<MotionEvent> getRecentMotionEvents() {
37 return mDataProvider.getRecentMotionEvents();
38 }
39
40 MotionEvent getFirstMotionEvent() {
41 return mDataProvider.getFirstRecentMotionEvent();
42 }
43
44 MotionEvent getLastMotionEvent() {
45 return mDataProvider.getLastMotionEvent();
46 }
47
48 boolean isHorizontal() {
49 return mDataProvider.isHorizontal();
50 }
51
52 boolean isRight() {
53 return mDataProvider.isRight();
54 }
55
56 boolean isVertical() {
57 return mDataProvider.isVertical();
58 }
59
60 boolean isUp() {
61 return mDataProvider.isUp();
62 }
63
64 float getAngle() {
65 return mDataProvider.getAngle();
66 }
67
68 int getWidthPixels() {
Dave Mankoff65b57692019-06-12 14:55:00 -040069 return mDataProvider.getWidthPixels();
Dave Mankoff07fb7b72019-06-10 16:36:19 -040070 }
71
72 int getHeightPixels() {
Dave Mankoff65b57692019-06-12 14:55:00 -040073 return mDataProvider.getHeightPixels();
Dave Mankoff07fb7b72019-06-10 16:36:19 -040074 }
75
76 float getXdpi() {
Dave Mankoff65b57692019-06-12 14:55:00 -040077 return mDataProvider.getXdpi();
Dave Mankoff07fb7b72019-06-10 16:36:19 -040078 }
79
80 float getYdpi() {
Dave Mankoff65b57692019-06-12 14:55:00 -040081 return mDataProvider.getYdpi();
Dave Mankoff07fb7b72019-06-10 16:36:19 -040082 }
83
84 final @Classifier.InteractionType int getInteractionType() {
85 return mDataProvider.getInteractionType();
86 }
87
88 final void setInteractionType(@Classifier.InteractionType int interactionType) {
89 mDataProvider.setInteractionType(interactionType);
90 }
91
92 /**
93 * Called whenever a MotionEvent occurs.
94 *
95 * Useful for classifiers that need to see every MotionEvent, but most can probably
96 * use {@link #getRecentMotionEvents()} instead, which will return a list of MotionEvents.
97 */
98 void onTouchEvent(MotionEvent motionEvent) {};
99
100 /**
101 * Called whenever a SensorEvent occurs, specifically the ProximitySensor.
102 */
103 void onSensorEvent(SensorEvent sensorEvent) {};
104
105 /**
106 * The phone screen has turned on and we need to begin falsing detection.
107 */
108 void onSessionStarted() {};
109
110 /**
111 * The phone screen has turned off and falsing data can be discarded.
112 */
113 void onSessionEnded() {};
114
115 /**
116 * Returns true if the data captured so far looks like a false touch.
117 */
118 abstract boolean isFalseTouch();
119
120 static void logDebug(String msg) {
121 BrightLineFalsingManager.logDebug(msg);
122 }
123
124 static void logInfo(String msg) {
125 BrightLineFalsingManager.logInfo(msg);
126 }
127
128 static void logError(String msg) {
129 BrightLineFalsingManager.logError(msg);
130 }
131}