diff options
author | Jeff Brown <jeffbrown@google.com> | 2010-06-22 01:27:15 -0700 |
---|---|---|
committer | Jeff Brown <jeffbrown@google.com> | 2010-06-28 19:10:54 -0700 |
commit | 349703effce5acc53ed96f7ed8556131f0c65e18 (patch) | |
tree | 359217d5076e3005c724b2117a59ffec81e7a83b /core | |
parent | f2b544f5ae7676f7ab4cdf3379b2ed3c60a65def (diff) | |
download | frameworks_base-349703effce5acc53ed96f7ed8556131f0c65e18.zip frameworks_base-349703effce5acc53ed96f7ed8556131f0c65e18.tar.gz frameworks_base-349703effce5acc53ed96f7ed8556131f0c65e18.tar.bz2 |
Native input event dispatching.
Target identification is now fully native.
Fixed a couple of minor issues related to input injection.
Native input enabled by default, can be disabled by setting
WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH to false.
Change-Id: I7edf66ed3e987cc9306ad4743ac57a116af452ff
Diffstat (limited to 'core')
-rw-r--r-- | core/java/android/service/wallpaper/WallpaperService.java | 11 | ||||
-rw-r--r-- | core/java/android/view/InputTarget.java | 57 | ||||
-rw-r--r-- | core/java/android/view/ViewRoot.java | 9 | ||||
-rw-r--r-- | core/java/android/view/WindowManagerPolicy.java | 2 | ||||
-rw-r--r-- | core/jni/Android.mk | 1 | ||||
-rw-r--r-- | core/jni/AndroidRuntime.cpp | 2 | ||||
-rw-r--r-- | core/jni/android_view_InputQueue.cpp | 4 | ||||
-rw-r--r-- | core/jni/android_view_InputTarget.cpp | 97 | ||||
-rw-r--r-- | core/jni/android_view_InputTarget.h | 31 |
9 files changed, 21 insertions, 193 deletions
diff --git a/core/java/android/service/wallpaper/WallpaperService.java b/core/java/android/service/wallpaper/WallpaperService.java index 3f5d6ca..249ad62 100644 --- a/core/java/android/service/wallpaper/WallpaperService.java +++ b/core/java/android/service/wallpaper/WallpaperService.java @@ -773,8 +773,6 @@ public abstract class WallpaperService extends Service { if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) { if (mInputChannel != null) { InputQueue.unregisterInputChannel(mInputChannel); - mInputChannel.dispose(); - mInputChannel = null; } } @@ -783,6 +781,15 @@ public abstract class WallpaperService extends Service { } mSurfaceHolder.mSurface.release(); mCreated = false; + + if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) { + // Dispose the input channel after removing the window so the Window Manager + // doesn't interpret the input channel being closed as an abnormal termination. + if (mInputChannel != null) { + mInputChannel.dispose(); + mInputChannel = null; + } + } } } } diff --git a/core/java/android/view/InputTarget.java b/core/java/android/view/InputTarget.java deleted file mode 100644 index 6ff7305..0000000 --- a/core/java/android/view/InputTarget.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.view; - -/** - * An input target specifies how an input event is to be dispatched to a particular window - * including the window's input channel, control flags, a timeout, and an X / Y offset to - * be added to input event coordinates to compensate for the absolute position of the - * window area. - * - * These parameters are used by the native input dispatching code. - * @hide - */ -public final class InputTarget { - public InputChannel mInputChannel; - public int mFlags; - public long mTimeoutNanos; - public float mXOffset; - public float mYOffset; - - /** - * This flag indicates that subsequent event delivery should be held until the - * current event is delivered to this target or a timeout occurs. - */ - public static int FLAG_SYNC = 0x01; - - /** - * This flag indicates that a MotionEvent with ACTION_DOWN falls outside of the area of - * this target and so should instead be delivered as an ACTION_OUTSIDE to this target. - */ - public static int FLAG_OUTSIDE = 0x02; - - /* - * This flag indicates that a KeyEvent or MotionEvent is being canceled. - * In the case of a key event, it should be delivered with KeyEvent.FLAG_CANCELED set. - * In the case of a motion event, it should be delivered as MotionEvent.ACTION_CANCEL. - */ - public static int FLAG_CANCEL = 0x04; - - public void recycle() { - mInputChannel = null; - } -} diff --git a/core/java/android/view/ViewRoot.java b/core/java/android/view/ViewRoot.java index 4854190..1dc82e8 100644 --- a/core/java/android/view/ViewRoot.java +++ b/core/java/android/view/ViewRoot.java @@ -1762,6 +1762,15 @@ public final class ViewRoot extends Handler implements ViewParent, sWindowSession.remove(mWindow); } catch (RemoteException e) { } + + if (WindowManagerPolicy.ENABLE_NATIVE_INPUT_DISPATCH) { + // Dispose the input channel after removing the window so the Window Manager + // doesn't interpret the input channel being closed as an abnormal termination. + if (mInputChannel != null) { + mInputChannel.dispose(); + mInputChannel = null; + } + } } void updateConfiguration(Configuration config, boolean force) { diff --git a/core/java/android/view/WindowManagerPolicy.java b/core/java/android/view/WindowManagerPolicy.java index 431b786..be1f6d2 100644 --- a/core/java/android/view/WindowManagerPolicy.java +++ b/core/java/android/view/WindowManagerPolicy.java @@ -83,7 +83,7 @@ public interface WindowManagerPolicy { * Temporary flag added during the transition to the new native input dispatcher. * This will be removed when the old input dispatch code is deleted. */ - public final static boolean ENABLE_NATIVE_INPUT_DISPATCH = false; + public final static boolean ENABLE_NATIVE_INPUT_DISPATCH = true; // flags for interceptKeyTq /** diff --git a/core/jni/Android.mk b/core/jni/Android.mk index d854e87..a008e96 100644 --- a/core/jni/Android.mk +++ b/core/jni/Android.mk @@ -47,7 +47,6 @@ LOCAL_SRC_FILES:= \ android_view_ViewRoot.cpp \ android_view_InputChannel.cpp \ android_view_InputQueue.cpp \ - android_view_InputTarget.cpp \ android_view_KeyEvent.cpp \ android_view_MotionEvent.cpp \ android_text_AndroidCharacter.cpp \ diff --git a/core/jni/AndroidRuntime.cpp b/core/jni/AndroidRuntime.cpp index 3e69c78..6fb1369 100644 --- a/core/jni/AndroidRuntime.cpp +++ b/core/jni/AndroidRuntime.cpp @@ -164,7 +164,6 @@ extern int register_android_backup_BackupHelperDispatcher(JNIEnv *env); extern int register_android_app_NativeActivity(JNIEnv *env); extern int register_android_view_InputChannel(JNIEnv* env); extern int register_android_view_InputQueue(JNIEnv* env); -extern int register_android_view_InputTarget(JNIEnv* env); extern int register_android_view_KeyEvent(JNIEnv* env); extern int register_android_view_MotionEvent(JNIEnv* env); @@ -1297,7 +1296,6 @@ static const RegJNIRec gRegJNI[] = { REG_JNI(register_android_app_NativeActivity), REG_JNI(register_android_view_InputChannel), REG_JNI(register_android_view_InputQueue), - REG_JNI(register_android_view_InputTarget), REG_JNI(register_android_view_KeyEvent), REG_JNI(register_android_view_MotionEvent), }; diff --git a/core/jni/android_view_InputQueue.cpp b/core/jni/android_view_InputQueue.cpp index 63e00d7..6fb3cf7 100644 --- a/core/jni/android_view_InputQueue.cpp +++ b/core/jni/android_view_InputQueue.cpp @@ -19,10 +19,10 @@ //#define LOG_NDEBUG 0 // Log debug messages about the dispatch cycle. -#define DEBUG_DISPATCH_CYCLE 1 +#define DEBUG_DISPATCH_CYCLE 0 // Log debug messages about registrations. -#define DEBUG_REGISTRATION 1 +#define DEBUG_REGISTRATION 0 #include "JNIHelp.h" diff --git a/core/jni/android_view_InputTarget.cpp b/core/jni/android_view_InputTarget.cpp deleted file mode 100644 index a0a7054..0000000 --- a/core/jni/android_view_InputTarget.cpp +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define LOG_TAG "InputTarget-JNI" - -#include "JNIHelp.h" - -#include <utils/Log.h> -#include <ui/InputDispatcher.h> -#include <ui/InputTransport.h> -#include "android_view_InputTarget.h" -#include "android_view_InputChannel.h" - -namespace android { - -// ---------------------------------------------------------------------------- - -static struct { - jclass clazz; - - jfieldID mInputChannel; - jfieldID mFlags; - jfieldID mTimeoutNanos; - jfieldID mXOffset; - jfieldID mYOffset; -} gInputTargetClassInfo; - -// ---------------------------------------------------------------------------- - -void android_view_InputTarget_toNative(JNIEnv* env, jobject inputTargetObj, - InputTarget* outInputTarget) { - jobject inputChannelObj = env->GetObjectField(inputTargetObj, - gInputTargetClassInfo.mInputChannel); - jint flags = env->GetIntField(inputTargetObj, - gInputTargetClassInfo.mFlags); - jlong timeoutNanos = env->GetLongField(inputTargetObj, - gInputTargetClassInfo.mTimeoutNanos); - jfloat xOffset = env->GetFloatField(inputTargetObj, - gInputTargetClassInfo.mXOffset); - jfloat yOffset = env->GetFloatField(inputTargetObj, - gInputTargetClassInfo.mYOffset); - - outInputTarget->inputChannel = android_view_InputChannel_getInputChannel(env, inputChannelObj); - outInputTarget->flags = flags; - outInputTarget->timeout = timeoutNanos; - outInputTarget->xOffset = xOffset; - outInputTarget->yOffset = yOffset; - - env->DeleteLocalRef(inputChannelObj); -} - -// ---------------------------------------------------------------------------- - -#define FIND_CLASS(var, className) \ - var = env->FindClass(className); \ - LOG_FATAL_IF(! var, "Unable to find class " className); \ - var = jclass(env->NewGlobalRef(var)); - -#define GET_FIELD_ID(var, clazz, fieldName, fieldDescriptor) \ - var = env->GetFieldID(clazz, fieldName, fieldDescriptor); \ - LOG_FATAL_IF(! var, "Unable to find field " fieldName); - -int register_android_view_InputTarget(JNIEnv* env) { - FIND_CLASS(gInputTargetClassInfo.clazz, "android/view/InputTarget"); - - GET_FIELD_ID(gInputTargetClassInfo.mInputChannel, gInputTargetClassInfo.clazz, - "mInputChannel", "Landroid/view/InputChannel;"); - - GET_FIELD_ID(gInputTargetClassInfo.mFlags, gInputTargetClassInfo.clazz, - "mFlags", "I"); - - GET_FIELD_ID(gInputTargetClassInfo.mTimeoutNanos, gInputTargetClassInfo.clazz, - "mTimeoutNanos", "J"); - - GET_FIELD_ID(gInputTargetClassInfo.mXOffset, gInputTargetClassInfo.clazz, - "mXOffset", "F"); - - GET_FIELD_ID(gInputTargetClassInfo.mYOffset, gInputTargetClassInfo.clazz, - "mYOffset", "F"); - - return 0; -} - -} // namespace android diff --git a/core/jni/android_view_InputTarget.h b/core/jni/android_view_InputTarget.h deleted file mode 100644 index 9230b1b..0000000 --- a/core/jni/android_view_InputTarget.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2010 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _ANDROID_VIEW_INPUTTARGET_H -#define _ANDROID_VIEW_INPUTTARGET_H - -#include "jni.h" - -namespace android { - -class InputTarget; - -extern void android_view_InputTarget_toNative(JNIEnv* env, jobject inputTargetObj, - InputTarget* outInputTarget); - -} // namespace android - -#endif // _ANDROID_OS_INPUTTARGET_H |