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

Commit 5c587cab authored by Louis Chang's avatar Louis Chang Committed by Android (Google) Code Review
Browse files

Merge "Avoid setting the same TaskDescription" into main

parents a6b083ac 504a4769
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -971,6 +971,7 @@ public class Activity extends ContextThemeWrapper

    private final ActivityManager.TaskDescription mTaskDescription =
            new ActivityManager.TaskDescription();
    private int mLastTaskDescriptionHashCode;

    protected static final int[] FOCUSED_STATE_SET = {com.android.internal.R.attr.state_focused};

@@ -7612,6 +7613,13 @@ public class Activity extends ContextThemeWrapper
                mTaskDescription.setIcon(Icon.createWithBitmap(icon));
            }
        }
        if (mLastTaskDescriptionHashCode == mTaskDescription.hashCode()) {
            // Early return if the hashCode is the same.
            // Note that we do not use #equals() to perform the check because there are several
            // places in this class that directly sets the value to mTaskDescription.
            return;
        }
        mLastTaskDescriptionHashCode = mTaskDescription.hashCode();
        ActivityClient.getInstance().setTaskDescription(mToken, mTaskDescription);
    }

+26 −0
Original line number Diff line number Diff line
@@ -2308,6 +2308,32 @@ public class ActivityManager {
                    + " colorBackgrounFloating: " + mColorBackgroundFloating;
        }

        @Override
        public int hashCode() {
            int result = 17;
            if (mLabel != null) {
                result = result * 31 + mLabel.hashCode();
            }
            if (mIcon != null) {
                result = result * 31 + mIcon.hashCode();
            }
            if (mIconFilename != null) {
                result = result * 31 + mIconFilename.hashCode();
            }
            result = result * 31 + mColorPrimary;
            result = result * 31 + mColorBackground;
            result = result * 31 + mColorBackgroundFloating;
            result = result * 31 + mStatusBarColor;
            result = result * 31 + mNavigationBarColor;
            result = result * 31 + mStatusBarAppearance;
            result = result * 31 + (mEnsureStatusBarContrastWhenTransparent ? 1 : 0);
            result = result * 31 + (mEnsureNavigationBarContrastWhenTransparent ? 1 : 0);
            result = result * 31 + mResizeMode;
            result = result * 31 + mMinWidth;
            result = result * 31 + mMinHeight;
            return result;
        }

        @Override
        public boolean equals(@Nullable Object obj) {
            if (!(obj instanceof TaskDescription)) {
+4 −1
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.hardware.display.DisplayManager;
import android.hardware.display.VirtualDisplay;
@@ -167,7 +168,7 @@ public class TaskStackChangedListenerTest {
    @Presubmit
    public void testTaskDescriptionChanged() throws Exception {
        final Object[] params = new Object[2];
        final CountDownLatch latch = new CountDownLatch(1);
        final CountDownLatch latch = new CountDownLatch(2);
        registerTaskStackChangedListener(new TaskStackListener() {
            int mTaskId = -1;

@@ -510,6 +511,8 @@ public class TaskStackChangedListenerTest {
        protected void onPostResume() {
            super.onPostResume();
            setTaskDescription(new TaskDescription("Test Label"));
            // Sets the color of the status-bar should update the TaskDescription again.
            getWindow().setStatusBarColor(Color.RED);
            synchronized (sLock) {
                // Hold the lock to ensure no one is trying to access fields of this Activity in
                // this test.