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

Commit 8c0e8a9b authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Inline the custom Lazy implementation in shell" into main

parents 9df8a1ad 6fd78130
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ filegroup {
    name: "wm_shell-shared-utils",
    srcs: [
        "src/com/android/wm/shell/shared/TransitionUtil.java",
        "src/com/android/wm/shell/shared/Utils.java",
    ],
}

+0 −46
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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 com.android.wm.shell.shared;

import android.annotation.NonNull;

import java.util.function.Supplier;

/**
 * This class provides generic utility methods and classes for shell
 */
public class Utils {

    /**
     * Lazily returns object from a supplier with caching
     * @param <T> type of object to get
     */
    public static class Lazy<T> {
        private T mInstance;

        /**
         * @param supplier the supplier to use, when the instance has not yet been initialized
         * @return the cached value or the value from the supplier
         */
        public final T get(@NonNull Supplier<T> supplier) {
            if (mInstance == null) {
                mInstance = supplier.get();
            }
            return mInstance;
        }
    }
}
+8 −4
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.wm.shell.shared.desktopmode;
import static android.hardware.display.DisplayManager.DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.hardware.display.DisplayManager;
import android.os.SystemProperties;
@@ -29,7 +30,6 @@ import android.window.DesktopModeFlags;
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
import com.android.window.flags.Flags;
import com.android.wm.shell.shared.Utils.Lazy;

import java.io.PrintWriter;
import java.util.Arrays;
@@ -42,7 +42,8 @@ public class DesktopModeStatus {

    private static final String TAG = "DesktopModeStatus";

    private static Lazy<Boolean> sIsLargeScreenDevice = new Lazy<>();
    @Nullable
    private static Boolean sIsLargeScreenDevice = null;

    /**
     * Flag to indicate whether task resizing is veiled.
@@ -287,12 +288,15 @@ public class DesktopModeStatus {
     * @return {@code true} if this device has an internal large screen
     */
    private static boolean deviceHasLargeScreen(@NonNull Context context) {
        return sIsLargeScreenDevice.get(() -> Arrays.stream(
        if (sIsLargeScreenDevice == null) {
            sIsLargeScreenDevice = Arrays.stream(
                context.getSystemService(DisplayManager.class)
                        .getDisplays(DISPLAY_CATEGORY_ALL_INCLUDING_DISABLED))
                .filter(display -> display.getType() == Display.TYPE_INTERNAL)
                .anyMatch(display -> display.getMinSizeDimensionDp()
                        >= WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP));
                        >= WindowManager.LARGE_SCREEN_SMALLEST_SCREEN_WIDTH_DP);
        }
        return sIsLargeScreenDevice;
    }

    /**