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

Commit f8e4e75d authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Avoid resolving secondary home activity if no need" into qt-dev

parents 8bfe7fd3 85ebc0d3
Loading
Loading
Loading
Loading
+46 −22
Original line number Original line Diff line number Diff line
@@ -94,6 +94,7 @@ import android.os.RemoteException;
import android.os.SystemClock;
import android.os.SystemClock;
import android.os.Trace;
import android.os.Trace;
import android.os.UserHandle;
import android.os.UserHandle;
import android.os.storage.StorageManager;
import android.provider.Settings;
import android.provider.Settings;
import android.service.voice.IVoiceInteractionSession;
import android.service.voice.IVoiceInteractionSession;
import android.util.ArraySet;
import android.util.ArraySet;
@@ -369,19 +370,17 @@ class RootActivityContainer extends ConfigurationContainer
            displayId = getTopDisplayFocusedStack().mDisplayId;
            displayId = getTopDisplayFocusedStack().mDisplayId;
        }
        }


        Intent homeIntent;
        Intent homeIntent = null;
        ActivityInfo aInfo;
        ActivityInfo aInfo = null;
        if (displayId == DEFAULT_DISPLAY) {
        if (displayId == DEFAULT_DISPLAY) {
            homeIntent = mService.getHomeIntent();
            homeIntent = mService.getHomeIntent();
            aInfo = resolveHomeActivity(userId, homeIntent);
            aInfo = resolveHomeActivity(userId, homeIntent);
        } else if (!mService.mSupportsMultiDisplay) {
        } else if (shouldPlaceSecondaryHomeOnDisplay(displayId)) {
            return false;
        } else {
            Pair<ActivityInfo, Intent> info = resolveSecondaryHomeActivity(userId, displayId);
            Pair<ActivityInfo, Intent> info = resolveSecondaryHomeActivity(userId, displayId);
            aInfo = info.first;
            aInfo = info.first;
            homeIntent = info.second;
            homeIntent = info.second;
        }
        }
        if (aInfo == null) {
        if (aInfo == null || homeIntent == null) {
            return false;
            return false;
        }
        }


@@ -533,6 +532,46 @@ class RootActivityContainer extends ConfigurationContainer
        return startHomeOnDisplay(mCurrentUser, myReason, displayId);
        return startHomeOnDisplay(mCurrentUser, myReason, displayId);
    }
    }


    /**
     * Check if the display is valid for secondary home activity.
     * @param displayId The id of the target display.
     * @return {@code true} if allow to launch, {@code false} otherwise.
     */
    boolean shouldPlaceSecondaryHomeOnDisplay(int displayId) {
        if (displayId == DEFAULT_DISPLAY) {
            throw new IllegalArgumentException(
                    "shouldPlaceSecondaryHomeOnDisplay: Should not be DEFAULT_DISPLAY");
        } else if (displayId == INVALID_DISPLAY) {
            return false;
        }

        if (!mService.mSupportsMultiDisplay) {
            // Can't launch home on secondary display if device does not support multi-display.
            return false;
        }

        final boolean deviceProvisioned = Settings.Global.getInt(
                mService.mContext.getContentResolver(),
                Settings.Global.DEVICE_PROVISIONED, 0) != 0;
        if (!deviceProvisioned) {
            // Can't launch home on secondary display before device is provisioned.
            return false;
        }

        if (!StorageManager.isUserKeyUnlocked(mCurrentUser)) {
            // Can't launch home on secondary displays if device is still locked.
            return false;
        }

        final ActivityDisplay display = getActivityDisplay(displayId);
        if (display == null || display.isRemoved() || !display.supportsSystemDecorations()) {
            // Can't launch home on display that doesn't support system decorations.
            return false;
        }

        return true;
    }

    /**
    /**
     * Check if home activity start should be allowed on a display.
     * Check if home activity start should be allowed on a display.
     * @param homeInfo {@code ActivityInfo} of the home activity that is going to be launched.
     * @param homeInfo {@code ActivityInfo} of the home activity that is going to be launched.
@@ -562,22 +601,7 @@ class RootActivityContainer extends ConfigurationContainer
            return true;
            return true;
        }
        }


        if (displayId != DEFAULT_DISPLAY && !mService.mSupportsMultiDisplay) {
        if (!shouldPlaceSecondaryHomeOnDisplay(displayId)) {
            // Can't launch home on secondary display if device not support multi-display.
            return false;
        }

        final boolean deviceProvisioned = Settings.Global.getInt(
                mService.mContext.getContentResolver(),
                Settings.Global.DEVICE_PROVISIONED, 0) != 0;
        if (displayId != DEFAULT_DISPLAY && displayId != INVALID_DISPLAY && !deviceProvisioned) {
            // Can't launch home on secondary display before device is provisioned.
            return false;
        }

        final ActivityDisplay display = getActivityDisplay(displayId);
        if (display == null || display.isRemoved() || !display.supportsSystemDecorations()) {
            // Can't launch home on display that doesn't support system decorations.
            return false;
            return false;
        }
        }


+42 −0
Original line number Original line Diff line number Diff line
@@ -467,6 +467,48 @@ public class RootActivityContainerTests extends ActivityTestsBase {
                true /* allowInstrumenting*/));
                true /* allowInstrumenting*/));
    }
    }


    /**
     * Tests that secondary home activity should not be resolved if device is still locked.
     */
    @Test
    public void testStartSecondaryHomeOnDisplayWithUserKeyLocked() {
        // Create secondary displays.
        final TestActivityDisplay secondDisplay = spy(createNewActivityDisplay());
        mRootActivityContainer.addChild(secondDisplay, POSITION_TOP);

        doReturn(true).when(secondDisplay).supportsSystemDecorations();
        // Use invalid user id to let StorageManager.isUserKeyUnlocked() return false.
        final int currentUser = mRootActivityContainer.mCurrentUser;
        mRootActivityContainer.mCurrentUser = -1;

        mRootActivityContainer.startHomeOnDisplay(0 /* userId */, "testStartSecondaryHome",
                secondDisplay.mDisplayId, true /* allowInstrumenting */, true /* fromHomeKey */);

        try {
            verify(mRootActivityContainer, never()).resolveSecondaryHomeActivity(anyInt(),
                    anyInt());
        } finally {
            mRootActivityContainer.mCurrentUser = currentUser;
        }
    }

    /**
     * Tests that secondary home activity should not be resolved if display does not support system
     * decorations.
     */
    @Test
    public void testStartSecondaryHomeOnDisplayWithoutSysDecorations() {
        // Create secondary displays.
        final TestActivityDisplay secondDisplay = spy(createNewActivityDisplay());
        mRootActivityContainer.addChild(secondDisplay, POSITION_TOP);
        doReturn(false).when(secondDisplay).supportsSystemDecorations();

        mRootActivityContainer.startHomeOnDisplay(0 /* userId */, "testStartSecondaryHome",
                secondDisplay.mDisplayId, true /* allowInstrumenting */, true /* fromHomeKey */);

        verify(mRootActivityContainer, never()).resolveSecondaryHomeActivity(anyInt(), anyInt());
    }

    /**
    /**
     * Tests that secondary home should be selected if default home not set.
     * Tests that secondary home should be selected if default home not set.
     */
     */