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

Commit 4ac61857 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add privacy dot flag for SystemUI" into sc-v2-dev am: 3af688be

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/15842430

Change-Id: Ib007991ddaac4971bb3bbb317c5a460140ac9635
parents b77e6c7c 3af688be
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -706,4 +706,8 @@
        <item>@drawable/rounded_corner_bottom</item>
        <item>@drawable/rounded_corner_bottom_secondary</item>
    </array>

    <!-- Flag to enable privacy dot views, it shall be true for normal case -->
    <bool name="config_enablePrivacyDot">true</bool>

</resources>
+65 −43
Original line number Diff line number Diff line
@@ -160,6 +160,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
    private Handler mHandler;
    private boolean mPendingRotationChange;
    private boolean mIsRoundedCornerMultipleRadius;
    private boolean mIsPrivacyDotEnabled;
    private int mStatusBarHeightPortrait;
    private int mStatusBarHeightLandscape;
    private Drawable mRoundedCornerDrawable;
@@ -253,6 +254,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        mRotation = mContext.getDisplay().getRotation();
        mDisplayUniqueId = mContext.getDisplay().getUniqueId();
        mIsRoundedCornerMultipleRadius = isRoundedCornerMultipleRadius(mContext, mDisplayUniqueId);
        mIsPrivacyDotEnabled = mContext.getResources().getBoolean(R.bool.config_enablePrivacyDot);
        mWindowManager = mContext.getSystemService(WindowManager.class);
        mDisplayManager = mContext.getSystemService(DisplayManager.class);
        updateRoundedCornerDrawable();
@@ -312,24 +314,24 @@ public class ScreenDecorations extends SystemUI implements Tunable {
    }

    private void setupDecorations() {
        if (hasRoundedCorners() || shouldDrawCutout()) {
        if (hasRoundedCorners() || shouldDrawCutout() || mIsPrivacyDotEnabled) {
            updateStatusBarHeight();
            final DisplayCutout cutout = getCutout();
            final Rect[] bounds = cutout == null ? null : cutout.getBoundingRectsAll();
            int rotatedPos;
            for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
                rotatedPos = getBoundPositionFromRotation(i, mRotation);
                if ((bounds != null && !bounds[rotatedPos].isEmpty())
                        || shouldShowRoundedCorner(i)) {
                    createOverlay(i);
                if (shouldShowCutout(i, cutout) || shouldShowRoundedCorner(i, cutout)
                        || shouldShowPrivacyDot(i, cutout)) {
                    createOverlay(i, cutout);
                } else {
                    removeOverlay(i);
                }
            }

            if (mIsPrivacyDotEnabled) {
                // Overlays have been created, send the dots to the controller
                //TODO: need a better way to do this
                mDotViewController.initialize(
                        mTopLeftDot, mTopRightDot, mBottomLeftDot, mBottomRightDot);
            }
        } else {
            removeAllOverlays();
        }
@@ -416,7 +418,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        mOverlays[pos] = null;
    }

    private void createOverlay(@BoundsPosition int pos) {
    private void createOverlay(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
        if (mOverlays == null) {
            mOverlays = new View[BOUNDS_POSITION_LENGTH];
        }
@@ -437,7 +439,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        mOverlays[pos].setAlpha(0);
        mOverlays[pos].setForceDarkAllowed(false);

        updateView(pos);
        updateView(pos, cutout);

        mWindowManager.addView(mOverlays[pos], getWindowLayoutParams(pos));

@@ -461,34 +463,19 @@ public class ScreenDecorations extends SystemUI implements Tunable {
     * Allow overrides for top/bottom positions
     */
    private View overlayForPosition(@BoundsPosition int pos) {
        switch (pos) {
            case BOUNDS_POSITION_TOP:
            case BOUNDS_POSITION_LEFT:
                View top = LayoutInflater.from(mContext)
                        .inflate(R.layout.rounded_corners_top, null);
                mTopLeftDot = top.findViewById(R.id.privacy_dot_left_container);
                mTopRightDot = top.findViewById(R.id.privacy_dot_right_container);
                return top;
            case BOUNDS_POSITION_BOTTOM:
            case BOUNDS_POSITION_RIGHT:
                View bottom =  LayoutInflater.from(mContext)
                        .inflate(R.layout.rounded_corners_bottom, null);
                mBottomLeftDot = bottom.findViewById(R.id.privacy_dot_left_container);
                mBottomRightDot = bottom.findViewById(R.id.privacy_dot_right_container);
                return bottom;
            default:
                throw new IllegalArgumentException("Unknown bounds position");
        }
        final int layoutId = (pos == BOUNDS_POSITION_LEFT || pos == BOUNDS_POSITION_TOP)
                ? R.layout.rounded_corners_top : R.layout.rounded_corners_bottom;
        return LayoutInflater.from(mContext).inflate(layoutId, null);
    }

    private void updateView(@BoundsPosition int pos) {
    private void updateView(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
        if (mOverlays == null || mOverlays[pos] == null) {
            return;
        }

        // update rounded corner view rotation
        updateRoundedCornerView(pos, R.id.left);
        updateRoundedCornerView(pos, R.id.right);
        updateRoundedCornerView(pos, R.id.left, cutout);
        updateRoundedCornerView(pos, R.id.right, cutout);
        updateRoundedCornerSize(mRoundedDefault, mRoundedDefaultTop, mRoundedDefaultBottom);
        updateRoundedCornerImageView();

@@ -496,6 +483,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        if (mCutoutViews != null && mCutoutViews[pos] != null) {
            mCutoutViews[pos].setRotation(mRotation);
        }

        updatePrivacyDotView(pos, cutout);
    }

    @VisibleForTesting
@@ -671,11 +660,12 @@ public class ScreenDecorations extends SystemUI implements Tunable {

            if (mOverlays != null) {
                updateLayoutParams();
                final DisplayCutout cutout = getCutout();
                for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
                    if (mOverlays[i] == null) {
                        continue;
                    }
                    updateView(i);
                    updateView(i, cutout);
                }
            }
        }
@@ -807,13 +797,14 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        return drawable;
    }

    private void updateRoundedCornerView(@BoundsPosition int pos, int id) {
    private void updateRoundedCornerView(@BoundsPosition int pos, int id,
            @Nullable DisplayCutout cutout) {
        final View rounded = mOverlays[pos].findViewById(id);
        if (rounded == null) {
            return;
        }
        rounded.setVisibility(View.GONE);
        if (shouldShowRoundedCorner(pos)) {
        if (shouldShowRoundedCorner(pos, cutout)) {
            final int gravity = getRoundedCornerGravity(pos, id == R.id.left);
            ((FrameLayout.LayoutParams) rounded.getLayoutParams()).gravity = gravity;
            setRoundedCornerOrientation(rounded, gravity);
@@ -821,6 +812,26 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        }
    }

    private void updatePrivacyDotView(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
        final ViewGroup viewGroup = (ViewGroup) mOverlays[pos];

        final View left = viewGroup.findViewById(R.id.privacy_dot_left_container);
        final View right = viewGroup.findViewById(R.id.privacy_dot_right_container);
        if (shouldShowPrivacyDot(pos, cutout)) {
            // TODO (b/201481944) Privacy Dots pos and var are wrong with long side cutout enable
            if (pos == BOUNDS_POSITION_LEFT || pos == BOUNDS_POSITION_TOP) {
                mTopLeftDot = left;
                mTopRightDot = right;
            } else {
                mBottomLeftDot = left;
                mBottomRightDot = right;
            }
        } else {
            viewGroup.removeView(left);
            viewGroup.removeView(right);
        }
    }

    private int getRoundedCornerGravity(@BoundsPosition int pos, boolean isStart) {
        final int rotatedPos = getBoundPositionFromRotation(pos, mRotation);
        switch (rotatedPos) {
@@ -872,12 +883,8 @@ public class ScreenDecorations extends SystemUI implements Tunable {
                || mIsRoundedCornerMultipleRadius;
    }

    private boolean shouldShowRoundedCorner(@BoundsPosition int pos) {
        if (!hasRoundedCorners()) {
            return false;
        }

        DisplayCutout cutout = getCutout();
    private boolean isDefaultShownOverlayPos(@BoundsPosition int pos,
            @Nullable DisplayCutout cutout) {
        // for cutout is null or cutout with only waterfall.
        final boolean emptyBoundsOrWaterfall = cutout == null || cutout.isBoundsEmpty();
        // Shows rounded corner on left and right overlays only when there is no top or bottom
@@ -892,6 +899,21 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        }
    }

    private boolean shouldShowRoundedCorner(@BoundsPosition int pos,
            @Nullable DisplayCutout cutout) {
        return hasRoundedCorners() && isDefaultShownOverlayPos(pos, cutout);
    }

    private boolean shouldShowPrivacyDot(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
        return mIsPrivacyDotEnabled && isDefaultShownOverlayPos(pos, cutout);
    }

    private boolean shouldShowCutout(@BoundsPosition int pos, @Nullable DisplayCutout cutout) {
        final Rect[] bounds = cutout == null ? null : cutout.getBoundingRectsAll();
        final int rotatedPos = getBoundPositionFromRotation(pos, mRotation);
        return (bounds != null && !bounds[rotatedPos].isEmpty());
    }

    private boolean shouldDrawCutout() {
        return shouldDrawCutout(mContext);
    }
+6 −4
Original line number Diff line number Diff line
@@ -72,6 +72,7 @@ public class KeyguardStatusBarView extends RelativeLayout {
    private boolean mKeyguardUserSwitcherEnabled;
    private final UserManager mUserManager;

    private boolean mIsPrivacyDotEnabled;
    private int mSystemIconsSwitcherHiddenExpandedMargin;
    private int mStatusBarPaddingEnd;
    private int mMinDotWidth;
@@ -112,7 +113,7 @@ public class KeyguardStatusBarView extends RelativeLayout {
        mCutoutSpace = findViewById(R.id.cutout_space_view);
        mStatusIconArea = findViewById(R.id.status_icon_area);
        mStatusIconContainer = findViewById(R.id.statusIcons);

        mIsPrivacyDotEnabled = mContext.getResources().getBoolean(R.bool.config_enablePrivacyDot);
        loadDimens();
    }

@@ -270,9 +271,10 @@ public class KeyguardStatusBarView extends RelativeLayout {
                        mDisplayCutout, cornerCutoutMargins, mRoundedCornerPadding);

        // consider privacy dot space
        final int minLeft = isLayoutRtl() ? Math.max(mMinDotWidth, mPadding.first) : mPadding.first;
        final int minRight = isLayoutRtl() ? mPadding.second :
                Math.max(mMinDotWidth, mPadding.second);
        final int minLeft = (isLayoutRtl() && mIsPrivacyDotEnabled)
                ? Math.max(mMinDotWidth, mPadding.first) : mPadding.first;
        final int minRight = (!isLayoutRtl() && mIsPrivacyDotEnabled)
                ? Math.max(mMinDotWidth, mPadding.second) : mPadding.second;

        setPadding(minLeft, waterfallTop, minRight, 0);
    }
+6 −2
Original line number Diff line number Diff line
@@ -70,6 +70,9 @@ class StatusBarContentInsetsProvider @Inject constructor(
    // (e.g. network displays)
    private val insetsCache = LruCache<CacheKey, Rect>(MAX_CACHE_SIZE)
    private val listeners = mutableSetOf<StatusBarContentInsetsChangedListener>()
    private val isPrivacyDotEnabled: Boolean by lazy(LazyThreadSafetyMode.PUBLICATION) {
        context.resources.getBoolean(R.bool.config_enablePrivacyDot)
    }

    init {
        configurationController.addCallback(this)
@@ -152,8 +155,9 @@ class StatusBarContentInsetsProvider @Inject constructor(
        val isRtl = rotatedResources.configuration.layoutDirection == LAYOUT_DIRECTION_RTL
        val roundedCornerPadding = rotatedResources
                .getDimensionPixelSize(R.dimen.rounded_corner_content_padding)
        val minDotWidth = rotatedResources
                .getDimensionPixelSize(R.dimen.ongoing_appops_dot_min_padding)
        val minDotWidth = if (isPrivacyDotEnabled)
                rotatedResources.getDimensionPixelSize(R.dimen.ongoing_appops_dot_min_padding)
            else 0

        val minLeft: Int
        val minRight: Int
+457 −95

File changed.

Preview size limit exceeded, changes collapsed.