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.plugins; 18 19 import android.annotation.IntDef; 20 import android.net.Uri; 21 import android.view.MotionEvent; 22 23 import com.android.systemui.plugins.annotations.ProvidesInterface; 24 25 import java.io.PrintWriter; 26 import java.lang.annotation.Retention; 27 import java.lang.annotation.RetentionPolicy; 28 29 /** 30 * Interface that decides whether a touch on the phone was accidental. i.e. Pocket Dialing. 31 * 32 * {@see com.android.systemui.classifier.BrightLineFalsingManager} 33 */ 34 @ProvidesInterface(version = FalsingManager.VERSION) 35 public interface FalsingManager { 36 int VERSION = 6; 37 38 int NO_PENALTY = 0; 39 int LOW_PENALTY = 1; 40 int MODERATE_PENALTY = 2; 41 int HIGH_PENALTY = 3; 42 43 @IntDef({ 44 NO_PENALTY, 45 LOW_PENALTY, 46 MODERATE_PENALTY, 47 HIGH_PENALTY 48 }) 49 @Retention(RetentionPolicy.SOURCE) 50 public @interface Penalty {} 51 onSuccessfulUnlock()52 void onSuccessfulUnlock(); 53 isUnlockingDisabled()54 boolean isUnlockingDisabled(); 55 56 /** Returns true if the gesture should be rejected. */ isFalseTouch(int interactionType)57 boolean isFalseTouch(int interactionType); 58 59 /** 60 * Does basic checking to see if gesture looks like a tap. 61 * 62 * Only does the most basic of checks. No penalty is applied if this method returns false. 63 * 64 * For more robust analysis, use {@link #isFalseTap(int)}. 65 */ isSimpleTap()66 boolean isSimpleTap(); 67 68 /** 69 * Returns true if the FalsingManager thinks the last gesture was not a valid tap. 70 * 71 * This method runs a more thorough analysis than the similar {@link #isSimpleTap()}, 72 * that can include historical interactions and other contextual cues to see 73 * if the tap looks accidental. 74 * 75 * Use this method to validate a tap for launching an action, like opening 76 * a notification. 77 * 78 * The only parameter, penalty, indicates how much this should affect future gesture 79 * classifications if this tap looks like a false. As single taps are hard to confirm as false 80 * or otherwise, a low penalty value is encouraged unless context indicates otherwise. 81 */ isFalseTap(@enalty int penalty)82 boolean isFalseTap(@Penalty int penalty); 83 84 /** 85 * Returns true if the FalsingManager thinks the last gesture was not a valid long tap. 86 * 87 * Use this method to validate a long tap for launching an action, like long press on a UMO 88 * 89 * The only parameter, penalty, indicates how much this should affect future gesture 90 * classifications if this long tap looks like a false. 91 * As long taps are hard to confirm as false or otherwise, 92 * a low penalty value is encouraged unless context indicates otherwise. 93 */ isFalseLongTap(@enalty int penalty)94 boolean isFalseLongTap(@Penalty int penalty); 95 96 /** 97 * Returns true if the last two gestures do not look like a double tap. 98 * 99 * Only works on data that has already been reported to the FalsingManager. Be sure that 100 * {@link com.android.systemui.classifier.FalsingCollector#onTouchEvent(MotionEvent)} 101 * has already been called for all of the taps you want considered. 102 * 103 * This looks at the last two gestures on the screen, ensuring that they meet the following 104 * criteria: 105 * 106 * a) There are at least two gestures. 107 * b) The last two gestures look like taps. 108 * c) The last two gestures look like a double tap taken together. 109 * 110 * This method is _not_ context aware. That is to say, if two taps occur on two neighboring 111 * views, but are otherwise close to one another, this will report a successful double tap. 112 * It is up to the caller to decide 113 * @return 114 */ isFalseDoubleTap()115 boolean isFalseDoubleTap(); 116 117 /** 118 * Whether the last proximity event reported NEAR. May be used to short circuit motion events 119 * that require the proximity sensor is not covered. 120 */ isProximityNear()121 boolean isProximityNear(); 122 isClassifierEnabled()123 boolean isClassifierEnabled(); 124 shouldEnforceBouncer()125 boolean shouldEnforceBouncer(); 126 reportRejectedTouch()127 Uri reportRejectedTouch(); 128 isReportingEnabled()129 boolean isReportingEnabled(); 130 131 /** From com.android.systemui.Dumpable. */ dump(PrintWriter pw, String[] args)132 void dump(PrintWriter pw, String[] args); 133 134 /** 135 * Don't call this. It's meant for internal use to allow switching between implementations. 136 * 137 * Tests may also call it. 138 **/ cleanupInternal()139 void cleanupInternal(); 140 141 /** Call to report a ProximityEvent to the FalsingManager. */ onProximityEvent(ProximityEvent proximityEvent)142 void onProximityEvent(ProximityEvent proximityEvent); 143 144 /** Adds a {@link FalsingBeliefListener}. */ addFalsingBeliefListener(FalsingBeliefListener listener)145 void addFalsingBeliefListener(FalsingBeliefListener listener); 146 147 /** Removes a {@link FalsingBeliefListener}. */ removeFalsingBeliefListener(FalsingBeliefListener listener)148 void removeFalsingBeliefListener(FalsingBeliefListener listener); 149 150 /** Adds a {@link FalsingTapListener}. */ addTapListener(FalsingTapListener falsingTapListener)151 void addTapListener(FalsingTapListener falsingTapListener); 152 153 /** Removes a {@link FalsingTapListener}. */ removeTapListener(FalsingTapListener falsingTapListener)154 void removeTapListener(FalsingTapListener falsingTapListener); 155 156 /** Listener that is alerted when falsing belief level crosses a predfined threshold. */ 157 interface FalsingBeliefListener { onFalse()158 void onFalse(); 159 } 160 161 /** 162 * Listener that is alerted when an additional tap is required to confirm a single tap. 163 **/ 164 interface FalsingTapListener { onAdditionalTapRequired()165 void onAdditionalTapRequired(); 166 } 167 168 /** Passed to {@link FalsingManager#onProximityEvent}. */ 169 interface ProximityEvent { 170 /** Returns true when the proximity sensor was covered. */ getCovered()171 boolean getCovered(); 172 173 /** Returns when the proximity sensor was covered in nanoseconds. */ getTimestampNs()174 long getTimestampNs(); 175 } 176 } 177