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

Commit 38565493 authored by Shivangi Dubey's avatar Shivangi Dubey
Browse files

Disable B&R for foldables of ACCELEROMETER_ROTATION

Foldables has DEVICE_STATE_ROTATION_LOCK which stores auto-rotate setting for valid device states.
ACCELEROMETER_ROTATION setting could be different based on what device state device is in.
Eg: If the backup occurs when the device is in UNFOLDED mode and restore when device is in folded mode, ACCELEROMETER_ROTATION setting will not be restored as we expect it to be.

This change skips restoration of ACCELEROMETER_ROTATION setting if target device is a foldable.
Later ACCELEROMETER_ROTATION will be set based on device state value and restored DEVICE_STATE_ROTATION_LOCK setting in DeviceStateAutoRotateSettingController.

Fixes: 414591058
Flag: com.android.window.flags.enable_omit_accelerometer_rotation_restore
Test: Following go/br-app-developer-guide-impl#testing test if auto-rotate settings are restored as expected
Change-Id: Ifcb4cfc16b5b8a007cd220b08861b3c9961fb098
parent 2e071263
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -21,8 +21,14 @@ import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.WindowManager;

import com.android.internal.R;
import com.android.window.flags.Flags;

/** Settings that should not be restored when target device is a large screen
 *  i.e. tablets and foldables in unfolded state
 *
 *  <p>If {@link Flags#FLAG_ENABLE_DEVICE_STATE_AUTO_ROTATE_SETTING_REFACTOR} is enabled, specified
 *  settings will not be restored when target device is a large screen i.e. tablets and foldables
 */
public class LargeScreenSettings {
    private static final float LARGE_SCREEN_MIN_DPS = 600;
@@ -43,7 +49,15 @@ public class LargeScreenSettings {
        final Rect bounds = windowManager.getCurrentWindowMetrics().getBounds();
        float smallestWidth = dpiFromPx(Math.min(bounds.width(), bounds.height()),
                context.getResources().getConfiguration().densityDpi);
        return smallestWidth >= LARGE_SCREEN_MIN_DPS;
        boolean isLargeScreen = smallestWidth >= LARGE_SCREEN_MIN_DPS;
        if (Flags.enableOmitAccelerometerRotationRestore()) {
            isLargeScreen = isLargeScreen || isFoldable(context);
        }
        return isLargeScreen;
    }

    private static boolean isFoldable(Context context) {
        return context.getResources().getIntArray(R.array.config_foldedDeviceStates).length > 0;
    }

    private static float dpiFromPx(float size, int densityDpi) {
+1 −1
Original line number Diff line number Diff line
@@ -979,7 +979,7 @@ public class SettingsBackupAgent extends BackupAgentHelper {

            if (LargeScreenSettings.doNotRestoreIfLargeScreenSetting(key, getBaseContext())) {
                Log.i(TAG, "Skipping restore for setting " + key + " as the target device "
                        + "is a large screen (i.e tablet or foldable in unfolded state)");
                        + "is a large screen (i.e tablet or foldable)");
                if (areAgentMetricsEnabled) {
                    mBackupRestoreEventLogger.logItemsRestoreFailed(
                            settingsKey, /* count= */ 1, ERROR_SKIPPED_DUE_TO_LARGE_SCREEN);