1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.server.wallpaper; 18 19 import android.os.Environment; 20 21 import java.io.File; 22 import java.util.ArrayList; 23 import java.util.List; 24 25 class WallpaperUtils { 26 27 static final String WALLPAPER = "wallpaper_orig"; 28 static final String WALLPAPER_CROP = "wallpaper"; 29 static final String WALLPAPER_LOCK_ORIG = "wallpaper_lock_orig"; 30 static final String WALLPAPER_LOCK_CROP = "wallpaper_lock"; 31 static final String WALLPAPER_INFO = "wallpaper_info.xml"; 32 static final String RECORD_FILE = "decode_record"; 33 static final String RECORD_LOCK_FILE = "decode_lock_record"; 34 35 // All the various per-user state files we need to be aware of 36 private static final String[] sPerUserFiles = new String[] { 37 WALLPAPER, WALLPAPER_CROP, 38 WALLPAPER_LOCK_ORIG, WALLPAPER_LOCK_CROP, 39 WALLPAPER_INFO 40 }; 41 42 /** 43 * ID of the current wallpaper, incremented every time anything sets a wallpaper. 44 * This is used for external detection of wallpaper update activity. 45 */ 46 private static int sWallpaperId; 47 getWallpaperDir(int userId)48 static File getWallpaperDir(int userId) { 49 return Environment.getUserSystemDirectory(userId); 50 } 51 52 /** 53 * generate a new wallpaper id 54 * should be called with the {@link WallpaperManagerService} lock held 55 */ makeWallpaperIdLocked()56 static int makeWallpaperIdLocked() { 57 do { 58 ++sWallpaperId; 59 } while (sWallpaperId == 0); 60 return sWallpaperId; 61 } 62 63 /** 64 * returns the id of the current wallpaper (the last one that has been set) 65 */ getCurrentWallpaperId()66 static int getCurrentWallpaperId() { 67 return sWallpaperId; 68 } 69 70 /** 71 * sets the id of the current wallpaper 72 * used when a wallpaper with higher id than current is loaded from settings 73 */ setCurrentWallpaperId(int id)74 static void setCurrentWallpaperId(int id) { 75 sWallpaperId = id; 76 } 77 getWallpaperFiles(int userId)78 static List<File> getWallpaperFiles(int userId) { 79 File wallpaperDir = getWallpaperDir(userId); 80 List<File> result = new ArrayList<File>(); 81 for (int i = 0; i < sPerUserFiles.length; i++) { 82 result.add(new File(wallpaperDir, sPerUserFiles[i])); 83 } 84 return result; 85 } 86 } 87