From 250dc7e5c425f932ea0e52563867d3575e1e0a4c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Pomini?= Date: Fri, 6 Jan 2023 10:21:24 +0000 Subject: [PATCH] Move WallpaperData in its own class This CL was entirely made by IntelliJ's refactor tool, except the field WallpaperData#callbacks which has been moved from private to default visibility. Note: the linter complains that the WallpaperData fields should start with "m". We may address this later, but for now renaming these would create unneccessarily more risks of conflicts. Bug: 264637309 Test: atest CtsWallpaperTestCases Test: treehugger Change-Id: I91c79a6988fada04886632844822de02e5dfde7a --- .../server/wallpaper/WallpaperData.java | 136 ++++++++++++++++++ .../wallpaper/WallpaperManagerService.java | 106 -------------- .../WallpaperManagerServiceTests.java | 1 - 3 files changed, 136 insertions(+), 107 deletions(-) create mode 100644 services/core/java/com/android/server/wallpaper/WallpaperData.java diff --git a/services/core/java/com/android/server/wallpaper/WallpaperData.java b/services/core/java/com/android/server/wallpaper/WallpaperData.java new file mode 100644 index 0000000000000..c3ad70c49710b --- /dev/null +++ b/services/core/java/com/android/server/wallpaper/WallpaperData.java @@ -0,0 +1,136 @@ +/* + * 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 com.android.server.wallpaper; + +import android.app.IWallpaperManagerCallback; +import android.app.WallpaperColors; +import android.content.ComponentName; +import android.graphics.Rect; +import android.os.RemoteCallbackList; +import android.util.ArrayMap; + +import java.io.File; + +/** + * The main wallpaper data model, used internally by the {@link WallpaperManagerService}.
+ * An instance of this class contains all the information about a wallpaper. + */ +class WallpaperData { + + int userId; + + final File wallpaperFile; // source image + final File cropFile; // eventual destination + + /** + * True while the client is writing a new wallpaper + */ + boolean imageWallpaperPending; + + /** + * Which wallpaper is set. Flag values are from + * {@link android.app.WallpaperManager.SetWallpaperFlags}. + */ + int mWhich; + + /** + * Callback once the set + crop is finished + */ + IWallpaperManagerCallback setComplete; + + /** + * Is the OS allowed to back up this wallpaper imagery? + */ + boolean allowBackup; + + /** + * Resource name if using a picture from the wallpaper gallery + */ + String name = ""; + + /** + * The component name of the currently set live wallpaper. + */ + ComponentName wallpaperComponent; + + /** + * The component name of the wallpaper that should be set next. + */ + ComponentName nextWallpaperComponent; + + /** + * The ID of this wallpaper + */ + int wallpaperId; + + /** + * Primary colors histogram + */ + WallpaperColors primaryColors; + + /** + * If the wallpaper was set from a foreground app (instead of from a background service). + */ + public boolean fromForegroundApp; + + WallpaperManagerService.WallpaperConnection connection; + long lastDiedTime; + boolean wallpaperUpdating; + WallpaperManagerService.WallpaperObserver wallpaperObserver; + + /** + * The dim amount to be applied to the wallpaper. + */ + float mWallpaperDimAmount = 0.0f; + + /** + * A map to keep track of the dimming set by different applications. The key is the calling + * UID and the value is the dim amount. + */ + ArrayMap mUidToDimAmount = new ArrayMap<>(); + + /** + * Whether we need to extract the wallpaper colors again to calculate the dark hints + * after dimming is applied. + */ + boolean mIsColorExtractedFromDim; + + /** + * List of callbacks registered they should each be notified when the wallpaper is changed. + */ + RemoteCallbackList callbacks = new RemoteCallbackList<>(); + + /** + * The crop hint supplied for displaying a subset of the source image + */ + final Rect cropHint = new Rect(0, 0, 0, 0); + + WallpaperData(int userId, File wallpaperDir, String inputFileName, String cropFileName) { + this.userId = userId; + wallpaperFile = new File(wallpaperDir, inputFileName); + cropFile = new File(wallpaperDir, cropFileName); + } + + // Called during initialization of a given user's wallpaper bookkeeping + boolean cropExists() { + return cropFile.exists(); + } + + boolean sourceExists() { + return wallpaperFile.exists(); + } +} diff --git a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java index cee78643d6b8a..933aa4b1809be 100644 --- a/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java +++ b/services/core/java/com/android/server/wallpaper/WallpaperManagerService.java @@ -921,112 +921,6 @@ public class WallpaperManagerService extends IWallpaperManager.Stub private boolean mInAmbientMode; private LocalColorRepository mLocalColorRepo = new LocalColorRepository(); - static class WallpaperData { - - int userId; - - final File wallpaperFile; // source image - final File cropFile; // eventual destination - - /** - * True while the client is writing a new wallpaper - */ - boolean imageWallpaperPending; - - /** - * Which wallpaper is set. Flag values are from {@link SetWallpaperFlags}. - */ - int mWhich; - - /** - * Callback once the set + crop is finished - */ - IWallpaperManagerCallback setComplete; - - /** - * Is the OS allowed to back up this wallpaper imagery? - */ - boolean allowBackup; - - /** - * Resource name if using a picture from the wallpaper gallery - */ - String name = ""; - - /** - * The component name of the currently set live wallpaper. - */ - ComponentName wallpaperComponent; - - /** - * The component name of the wallpaper that should be set next. - */ - ComponentName nextWallpaperComponent; - - /** - * The ID of this wallpaper - */ - int wallpaperId; - - /** - * Primary colors histogram - */ - WallpaperColors primaryColors; - - /** - * If the wallpaper was set from a foreground app (instead of from a background service). - */ - public boolean fromForegroundApp; - - WallpaperConnection connection; - long lastDiedTime; - boolean wallpaperUpdating; - WallpaperObserver wallpaperObserver; - - /** - * The dim amount to be applied to the wallpaper. - */ - float mWallpaperDimAmount = 0.0f; - - /** - * A map to keep track of the dimming set by different applications. The key is the calling - * UID and the value is the dim amount. - */ - ArrayMap mUidToDimAmount = new ArrayMap<>(); - - /** - * Whether we need to extract the wallpaper colors again to calculate the dark hints - * after dimming is applied. - */ - boolean mIsColorExtractedFromDim; - - /** - * List of callbacks registered they should each be notified when the wallpaper is changed. - */ - private RemoteCallbackList callbacks - = new RemoteCallbackList(); - - /** - * The crop hint supplied for displaying a subset of the source image - */ - final Rect cropHint = new Rect(0, 0, 0, 0); - - WallpaperData(int userId, File wallpaperDir, String inputFileName, String cropFileName) { - this.userId = userId; - wallpaperFile = new File(wallpaperDir, inputFileName); - cropFile = new File(wallpaperDir, cropFileName); - } - - // Called during initialization of a given user's wallpaper bookkeeping - boolean cropExists() { - return cropFile.exists(); - } - - boolean sourceExists() { - return wallpaperFile.exists(); - } - } - @VisibleForTesting static final class DisplayData { int mWidth = -1; diff --git a/services/tests/mockingservicestests/src/com/android/server/wallpaper/WallpaperManagerServiceTests.java b/services/tests/mockingservicestests/src/com/android/server/wallpaper/WallpaperManagerServiceTests.java index 7fd1ddbfcbdc1..a8a2310c0e548 100644 --- a/services/tests/mockingservicestests/src/com/android/server/wallpaper/WallpaperManagerServiceTests.java +++ b/services/tests/mockingservicestests/src/com/android/server/wallpaper/WallpaperManagerServiceTests.java @@ -81,7 +81,6 @@ import com.android.internal.R; import com.android.modules.utils.TypedXmlPullParser; import com.android.modules.utils.TypedXmlSerializer; import com.android.server.LocalServices; -import com.android.server.wallpaper.WallpaperManagerService.WallpaperData; import com.android.server.wm.WindowManagerInternal; import org.hamcrest.CoreMatchers;