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

Commit 989d085f authored by Aurélien Pomini's avatar Aurélien Pomini
Browse files

Move more stuff in WallpaperUtils

The method makeWallpaperId, and a few constants (the file names) have
been moved from WallpaperManagerService to WallpaperUtils

Test: treehugger (safe, no logic change)
Bug: 264637309
Change-Id: I3b04da606ce787c195b7c42737a7a4ee046368b0
parent ffd5aad4
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -18,10 +18,10 @@ package com.android.server.wallpaper;

import static android.app.WallpaperManager.FLAG_LOCK;

import static com.android.server.wallpaper.WallpaperManagerService.WALLPAPER;
import static com.android.server.wallpaper.WallpaperManagerService.WALLPAPER_CROP;
import static com.android.server.wallpaper.WallpaperManagerService.WALLPAPER_LOCK_CROP;
import static com.android.server.wallpaper.WallpaperManagerService.WALLPAPER_LOCK_ORIG;
import static com.android.server.wallpaper.WallpaperUtils.WALLPAPER;
import static com.android.server.wallpaper.WallpaperUtils.WALLPAPER_CROP;
import static com.android.server.wallpaper.WallpaperUtils.WALLPAPER_LOCK_CROP;
import static com.android.server.wallpaper.WallpaperUtils.WALLPAPER_LOCK_ORIG;
import static com.android.server.wallpaper.WallpaperUtils.getWallpaperDir;

import android.app.IWallpaperManagerCallback;
+13 −38
Original line number Diff line number Diff line
@@ -32,7 +32,14 @@ import static android.os.ParcelFileDescriptor.MODE_TRUNCATE;
import static android.view.Display.DEFAULT_DISPLAY;
import static android.view.WindowManager.LayoutParams.TYPE_WALLPAPER;

import static com.android.server.wallpaper.WallpaperUtils.RECORD_FILE;
import static com.android.server.wallpaper.WallpaperUtils.RECORD_LOCK_FILE;
import static com.android.server.wallpaper.WallpaperUtils.WALLPAPER;
import static com.android.server.wallpaper.WallpaperUtils.WALLPAPER_CROP;
import static com.android.server.wallpaper.WallpaperUtils.WALLPAPER_INFO;
import static com.android.server.wallpaper.WallpaperUtils.WALLPAPER_LOCK_ORIG;
import static com.android.server.wallpaper.WallpaperUtils.getWallpaperDir;
import static com.android.server.wallpaper.WallpaperUtils.makeWallpaperIdLocked;

import android.annotation.NonNull;
import android.app.ActivityManager;
@@ -199,20 +206,6 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
     */
    private static final long MIN_WALLPAPER_CRASH_TIME = 10000;
    private static final int MAX_WALLPAPER_COMPONENT_LOG_LENGTH = 128;
    static final String WALLPAPER = "wallpaper_orig";
    static final String WALLPAPER_CROP = "wallpaper";
    static final String WALLPAPER_LOCK_ORIG = "wallpaper_lock_orig";
    static final String WALLPAPER_LOCK_CROP = "wallpaper_lock";
    static final String WALLPAPER_INFO = "wallpaper_info.xml";
    private static final String RECORD_FILE = "decode_record";
    private static final String RECORD_LOCK_FILE = "decode_lock_record";

    // All the various per-user state files we need to be aware of
    private static final String[] sPerUserFiles = new String[] {
        WALLPAPER, WALLPAPER_CROP,
        WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP,
        WALLPAPER_INFO
    };

    /**
     * Observes the wallpaper for changes and notifies all IWallpaperServiceCallbacks
@@ -888,12 +881,6 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
    private boolean mWaitingForUnlock;
    private boolean mShuttingDown;

    /**
     * ID of the current wallpaper, changed every time anything sets a wallpaper.
     * This is used for external detection of wallpaper update activity.
     */
    private int mWallpaperId;

    /**
     * Name of the component used to display bitmap wallpapers from either the gallery or
     * built-in wallpapers.
@@ -976,13 +963,6 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        }
    }

    int makeWallpaperIdLocked() {
        do {
            ++mWallpaperId;
        } while (mWallpaperId == 0);
        return mWallpaperId;
    }

    private boolean supportsMultiDisplay(WallpaperConnection connection) {
        if (connection != null) {
            return connection.mInfo == null // This is image wallpaper
@@ -1852,11 +1832,9 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
                        final TimingsTraceAndSlog t = new TimingsTraceAndSlog(TAG);
                        t.traceBegin("Wallpaper_selinux_restorecon-" + userId);
                        try {
                            final File wallpaperDir = getWallpaperDir(userId);
                            for (String filename : sPerUserFiles) {
                                File f = new File(wallpaperDir, filename);
                                if (f.exists()) {
                                    SELinux.restorecon(f);
                            for (File file: WallpaperUtils.getWallpaperFiles(userId)) {
                                if (file.exists()) {
                                    SELinux.restorecon(file);
                                }
                            }
                        } finally {
@@ -1872,12 +1850,9 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
    void onRemoveUser(int userId) {
        if (userId < 1) return;

        final File wallpaperDir = getWallpaperDir(userId);
        synchronized (mLock) {
            stopObserversLocked(userId);
            for (String filename : sPerUserFiles) {
                new File(wallpaperDir, filename).delete();
            }
            WallpaperUtils.getWallpaperFiles(userId).forEach(File::delete);
            mUserRestorecon.delete(userId);
        }
    }
@@ -3624,8 +3599,8 @@ public class WallpaperManagerService extends IWallpaperManager.Stub
        final int id = parser.getAttributeInt(null, "id", -1);
        if (id != -1) {
            wallpaper.wallpaperId = id;
            if (id > mWallpaperId) {
                mWallpaperId = id;
            if (id > WallpaperUtils.getCurrentWallpaperId()) {
                WallpaperUtils.setCurrentWallpaperId(id);
            }
        } else {
            wallpaper.wallpaperId = makeWallpaperIdLocked();
+58 −0
Original line number Diff line number Diff line
@@ -19,10 +19,68 @@ package com.android.server.wallpaper;
import android.os.Environment;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

class WallpaperUtils {

    static final String WALLPAPER = "wallpaper_orig";
    static final String WALLPAPER_CROP = "wallpaper";
    static final String WALLPAPER_LOCK_ORIG = "wallpaper_lock_orig";
    static final String WALLPAPER_LOCK_CROP = "wallpaper_lock";
    static final String WALLPAPER_INFO = "wallpaper_info.xml";
    static final String RECORD_FILE = "decode_record";
    static final String RECORD_LOCK_FILE = "decode_lock_record";

    // All the various per-user state files we need to be aware of
    private static final String[] sPerUserFiles = new String[] {
            WALLPAPER, WALLPAPER_CROP,
            WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP,
            WALLPAPER_INFO
    };

    /**
     * ID of the current wallpaper, incremented every time anything sets a wallpaper.
     * This is used for external detection of wallpaper update activity.
     */
    private static int sWallpaperId;

    static File getWallpaperDir(int userId) {
        return Environment.getUserSystemDirectory(userId);
    }

    /**
     * generate a new wallpaper id
     * should be called with the {@link WallpaperManagerService} lock held
     */
    static int makeWallpaperIdLocked() {
        do {
            ++sWallpaperId;
        } while (sWallpaperId == 0);
        return sWallpaperId;
    }

    /**
     * returns the id of the current wallpaper (the last one that has been set)
     */
    static int getCurrentWallpaperId() {
        return sWallpaperId;
    }

    /**
     * sets the id of the current wallpaper
     * used when a wallpaper with higher id than current is loaded from settings
     */
    static void setCurrentWallpaperId(int id) {
        sWallpaperId = id;
    }

    static List<File> getWallpaperFiles(int userId) {
        File wallpaperDir = getWallpaperDir(userId);
        List<File> result = new ArrayList<File>();
        for (int i = 0; i < sPerUserFiles.length; i++) {
            result.add(new File(wallpaperDir, sPerUserFiles[i]));
        }
        return result;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -28,7 +28,7 @@ import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mock;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.mockitoSession;
import static com.android.dx.mockito.inline.extended.ExtendedMockito.spyOn;
import static com.android.server.wallpaper.WallpaperManagerService.WALLPAPER;
import static com.android.server.wallpaper.WallpaperUtils.WALLPAPER;

import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertEquals;