Merge "Move DimenPxIntSupplier to shared utils" into main
diff --git a/services/core/java/com/android/server/wm/LetterboxConfiguration.java b/services/core/java/com/android/server/wm/LetterboxConfiguration.java
index b5af806..0161ae5 100644
--- a/services/core/java/com/android/server/wm/LetterboxConfiguration.java
+++ b/services/core/java/com/android/server/wm/LetterboxConfiguration.java
@@ -19,7 +19,6 @@
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_ATM;
import static com.android.server.wm.ActivityTaskManagerDebugConfig.TAG_WITH_CLASS_NAME;
-import android.annotation.DimenRes;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;
@@ -29,11 +28,11 @@
import com.android.internal.R;
import com.android.internal.annotations.VisibleForTesting;
+import com.android.server.wm.utils.DimenPxIntSupplier;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.function.Function;
-import java.util.function.IntSupplier;
/** Reads letterbox configs from resources and controls their overrides at runtime. */
final class LetterboxConfiguration {
@@ -308,34 +307,6 @@
// Flags dynamically updated with {@link android.provider.DeviceConfig}.
@NonNull private final SynchedDeviceConfig mDeviceConfig;
- // Cached version of IntSupplier customised to evaluate new dimen in pixels
- // when density changes
- private static class DimenPxIntSupplier implements IntSupplier {
-
- @NonNull
- private final Context mContext;
-
- private final int mResourceId;
-
- private float mLastDensity = Float.MIN_VALUE;
- private int mValue = 0;
-
- private DimenPxIntSupplier(@NonNull Context context, @DimenRes int resourceId) {
- mContext = context;
- mResourceId = resourceId;
- }
-
- @Override
- public int getAsInt() {
- final float newDensity = mContext.getResources().getDisplayMetrics().density;
- if (newDensity != mLastDensity) {
- mLastDensity = newDensity;
- mValue = mContext.getResources().getDimensionPixelSize(mResourceId);
- }
- return mValue;
- }
- }
-
LetterboxConfiguration(@NonNull final Context systemUiContext) {
this(systemUiContext, new LetterboxConfigurationPersister(
() -> readLetterboxHorizontalReachabilityPositionFromConfig(
diff --git a/services/core/java/com/android/server/wm/utils/DimenPxIntSupplier.java b/services/core/java/com/android/server/wm/utils/DimenPxIntSupplier.java
new file mode 100644
index 0000000..5e49345
--- /dev/null
+++ b/services/core/java/com/android/server/wm/utils/DimenPxIntSupplier.java
@@ -0,0 +1,54 @@
+/*
+ * 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.server.wm.utils;
+
+import android.annotation.DimenRes;
+import android.annotation.NonNull;
+import android.content.Context;
+
+import java.util.function.IntSupplier;
+
+/**
+ * Cached version of IntSupplier customised to evaluate new dimen in pixels
+ * when density changes.
+ * @hide
+ */
+public class DimenPxIntSupplier implements IntSupplier {
+
+ @NonNull
+ private final Context mContext;
+
+ private final int mResourceId;
+
+ private float mLastDensity = Float.MIN_VALUE;
+ private int mValue = 0;
+
+ public DimenPxIntSupplier(@NonNull Context context, @DimenRes int resourceId) {
+ mContext = context;
+ mResourceId = resourceId;
+ }
+
+ @Override
+ public int getAsInt() {
+ final float newDensity = mContext.getResources().getDisplayMetrics().density;
+ if (newDensity != mLastDensity) {
+ mLastDensity = newDensity;
+ mValue = mContext.getResources().getDimensionPixelSize(mResourceId);
+ }
+ return mValue;
+ }
+}