1 /* 2 * Copyright (C) 2021 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 package com.android.wallpaper.module 17 18 import android.app.WallpaperManager 19 import android.util.Log 20 import java.io.IOException 21 22 /** Default implementation of [WallpaperStatusChecker]. */ 23 class DefaultWallpaperStatusChecker( 24 private val wallpaperManager: WallpaperManager, 25 ) : WallpaperStatusChecker { isHomeStaticWallpaperSetnull26 override fun isHomeStaticWallpaperSet(): Boolean { 27 val systemWallpaperFile = wallpaperManager.getWallpaperFile(WallpaperManager.FLAG_SYSTEM) 28 return if (systemWallpaperFile != null) { 29 try { 30 systemWallpaperFile.close() 31 } catch (e: IOException) { 32 Log.e(TAG, "Unable to close system wallpaper ParcelFileDescriptor", e) 33 } 34 true 35 } else { 36 false 37 } 38 } 39 isLockWallpaperSetnull40 override fun isLockWallpaperSet(): Boolean { 41 return wallpaperManager.getWallpaperId(WallpaperManager.FLAG_LOCK) >= 0 42 } 43 44 companion object { 45 private const val TAG = "DefaultWallpaperStatusChecker" 46 } 47 } 48