• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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 package com.android.quickstep;
17 
18 import android.annotation.TargetApi;
19 import android.os.Build;
20 import android.view.InputEvent;
21 import android.view.KeyEvent;
22 import android.view.MotionEvent;
23 
24 import com.android.launcher3.tracing.InputConsumerProto;
25 import com.android.launcher3.tracing.TouchInteractionServiceProto;
26 
27 @TargetApi(Build.VERSION_CODES.O)
28 public interface InputConsumer {
29 
30     int TYPE_NO_OP = 1 << 0;
31     int TYPE_OVERVIEW = 1 << 1;
32     int TYPE_OTHER_ACTIVITY = 1 << 2;
33     int TYPE_ASSISTANT = 1 << 3;
34     int TYPE_DEVICE_LOCKED = 1 << 4;
35     int TYPE_ACCESSIBILITY = 1 << 5;
36     int TYPE_SCREEN_PINNED = 1 << 6;
37     int TYPE_OVERVIEW_WITHOUT_FOCUS = 1 << 7;
38     int TYPE_RESET_GESTURE = 1 << 8;
39     int TYPE_OVERSCROLL = 1 << 9;
40     int TYPE_SYSUI_OVERLAY = 1 << 10;
41     int TYPE_ONE_HANDED = 1 << 11;
42 
43     String[] NAMES = new String[] {
44            "TYPE_NO_OP",                    // 0
45             "TYPE_OVERVIEW",                // 1
46             "TYPE_OTHER_ACTIVITY",          // 2
47             "TYPE_ASSISTANT",               // 3
48             "TYPE_DEVICE_LOCKED",           // 4
49             "TYPE_ACCESSIBILITY",           // 5
50             "TYPE_SCREEN_PINNED",           // 6
51             "TYPE_OVERVIEW_WITHOUT_FOCUS",  // 7
52             "TYPE_RESET_GESTURE",           // 8
53             "TYPE_OVERSCROLL",              // 9
54             "TYPE_SYSUI_OVERLAY",           // 10
55             "TYPE_ONE_HANDED",              // 11
56     };
57 
58     InputConsumer NO_OP = () -> TYPE_NO_OP;
59 
getType()60     int getType();
61 
62     /**
63      * Returns true if the user has crossed the threshold for it to be an explicit action.
64      */
allowInterceptByParent()65     default boolean allowInterceptByParent() {
66         return true;
67     }
68 
69     /**
70      * Returns true if the lifecycle of this input consumer is detached from the normal gesture
71      * down/up flow. If so, it is the responsibility of the input consumer to call back to
72      * {@link TouchInteractionService#onConsumerInactive(InputConsumer)} after the consumer is
73      * finished.
74      */
isConsumerDetachedFromGesture()75     default boolean isConsumerDetachedFromGesture() {
76         return false;
77     }
78 
79     /**
80      * Handle and specific setup necessary based on the orientation of the device
81      */
notifyOrientationSetup()82     default void notifyOrientationSetup() {}
83 
84     /**
85      * Returns the active input consumer is in the hierarchy of this input consumer.
86      */
getActiveConsumerInHierarchy()87     default InputConsumer getActiveConsumerInHierarchy() {
88         return this;
89     }
90 
91     /**
92      * Called by the event queue when the consumer is about to be switched to a new consumer.
93      * Consumers should update the state accordingly here before the state is passed to the new
94      * consumer.
95      */
onConsumerAboutToBeSwitched()96     default void onConsumerAboutToBeSwitched() { }
97 
onMotionEvent(MotionEvent ev)98     default void onMotionEvent(MotionEvent ev) { }
99 
onKeyEvent(KeyEvent ev)100     default void onKeyEvent(KeyEvent ev) { }
101 
onInputEvent(InputEvent ev)102     default void onInputEvent(InputEvent ev) {
103         if (ev instanceof MotionEvent) {
104             onMotionEvent((MotionEvent) ev);
105         } else {
106             onKeyEvent((KeyEvent) ev);
107         }
108     }
109 
getName()110     default String getName() {
111         StringBuilder name = new StringBuilder();
112         for (int i = 0; i < NAMES.length; i++) {
113             if ((getType() & (1 << i)) != 0) {
114                 if (name.length() > 0) {
115                     name.append(":");
116                 }
117                 name.append(NAMES[i]);
118             }
119         }
120         return name.toString();
121     }
122 
123     /**
124      * Used for winscope tracing, see launcher_trace.proto
125      * @see com.android.systemui.shared.tracing.ProtoTraceable#writeToProto
126      * @param serviceProto The parent of this proto message.
127      */
writeToProto(TouchInteractionServiceProto.Builder serviceProto)128     default void writeToProto(TouchInteractionServiceProto.Builder serviceProto) {
129         InputConsumerProto.Builder inputConsumerProto = InputConsumerProto.newBuilder();
130         inputConsumerProto.setName(getName());
131         writeToProtoInternal(inputConsumerProto);
132         serviceProto.setInputConsumer(inputConsumerProto);
133     }
134 
135     /**
136      * @see #writeToProto - allows subclasses to write additional info to the proto.
137      */
writeToProtoInternal(InputConsumerProto.Builder inputConsumerProto)138     default void writeToProtoInternal(InputConsumerProto.Builder inputConsumerProto) {}
139 }
140