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

Commit 12bd37dd authored by yyalan's avatar yyalan
Browse files

Fix homescreen rotation delay during fold

The issue is caused by the delay that Launcher handles the rotation; onDisplayInfoChanged that RotationHelper listens to is triggered later than the screen turning on. onDeviceProfileChanged is triggered earlier, but it only receives callback when in foreground. Using both listeners means that if in the background, we can still rely on onDisplayInfoChanged to update, assuming by the delay is tolerable given it takes time to changes to foreground.

Bug: 300929233
Flag: NA
Test: Manual and Perfetto trace in the bug
Change-Id: I5c6983649a38c3e4fe2b8c4a950435ceb07afa5a
parent f21220c7
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.WorkerThread;

import com.android.launcher3.BaseActivity;
import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherPrefs;
import com.android.launcher3.util.DisplayController;

@@ -42,6 +43,7 @@ import com.android.launcher3.util.DisplayController;
 * Utility class to manage launcher rotation
 */
public class RotationHelper implements OnSharedPreferenceChangeListener,
        DeviceProfile.OnDeviceProfileChangeListener,
        DisplayController.DisplayInfoChangeListener {

    public static final String ALLOW_ROTATION_PREFERENCE_KEY = "pref_allowRotation";
@@ -119,10 +121,24 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
        }
    }

    /**
     * Listening to both onDisplayInfoChanged and onDeviceProfileChanged to reduce delay. While
     * onDeviceProfileChanged is triggered earlier, it only receives callback when Launcher is in
     * the foreground. When in the background, we can still rely on onDisplayInfoChanged to update,
     * assuming that the delay is tolerable since it takes time to change to foreground.
     */
    @Override
    public void onDisplayInfoChanged(Context context, DisplayController.Info info, int flags) {
        onIgnoreAutoRotateChanged(info.isTablet(info.realBounds));
    }

    @Override
    public void onDeviceProfileChanged(DeviceProfile dp) {
        onIgnoreAutoRotateChanged(dp.isTablet);
    }

    private void onIgnoreAutoRotateChanged(boolean ignoreAutoRotateSettings) {
        if (mDestroyed) return;
        boolean ignoreAutoRotateSettings = info.isTablet(info.realBounds);
        if (mIgnoreAutoRotateSettings != ignoreAutoRotateSettings) {
            setIgnoreAutoRotateSettings(ignoreAutoRotateSettings);
            notifyChange();
@@ -161,12 +177,14 @@ public class RotationHelper implements OnSharedPreferenceChangeListener,
        DisplayController.Info info = displayController.getInfo();
        setIgnoreAutoRotateSettings(info.isTablet(info.realBounds));
        displayController.addChangeListener(this);
        mActivity.addOnDeviceProfileChangeListener(this);
        notifyChange();
    }

    public void destroy() {
        if (mDestroyed) return;
        mDestroyed = true;
        mActivity.removeOnDeviceProfileChangeListener(this);
        DisplayController.INSTANCE.get(mActivity).removeChangeListener(this);
        LauncherPrefs.get(mActivity).removeListener(this, ALLOW_ROTATION);
    }