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