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

Commit a95ca8de authored by Jorim Jaggi's avatar Jorim Jaggi
Browse files

Fix unneccesary activity relaunches

When going from fullscreen to non-fullscreen configuration, task config
changes was always non-zero because in fullscreen, task override config
was empty. Instead, use the actual previous configuration to calculate
diff.

Also make recents handle screenLayout changes.

Bug: 26593320
Change-Id: I57633d60b1e0fc4ae506e276410191a44e1fe221
parent 98bc797d
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -226,7 +226,7 @@
                  android:resumeWhilePausing="true"
                  android:screenOrientation="behind"
                  android:resizeableActivity="true"
                  android:configChanges="orientation|screenSize|smallestScreenSize"
                  android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|layoutDirection"
                  android:theme="@style/RecentsTheme.Wallpaper">
            <intent-filter>
                <action android:name="com.android.systemui.recents.TOGGLE_RECENTS" />
+8 −0
Original line number Diff line number Diff line
@@ -4243,6 +4243,14 @@ final class ActivityStack {

    private int getTaskConfigurationChanges(ActivityRecord record, Configuration taskConfig,
            Configuration oldTaskOverride) {

        // If we went from full-screen to non-full-screen, make sure to use the correct
        // configuration task diff, so the diff stays as small as possible.
        if (Configuration.EMPTY.equals(oldTaskOverride)
                && !Configuration.EMPTY.equals(taskConfig)) {
            oldTaskOverride = record.task.extractOverrideConfig(record.configuration);
        }

        // Determine what has changed.  May be nothing, if this is a config
        // that has come back from the app after going idle.  In that case
        // we just want to leave the official config object now in the
+36 −18
Original line number Diff line number Diff line
@@ -1291,31 +1291,49 @@ final class TaskRecord {
            if (stack == null || StackId.persistTaskBounds(stack.mStackId)) {
                mLastNonFullscreenBounds = mBounds;
            }
            mOverrideConfig = calculateOverrideConfig(mBounds);
        }

        if (mFullscreen != oldFullscreen) {
            reportMultiWindowModeChange();
        }

        return !mOverrideConfig.equals(oldConfig) ? mOverrideConfig : null;
    }

    Configuration calculateOverrideConfig(Rect bounds) {
        final Configuration serviceConfig = mService.mConfiguration;
            mOverrideConfig = new Configuration(Configuration.EMPTY);
        final Configuration config = new Configuration(Configuration.EMPTY);
        // TODO(multidisplay): Update Dp to that of display stack is on.
        final float density = serviceConfig.densityDpi * DisplayMetrics.DENSITY_DEFAULT_SCALE;
            mOverrideConfig.screenWidthDp =
                    Math.min((int)(mBounds.width() / density), serviceConfig.screenWidthDp);
            mOverrideConfig.screenHeightDp =
                    Math.min((int)(mBounds.height() / density), serviceConfig.screenHeightDp);
            mOverrideConfig.smallestScreenWidthDp =
                    Math.min(mOverrideConfig.screenWidthDp, mOverrideConfig.screenHeightDp);
            mOverrideConfig.orientation =
                    (mOverrideConfig.screenWidthDp <= mOverrideConfig.screenHeightDp)
        config.screenWidthDp =
                Math.min((int)(bounds.width() / density), serviceConfig.screenWidthDp);
        config.screenHeightDp =
                Math.min((int)(bounds.height() / density), serviceConfig.screenHeightDp);
        config.smallestScreenWidthDp =
                Math.min(config.screenWidthDp, config.screenHeightDp);
        config.orientation = (config.screenWidthDp <= config.screenHeightDp)
                ? Configuration.ORIENTATION_PORTRAIT
                : Configuration.ORIENTATION_LANDSCAPE;
        final int sl = Configuration.resetScreenLayout(serviceConfig.screenLayout);
            mOverrideConfig.screenLayout = Configuration.reduceScreenLayout(
                    sl, mOverrideConfig.screenWidthDp, mOverrideConfig.screenHeightDp);
        config.screenLayout = Configuration.reduceScreenLayout(
                sl, config.screenWidthDp, config.screenHeightDp);
        return config;
    }

        if (mFullscreen != oldFullscreen) {
            reportMultiWindowModeChange();
        }

        return !mOverrideConfig.equals(oldConfig) ? mOverrideConfig : null;
    /**
     * Using the existing configuration {@param config}, creates a new task override config such
     * that all the fields that are usually set in an override config are set to the ones in
     * {@param config}.
     */
    Configuration extractOverrideConfig(Configuration config) {
        final Configuration extracted = new Configuration(Configuration.EMPTY);
        extracted.screenWidthDp = config.screenWidthDp;
        extracted.screenHeightDp = config.screenHeightDp;
        extracted.smallestScreenWidthDp = config.smallestScreenWidthDp;
        extracted.orientation = config.orientation;
        extracted.screenLayout = config.screenLayout;
        return extracted;
    }

    Rect updateOverrideConfigurationFromLaunchBounds() {