Merge "Pass IWindow to InputWindowHandle." into sc-v2-dev

This commit is contained in:
Chavi Weingarten
2021-08-18 22:27:54 +00:00
committed by Android (Google) Code Review
5 changed files with 44 additions and 3 deletions

View File

@@ -44,6 +44,12 @@ public final class InputWindowHandle {
// channel and the server input channel will both contain this token. // channel and the server input channel will both contain this token.
public IBinder token; public IBinder token;
/**
* The {@link IWindow} handle if InputWindowHandle is associated with a window, null otherwise.
*/
@Nullable
private IBinder windowToken;
// The window name. // The window name.
public String name; public String name;
@@ -145,6 +151,7 @@ public final class InputWindowHandle {
.append(", visible=").append(visible) .append(", visible=").append(visible)
.append(", scaleFactor=").append(scaleFactor) .append(", scaleFactor=").append(scaleFactor)
.append(", transform=").append(transform) .append(", transform=").append(transform)
.append(", windowToken=").append(getWindow())
.toString(); .toString();
} }
@@ -176,4 +183,12 @@ public final class InputWindowHandle {
public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) { public void setTouchableRegionCrop(@Nullable SurfaceControl bounds) {
touchableRegionSurfaceControl = new WeakReference<>(bounds); touchableRegionSurfaceControl = new WeakReference<>(bounds);
} }
public void setWindowToken(IWindow iwindow) {
windowToken = iwindow.asBinder();
}
public IWindow getWindow() {
return IWindow.Stub.asInterface(windowToken);
}
} }

View File

@@ -76,6 +76,7 @@ static struct {
jfieldID replaceTouchableRegionWithCrop; jfieldID replaceTouchableRegionWithCrop;
WeakRefHandleField touchableRegionSurfaceControl; WeakRefHandleField touchableRegionSurfaceControl;
jfieldID transform; jfieldID transform;
jfieldID windowToken;
} gInputWindowHandleClassInfo; } gInputWindowHandleClassInfo;
static struct { static struct {
@@ -215,6 +216,14 @@ bool NativeInputWindowHandle::updateInfo() {
mInfo.touchableRegionCropHandle.clear(); mInfo.touchableRegionCropHandle.clear();
} }
jobject windowTokenObj = env->GetObjectField(obj, gInputWindowHandleClassInfo.windowToken);
if (windowTokenObj) {
mInfo.windowToken = ibinderForJavaObject(env, windowTokenObj);
env->DeleteLocalRef(windowTokenObj);
} else {
mInfo.windowToken.clear();
}
env->DeleteLocalRef(obj); env->DeleteLocalRef(obj);
return true; return true;
} }
@@ -314,6 +323,9 @@ jobject android_view_InputWindowHandle_fromWindowInfo(JNIEnv* env, gui::WindowIn
ScopedLocalRef<jobject> matrixObj(env, AMatrix_newInstance(env, transformVals)); ScopedLocalRef<jobject> matrixObj(env, AMatrix_newInstance(env, transformVals));
env->SetObjectField(inputWindowHandle, gInputWindowHandleClassInfo.transform, matrixObj.get()); env->SetObjectField(inputWindowHandle, gInputWindowHandleClassInfo.transform, matrixObj.get());
env->SetObjectField(inputWindowHandle, gInputWindowHandleClassInfo.windowToken,
javaObjectForIBinder(env, windowInfo.windowToken));
return inputWindowHandle; return inputWindowHandle;
} }
@@ -441,6 +453,9 @@ int register_android_view_InputWindowHandle(JNIEnv* env) {
GET_FIELD_ID(gInputWindowHandleClassInfo.transform, clazz, "transform", GET_FIELD_ID(gInputWindowHandleClassInfo.transform, clazz, "transform",
"Landroid/graphics/Matrix;"); "Landroid/graphics/Matrix;");
GET_FIELD_ID(gInputWindowHandleClassInfo.windowToken, clazz, "windowToken",
"Landroid/os/IBinder;");
jclass weakRefClazz; jclass weakRefClazz;
FIND_CLASS(weakRefClazz, "java/lang/ref/Reference"); FIND_CLASS(weakRefClazz, "java/lang/ref/Reference");

View File

@@ -289,6 +289,7 @@ final class InputMonitor {
inputWindowHandle.setInputFeatures(w.mAttrs.inputFeatures); inputWindowHandle.setInputFeatures(w.mAttrs.inputFeatures);
inputWindowHandle.setPaused(w.mActivityRecord != null && w.mActivityRecord.paused); inputWindowHandle.setPaused(w.mActivityRecord != null && w.mActivityRecord.paused);
inputWindowHandle.setVisible(w.isVisible()); inputWindowHandle.setVisible(w.isVisible());
inputWindowHandle.setWindowToken(w.mClient);
final boolean focusable = w.canReceiveKeys() final boolean focusable = w.canReceiveKeys()
&& (mService.mPerDisplayFocusEnabled || mDisplayContent.isOnTop()); && (mService.mPerDisplayFocusEnabled || mDisplayContent.isOnTop());

View File

@@ -20,6 +20,7 @@ import android.annotation.NonNull;
import android.annotation.Nullable; import android.annotation.Nullable;
import android.graphics.Region; import android.graphics.Region;
import android.os.IBinder; import android.os.IBinder;
import android.view.IWindow;
import android.view.InputApplicationHandle; import android.view.InputApplicationHandle;
import android.view.InputWindowHandle; import android.view.InputWindowHandle;
import android.view.SurfaceControl; import android.view.SurfaceControl;
@@ -275,6 +276,14 @@ class InputWindowHandleWrapper {
mChanged = true; mChanged = true;
} }
void setWindowToken(IWindow windowToken) {
if (mHandle.getWindow() == windowToken) {
return;
}
mHandle.setWindowToken(windowToken);
mChanged = true;
}
@Override @Override
public String toString() { public String toString() {
return mHandle + ", changed=" + mChanged; return mHandle + ", changed=" + mChanged;

View File

@@ -8256,7 +8256,7 @@ public class WindowManagerService extends IWindowManager.Stub
} }
updateInputChannel(clientChannel.getToken(), callingUid, callingPid, displayId, surface, updateInputChannel(clientChannel.getToken(), callingUid, callingPid, displayId, surface,
name, applicationHandle, flags, privateFlags, type, null /* region */); name, applicationHandle, flags, privateFlags, type, null /* region */, window);
clientChannel.copyTo(outInputChannel); clientChannel.copyTo(outInputChannel);
} }
@@ -8264,9 +8264,10 @@ public class WindowManagerService extends IWindowManager.Stub
private void updateInputChannel(IBinder channelToken, int callingUid, int callingPid, private void updateInputChannel(IBinder channelToken, int callingUid, int callingPid,
int displayId, SurfaceControl surface, String name, int displayId, SurfaceControl surface, String name,
InputApplicationHandle applicationHandle, int flags, InputApplicationHandle applicationHandle, int flags,
int privateFlags, int type, Region region) { int privateFlags, int type, Region region, IWindow window) {
InputWindowHandle h = new InputWindowHandle(applicationHandle, displayId); InputWindowHandle h = new InputWindowHandle(applicationHandle, displayId);
h.token = channelToken; h.token = channelToken;
h.setWindowToken(window);
h.name = name; h.name = name;
final int sanitizedFlags = flags & (LayoutParams.FLAG_NOT_TOUCHABLE final int sanitizedFlags = flags & (LayoutParams.FLAG_NOT_TOUCHABLE
@@ -8322,7 +8323,7 @@ public class WindowManagerService extends IWindowManager.Stub
} }
updateInputChannel(channelToken, win.mOwnerUid, win.mOwnerPid, displayId, surface, name, updateInputChannel(channelToken, win.mOwnerUid, win.mOwnerPid, displayId, surface, name,
applicationHandle, flags, privateFlags, win.mWindowType, region); applicationHandle, flags, privateFlags, win.mWindowType, region, win.mClient);
} }
/** Return whether layer tracing is enabled */ /** Return whether layer tracing is enabled */