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