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

Commit 6538db51 authored by Riddle Hsu's avatar Riddle Hsu Committed by Android (Google) Code Review
Browse files

Merge "Clean up some unnecessary methods of ActivityRecord" into main

parents b56d2e55 0375fef9
Loading
Loading
Loading
Loading
+0 −18
Original line number Diff line number Diff line
@@ -3965,20 +3965,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        return removedFromHistory;
    }

    boolean safelyDestroy(String reason) {
        if (isDestroyable()) {
            if (DEBUG_SWITCH) {
                final Task task = getTask();
                Slog.v(TAG_SWITCH, "Safely destroying " + this + " in state " + getState()
                        + " resumed=" + task.getTopResumedActivity()
                        + " pausing=" + task.getTopPausingActivity()
                        + " for reason " + reason);
            }
            return destroyImmediately(reason);
        }
        return false;
    }

    /** Note: call {@link #cleanUp(boolean, boolean)} before this method. */
    void removeFromHistory(String reason) {
        finishActivityResults(Activity.RESULT_CANCELED,
@@ -4047,10 +4033,6 @@ final class ActivityRecord extends WindowToken implements WindowManagerService.A
        }
    }

    boolean isFinishing() {
        return finishing;
    }

    /**
     * This method is to only be called from the client via binder when the activity is destroyed
     * AND finished.
+1 −1
Original line number Diff line number Diff line
@@ -1726,7 +1726,7 @@ public class BackgroundActivityStartController {
        return ar
                + " :: visible=" + ar.isVisible()
                + ", visibleRequested=" + ar.isVisibleRequested()
                + ", finishing=" + ar.isFinishing()
                + ", finishing=" + ar.finishing
                + ", alwaysOnTop=" + ar.isAlwaysOnTop()
                + ", lastLaunchTime=" + ar.lastLaunchTime
                + ", lastVisibleTime=" + ar.lastVisibleTime
+1 −1
Original line number Diff line number Diff line
@@ -148,7 +148,7 @@ import java.util.function.Predicate;
final class LetterboxUiController {

    private static final Predicate<ActivityRecord> FIRST_OPAQUE_NOT_FINISHING_ACTIVITY_PREDICATE =
            activityRecord -> activityRecord.fillsParent() && !activityRecord.isFinishing();
            ActivityRecord::occludesParent;

    private static final String TAG = TAG_WITH_CLASS_NAME ? "LetterboxUiController" : TAG_ATM;

+0 −26
Original line number Diff line number Diff line
@@ -1762,32 +1762,6 @@ public class ActivityRecordTests extends WindowTestsBase {
        assertEquals(1, task.getChildCount());
    }

    /**
     * Test that an activity will not be destroyed if it is marked as non-destroyable.
     */
    @Test
    public void testSafelyDestroy_nonDestroyable() {
        final ActivityRecord activity = createActivityWithTask();
        doReturn(false).when(activity).isDestroyable();

        activity.safelyDestroy("test");

        verify(activity, never()).destroyImmediately(anyString());
    }

    /**
     * Test that an activity will not be destroyed if it is marked as non-destroyable.
     */
    @Test
    public void testSafelyDestroy_destroyable() {
        final ActivityRecord activity = createActivityWithTask();
        doReturn(true).when(activity).isDestroyable();

        activity.safelyDestroy("test");

        verify(activity).destroyImmediately(anyString());
    }

    @Test
    public void testRemoveImmediately() {
        final Consumer<Consumer<ActivityRecord>> test = setup -> {
+22 −18
Original line number Diff line number Diff line
@@ -197,10 +197,10 @@ public class SizeCompatTests extends WindowTestsBase {
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        // Translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);

        translucentActivity.setState(DESTROYED, "testing");
@@ -225,10 +225,10 @@ public class SizeCompatTests extends WindowTestsBase {

        // Translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);

        spyOn(translucentActivity.mLetterboxUiController);
@@ -300,10 +300,10 @@ public class SizeCompatTests extends WindowTestsBase {

        // Translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_LANDSCAPE)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);

        spyOn(translucentActivity.mLetterboxUiController);
@@ -376,10 +376,10 @@ public class SizeCompatTests extends WindowTestsBase {

        // Launch translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);
        // Transparent strategy applied
        assertTrue(translucentActivity.mLetterboxUiController.hasInheritedLetterboxBehavior());
@@ -404,10 +404,10 @@ public class SizeCompatTests extends WindowTestsBase {

        // Launch translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);
        // Transparent strategy applied
        assertTrue(translucentActivity.mLetterboxUiController.hasInheritedLetterboxBehavior());
@@ -441,10 +441,10 @@ public class SizeCompatTests extends WindowTestsBase {

        // Launch translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);
        // Transparent strategy applied
        assertTrue(translucentActivity.mLetterboxUiController.hasInheritedLetterboxBehavior());
@@ -465,12 +465,12 @@ public class SizeCompatTests extends WindowTestsBase {
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        // Translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_LANDSCAPE)
                .setMinAspectRatio(1.1f)
                .setMaxAspectRatio(3f)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);
        // We check bounds
        final Rect opaqueBounds = mActivity.getConfiguration().windowConfiguration.getBounds();
@@ -493,9 +493,9 @@ public class SizeCompatTests extends WindowTestsBase {
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        // Translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        final Configuration requestedConfig =
                translucentActivity.getRequestedOverrideConfiguration();
        final WindowConfiguration translucentWinConf = requestedConfig.windowConfiguration;
@@ -525,12 +525,12 @@ public class SizeCompatTests extends WindowTestsBase {
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        // Translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_LANDSCAPE)
                .setMinAspectRatio(1.1f)
                .setMaxAspectRatio(3f)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);
        // We check bounds
        final Rect opaqueBounds = mActivity.getConfiguration().windowConfiguration.getBounds();
@@ -538,10 +538,10 @@ public class SizeCompatTests extends WindowTestsBase {
        assertEquals(opaqueBounds, translucentRequestedBounds);
        // Launch another translucent activity
        final ActivityRecord translucentActivity2 = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_LANDSCAPE)
                .build();
        doReturn(false).when(translucentActivity2).fillsParent();
        mTask.addChild(translucentActivity2);
        // We check bounds
        final Rect translucent2RequestedBounds = translucentActivity2.getRequestedOverrideBounds();
@@ -558,9 +558,9 @@ public class SizeCompatTests extends WindowTestsBase {
        // simplicity.
        doReturn(true).when(mActivity).isEmbedded();
        // Translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm).build();
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent).build();
        doReturn(false).when(translucentActivity).matchParentBounds();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);
        // Check the strategy has not being applied
        assertFalse(translucentActivity.mLetterboxUiController.hasInheritedLetterboxBehavior());
@@ -580,10 +580,10 @@ public class SizeCompatTests extends WindowTestsBase {
        assertFalse(mActivity.inSizeCompatMode());
        // We launch a transparent activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);
        // It should not be in SCM
        assertFalse(translucentActivity.inSizeCompatMode());
@@ -600,12 +600,16 @@ public class SizeCompatTests extends WindowTestsBase {
        mActivity.mDisplayContent.setIgnoreOrientationRequest(true /* ignoreOrientationRequest */);
        // Translucent Activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        spyOn(mActivity);
        assertFalse(translucentActivity.fillsParent());
        assertTrue(mActivity.fillsParent());
        mActivity.finishing = true;
        assertFalse(mActivity.occludesParent());
        mTask.addChild(translucentActivity);
        verify(mActivity).isFinishing();
        // The translucent activity won't inherit letterbox behavior from a finishing activity.
        assertFalse(translucentActivity.mLetterboxUiController.hasInheritedLetterboxBehavior());
    }

    @Test
@@ -619,10 +623,10 @@ public class SizeCompatTests extends WindowTestsBase {
        prepareUnresizable(mActivity, SCREEN_ORIENTATION_PORTRAIT);
        // We launch a transparent activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);
        assertEquals(translucentActivity.getBounds(), mActivity.getBounds());

@@ -655,10 +659,10 @@ public class SizeCompatTests extends WindowTestsBase {

        // We launch a transparent activity
        final ActivityRecord translucentActivity = new ActivityBuilder(mAtm)
                .setActivityTheme(android.R.style.Theme_Translucent)
                .setLaunchedFromUid(mActivity.getUid())
                .setScreenOrientation(SCREEN_ORIENTATION_PORTRAIT)
                .build();
        doReturn(false).when(translucentActivity).fillsParent();
        mTask.addChild(translucentActivity);

        // The transparent activity inherits the compat display insets of the opaque activity