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

Commit ad4506ae authored by Hector Dearman's avatar Hector Dearman
Browse files

Prevent clock becoming visible when icon disabled

When the status bar clock is disabled (via a "clock" entry in icon_blacklist
setting) it could mistakenly reappear due to
CollapsedStatusBarFragment#animateShow (which directly modifies the
visibility of the view via setVisibility). Prevent this by overriding
setVisibility to stop the view becoming visible when it should be
it should be hidden.

Test: am start com.android.systemui/com.android.systemui.DemoMode
      Status bar > Toggle Clock to "don't show"
      (Status bar clock should disappear)
      Pull down shade
      (Status bar clock should remain gone)

Bug: b/113087760 (See 2.)
Change-Id: I8537fec1f29c928cdf21a60c209cfb8ac86cc95a
parent 0c9e5fe0
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -165,7 +165,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
        mClockVisibleByUser = bundle.getBoolean(VISIBLE_BY_USER, true);
        mShowSeconds = bundle.getBoolean(SHOW_SECONDS, false);
        if (bundle.containsKey(VISIBILITY)) {
            setVisibility(bundle.getInt(VISIBILITY));
            super.setVisibility(bundle.getInt(VISIBILITY));
        }
    }

@@ -203,6 +203,7 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C

        // Make sure we update to the current time
        updateClock();
        updateClockVisibility();
        updateShowSeconds();
    }

@@ -247,6 +248,15 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
        }
    };

    @Override
    public void setVisibility(int visibility) {
        if (visibility == View.VISIBLE && !shouldBeVisible()) {
            return;
        }

        super.setVisibility(visibility);
    }

    public void setClockVisibleByUser(boolean visible) {
        mClockVisibleByUser = visible;
        updateClockVisibility();
@@ -257,11 +267,15 @@ public class Clock extends TextView implements DemoMode, Tunable, CommandQueue.C
        updateClockVisibility();
    }

    private boolean shouldBeVisible() {
        return mClockVisibleByPolicy && mClockVisibleByUser;
    }

    private void updateClockVisibility() {
        boolean visible = mClockVisibleByPolicy && mClockVisibleByUser;
        boolean visible = shouldBeVisible();
        Dependency.get(IconLogger.class).onIconVisibility("clock", visible);
        int visibility = visible ? View.VISIBLE : View.GONE;
        setVisibility(visibility);
        super.setVisibility(visibility);
    }

    final void updateClock() {