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

Commit 7371d0be authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Remove client side deferred config for cached state

Since [1], the server side won't send the config change to a
cached state process, until it has an active state again.
So the logic of client side deferring can be removed.

[1]: I09c2feffba2fc124c623796af69de9f6adb60a39

Bug: 217934273
Test: ActivityThreadTest

Change-Id: Ibd113f4fb3b566e4e9cf5d7960b63a5c7790fb75
parent c0537b75
Loading
Loading
Loading
Loading
+0 −30
Original line number Diff line number Diff line
@@ -3410,26 +3410,12 @@ public final class ActivityThread extends ClientTransactionHandler
        }
    }

    /**
     * Returns {@code true} if the {@link android.app.ActivityManager.ProcessState} of the current
     * process is cached.
     */
    @Override
    @VisibleForTesting
    public boolean isCachedProcessState() {
        synchronized (mAppThread) {
            return mLastProcessState >= ActivityManager.PROCESS_STATE_CACHED_ACTIVITY;
        }
    }

    @Override
    public void updateProcessState(int processState, boolean fromIpc) {
        final boolean wasCached;
        synchronized (mAppThread) {
            if (mLastProcessState == processState) {
                return;
            }
            wasCached = isCachedProcessState();
            mLastProcessState = processState;
            // Defer the top state for VM to avoid aggressive JIT compilation affecting activity
            // launch time.
@@ -3446,22 +3432,6 @@ public final class ActivityThread extends ClientTransactionHandler
                        + (fromIpc ? " (from ipc" : ""));
            }
        }

        // Handle the pending configuration if the process state is changed from cached to
        // non-cached. Except the case where there is a launching activity because the
        // LaunchActivityItem will handle it.
        if (wasCached && !isCachedProcessState() && mNumLaunchingActivities.get() == 0) {
            final Configuration pendingConfig =
                    mConfigurationController.getPendingConfiguration(false /* clearPending */);
            if (pendingConfig == null) {
                return;
            }
            if (Looper.myLooper() == mH.getLooper()) {
                handleConfigurationChanged(pendingConfig);
            } else {
                sendMessage(H.CONFIGURATION_CHANGED, pendingConfig);
            }
        }
    }

    /** Update VM state based on ActivityManager.PROCESS_STATE_* constants. */
+0 −2
Original line number Diff line number Diff line
@@ -32,8 +32,6 @@ interface ActivityThreadInternal {

    boolean isInDensityCompatMode();

    boolean isCachedProcessState();

    Application getApplication();

    ArrayList<ComponentCallbacks2> collectComponentCallbacks(boolean includeUiContexts);
+0 −6
Original line number Diff line number Diff line
@@ -124,12 +124,6 @@ class ConfigurationController {
     * @param config The new configuration.
     */
    void handleConfigurationChanged(@NonNull Configuration config) {
        if (mActivityThread.isCachedProcessState()) {
            updatePendingConfiguration(config);
            // If the process is in a cached state, delay the handling until the process is no
            // longer cached.
            return;
        }
        Trace.traceBegin(Trace.TRACE_TAG_ACTIVITY_MANAGER, "configChanged");
        handleConfigurationChanged(config, null /* compat */);
        Trace.traceEnd(Trace.TRACE_TAG_ACTIVITY_MANAGER);
+0 −48
Original line number Diff line number Diff line
@@ -31,7 +31,6 @@ import static org.junit.Assert.assertTrue;

import android.annotation.Nullable;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityThread;
import android.app.ActivityThread.ActivityClientRecord;
import android.app.IApplicationThread;
@@ -570,53 +569,6 @@ public class ActivityThreadTest {
        });
    }

    @Test
    public void testHandleProcessConfigurationChanged_DependOnProcessState() {
        final ActivityThread activityThread = ActivityThread.currentActivityThread();
        final Configuration origConfig = activityThread.getConfiguration();
        final int newDpi = origConfig.densityDpi + 10;
        final Configuration newConfig = new Configuration(origConfig);
        newConfig.seq++;
        newConfig.densityDpi = newDpi;

        activityThread.updateProcessState(ActivityManager.PROCESS_STATE_CACHED_ACTIVITY,
                false /* fromIPC */);

        applyProcessConfiguration(activityThread, newConfig);
        try {
            // In the cached state, the configuration is only set as pending and not applied.
            assertEquals(origConfig.densityDpi, activityThread.getConfiguration().densityDpi);
            assertTrue(activityThread.isCachedProcessState());
        } finally {
            // The foreground state is the default state of instrumentation.
            activityThread.updateProcessState(ActivityManager.PROCESS_STATE_FOREGROUND_SERVICE,
                    false /* fromIPC */);
        }
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();

        try {
            // The state becomes non-cached, the pending configuration should be applied.
            assertEquals(newConfig.densityDpi, activityThread.getConfiguration().densityDpi);
            assertFalse(activityThread.isCachedProcessState());
        } finally {
            // Restore to the original configuration.
            activityThread.getConfiguration().seq = origConfig.seq - 1;
            applyProcessConfiguration(activityThread, origConfig);
        }
    }

    private static void applyProcessConfiguration(ActivityThread thread, Configuration config) {
        final ClientTransaction clientTransaction = newTransaction(thread,
                null /* activityToken */);
        clientTransaction.addCallback(ConfigurationChangeItem.obtain(config));
        final IApplicationThread appThread = thread.getApplicationThread();
        try {
            appThread.scheduleTransaction(clientTransaction);
        } catch (Exception ignored) {
        }
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    }

    @Test
    public void testResumeAfterNewIntent() {
        final Activity activity = mActivityTestRule.launchActivity(new Intent());