Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3bf2e57f authored by Albert Chaulk's avatar Albert Chaulk
Browse files

Propagate surface type and owner through to SurfaceFlinger.

This allows VrWindowManager to identify things like permission
dialogues in the list of SurfaceFlinger layers that show up while a
VR application is running and display them without leaving VR mode.

Bug: 30984984
Test: Run VR application, request permission at runtime, observe and
  accept permission in VrWindowManager without leaving VR mode.

Change-Id: I347313b5fcd08dea3cd6fddfaeb15640938e3a87
parent df9a4f9a
Loading
Loading
Loading
Loading
+14 −5
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ public class SurfaceControl {
    private static final String TAG = "SurfaceControl";

    private static native long nativeCreate(SurfaceSession session, String name,
            int w, int h, int format, int flags, long parentObject)
            int w, int h, int format, int flags, long parentObject, int windowType, int ownerUid)
            throws OutOfResourcesException;
    private static native void nativeRelease(long nativeObject);
    private static native void nativeDestroy(long nativeObject);
@@ -281,17 +281,25 @@ public class SurfaceControl {
     * @param h The surface initial height.
     * @param flags The surface creation flags.  Should always include {@link #HIDDEN}
     * in the creation flags.
     * @param windowType The type of the window as specified in WindowManager.java.
     * @param ownerUid A unique per-app ID.
     *
     * @throws throws OutOfResourcesException If the SurfaceControl cannot be created.
     */
    public SurfaceControl(SurfaceSession session,
            String name, int w, int h, int format, int flags)
            String name, int w, int h, int format, int flags, int windowType, int ownerUid)
                    throws OutOfResourcesException {
        this(session, name, w, h, format, flags, null);
        this(session, name, w, h, format, flags, null, windowType, ownerUid);
    }

    public SurfaceControl(SurfaceSession session,
            String name, int w, int h, int format, int flags, SurfaceControl parent)
            String name, int w, int h, int format, int flags)
                    throws OutOfResourcesException {
        this(session, name, w, h, format, flags, null, -1, -1);
    }

    public SurfaceControl(SurfaceSession session, String name, int w, int h, int format, int flags,
            SurfaceControl parent, int windowType, int ownerUid)
                    throws OutOfResourcesException {
        if (session == null) {
            throw new IllegalArgumentException("session must not be null");
@@ -310,7 +318,8 @@ public class SurfaceControl {
        }

        mName = name;
        mNativeObject = nativeCreate(session, name, w, h, format, flags, parent != null ? parent.mNativeObject : 0);
        mNativeObject = nativeCreate(session, name, w, h, format, flags,
            parent != null ? parent.mNativeObject : 0, windowType, ownerUid);
        if (mNativeObject == 0) {
            throw new OutOfResourcesException(
                    "Couldn't allocate SurfaceControl native object");
+5 −3
Original line number Diff line number Diff line
@@ -98,16 +98,18 @@ static struct {
// ----------------------------------------------------------------------------

static jlong nativeCreate(JNIEnv* env, jclass clazz, jobject sessionObj,
        jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject) {
        jstring nameStr, jint w, jint h, jint format, jint flags, jlong parentObject,
        jint windowType, jint ownerUid) {
    ScopedUtfChars name(env, nameStr);
    sp<SurfaceComposerClient> client(android_view_SurfaceSession_getClient(env, sessionObj));
    SurfaceControl *parent = reinterpret_cast<SurfaceControl*>(parentObject);
    sp<SurfaceControl> surface = client->createSurface(
            String8(name.c_str()), w, h, format, flags, parent);
            String8(name.c_str()), w, h, format, flags, parent, windowType, ownerUid);
    if (surface == NULL) {
        jniThrowException(env, OutOfResourcesException, NULL);
        return 0;
    }

    surface->incStrong((void *)nativeCreate);
    return reinterpret_cast<jlong>(surface.get());
}
@@ -742,7 +744,7 @@ static jobject nativeGetHdrCapabilities(JNIEnv* env, jclass clazz, jobject token
// ----------------------------------------------------------------------------

static const JNINativeMethod sSurfaceControlMethods[] = {
    {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJ)J",
    {"nativeCreate", "(Landroid/view/SurfaceSession;Ljava/lang/String;IIIIJII)J",
            (void*)nativeCreate },
    {"nativeRelease", "(J)V",
            (void*)nativeRelease },
+2 −1
Original line number Diff line number Diff line
@@ -2171,7 +2171,8 @@ public class WindowManagerService extends IWindowManager.Stub
        if (!win.mHasSurface) {
            result |= RELAYOUT_RES_SURFACE_CHANGED;
        }
        WindowSurfaceController surfaceController = winAnimator.createSurfaceLocked();
        WindowSurfaceController surfaceController = winAnimator.createSurfaceLocked(
            win.mAttrs.type, win.mOwnerUid);
        if (surfaceController != null) {
            surfaceController.getSurface(outSurface);
            if (SHOW_TRANSACTIONS) Slog.i(TAG_WM, "  OUT SURFACE " + outSurface + ": copied");
+2 −2
Original line number Diff line number Diff line
@@ -577,7 +577,7 @@ class WindowStateAnimator {
        }
    }

    WindowSurfaceController createSurfaceLocked() {
    WindowSurfaceController createSurfaceLocked(int windowType, int ownerUid) {
        final WindowState w = mWin;
        if (w.restoreSavedSurface()) {
            if (DEBUG_ANIM) Slog.i(TAG,
@@ -653,7 +653,7 @@ class WindowStateAnimator {

            mSurfaceController = new WindowSurfaceController(mSession.mSurfaceSession,
                    attrs.getTitle().toString(),
                    width, height, format, flags, this);
                    width, height, format, flags, this, windowType, ownerUid);

            w.setHasSurface(true);

+23 −12
Original line number Diff line number Diff line
@@ -79,8 +79,8 @@ class WindowSurfaceController {

    private final WindowManagerService mService;

    public WindowSurfaceController(SurfaceSession s,
            String name, int w, int h, int format, int flags, WindowStateAnimator animator) {
    public WindowSurfaceController(SurfaceSession s, String name, int w, int h, int format,
            int flags, WindowStateAnimator animator, int windowType, int ownerUid) {
        mAnimator = animator;

        mSurfaceW = w;
@@ -98,13 +98,13 @@ class WindowSurfaceController {
                animator.mWin.mSubLayer < 0 &&
                animator.mWin.mAppToken != null) {
            mSurfaceControl = new SurfaceControlWithBackground(s,
                    name, w, h, format, flags, animator.mWin.mAppToken);
                    name, w, h, format, flags, animator.mWin.mAppToken, windowType, ownerUid);
        } else if (DEBUG_SURFACE_TRACE) {
            mSurfaceControl = new SurfaceTrace(
                    s, name, w, h, format, flags);
                    s, name, w, h, format, flags, windowType, ownerUid);
        } else {
            mSurfaceControl = new SurfaceControl(
                    s, name, w, h, format, flags);
                    s, name, w, h, format, flags, windowType, ownerUid);
        }

        if (mService.mRoot.mSurfaceTraceEnabled) {
@@ -569,9 +569,21 @@ class WindowSurfaceController {
        private float mDsdx, mDtdx, mDsdy, mDtdy;
        private final String mName;

        public SurfaceTrace(SurfaceSession s,
                       String name, int w, int h, int format, int flags)
        public SurfaceTrace(SurfaceSession s, String name, int w, int h, int format, int flags,
                        int windowType, int ownerUid)
                    throws OutOfResourcesException {
            super(s, name, w, h, format, flags, windowType, ownerUid);
            mName = name != null ? name : "Not named";
            mSize.set(w, h);
            if (LOG_SURFACE_TRACE) Slog.v(SURFACE_TAG, "ctor: " + this + ". Called by "
                    + Debug.getCallers(3));
            synchronized (sSurfaces) {
                sSurfaces.add(0, this);
            }
        }

        public SurfaceTrace(SurfaceSession s,
                        String name, int w, int h, int format, int flags) {
            super(s, name, w, h, format, flags);
            mName = name != null ? name : "Not named";
            mSize.set(w, h);
@@ -806,11 +818,10 @@ class WindowSurfaceController {
        public boolean mVisible = false;
        public int mLayer = -1;

        public SurfaceControlWithBackground(SurfaceSession s,
                        String name, int w, int h, int format, int flags,
                        AppWindowToken token)
        public SurfaceControlWithBackground(SurfaceSession s, String name, int w, int h, int format,
                    int flags, AppWindowToken token, int windowType, int ownerUid)
                throws OutOfResourcesException {
            super(s, name, w, h, format, flags);
            super(s, name, w, h, format, flags, windowType, ownerUid);
            mBackgroundControl = new SurfaceControl(s, name, w, h,
                    PixelFormat.OPAQUE, flags | SurfaceControl.FX_SURFACE_DIM);
            mOpaque = (flags & SurfaceControl.OPAQUE) != 0;