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