2 * Copyright (C) 2010 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef _ANDROID_APP_NATIVEACTIVITY_H
18 #define _ANDROID_APP_NATIVEACTIVITY_H
20 #include <androidfw/InputTransport.h>
21 #include <utils/Looper.h>
23 #include <android/native_activity.h>
29 extern void android_NativeActivity_finish(
30 ANativeActivity* activity);
32 extern void android_NativeActivity_setWindowFormat(
33 ANativeActivity* activity, int32_t format);
35 extern void android_NativeActivity_setWindowFlags(
36 ANativeActivity* activity, int32_t values, int32_t mask);
38 extern void android_NativeActivity_showSoftInput(
39 ANativeActivity* activity, int32_t flags);
41 extern void android_NativeActivity_hideSoftInput(
42 ANativeActivity* activity, int32_t flags);
44 } // namespace android
48 * NDK input queue API.
50 * Here is the event flow:
51 * 1. Event arrives in input consumer, and is returned by getEvent().
52 * 2. Application calls preDispatchEvent():
53 * a. Event is assigned a sequence ID and enqueued in mPreDispatchingKeys.
54 * b. Main thread picks up event, hands to input method.
55 * c. Input method eventually returns sequence # and whether it was handled.
56 * d. finishPreDispatch() is called to enqueue the information.
57 * e. next getEvent() call will:
58 * - finish any pre-dispatch events that the input method handled
59 * - return the next pre-dispatched event that the input method didn't handle.
60 * f. (A preDispatchEvent() call on this event will now return false).
61 * 3. Application calls finishEvent() with whether it was handled.
62 * - If handled is true, the event is finished.
63 * - If handled is false, the event is put on mUnhandledKeys, and:
64 * a. Main thread receives event from consumeUnhandledEvent().
65 * b. Java sends event through default key handler.
66 * c. event is finished.
70 /* Creates a consumer associated with an input channel. */
71 explicit AInputQueue(const android::sp<android::InputChannel>& channel, int workWrite);
73 /* Destroys the consumer and releases its input channel. */
76 void attachLooper(ALooper* looper, int ident, ALooper_callbackFunc callback, void* data);
82 int32_t getEvent(AInputEvent** outEvent);
84 bool preDispatchEvent(AInputEvent* event);
86 void finishEvent(AInputEvent* event, bool handled, bool didDefaultHandling);
88 // ----------------------------------------------------------
90 inline android::InputConsumer& getConsumer() { return mConsumer; }
92 void dispatchEvent(android::KeyEvent* event);
94 void finishPreDispatch(int seq, bool handled);
96 android::KeyEvent* consumeUnhandledEvent();
97 android::KeyEvent* consumePreDispatchingEvent(int* outSeq);
99 android::KeyEvent* createKeyEvent();
104 void doUnhandledKey(android::KeyEvent* keyEvent);
105 bool preDispatchKey(android::KeyEvent* keyEvent);
106 void wakeupDispatchLocked();
108 android::PooledInputEventFactory mPooledInputEventFactory;
109 android::InputConsumer mConsumer;
110 android::sp<android::Looper> mLooper;
112 int mDispatchKeyRead;
113 int mDispatchKeyWrite;
115 struct in_flight_event {
116 android::InputEvent* event;
117 int seq; // internal sequence number for synthetic pre-dispatch events
118 uint32_t finishSeq; // sequence number for sendFinishedSignal, or 0 if finish not required
121 struct finish_pre_dispatch {
126 android::Mutex mLock;
130 // All input events that are actively being processed.
131 android::Vector<in_flight_event> mInFlightEvents;
133 // Key events that the app didn't handle, and are pending for
134 // delivery to the activity's default key handling.
135 android::Vector<android::KeyEvent*> mUnhandledKeys;
137 // Keys that arrived in the Java framework and need to be
138 // dispatched to the app.
139 android::Vector<android::KeyEvent*> mDispatchingKeys;
141 // Key events that are pending to be pre-dispatched to the IME.
142 android::Vector<in_flight_event> mPreDispatchingKeys;
144 // Event sequence numbers that we have finished pre-dispatching.
145 android::Vector<finish_pre_dispatch> mFinishPreDispatches;
148 #endif // _ANDROID_APP_NATIVEACTIVITY_H