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

Commit 9792fed3 authored by Beatrice Marchegiani's avatar Beatrice Marchegiani Committed by Automerger Merge Worker
Browse files

Merge "Do not restore auto-rotation setting when target device is a tablet"...

Merge "Do not restore auto-rotation setting when target device is a tablet" into tm-qpr-dev am: 4301af1a am: 6275b59b

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21084963



Change-Id: If7080a004ead5e852647b4b9c330e9399c15c4b3
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 95c846dd 6275b59b
Loading
Loading
Loading
Loading
+53 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package android.provider.settings.backup;

import android.content.Context;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.WindowManager;

/** Settings that should not be restored when target device is a large screen
 *  i.e. tablets and foldables in unfolded state
 */
public class LargeScreenSettings {
    private static final float LARGE_SCREEN_MIN_DPS = 600;
    private static final String LARGE_SCREEN_DO_NOT_RESTORE = "accelerometer_rotation";

   /**
    * Autorotation setting should not be restored when the target device is a large screen.
    * (b/243489549)
    */
    public static boolean doNotRestoreIfLargeScreenSetting(String key, Context context) {
        return isLargeScreen(context) && LARGE_SCREEN_DO_NOT_RESTORE.equals(key);
    }

    // copied from systemui/shared/...Utilities.java
    // since we don't want to add compile time dependency on sys ui package
    private static boolean isLargeScreen(Context context) {
        final WindowManager windowManager = context.getSystemService(WindowManager.class);
        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;
    }

    private static float dpiFromPx(float size, int densityDpi) {
        float densityRatio = (float) densityDpi / DisplayMetrics.DENSITY_DEFAULT;
        return (size / densityRatio);
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ import android.os.UserHandle;
import android.provider.Settings;
import android.provider.settings.backup.DeviceSpecificSettings;
import android.provider.settings.backup.GlobalSettings;
import android.provider.settings.backup.LargeScreenSettings;
import android.provider.settings.backup.SecureSettings;
import android.provider.settings.backup.SystemSettings;
import android.provider.settings.validators.GlobalSettingsValidators;
@@ -812,6 +813,12 @@ public class SettingsBackupAgent extends BackupAgentHelper {
                continue;
            }

            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)");
                continue;
            }

            String value = null;
            boolean hasValueToRestore = false;
            if (cachedEntries.indexOfKey(key) >= 0) {