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 18 package com.android.wallpaper.picker.customization.shared.model 19 20 import android.app.WallpaperManager.FLAG_LOCK 21 import android.app.WallpaperManager.FLAG_SYSTEM 22 import android.app.WallpaperManager.SetWallpaperFlags 23 import com.android.wallpaper.module.WallpaperPersister.DEST_BOTH 24 import com.android.wallpaper.module.WallpaperPersister.DEST_HOME_SCREEN 25 import com.android.wallpaper.module.WallpaperPersister.DEST_LOCK_SCREEN 26 import com.android.wallpaper.module.WallpaperPersister.Destination 27 28 /** Enumerates all known wallpaper destinations. */ 29 enum class WallpaperDestination { 30 /** Both [HOME] and [LOCK] destinations. */ 31 BOTH, 32 /** The home screen wallpaper. */ 33 HOME, 34 /** The lock screen wallpaper. */ 35 LOCK; 36 37 companion object { fromFlagsnull38 fun fromFlags(@SetWallpaperFlags flags: Int): WallpaperDestination { 39 return when (flags) { 40 FLAG_SYSTEM or FLAG_LOCK -> BOTH 41 FLAG_SYSTEM -> HOME 42 FLAG_LOCK -> LOCK 43 else -> throw IllegalArgumentException("Bad @SetWallpaperFlags value $flags") 44 } 45 } 46 47 @Destination WallpaperDestinationnull48 fun WallpaperDestination.toDestinationInt(): Int { 49 return when (this) { 50 BOTH -> DEST_BOTH 51 HOME -> DEST_HOME_SCREEN 52 LOCK -> DEST_LOCK_SCREEN 53 } 54 } 55 } 56 } 57