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

Commit 13451a25 authored by John Spurlock's avatar John Spurlock
Browse files

Status bar: Keep disabled state per user.

Bug:7165607
Change-Id: If6f7a41c2516996612aef5e013dd0d2bd23f9084
parent 135e5fb7
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ interface IStatusBarService
    void topAppWindowChanged(boolean menuVisible);
    void setImeWindowStatus(in IBinder token, int vis, int backDisposition);
    void expandSettingsPanel();
    void setCurrentUser(int newUserId);

    // ---- Methods below are for use by the status bar policy services ----
    // You need the STATUS_BAR_SERVICE permission
+7 −0
Original line number Diff line number Diff line
@@ -4298,6 +4298,13 @@ public class PhoneWindowManager implements WindowManagerPolicy {
        if (mKeyguardMediator != null) {
            mKeyguardMediator.setCurrentUser(newUserId);
        }
        if (mStatusBarService != null) {
            try {
                mStatusBarService.setCurrentUser(newUserId);
            } catch (RemoteException e) {
                // oh well
            }
        }
    }

    @Override
+38 −16
Original line number Diff line number Diff line
@@ -64,7 +64,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub
            = new HashMap<IBinder,StatusBarNotification>();

    // for disabling the status bar
    ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
    final ArrayList<DisableRecord> mDisableRecords = new ArrayList<DisableRecord>();
    IBinder mSysUiVisToken = new Binder();
    int mDisabled = 0;

@@ -75,15 +75,17 @@ public class StatusBarManagerService extends IStatusBarService.Stub
    int mImeWindowVis = 0;
    int mImeBackDisposition;
    IBinder mImeToken = null;
    int mCurrentUserId;

    private class DisableRecord implements IBinder.DeathRecipient {
        int userId;
        String pkg;
        int what;
        IBinder token;

        public void binderDied() {
            Slog.i(TAG, "binder died for pkg=" + pkg);
            disable(0, token, pkg);
            disableInternal(userId, 0, token, pkg);
            token.unlinkToDeath(this, 0);
        }
    }
@@ -151,20 +153,24 @@ public class StatusBarManagerService extends IStatusBarService.Stub
    }

    public void disable(int what, IBinder token, String pkg) {
        disableInternal(mCurrentUserId, what, token, pkg);
    }

    private void disableInternal(int userId, int what, IBinder token, String pkg) {
        enforceStatusBar();

        synchronized (mLock) {
            disableLocked(what, token, pkg);
            disableLocked(userId, what, token, pkg);
        }
    }

    private void disableLocked(int what, IBinder token, String pkg) {
    private void disableLocked(int userId, int what, IBinder token, String pkg) {
        // It's important that the the callback and the call to mBar get done
        // in the same order when multiple threads are calling this function
        // so they are paired correctly.  The messages on the handler will be
        // handled in the order they were enqueued, but will be outside the lock.
        manageDisableListLocked(what, token, pkg);
        final int net = gatherDisableActionsLocked();
        manageDisableListLocked(userId, what, token, pkg);
        final int net = gatherDisableActionsLocked(userId);
        if (net != mDisabled) {
            mDisabled = net;
            mHandler.post(new Runnable() {
@@ -312,7 +318,10 @@ public class StatusBarManagerService extends IStatusBarService.Stub

        synchronized (mLock) {
            updateUiVisibilityLocked(vis, mask);
            disableLocked(vis & StatusBarManager.DISABLE_MASK, mSysUiVisToken,
            disableLocked(
                    mCurrentUserId,
                    vis & StatusBarManager.DISABLE_MASK,
                    mSysUiVisToken,
                    "WindowManager.LayoutParams");
        }
    }
@@ -382,6 +391,12 @@ public class StatusBarManagerService extends IStatusBarService.Stub
        }
    }

    @Override
    public void setCurrentUser(int newUserId) {
        if (SPEW) Slog.d(TAG, "Setting current user to user " + newUserId);
        mCurrentUserId = newUserId;
    }

    private void enforceStatusBar() {
        mContext.enforceCallingOrSelfPermission(android.Manifest.permission.STATUS_BAR,
                "StatusBarManagerService");
@@ -417,7 +432,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub
            }
        }
        synchronized (mLock) {
            switches[0] = gatherDisableActionsLocked();
            switches[0] = gatherDisableActionsLocked(mCurrentUserId);
            switches[1] = mSystemUiVisibility;
            switches[2] = mMenuVisible ? 1 : 0;
            switches[3] = mImeWindowVis;
@@ -518,9 +533,10 @@ public class StatusBarManagerService extends IStatusBarService.Stub
    // ================================================================================

    // lock on mDisableRecords
    void manageDisableListLocked(int what, IBinder token, String pkg) {
    void manageDisableListLocked(int userId, int what, IBinder token, String pkg) {
        if (SPEW) {
            Slog.d(TAG, "manageDisableList what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
            Slog.d(TAG, "manageDisableList userId=" + userId
                    + " what=0x" + Integer.toHexString(what) + " pkg=" + pkg);
        }
        // update the list
        final int N = mDisableRecords.size();
@@ -541,6 +557,7 @@ public class StatusBarManagerService extends IStatusBarService.Stub
        } else {
            if (tok == null) {
                tok = new DisableRecord();
                tok.userId = userId;
                try {
                    token.linkToDeath(tok, 0);
                }
@@ -556,12 +573,15 @@ public class StatusBarManagerService extends IStatusBarService.Stub
    }

    // lock on mDisableRecords
    int gatherDisableActionsLocked() {
    int gatherDisableActionsLocked(int userId) {
        final int N = mDisableRecords.size();
        // gather the new net flags
        int net = 0;
        for (int i=0; i<N; i++) {
            net |= mDisableRecords.get(i).what;
            final DisableRecord rec = mDisableRecords.get(i);
            if (rec.userId == userId) {
                net |= rec.what;
            }
        }
        return net;
    }
@@ -593,13 +613,15 @@ public class StatusBarManagerService extends IStatusBarService.Stub
        }

        synchronized (mLock) {
            pw.println("  mDisabled=0x" + Integer.toHexString(mDisabled));
            final int N = mDisableRecords.size();
            pw.println("  mDisableRecords.size=" + N
                    + " mDisabled=0x" + Integer.toHexString(mDisabled));
            pw.println("  mDisableRecords.size=" + N);
            for (int i=0; i<N; i++) {
                DisableRecord tok = mDisableRecords.get(i);
                pw.println("    [" + i + "] what=0x" + Integer.toHexString(tok.what)
                                + " pkg=" + tok.pkg + " token=" + tok.token);
                pw.println("    [" + i + "] userId=" + tok.userId
                                + " what=0x" + Integer.toHexString(tok.what)
                                + " pkg=" + tok.pkg
                                + " token=" + tok.token);
            }
        }
    }