1 /* 2 * Copyright (C) 2020 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 android.content.res.Resources; 20 import android.view.ViewConfiguration; 21 22 import com.android.systemui.R; 23 import com.android.systemui.dagger.SysUISingleton; 24 import com.android.systemui.dagger.qualifiers.Main; 25 import com.android.systemui.statusbar.phone.NotificationTapHelper; 26 27 import java.util.Arrays; 28 import java.util.HashSet; 29 import java.util.Set; 30 31 import javax.inject.Named; 32 33 import dagger.Binds; 34 import dagger.Module; 35 import dagger.Provides; 36 import dagger.multibindings.ElementsIntoSet; 37 38 /** Dagger Module for Falsing. */ 39 @Module 40 public interface FalsingModule { 41 String BRIGHT_LINE_GESTURE_CLASSIFERS = "bright_line_gesture_classifiers"; 42 String SINGLE_TAP_TOUCH_SLOP = "falsing_single_tap_touch_slop"; 43 String LONG_TAP_TOUCH_SLOP = "falsing_long_tap_slop"; 44 String DOUBLE_TAP_TOUCH_SLOP = "falsing_double_tap_touch_slop"; 45 String DOUBLE_TAP_TIMEOUT_MS = "falsing_double_tap_timeout_ms"; 46 String IS_FOLDABLE_DEVICE = "falsing_foldable_device"; 47 48 /** */ 49 @Binds 50 @SysUISingleton bindsFalsingCollector(FalsingCollectorImpl impl)51 FalsingCollector bindsFalsingCollector(FalsingCollectorImpl impl); 52 53 /** */ 54 @Provides 55 @ElementsIntoSet 56 @Named(BRIGHT_LINE_GESTURE_CLASSIFERS) providesBrightLineGestureClassifiers( DistanceClassifier distanceClassifier, ProximityClassifier proximityClassifier, PointerCountClassifier pointerCountClassifier, TypeClassifier typeClassifier, DiagonalClassifier diagonalClassifier, ZigZagClassifier zigZagClassifier)57 static Set<FalsingClassifier> providesBrightLineGestureClassifiers( 58 DistanceClassifier distanceClassifier, ProximityClassifier proximityClassifier, 59 PointerCountClassifier pointerCountClassifier, TypeClassifier typeClassifier, 60 DiagonalClassifier diagonalClassifier, ZigZagClassifier zigZagClassifier) { 61 return new HashSet<>(Arrays.asList( 62 pointerCountClassifier, typeClassifier, diagonalClassifier, distanceClassifier, 63 proximityClassifier, zigZagClassifier)); 64 } 65 66 /** */ 67 @Provides 68 @Named(DOUBLE_TAP_TIMEOUT_MS) providesDoubleTapTimeoutMs()69 static long providesDoubleTapTimeoutMs() { 70 return NotificationTapHelper.DOUBLE_TAP_TIMEOUT_MS; 71 } 72 73 /** */ 74 @Provides 75 @Named(DOUBLE_TAP_TOUCH_SLOP) providesDoubleTapTouchSlop(@ain Resources resources)76 static float providesDoubleTapTouchSlop(@Main Resources resources) { 77 return resources.getDimension(R.dimen.double_tap_slop); 78 } 79 80 /** */ 81 @Provides 82 @Named(SINGLE_TAP_TOUCH_SLOP) providesSingleTapTouchSlop(ViewConfiguration viewConfiguration)83 static float providesSingleTapTouchSlop(ViewConfiguration viewConfiguration) { 84 return viewConfiguration.getScaledTouchSlop(); 85 } 86 87 /** */ 88 @Provides 89 @Named(LONG_TAP_TOUCH_SLOP) providesLongTapTouchSlop(ViewConfiguration viewConfiguration)90 static float providesLongTapTouchSlop(ViewConfiguration viewConfiguration) { 91 return viewConfiguration.getScaledTouchSlop() * 1.25f; 92 } 93 94 /** */ 95 @Provides 96 @Named(IS_FOLDABLE_DEVICE) providesIsFoldableDevice(@ain Resources resources)97 static boolean providesIsFoldableDevice(@Main Resources resources) { 98 try { 99 return resources.getIntArray( 100 com.android.internal.R.array.config_foldedDeviceStates).length != 0; 101 } catch (Resources.NotFoundException e) { 102 return false; 103 } 104 } 105 } 106