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

Commit cbb9454c authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Ensure clearCallingIdentity for getDisplayContentOrCreate"

parents 922e1fee 1371c57f
Loading
Loading
Loading
Loading
+15 −14
Original line number Diff line number Diff line
@@ -934,17 +934,17 @@ public class DisplayPolicy {
     * @return If ok, WindowManagerImpl.ADD_OKAY.  If too many singletons,
     * WindowManagerImpl.ADD_MULTIPLE_SINGLETON
     */
    int validateAddingWindowLw(WindowManager.LayoutParams attrs) {
    int validateAddingWindowLw(WindowManager.LayoutParams attrs, int callingPid, int callingUid) {
        if ((attrs.privateFlags & PRIVATE_FLAG_IS_SCREEN_DECOR) != 0) {
            mContext.enforceCallingOrSelfPermission(
                    android.Manifest.permission.STATUS_BAR_SERVICE,
            mContext.enforcePermission(
                    android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid,
                    "DisplayPolicy");
        }

        switch (attrs.type) {
            case TYPE_STATUS_BAR:
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE,
                mContext.enforcePermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid,
                        "DisplayPolicy");
                if (mStatusBar != null) {
                    if (mStatusBar.isAlive()) {
@@ -953,8 +953,8 @@ public class DisplayPolicy {
                }
                break;
            case TYPE_NOTIFICATION_SHADE:
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE,
                mContext.enforcePermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid,
                        "DisplayPolicy");
                if (mNotificationShade != null) {
                    if (mNotificationShade.isAlive()) {
@@ -963,8 +963,8 @@ public class DisplayPolicy {
                }
                break;
            case TYPE_NAVIGATION_BAR:
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE,
                mContext.enforcePermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid,
                        "DisplayPolicy");
                if (mNavigationBar != null) {
                    if (mNavigationBar.isAlive()) {
@@ -974,16 +974,17 @@ public class DisplayPolicy {
                break;
            case TYPE_NAVIGATION_BAR_PANEL:
                // Check for permission if the caller is not the recents component.
                if (!mService.mAtmInternal.isCallerRecents(Binder.getCallingUid())) {
                    mContext.enforceCallingOrSelfPermission(
                            android.Manifest.permission.STATUS_BAR_SERVICE, "DisplayPolicy");
                if (!mService.mAtmInternal.isCallerRecents(callingUid)) {
                    mContext.enforcePermission(
                            android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid,
                            "DisplayPolicy");
                }
                break;
            case TYPE_STATUS_BAR_PANEL:
            case TYPE_STATUS_BAR_SUB_PANEL:
            case TYPE_VOICE_INTERACTION_STARTING:
                mContext.enforceCallingOrSelfPermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE,
                mContext.enforcePermission(
                        android.Manifest.permission.STATUS_BAR_SERVICE, callingPid, callingUid,
                        "DisplayPolicy");
                break;
        }
+70 −63
Original line number Diff line number Diff line
@@ -1345,8 +1345,9 @@ public class WindowManagerService extends IWindowManager.Stub
        }

        WindowState parentWindow = null;
        long origId;
        final int callingUid = Binder.getCallingUid();
        final int callingPid = Binder.getCallingPid();
        final long origId = Binder.clearCallingIdentity();
        final int type = attrs.type;

        synchronized (mGlobalLock) {
@@ -1505,10 +1506,9 @@ public class WindowManagerService extends IWindowManager.Stub
            }

            final DisplayPolicy displayPolicy = displayContent.getDisplayPolicy();
            displayPolicy.adjustWindowParamsLw(win, win.mAttrs, Binder.getCallingPid(),
                    Binder.getCallingUid());
            displayPolicy.adjustWindowParamsLw(win, win.mAttrs, callingPid, callingUid);

            res = displayPolicy.validateAddingWindowLw(attrs);
            res = displayPolicy.validateAddingWindowLw(attrs, callingPid, callingUid);
            if (res != WindowManagerGlobal.ADD_OKAY) {
                return res;
            }
@@ -1560,8 +1560,6 @@ public class WindowManagerService extends IWindowManager.Stub
                displayContent.mTapExcludedWindows.add(win);
            }

            origId = Binder.clearCallingIdentity();

            win.attach();
            mWindowMap.put(client.asBinder(), win);
            win.initAppOpsState();
@@ -2568,10 +2566,14 @@ public class WindowManagerService extends IWindowManager.Stub
            }
        }

        final int callingUid = Binder.getCallingUid();
        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                if (!callerCanManageAppTokens) {
                if (!unprivilegedAppCanCreateTokenWith(null, Binder.getCallingUid(), type, type,
                        null, packageName) || packageName == null) {
                    if (packageName == null || !unprivilegedAppCanCreateTokenWith(
                            null /* parentWindow */, callingUid, type, type, null /* tokenForLog */,
                            packageName)) {
                        throw new SecurityException("Requires MANAGE_APP_TOKENS permission");
                    }
                }
@@ -2597,6 +2599,9 @@ public class WindowManagerService extends IWindowManager.Stub
                    new WindowToken(this, binder, type, true, dc, callerCanManageAppTokens);
                }
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
        return WindowManagerGlobal.ADD_OKAY;
    }

@@ -6842,6 +6847,8 @@ public class WindowManagerService extends IWindowManager.Stub
            throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
        }

        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                final DisplayContent displayContent = getDisplayContentOrCreate(displayId, null);
                if (displayContent == null) {
@@ -6857,20 +6864,16 @@ public class WindowManagerService extends IWindowManager.Stub
                displayContent.reconfigureDisplayLocked();

                if (lastWindowingMode != displayContent.getWindowingMode()) {
                // reconfigure won't detect this change in isolation because the windowing mode is
                // already set on the display, so fire off a new config now.

                final long origId = Binder.clearCallingIdentity();
                try {
                    // direct call since lock is shared.
                    // reconfigure won't detect this change in isolation because the windowing mode
                    // is already set on the display, so fire off a new config now.
                    displayContent.sendNewConfiguration();
                } finally {
                    Binder.restoreCallingIdentity(origId);
                }
                // Now that all configurations are updated, execute pending transitions
                    // Now that all configurations are updated, execute pending transitions.
                    displayContent.executeAppTransition();
                }
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
    }

    @Override
@@ -6897,6 +6900,8 @@ public class WindowManagerService extends IWindowManager.Stub
            throw new SecurityException("Requires INTERNAL_SYSTEM_WINDOW permission");
        }

        final long origId = Binder.clearCallingIdentity();
        try {
            synchronized (mGlobalLock) {
                final DisplayContent displayContent = getDisplayContentOrCreate(displayId, null);
                if (displayContent == null) {
@@ -6907,9 +6912,11 @@ public class WindowManagerService extends IWindowManager.Stub
                }

                mDisplayWindowSettings.setRemoveContentModeLocked(displayContent, mode);

                displayContent.reconfigureDisplayLocked();
            }
        } finally {
            Binder.restoreCallingIdentity(origId);
        }
    }

    @Override
+4 −3
Original line number Diff line number Diff line
@@ -102,10 +102,11 @@ public class DisplayPolicyTestsBase extends WindowTestsBase {
    }

    void addWindow(WindowState win) {
        mDisplayPolicy.adjustWindowParamsLw(win, win.mAttrs, Binder.getCallingPid(),
                Binder.getCallingUid());
        final int callingPid = Binder.getCallingPid();
        final int callingUid = Binder.getCallingUid();
        mDisplayPolicy.adjustWindowParamsLw(win, win.mAttrs, callingPid, callingUid);
        assertEquals(WindowManagerGlobal.ADD_OKAY,
                mDisplayPolicy.validateAddingWindowLw(win.mAttrs));
                mDisplayPolicy.validateAddingWindowLw(win.mAttrs, callingPid, callingUid));
        mDisplayPolicy.addWindowLw(win, win.mAttrs);
        win.mHasSurface = true;
    }