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

Commit c5e29907 authored by Mehdi Alizadeh's avatar Mehdi Alizadeh
Browse files

Fix TaskDescription's copy method

copyFromPreserveHiddenFields should only copy hidden fields if the field
is set in the other TaskDescription.

Bug: 144348683
Test: atest FrameworksCoreTests:ActivityManagerTest

Change-Id: I8475e82b7aeb0b7fc6a8cc0de88b926a847c7ac2
parent 1c664739
Loading
Loading
Loading
Loading
+14 −5
Original line number Original line Diff line number Diff line
@@ -1120,8 +1120,8 @@ public class ActivityManager {
        }
        }


        /**
        /**
         * Copies this the values from another TaskDescription, but preserves the hidden fields
         * Copies values from another TaskDescription, but preserves the hidden fields if they
         * if they weren't set on {@code other}
         * weren't set on {@code other}. Public fields will be overwritten anyway.
         * @hide
         * @hide
         */
         */
        public void copyFromPreserveHiddenFields(TaskDescription other) {
        public void copyFromPreserveHiddenFields(TaskDescription other) {
@@ -1130,6 +1130,7 @@ public class ActivityManager {
            mIconRes = other.mIconRes;
            mIconRes = other.mIconRes;
            mIconFilename = other.mIconFilename;
            mIconFilename = other.mIconFilename;
            mColorPrimary = other.mColorPrimary;
            mColorPrimary = other.mColorPrimary;

            if (other.mColorBackground != 0) {
            if (other.mColorBackground != 0) {
                mColorBackground = other.mColorBackground;
                mColorBackground = other.mColorBackground;
            }
            }
@@ -1139,13 +1140,21 @@ public class ActivityManager {
            if (other.mNavigationBarColor != 0) {
            if (other.mNavigationBarColor != 0) {
                mNavigationBarColor = other.mNavigationBarColor;
                mNavigationBarColor = other.mNavigationBarColor;
            }
            }

            mEnsureStatusBarContrastWhenTransparent = other.mEnsureStatusBarContrastWhenTransparent;
            mEnsureStatusBarContrastWhenTransparent = other.mEnsureStatusBarContrastWhenTransparent;
            mEnsureNavigationBarContrastWhenTransparent =
            mEnsureNavigationBarContrastWhenTransparent =
                    other.mEnsureNavigationBarContrastWhenTransparent;
                    other.mEnsureNavigationBarContrastWhenTransparent;

            if (other.mResizeMode != RESIZE_MODE_RESIZEABLE) {
                mResizeMode = other.mResizeMode;
                mResizeMode = other.mResizeMode;
            }
            if (other.mMinWidth != -1) {
                mMinWidth = other.mMinWidth;
                mMinWidth = other.mMinWidth;
            }
            if (other.mMinHeight != -1) {
                mMinHeight = other.mMinHeight;
                mMinHeight = other.mMinHeight;
            }
            }
        }


        private TaskDescription(Parcel source) {
        private TaskDescription(Parcel source) {
            readFromParcel(source);
            readFromParcel(source);
+121 −1
Original line number Original line Diff line number Diff line
@@ -16,7 +16,11 @@


package android.app.activity;
package android.app.activity;


import static android.content.pm.ActivityInfo.RESIZE_MODE_RESIZEABLE;
import static android.content.pm.ActivityInfo.RESIZE_MODE_UNRESIZEABLE;

import android.app.ActivityManager;
import android.app.ActivityManager;
import android.app.ActivityManager.TaskDescription;
import android.content.Context;
import android.content.Context;
import android.content.pm.ConfigurationInfo;
import android.content.pm.ConfigurationInfo;
import android.content.res.Configuration;
import android.content.res.Configuration;
@@ -111,6 +115,122 @@ public class ActivityManagerTest extends AndroidTestCase {
        }    
        }    
    }
    }


    @SmallTest
    public void testTaskDescriptionCopyFrom() {
        TaskDescription td1 = new TaskDescription(
                "test label",            // label
                null,                    // bitmap
                21,                      // iconRes
                "dummy file",            // iconFilename
                0x111111,                // colorPrimary
                0x222222,                // colorBackground
                0x333333,                // statusBarColor
                0x444444,                // navigationBarColor
                true,                    // ensureStatusBarContrastWhenTransparent
                true,                    // ensureNavigationBarContrastWhenTransparent
                RESIZE_MODE_RESIZEABLE,  // resizeMode
                10,                      // minWidth
                20                       // minHeight
        );

        TaskDescription td2 = new TaskDescription();
        // Must overwrite all the fields
        td2.copyFrom(td1);

        assertEquals(td1.getLabel(), td2.getLabel());
        assertEquals(td1.getInMemoryIcon(), td2.getInMemoryIcon());
        assertEquals(td1.getIconFilename(), td2.getIconFilename());
        assertEquals(td1.getIconResource(), td2.getIconResource());
        assertEquals(td1.getPrimaryColor(), td2.getPrimaryColor());
        assertEquals(td1.getBackgroundColor(), td2.getBackgroundColor());
        assertEquals(td1.getStatusBarColor(), td2.getStatusBarColor());
        assertEquals(td1.getNavigationBarColor(), td2.getNavigationBarColor());
        assertEquals(td1.getEnsureStatusBarContrastWhenTransparent(),
                td2.getEnsureStatusBarContrastWhenTransparent());
        assertEquals(td1.getEnsureNavigationBarContrastWhenTransparent(),
                td2.getEnsureNavigationBarContrastWhenTransparent());
        assertEquals(td1.getResizeMode(), td2.getResizeMode());
        assertEquals(td1.getMinWidth(), td2.getMinWidth());
        assertEquals(td1.getMinHeight(), td2.getMinHeight());
    }

    @SmallTest
    public void testTaskDescriptionCopyFromPreserveHiddenFields() {
        TaskDescription td1 = new TaskDescription(
                "test label",              // label
                null,                      // bitmap
                21,                        // iconRes
                "dummy file",              // iconFilename
                0x111111,                  // colorPrimary
                0x222222,                  // colorBackground
                0x333333,                  // statusBarColor
                0x444444,                  // navigationBarColor
                false,                     // ensureStatusBarContrastWhenTransparent
                false,                     // ensureNavigationBarContrastWhenTransparent
                RESIZE_MODE_UNRESIZEABLE,  // resizeMode
                10,                        // minWidth
                20                         // minHeight
        );

        TaskDescription td2 = new TaskDescription(
                "test label2",           // label
                null,                    // bitmap
                212,                     // iconRes
                "dummy file2",           // iconFilename
                0x1111112,               // colorPrimary
                0x2222222,               // colorBackground
                0x3333332,               // statusBarColor
                0x4444442,               // navigationBarColor
                true,                    // ensureStatusBarContrastWhenTransparent
                true,                    // ensureNavigationBarContrastWhenTransparent
                RESIZE_MODE_RESIZEABLE,  // resizeMode
                102,                     // minWidth
                202                      // minHeight
        );

        // Must overwrite all public and hidden fields, since other has all fields set.
        td2.copyFromPreserveHiddenFields(td1);

        assertEquals(td1.getLabel(), td2.getLabel());
        assertEquals(td1.getInMemoryIcon(), td2.getInMemoryIcon());
        assertEquals(td1.getIconFilename(), td2.getIconFilename());
        assertEquals(td1.getIconResource(), td2.getIconResource());
        assertEquals(td1.getPrimaryColor(), td2.getPrimaryColor());
        assertEquals(td1.getBackgroundColor(), td2.getBackgroundColor());
        assertEquals(td1.getStatusBarColor(), td2.getStatusBarColor());
        assertEquals(td1.getNavigationBarColor(), td2.getNavigationBarColor());
        assertEquals(td1.getEnsureStatusBarContrastWhenTransparent(),
                td2.getEnsureStatusBarContrastWhenTransparent());
        assertEquals(td1.getEnsureNavigationBarContrastWhenTransparent(),
                td2.getEnsureNavigationBarContrastWhenTransparent());
        assertEquals(td1.getResizeMode(), td2.getResizeMode());
        assertEquals(td1.getMinWidth(), td2.getMinWidth());
        assertEquals(td1.getMinHeight(), td2.getMinHeight());

        TaskDescription td3 = new TaskDescription();
        // Must overwrite only public fields, and preserve hidden fields.
        td2.copyFromPreserveHiddenFields(td3);

        // Overwritten fields
        assertEquals(td3.getLabel(), td2.getLabel());
        assertEquals(td3.getInMemoryIcon(), td2.getInMemoryIcon());
        assertEquals(td3.getIconFilename(), td2.getIconFilename());
        assertEquals(td3.getIconResource(), td2.getIconResource());
        assertEquals(td3.getPrimaryColor(), td2.getPrimaryColor());
        assertEquals(td3.getEnsureStatusBarContrastWhenTransparent(),
                td2.getEnsureStatusBarContrastWhenTransparent());
        assertEquals(td3.getEnsureNavigationBarContrastWhenTransparent(),
                td2.getEnsureNavigationBarContrastWhenTransparent());

        // Preserved fields
        assertEquals(td1.getBackgroundColor(), td2.getBackgroundColor());
        assertEquals(td1.getStatusBarColor(), td2.getStatusBarColor());
        assertEquals(td1.getNavigationBarColor(), td2.getNavigationBarColor());
        assertEquals(td1.getResizeMode(), td2.getResizeMode());
        assertEquals(td1.getMinWidth(), td2.getMinWidth());
        assertEquals(td1.getMinHeight(), td2.getMinHeight());
    }

    // If any entries in appear in the list, sanity check them against all running applications
    // If any entries in appear in the list, sanity check them against all running applications
    private void checkErrorListSanity(List<ActivityManager.ProcessErrorStateInfo> errList) {
    private void checkErrorListSanity(List<ActivityManager.ProcessErrorStateInfo> errList) {
        if (errList == null) return;
        if (errList == null) return;
+1 −1
Original line number Original line Diff line number Diff line
@@ -202,7 +202,7 @@ class TaskSnapshotSurface implements StartingSurface {


            final TaskDescription td = task.getTaskDescription();
            final TaskDescription td = task.getTaskDescription();
            if (td != null) {
            if (td != null) {
                taskDescription.copyFrom(td);
                taskDescription.copyFromPreserveHiddenFields(td);
            }
            }
            taskBounds = new Rect();
            taskBounds = new Rect();
            task.getBounds(taskBounds);
            task.getBounds(taskBounds);