Merge changes from topic "sfinput3"
* changes: WindowManager: Communicate with input system by WindowTokens. Plumbing for SurfaceControl#setInputWindowInfo.
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.input;
|
||||
package android.view;
|
||||
|
||||
/**
|
||||
* Functions as a handle for an application that can receive input.
|
||||
@@ -18,6 +18,7 @@ package android.view;
|
||||
|
||||
import android.annotation.UnsupportedAppUsage;
|
||||
import android.os.Parcel;
|
||||
import android.os.IBinder;
|
||||
import android.os.Parcelable;
|
||||
import android.util.Slog;
|
||||
|
||||
@@ -50,15 +51,17 @@ public final class InputChannel implements Parcelable {
|
||||
@SuppressWarnings("unused")
|
||||
@UnsupportedAppUsage
|
||||
private long mPtr; // used by native code
|
||||
|
||||
|
||||
private static native InputChannel[] nativeOpenInputChannelPair(String name);
|
||||
|
||||
|
||||
private native void nativeDispose(boolean finalized);
|
||||
private native void nativeTransferTo(InputChannel other);
|
||||
private native void nativeReadFromParcel(Parcel parcel);
|
||||
private native void nativeWriteToParcel(Parcel parcel);
|
||||
private native void nativeDup(InputChannel target);
|
||||
|
||||
private native IBinder nativeGetToken();
|
||||
private native void nativeSetToken(IBinder token);
|
||||
|
||||
private native String nativeGetName();
|
||||
|
||||
/**
|
||||
@@ -159,14 +162,22 @@ public final class InputChannel implements Parcelable {
|
||||
}
|
||||
|
||||
nativeWriteToParcel(out);
|
||||
|
||||
|
||||
if ((flags & PARCELABLE_WRITE_RETURN_VALUE) != 0) {
|
||||
dispose();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public IBinder getToken() {
|
||||
return nativeGetToken();
|
||||
}
|
||||
|
||||
public void setToken(IBinder token) {
|
||||
nativeSetToken(token);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.server.input;
|
||||
package android.view;
|
||||
|
||||
import android.graphics.Region;
|
||||
import android.view.IWindow;
|
||||
@@ -34,9 +34,6 @@ public final class InputWindowHandle {
|
||||
// The input application handle.
|
||||
public final InputApplicationHandle inputApplicationHandle;
|
||||
|
||||
// The window manager's window state.
|
||||
public final Object windowState;
|
||||
|
||||
// The client window.
|
||||
public final IWindow clientWindow;
|
||||
|
||||
@@ -97,9 +94,8 @@ public final class InputWindowHandle {
|
||||
private native void nativeDispose();
|
||||
|
||||
public InputWindowHandle(InputApplicationHandle inputApplicationHandle,
|
||||
Object windowState, IWindow clientWindow, int displayId) {
|
||||
IWindow clientWindow, int displayId) {
|
||||
this.inputApplicationHandle = inputApplicationHandle;
|
||||
this.windowState = windowState;
|
||||
this.clientWindow = clientWindow;
|
||||
this.displayId = displayId;
|
||||
}
|
||||
@@ -153,6 +153,9 @@ public class SurfaceControl implements Parcelable {
|
||||
|
||||
private static native Display.HdrCapabilities nativeGetHdrCapabilities(IBinder displayToken);
|
||||
|
||||
private static native void nativeSetInputWindowInfo(long transactionObj, long nativeObject,
|
||||
InputWindowHandle handle);
|
||||
|
||||
|
||||
private final CloseGuard mCloseGuard = CloseGuard.get();
|
||||
private final String mName;
|
||||
@@ -1459,6 +1462,12 @@ public class SurfaceControl implements Parcelable {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Transaction setInputWindowInfo(SurfaceControl sc, InputWindowHandle handle) {
|
||||
sc.checkNotReleased();
|
||||
nativeSetInputWindowInfo(mNativeObject, sc.mNativeObject, handle);
|
||||
return this;
|
||||
}
|
||||
|
||||
@UnsupportedAppUsage
|
||||
public Transaction setMatrix(SurfaceControl sc,
|
||||
float dsdx, float dtdx, float dtdy, float dsdy) {
|
||||
|
||||
@@ -135,13 +135,13 @@ static const JNINativeMethod gInputApplicationHandleMethods[] = {
|
||||
LOG_FATAL_IF(! (var), "Unable to find field " fieldName);
|
||||
|
||||
int register_android_server_InputApplicationHandle(JNIEnv* env) {
|
||||
int res = jniRegisterNativeMethods(env, "com/android/server/input/InputApplicationHandle",
|
||||
int res = jniRegisterNativeMethods(env, "android/view/InputApplicationHandle",
|
||||
gInputApplicationHandleMethods, NELEM(gInputApplicationHandleMethods));
|
||||
(void) res; // Faked use when LOG_NDEBUG.
|
||||
LOG_FATAL_IF(res < 0, "Unable to register native methods.");
|
||||
|
||||
jclass clazz;
|
||||
FIND_CLASS(clazz, "com/android/server/input/InputApplicationHandle");
|
||||
FIND_CLASS(clazz, "android/view/InputApplicationHandle");
|
||||
|
||||
GET_FIELD_ID(gInputApplicationHandleClassInfo.ptr, clazz,
|
||||
"ptr", "J");
|
||||
|
||||
@@ -221,20 +221,20 @@ static const JNINativeMethod gInputWindowHandleMethods[] = {
|
||||
LOG_FATAL_IF(! (var), "Unable to find field " fieldName);
|
||||
|
||||
int register_android_server_InputWindowHandle(JNIEnv* env) {
|
||||
int res = jniRegisterNativeMethods(env, "com/android/server/input/InputWindowHandle",
|
||||
int res = jniRegisterNativeMethods(env, "android/view/InputWindowHandle",
|
||||
gInputWindowHandleMethods, NELEM(gInputWindowHandleMethods));
|
||||
(void) res; // Faked use when LOG_NDEBUG.
|
||||
LOG_FATAL_IF(res < 0, "Unable to register native methods.");
|
||||
|
||||
jclass clazz;
|
||||
FIND_CLASS(clazz, "com/android/server/input/InputWindowHandle");
|
||||
FIND_CLASS(clazz, "android/view/InputWindowHandle");
|
||||
|
||||
GET_FIELD_ID(gInputWindowHandleClassInfo.ptr, clazz,
|
||||
"ptr", "J");
|
||||
|
||||
GET_FIELD_ID(gInputWindowHandleClassInfo.inputApplicationHandle,
|
||||
clazz,
|
||||
"inputApplicationHandle", "Lcom/android/server/input/InputApplicationHandle;");
|
||||
"inputApplicationHandle", "Landroid/view/InputApplicationHandle;");
|
||||
|
||||
GET_FIELD_ID(gInputWindowHandleClassInfo.inputChannel, clazz,
|
||||
"inputChannel", "Landroid/view/InputChannel;");
|
||||
|
||||
@@ -249,6 +249,24 @@ static void android_view_InputChannel_nativeDup(JNIEnv* env, jobject obj, jobjec
|
||||
}
|
||||
}
|
||||
|
||||
static jobject android_view_InputChannel_nativeGetToken(JNIEnv* env, jobject obj) {
|
||||
NativeInputChannel* nativeInputChannel =
|
||||
android_view_InputChannel_getNativeInputChannel(env, obj);
|
||||
if (nativeInputChannel) {
|
||||
return javaObjectForIBinder(env, nativeInputChannel->getInputChannel()->getToken());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void android_view_InputChannel_nativeSetToken(JNIEnv* env, jobject obj, jobject tokenObj) {
|
||||
NativeInputChannel* nativeInputChannel =
|
||||
android_view_InputChannel_getNativeInputChannel(env, obj);
|
||||
sp<IBinder> token = ibinderForJavaObject(env, tokenObj);
|
||||
if (nativeInputChannel != nullptr) {
|
||||
nativeInputChannel->getInputChannel()->setToken(token);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
static const JNINativeMethod gInputChannelMethods[] = {
|
||||
@@ -267,6 +285,10 @@ static const JNINativeMethod gInputChannelMethods[] = {
|
||||
(void*)android_view_InputChannel_nativeGetName },
|
||||
{ "nativeDup", "(Landroid/view/InputChannel;)V",
|
||||
(void*)android_view_InputChannel_nativeDup },
|
||||
{ "nativeGetToken", "()Landroid/os/IBinder;",
|
||||
(void*)android_view_InputChannel_nativeGetToken },
|
||||
{ "nativeSetToken", "(Landroid/os/IBinder;)V",
|
||||
(void*)android_view_InputChannel_nativeSetToken }
|
||||
};
|
||||
|
||||
int register_android_view_InputChannel(JNIEnv* env) {
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#include "android_os_Parcel.h"
|
||||
#include "android_util_Binder.h"
|
||||
#include "android_hardware_input_InputWindowHandle.h"
|
||||
#include "android/graphics/Bitmap.h"
|
||||
#include "android/graphics/GraphicsJNI.h"
|
||||
#include "android/graphics/Region.h"
|
||||
@@ -324,6 +325,18 @@ static void nativeSetAlpha(JNIEnv* env, jclass clazz, jlong transactionObj,
|
||||
transaction->setAlpha(ctrl, alpha);
|
||||
}
|
||||
|
||||
static void nativeSetInputWindowInfo(JNIEnv* env, jclass clazz, jlong transactionObj,
|
||||
jlong nativeObject, jobject inputWindow) {
|
||||
auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
|
||||
|
||||
sp<NativeInputWindowHandle> handle = android_server_InputWindowHandle_getHandle(
|
||||
env, inputWindow);
|
||||
handle->updateInfo();
|
||||
|
||||
SurfaceControl* const ctrl = reinterpret_cast<SurfaceControl *>(nativeObject);
|
||||
transaction->setInputWindowInfo(ctrl, *handle->getInfo());
|
||||
}
|
||||
|
||||
static void nativeSetColor(JNIEnv* env, jclass clazz, jlong transactionObj,
|
||||
jlong nativeObject, jfloatArray fColor) {
|
||||
auto transaction = reinterpret_cast<SurfaceComposerClient::Transaction*>(transactionObj);
|
||||
@@ -930,6 +943,8 @@ static const JNINativeMethod sSurfaceControlMethods[] = {
|
||||
(void*)nativeScreenshot },
|
||||
{"nativeCaptureLayers", "(Landroid/os/IBinder;Landroid/graphics/Rect;F)Landroid/graphics/GraphicBuffer;",
|
||||
(void*)nativeCaptureLayers },
|
||||
{"nativeSetInputWindowInfo", "(JJLandroid/view/InputWindowHandle;)V",
|
||||
(void*)nativeSetInputWindowInfo },
|
||||
};
|
||||
|
||||
int register_android_view_SurfaceControl(JNIEnv* env)
|
||||
|
||||
@@ -72,6 +72,8 @@ import android.view.IInputFilter;
|
||||
import android.view.IInputFilterHost;
|
||||
import android.view.IWindow;
|
||||
import android.view.InputChannel;
|
||||
import android.view.InputApplicationHandle;
|
||||
import android.view.InputWindowHandle;
|
||||
import android.view.InputDevice;
|
||||
import android.view.InputEvent;
|
||||
import android.view.KeyEvent;
|
||||
@@ -197,7 +199,7 @@ public class InputManagerService extends IInputManager.Stub
|
||||
private static native boolean nativeHasKeys(long ptr,
|
||||
int deviceId, int sourceMask, int[] keyCodes, boolean[] keyExists);
|
||||
private static native void nativeRegisterInputChannel(long ptr, InputChannel inputChannel,
|
||||
InputWindowHandle inputWindowHandle, int displayId);
|
||||
int displayId);
|
||||
private static native void nativeUnregisterInputChannel(long ptr, InputChannel inputChannel);
|
||||
private static native void nativeSetInputFilterEnabled(long ptr, boolean enable);
|
||||
private static native int nativeInjectInputEvent(long ptr, InputEvent event,
|
||||
@@ -486,8 +488,7 @@ public class InputManagerService extends IInputManager.Stub
|
||||
}
|
||||
|
||||
InputChannel[] inputChannels = InputChannel.openInputChannelPair(inputChannelName);
|
||||
// Register channel for monitor.
|
||||
nativeRegisterInputChannel(mPtr, inputChannels[0], null, displayId);
|
||||
nativeRegisterInputChannel(mPtr, inputChannels[0], displayId);
|
||||
inputChannels[0].dispose(); // don't need to retain the Java object reference
|
||||
return inputChannels[1];
|
||||
}
|
||||
@@ -498,14 +499,17 @@ public class InputManagerService extends IInputManager.Stub
|
||||
* @param inputWindowHandle The handle of the input window associated with the
|
||||
* input channel, or null if none.
|
||||
*/
|
||||
public void registerInputChannel(InputChannel inputChannel,
|
||||
InputWindowHandle inputWindowHandle) {
|
||||
public void registerInputChannel(InputChannel inputChannel, IBinder token) {
|
||||
if (inputChannel == null) {
|
||||
throw new IllegalArgumentException("inputChannel must not be null.");
|
||||
}
|
||||
|
||||
// Register channel for normal.
|
||||
nativeRegisterInputChannel(mPtr, inputChannel, inputWindowHandle, Display.INVALID_DISPLAY);
|
||||
if (token == null) {
|
||||
token = new Binder();
|
||||
}
|
||||
inputChannel.setToken(token);
|
||||
|
||||
nativeRegisterInputChannel(mPtr, inputChannel, Display.INVALID_DISPLAY);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1791,15 +1795,15 @@ public class InputManagerService extends IInputManager.Stub
|
||||
}
|
||||
|
||||
// Native callback.
|
||||
private void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
|
||||
mWindowManagerCallbacks.notifyInputChannelBroken(inputWindowHandle);
|
||||
private void notifyInputChannelBroken(IBinder token) {
|
||||
mWindowManagerCallbacks.notifyInputChannelBroken(token);
|
||||
}
|
||||
|
||||
// Native callback.
|
||||
private long notifyANR(InputApplicationHandle inputApplicationHandle,
|
||||
InputWindowHandle inputWindowHandle, String reason) {
|
||||
IBinder token, String reason) {
|
||||
return mWindowManagerCallbacks.notifyANR(
|
||||
inputApplicationHandle, inputWindowHandle, reason);
|
||||
inputApplicationHandle, token, reason);
|
||||
}
|
||||
|
||||
// Native callback.
|
||||
@@ -1830,13 +1834,13 @@ public class InputManagerService extends IInputManager.Stub
|
||||
}
|
||||
|
||||
// Native callback.
|
||||
private long interceptKeyBeforeDispatching(InputWindowHandle focus,
|
||||
private long interceptKeyBeforeDispatching(IBinder focus,
|
||||
KeyEvent event, int policyFlags) {
|
||||
return mWindowManagerCallbacks.interceptKeyBeforeDispatching(focus, event, policyFlags);
|
||||
}
|
||||
|
||||
// Native callback.
|
||||
private KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
|
||||
private KeyEvent dispatchUnhandledKey(IBinder focus,
|
||||
KeyEvent event, int policyFlags) {
|
||||
return mWindowManagerCallbacks.dispatchUnhandledKey(focus, event, policyFlags);
|
||||
}
|
||||
@@ -1987,19 +1991,19 @@ public class InputManagerService extends IInputManager.Stub
|
||||
|
||||
public void notifyCameraLensCoverSwitchChanged(long whenNanos, boolean lensCovered);
|
||||
|
||||
public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle);
|
||||
public void notifyInputChannelBroken(IBinder token);
|
||||
|
||||
public long notifyANR(InputApplicationHandle inputApplicationHandle,
|
||||
InputWindowHandle inputWindowHandle, String reason);
|
||||
IBinder token, String reason);
|
||||
|
||||
public int interceptKeyBeforeQueueing(KeyEvent event, int policyFlags);
|
||||
|
||||
public int interceptMotionBeforeQueueingNonInteractive(long whenNanos, int policyFlags);
|
||||
|
||||
public long interceptKeyBeforeDispatching(InputWindowHandle focus,
|
||||
public long interceptKeyBeforeDispatching(IBinder token,
|
||||
KeyEvent event, int policyFlags);
|
||||
|
||||
public KeyEvent dispatchUnhandledKey(InputWindowHandle focus,
|
||||
public KeyEvent dispatchUnhandledKey(IBinder token,
|
||||
KeyEvent event, int policyFlags);
|
||||
|
||||
public int getPointerLayer();
|
||||
|
||||
@@ -95,6 +95,7 @@ import android.util.Slog;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
import android.view.DisplayInfo;
|
||||
import android.view.IApplicationToken;
|
||||
import android.view.InputApplicationHandle;
|
||||
import android.view.RemoteAnimationDefinition;
|
||||
import android.view.SurfaceControl;
|
||||
import android.view.SurfaceControl.Transaction;
|
||||
@@ -105,7 +106,6 @@ import android.view.animation.Animation;
|
||||
import com.android.internal.R;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.ToBooleanFunction;
|
||||
import com.android.server.input.InputApplicationHandle;
|
||||
import com.android.server.policy.WindowManagerPolicy.StartingSurface;
|
||||
import com.android.server.wm.WindowManagerService.H;
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ import android.view.SurfaceSession;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.internal.util.Preconditions;
|
||||
import com.android.server.input.InputWindowHandle;
|
||||
import android.view.InputWindowHandle;
|
||||
import com.android.server.wm.WindowManagerInternal.IDragDropCallback;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
|
||||
@@ -57,8 +57,8 @@ import android.view.animation.Interpolator;
|
||||
|
||||
import com.android.internal.view.IDragAndDropPermissions;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.input.InputApplicationHandle;
|
||||
import com.android.server.input.InputWindowHandle;
|
||||
import android.view.InputApplicationHandle;
|
||||
import android.view.InputWindowHandle;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
@@ -223,7 +223,7 @@ class DragState {
|
||||
mDragApplicationHandle.dispatchingTimeoutNanos =
|
||||
WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
|
||||
|
||||
mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null, null,
|
||||
mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null,
|
||||
display.getDisplayId());
|
||||
mDragWindowHandle.name = "drag";
|
||||
mDragWindowHandle.inputChannel = mServerChannel;
|
||||
|
||||
@@ -23,8 +23,8 @@ import android.os.UserHandle;
|
||||
import android.view.InputChannel;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.android.server.input.InputApplicationHandle;
|
||||
import com.android.server.input.InputWindowHandle;
|
||||
import android.view.InputApplicationHandle;
|
||||
import android.view.InputWindowHandle;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@@ -63,7 +63,7 @@ class InputConsumerImpl implements IBinder.DeathRecipient {
|
||||
mApplicationHandle.dispatchingTimeoutNanos =
|
||||
WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
|
||||
|
||||
mWindowHandle = new InputWindowHandle(mApplicationHandle, null, null, displayId);
|
||||
mWindowHandle = new InputWindowHandle(mApplicationHandle, null, displayId);
|
||||
mWindowHandle.name = name;
|
||||
mWindowHandle.inputChannel = mServerChannel;
|
||||
mWindowHandle.layoutParamsType = WindowManager.LayoutParams.TYPE_INPUT_CONSUMER;
|
||||
|
||||
@@ -8,16 +8,19 @@ import static com.android.server.wm.WindowManagerDebugConfig.TAG_WM;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.os.Debug;
|
||||
import android.os.IBinder;
|
||||
import android.os.RemoteException;
|
||||
import android.util.Slog;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.android.server.input.InputApplicationHandle;
|
||||
import android.view.InputApplicationHandle;
|
||||
import com.android.server.input.InputManagerService;
|
||||
import com.android.server.input.InputWindowHandle;
|
||||
import android.view.InputWindowHandle;
|
||||
import android.view.InputChannel;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
import java.util.HashMap;
|
||||
|
||||
final class InputManagerCallback implements InputManagerService.WindowManagerCallbacks {
|
||||
private final WindowManagerService mService;
|
||||
@@ -48,13 +51,13 @@ final class InputManagerCallback implements InputManagerService.WindowManagerCal
|
||||
* Called by the InputManager.
|
||||
*/
|
||||
@Override
|
||||
public void notifyInputChannelBroken(InputWindowHandle inputWindowHandle) {
|
||||
if (inputWindowHandle == null) {
|
||||
public void notifyInputChannelBroken(IBinder token) {
|
||||
if (token == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
synchronized (mService.mGlobalLock) {
|
||||
WindowState windowState = (WindowState) inputWindowHandle.windowState;
|
||||
WindowState windowState = mService.windowForClientLocked(null, token, false);
|
||||
if (windowState != null) {
|
||||
Slog.i(TAG_WM, "WINDOW DIED " + windowState);
|
||||
windowState.removeIfPossible();
|
||||
@@ -70,13 +73,13 @@ final class InputManagerCallback implements InputManagerService.WindowManagerCal
|
||||
*/
|
||||
@Override
|
||||
public long notifyANR(InputApplicationHandle inputApplicationHandle,
|
||||
InputWindowHandle inputWindowHandle, String reason) {
|
||||
IBinder token, String reason) {
|
||||
AppWindowToken appWindowToken = null;
|
||||
WindowState windowState = null;
|
||||
boolean aboveSystem = false;
|
||||
synchronized (mService.mGlobalLock) {
|
||||
if (inputWindowHandle != null) {
|
||||
windowState = (WindowState) inputWindowHandle.windowState;
|
||||
if (token != null) {
|
||||
windowState = mService.windowForClientLocked(null, token, false);
|
||||
if (windowState != null) {
|
||||
appWindowToken = windowState.mAppToken;
|
||||
}
|
||||
@@ -188,8 +191,8 @@ final class InputManagerCallback implements InputManagerService.WindowManagerCal
|
||||
*/
|
||||
@Override
|
||||
public long interceptKeyBeforeDispatching(
|
||||
InputWindowHandle focus, KeyEvent event, int policyFlags) {
|
||||
WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
|
||||
IBinder focus, KeyEvent event, int policyFlags) {
|
||||
WindowState windowState = mService.windowForClientLocked(null, focus, false);
|
||||
return mService.mPolicy.interceptKeyBeforeDispatching(windowState, event, policyFlags);
|
||||
}
|
||||
|
||||
@@ -199,8 +202,8 @@ final class InputManagerCallback implements InputManagerService.WindowManagerCal
|
||||
*/
|
||||
@Override
|
||||
public KeyEvent dispatchUnhandledKey(
|
||||
InputWindowHandle focus, KeyEvent event, int policyFlags) {
|
||||
WindowState windowState = focus != null ? (WindowState) focus.windowState : null;
|
||||
IBinder focus, KeyEvent event, int policyFlags) {
|
||||
WindowState windowState = mService.windowForClientLocked(null, focus, false);
|
||||
return mService.mPolicy.dispatchUnhandledKey(windowState, event, policyFlags);
|
||||
}
|
||||
|
||||
|
||||
@@ -42,9 +42,12 @@ import android.util.Log;
|
||||
import android.util.Slog;
|
||||
import android.view.InputChannel;
|
||||
import android.view.InputEventReceiver;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.WindowManager;
|
||||
import android.view.InputApplicationHandle;
|
||||
import android.view.InputWindowHandle;
|
||||
|
||||
import com.android.server.input.InputApplicationHandle;
|
||||
import com.android.server.input.InputWindowHandle;
|
||||
import com.android.server.input.InputManagerService;
|
||||
import com.android.server.policy.WindowManagerPolicy;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
@@ -43,6 +43,7 @@ import android.util.Slog;
|
||||
import android.util.SparseBooleanArray;
|
||||
import android.util.SparseIntArray;
|
||||
import android.util.proto.ProtoOutputStream;
|
||||
import android.view.InputWindowHandle;
|
||||
import android.view.IRecentsAnimationController;
|
||||
import android.view.IRecentsAnimationRunner;
|
||||
import android.view.RemoteAnimationTarget;
|
||||
@@ -50,7 +51,6 @@ import android.view.SurfaceControl;
|
||||
import android.view.SurfaceControl.Transaction;
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.server.LocalServices;
|
||||
import com.android.server.input.InputWindowHandle;
|
||||
import com.android.server.inputmethod.InputMethodManagerInternal;
|
||||
import com.android.server.wm.SurfaceAnimator.OnAnimationFinishedCallback;
|
||||
import com.android.server.wm.utils.InsetUtils;
|
||||
|
||||
@@ -49,8 +49,9 @@ import android.view.MotionEvent;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.server.input.InputApplicationHandle;
|
||||
import com.android.server.input.InputWindowHandle;
|
||||
import android.view.InputApplicationHandle;
|
||||
import android.view.InputWindowHandle;
|
||||
import com.android.server.wm.WindowManagerService.H;
|
||||
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
@@ -265,7 +266,7 @@ class TaskPositioner {
|
||||
mDragApplicationHandle.dispatchingTimeoutNanos =
|
||||
WindowManagerService.DEFAULT_INPUT_DISPATCHING_TIMEOUT_NANOS;
|
||||
|
||||
mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null, null,
|
||||
mDragWindowHandle = new InputWindowHandle(mDragApplicationHandle, null,
|
||||
display.getDisplayId());
|
||||
mDragWindowHandle.name = TAG;
|
||||
mDragWindowHandle.inputChannel = mServerChannel;
|
||||
|
||||
@@ -29,7 +29,7 @@ import android.view.IWindow;
|
||||
|
||||
import com.android.internal.annotations.GuardedBy;
|
||||
import com.android.server.input.InputManagerService;
|
||||
import com.android.server.input.InputWindowHandle;
|
||||
import android.view.InputWindowHandle;
|
||||
|
||||
/**
|
||||
* Controller for task positioning by drag.
|
||||
|
||||
@@ -191,7 +191,7 @@ import android.view.animation.Interpolator;
|
||||
|
||||
import com.android.internal.annotations.VisibleForTesting;
|
||||
import com.android.internal.util.ToBooleanFunction;
|
||||
import com.android.server.input.InputWindowHandle;
|
||||
import android.view.InputWindowHandle;
|
||||
import com.android.server.policy.WindowManagerPolicy;
|
||||
import com.android.server.wm.LocalAnimationAdapter.AnimationSpec;
|
||||
import com.android.server.wm.utils.InsetUtils;
|
||||
@@ -718,7 +718,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
|
||||
mLastRequestedHeight = 0;
|
||||
mLayer = 0;
|
||||
mInputWindowHandle = new InputWindowHandle(
|
||||
mAppToken != null ? mAppToken.mInputApplicationHandle : null, this, c,
|
||||
mAppToken != null ? mAppToken.mInputApplicationHandle : null, c,
|
||||
getDisplayId());
|
||||
}
|
||||
|
||||
@@ -2047,7 +2047,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
|
||||
// Create dummy event receiver that simply reports all events as handled.
|
||||
mDeadWindowEventReceiver = new DeadWindowEventReceiver(mClientChannel);
|
||||
}
|
||||
mService.mInputManager.registerInputChannel(mInputChannel, mInputWindowHandle);
|
||||
mService.mInputManager.registerInputChannel(mInputChannel, mClient.asBinder());
|
||||
}
|
||||
|
||||
void disposeInputChannel() {
|
||||
@@ -2059,6 +2059,7 @@ class WindowState extends WindowContainer<WindowState> implements WindowManagerP
|
||||
// unregister server channel first otherwise it complains about broken channel
|
||||
if (mInputChannel != null) {
|
||||
mService.mInputManager.unregisterInputChannel(mInputChannel);
|
||||
|
||||
mInputChannel.dispose();
|
||||
mInputChannel = null;
|
||||
}
|
||||
|
||||
@@ -42,6 +42,8 @@
|
||||
#include <utils/Trace.h>
|
||||
#include <utils/SortedVector.h>
|
||||
|
||||
#include <binder/IServiceManager.h>
|
||||
|
||||
#include <input/PointerController.h>
|
||||
#include <input/SpriteController.h>
|
||||
|
||||
@@ -63,6 +65,7 @@
|
||||
#include "android_hardware_input_InputApplicationHandle.h"
|
||||
#include "android_hardware_input_InputWindowHandle.h"
|
||||
#include "android_hardware_display_DisplayViewport.h"
|
||||
#include "android_util_Binder.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -153,15 +156,6 @@ static jobject getInputApplicationHandleObjLocalRef(JNIEnv* env,
|
||||
getInputApplicationHandleObjLocalRef(env);
|
||||
}
|
||||
|
||||
static jobject getInputWindowHandleObjLocalRef(JNIEnv* env,
|
||||
const sp<InputWindowHandle>& inputWindowHandle) {
|
||||
if (inputWindowHandle == nullptr) {
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<NativeInputWindowHandle*>(inputWindowHandle.get())->
|
||||
getInputWindowHandleObjLocalRef(env);
|
||||
}
|
||||
|
||||
static void loadSystemIconAsSpriteWithPointerIcon(JNIEnv* env, jobject contextObj, int32_t style,
|
||||
PointerIcon* outPointerIcon, SpriteIcon* outSpriteIcon) {
|
||||
status_t status = android_view_PointerIcon_loadSystemIcon(env,
|
||||
@@ -216,8 +210,7 @@ public:
|
||||
|
||||
void setDisplayViewports(JNIEnv* env, jobjectArray viewportObjArray);
|
||||
|
||||
status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel,
|
||||
const sp<InputWindowHandle>& inputWindowHandle, int32_t displayId);
|
||||
status_t registerInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel, int32_t displayId);
|
||||
status_t unregisterInputChannel(JNIEnv* env, const sp<InputChannel>& inputChannel);
|
||||
|
||||
void setInputWindows(JNIEnv* env, jobjectArray windowHandleObjArray, int32_t displayId);
|
||||
@@ -253,17 +246,17 @@ public:
|
||||
uint32_t policyFlags);
|
||||
virtual void notifyConfigurationChanged(nsecs_t when);
|
||||
virtual nsecs_t notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
|
||||
const sp<InputWindowHandle>& inputWindowHandle,
|
||||
const sp<IBinder>& token,
|
||||
const std::string& reason);
|
||||
virtual void notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle);
|
||||
virtual void notifyInputChannelBroken(const sp<IBinder>& token);
|
||||
virtual bool filterInputEvent(const InputEvent* inputEvent, uint32_t policyFlags);
|
||||
virtual void getDispatcherConfiguration(InputDispatcherConfiguration* outConfig);
|
||||
virtual void interceptKeyBeforeQueueing(const KeyEvent* keyEvent, uint32_t& policyFlags);
|
||||
virtual void interceptMotionBeforeQueueing(nsecs_t when, uint32_t& policyFlags);
|
||||
virtual nsecs_t interceptKeyBeforeDispatching(
|
||||
const sp<InputWindowHandle>& inputWindowHandle,
|
||||
const sp<IBinder>& token,
|
||||
const KeyEvent* keyEvent, uint32_t policyFlags);
|
||||
virtual bool dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
|
||||
virtual bool dispatchUnhandledKey(const sp<IBinder>& token,
|
||||
const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent);
|
||||
virtual void pokeUserActivity(nsecs_t eventTime, int32_t eventType);
|
||||
virtual bool checkInjectEventsPermissionNonReentrant(
|
||||
@@ -442,11 +435,10 @@ void NativeInputManager::setDisplayViewports(JNIEnv* env, jobjectArray viewportO
|
||||
}
|
||||
|
||||
status_t NativeInputManager::registerInputChannel(JNIEnv* /* env */,
|
||||
const sp<InputChannel>& inputChannel, const sp<InputWindowHandle>& inputWindowHandle,
|
||||
int32_t displayId) {
|
||||
const sp<InputChannel>& inputChannel, int32_t displayId) {
|
||||
ATRACE_CALL();
|
||||
return mInputManager->getDispatcher()->registerInputChannel(inputChannel, inputWindowHandle,
|
||||
displayId);
|
||||
return mInputManager->getDispatcher()->registerInputChannel(
|
||||
inputChannel, displayId);
|
||||
}
|
||||
|
||||
status_t NativeInputManager::unregisterInputChannel(JNIEnv* /* env */,
|
||||
@@ -657,7 +649,7 @@ void NativeInputManager::notifyConfigurationChanged(nsecs_t when) {
|
||||
}
|
||||
|
||||
nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApplicationHandle,
|
||||
const sp<InputWindowHandle>& inputWindowHandle, const std::string& reason) {
|
||||
const sp<IBinder>& token, const std::string& reason) {
|
||||
#if DEBUG_INPUT_DISPATCHER_POLICY
|
||||
ALOGD("notifyANR");
|
||||
#endif
|
||||
@@ -667,12 +659,11 @@ nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApp
|
||||
|
||||
jobject inputApplicationHandleObj =
|
||||
getInputApplicationHandleObjLocalRef(env, inputApplicationHandle);
|
||||
jobject inputWindowHandleObj =
|
||||
getInputWindowHandleObjLocalRef(env, inputWindowHandle);
|
||||
jobject tokenObj = javaObjectForIBinder(env, token);
|
||||
jstring reasonObj = env->NewStringUTF(reason.c_str());
|
||||
|
||||
jlong newTimeout = env->CallLongMethod(mServiceObj,
|
||||
gServiceClassInfo.notifyANR, inputApplicationHandleObj, inputWindowHandleObj,
|
||||
gServiceClassInfo.notifyANR, inputApplicationHandleObj, tokenObj,
|
||||
reasonObj);
|
||||
if (checkAndClearExceptionFromCallback(env, "notifyANR")) {
|
||||
newTimeout = 0; // abort dispatch
|
||||
@@ -681,12 +672,11 @@ nsecs_t NativeInputManager::notifyANR(const sp<InputApplicationHandle>& inputApp
|
||||
}
|
||||
|
||||
env->DeleteLocalRef(reasonObj);
|
||||
env->DeleteLocalRef(inputWindowHandleObj);
|
||||
env->DeleteLocalRef(inputApplicationHandleObj);
|
||||
return newTimeout;
|
||||
}
|
||||
|
||||
void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& inputWindowHandle) {
|
||||
void NativeInputManager::notifyInputChannelBroken(const sp<IBinder>& token) {
|
||||
#if DEBUG_INPUT_DISPATCHER_POLICY
|
||||
ALOGD("notifyInputChannelBroken");
|
||||
#endif
|
||||
@@ -694,14 +684,11 @@ void NativeInputManager::notifyInputChannelBroken(const sp<InputWindowHandle>& i
|
||||
|
||||
JNIEnv* env = jniEnv();
|
||||
|
||||
jobject inputWindowHandleObj =
|
||||
getInputWindowHandleObjLocalRef(env, inputWindowHandle);
|
||||
if (inputWindowHandleObj) {
|
||||
jobject tokenObj = javaObjectForIBinder(env, token);
|
||||
if (tokenObj) {
|
||||
env->CallVoidMethod(mServiceObj, gServiceClassInfo.notifyInputChannelBroken,
|
||||
inputWindowHandleObj);
|
||||
tokenObj);
|
||||
checkAndClearExceptionFromCallback(env, "notifyInputChannelBroken");
|
||||
|
||||
env->DeleteLocalRef(inputWindowHandleObj);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1061,7 +1048,7 @@ void NativeInputManager::handleInterceptActions(jint wmActions, nsecs_t when,
|
||||
}
|
||||
|
||||
nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
|
||||
const sp<InputWindowHandle>& inputWindowHandle,
|
||||
const sp<IBinder>& token,
|
||||
const KeyEvent* keyEvent, uint32_t policyFlags) {
|
||||
ATRACE_CALL();
|
||||
// Policy:
|
||||
@@ -1072,13 +1059,14 @@ nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
|
||||
if (policyFlags & POLICY_FLAG_TRUSTED) {
|
||||
JNIEnv* env = jniEnv();
|
||||
|
||||
// Note: inputWindowHandle may be null.
|
||||
jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
|
||||
// Token may be null
|
||||
jobject tokenObj = javaObjectForIBinder(env, token);
|
||||
|
||||
jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
|
||||
if (keyEventObj) {
|
||||
jlong delayMillis = env->CallLongMethod(mServiceObj,
|
||||
gServiceClassInfo.interceptKeyBeforeDispatching,
|
||||
inputWindowHandleObj, keyEventObj, policyFlags);
|
||||
tokenObj, keyEventObj, policyFlags);
|
||||
bool error = checkAndClearExceptionFromCallback(env, "interceptKeyBeforeDispatching");
|
||||
android_view_KeyEvent_recycle(env, keyEventObj);
|
||||
env->DeleteLocalRef(keyEventObj);
|
||||
@@ -1092,12 +1080,11 @@ nsecs_t NativeInputManager::interceptKeyBeforeDispatching(
|
||||
} else {
|
||||
ALOGE("Failed to obtain key event object for interceptKeyBeforeDispatching.");
|
||||
}
|
||||
env->DeleteLocalRef(inputWindowHandleObj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& inputWindowHandle,
|
||||
bool NativeInputManager::dispatchUnhandledKey(const sp<IBinder>& token,
|
||||
const KeyEvent* keyEvent, uint32_t policyFlags, KeyEvent* outFallbackKeyEvent) {
|
||||
ATRACE_CALL();
|
||||
// Policy:
|
||||
@@ -1106,13 +1093,13 @@ bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& input
|
||||
if (policyFlags & POLICY_FLAG_TRUSTED) {
|
||||
JNIEnv* env = jniEnv();
|
||||
|
||||
// Note: inputWindowHandle may be null.
|
||||
jobject inputWindowHandleObj = getInputWindowHandleObjLocalRef(env, inputWindowHandle);
|
||||
// Note: tokenObj may be null.
|
||||
jobject tokenObj = javaObjectForIBinder(env, token);
|
||||
jobject keyEventObj = android_view_KeyEvent_fromNative(env, keyEvent);
|
||||
if (keyEventObj) {
|
||||
jobject fallbackKeyEventObj = env->CallObjectMethod(mServiceObj,
|
||||
gServiceClassInfo.dispatchUnhandledKey,
|
||||
inputWindowHandleObj, keyEventObj, policyFlags);
|
||||
tokenObj, keyEventObj, policyFlags);
|
||||
if (checkAndClearExceptionFromCallback(env, "dispatchUnhandledKey")) {
|
||||
fallbackKeyEventObj = nullptr;
|
||||
}
|
||||
@@ -1131,7 +1118,6 @@ bool NativeInputManager::dispatchUnhandledKey(const sp<InputWindowHandle>& input
|
||||
} else {
|
||||
ALOGE("Failed to obtain key event object for dispatchUnhandledKey.");
|
||||
}
|
||||
env->DeleteLocalRef(inputWindowHandleObj);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -1316,7 +1302,7 @@ static void handleInputChannelDisposed(JNIEnv* env,
|
||||
}
|
||||
|
||||
static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */,
|
||||
jlong ptr, jobject inputChannelObj, jobject inputWindowHandleObj, jint displayId) {
|
||||
jlong ptr, jobject inputChannelObj, jint displayId) {
|
||||
NativeInputManager* im = reinterpret_cast<NativeInputManager*>(ptr);
|
||||
|
||||
sp<InputChannel> inputChannel = android_view_InputChannel_getInputChannel(env,
|
||||
@@ -1325,12 +1311,10 @@ static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */,
|
||||
throwInputChannelNotInitialized(env);
|
||||
return;
|
||||
}
|
||||
bool monitor = inputChannel->getToken() == nullptr && displayId != ADISPLAY_ID_NONE;
|
||||
|
||||
sp<InputWindowHandle> inputWindowHandle =
|
||||
android_server_InputWindowHandle_getHandle(env, inputWindowHandleObj);
|
||||
status_t status = im->registerInputChannel(env, inputChannel, displayId);
|
||||
|
||||
status_t status = im->registerInputChannel(
|
||||
env, inputChannel, inputWindowHandle, displayId);
|
||||
if (status) {
|
||||
std::string message;
|
||||
message += StringPrintf("Failed to register input channel. status=%d", status);
|
||||
@@ -1339,7 +1323,7 @@ static void nativeRegisterInputChannel(JNIEnv* env, jclass /* clazz */,
|
||||
}
|
||||
|
||||
// If inputWindowHandle is null and displayId >= 0, treat inputChannel as monitor.
|
||||
if (inputWindowHandle != nullptr || displayId == ADISPLAY_ID_NONE) {
|
||||
if (!monitor) {
|
||||
android_view_InputChannel_setDisposeCallback(env, inputChannelObj,
|
||||
handleInputChannelDisposed, im);
|
||||
}
|
||||
@@ -1640,7 +1624,7 @@ static const JNINativeMethod gInputManagerMethods[] = {
|
||||
{ "nativeHasKeys", "(JII[I[Z)Z",
|
||||
(void*) nativeHasKeys },
|
||||
{ "nativeRegisterInputChannel",
|
||||
"(JLandroid/view/InputChannel;Lcom/android/server/input/InputWindowHandle;I)V",
|
||||
"(JLandroid/view/InputChannel;I)V",
|
||||
(void*) nativeRegisterInputChannel },
|
||||
{ "nativeUnregisterInputChannel", "(JLandroid/view/InputChannel;)V",
|
||||
(void*) nativeUnregisterInputChannel },
|
||||
@@ -1650,9 +1634,9 @@ static const JNINativeMethod gInputManagerMethods[] = {
|
||||
(void*) nativeInjectInputEvent },
|
||||
{ "nativeToggleCapsLock", "(JI)V",
|
||||
(void*) nativeToggleCapsLock },
|
||||
{ "nativeSetInputWindows", "(J[Lcom/android/server/input/InputWindowHandle;I)V",
|
||||
{ "nativeSetInputWindows", "(J[Landroid/view/InputWindowHandle;I)V",
|
||||
(void*) nativeSetInputWindows },
|
||||
{ "nativeSetFocusedApplication", "(JILcom/android/server/input/InputApplicationHandle;)V",
|
||||
{ "nativeSetFocusedApplication", "(JILandroid/view/InputApplicationHandle;)V",
|
||||
(void*) nativeSetFocusedApplication },
|
||||
{ "nativeSetFocusedDisplay", "(JI)V",
|
||||
(void*) nativeSetFocusedDisplay },
|
||||
@@ -1731,11 +1715,11 @@ int register_android_server_InputManager(JNIEnv* env) {
|
||||
"notifySwitch", "(JII)V");
|
||||
|
||||
GET_METHOD_ID(gServiceClassInfo.notifyInputChannelBroken, clazz,
|
||||
"notifyInputChannelBroken", "(Lcom/android/server/input/InputWindowHandle;)V");
|
||||
"notifyInputChannelBroken", "(Landroid/os/IBinder;)V");
|
||||
|
||||
GET_METHOD_ID(gServiceClassInfo.notifyANR, clazz,
|
||||
"notifyANR",
|
||||
"(Lcom/android/server/input/InputApplicationHandle;Lcom/android/server/input/InputWindowHandle;Ljava/lang/String;)J");
|
||||
"(Landroid/view/InputApplicationHandle;Landroid/os/IBinder;Ljava/lang/String;)J");
|
||||
|
||||
GET_METHOD_ID(gServiceClassInfo.filterInputEvent, clazz,
|
||||
"filterInputEvent", "(Landroid/view/InputEvent;I)Z");
|
||||
@@ -1748,11 +1732,11 @@ int register_android_server_InputManager(JNIEnv* env) {
|
||||
|
||||
GET_METHOD_ID(gServiceClassInfo.interceptKeyBeforeDispatching, clazz,
|
||||
"interceptKeyBeforeDispatching",
|
||||
"(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)J");
|
||||
"(Landroid/os/IBinder;Landroid/view/KeyEvent;I)J");
|
||||
|
||||
GET_METHOD_ID(gServiceClassInfo.dispatchUnhandledKey, clazz,
|
||||
"dispatchUnhandledKey",
|
||||
"(Lcom/android/server/input/InputWindowHandle;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
|
||||
"(Landroid/os/IBinder;Landroid/view/KeyEvent;I)Landroid/view/KeyEvent;");
|
||||
|
||||
GET_METHOD_ID(gServiceClassInfo.checkInjectEventsPermission, clazz,
|
||||
"checkInjectEventsPermission", "(II)Z");
|
||||
|
||||
Reference in New Issue
Block a user