1 /* 2 * Copyright 2023 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.domain.interactor 18 19 import android.view.MotionEvent 20 import com.android.systemui.classifier.Classifier 21 import com.android.systemui.classifier.FalsingClassifier 22 import com.android.systemui.classifier.FalsingCollector 23 import com.android.systemui.classifier.FalsingCollectorActual 24 import com.android.systemui.dagger.SysUISingleton 25 import com.android.systemui.plugins.FalsingManager 26 import javax.inject.Inject 27 28 /** 29 * Exposes the subset of the [FalsingCollector] and [FalsingManager] APIs that's required by 30 * external callers. 31 * 32 * E.g. methods of the above APIs that are not exposed by this class either don't need to be invoked 33 * by external callers (as they're already called by the scene framework) or haven't been added yet. 34 */ 35 @SysUISingleton 36 class FalsingInteractor 37 @Inject 38 constructor( 39 @FalsingCollectorActual private val collector: FalsingCollector, 40 private val manager: FalsingManager, 41 ) { 42 /** 43 * Notifies of a [MotionEvent] that passed through the UI. 44 * 45 * Must call [onMotionEventComplete] when done with this event. 46 */ onTouchEventnull47 fun onTouchEvent(event: MotionEvent) = collector.onTouchEvent(event) 48 49 /** 50 * Notifies that a [MotionEvent] has finished being dispatched through the UI. 51 * 52 * Must be called after each call to [onTouchEvent]. 53 */ 54 fun onMotionEventComplete() = collector.onMotionEventComplete() 55 56 /** 57 * Instructs the falsing system to ignore the rest of the current input gesture; automatically 58 * resets when another gesture is started (with the next down event). 59 */ 60 fun avoidGesture() = collector.avoidGesture() 61 62 /** 63 * Inserts the given [result] into the falsing system, affecting future runs of the classifier 64 * as if this was a result that had organically happened before. 65 */ 66 fun updateFalseConfidence( 67 result: FalsingClassifier.Result, 68 ) = collector.updateFalseConfidence(result) 69 70 /** Returns `true` if the gesture should be rejected. */ 71 fun isFalseTouch( 72 @Classifier.InteractionType interactionType: Int, 73 ): Boolean = manager.isFalseTouch(interactionType) 74 } 75