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 static android.app.WallpaperManager.FLAG_LOCK; 19 20 import android.app.WallpaperManager; 21 import android.content.Context; 22 import android.os.ParcelFileDescriptor; 23 import android.util.Log; 24 25 import com.android.wallpaper.compat.WallpaperManagerCompat; 26 27 import java.io.IOException; 28 29 /** 30 * Default implementation of {@link WallpaperStatusChecker}. 31 */ 32 public final class DefaultWallpaperStatusChecker implements WallpaperStatusChecker { 33 34 private static final String TAG = "DefaultWallpaperStatusChecker"; 35 36 @Override isHomeStaticWallpaperSet(Context context)37 public boolean isHomeStaticWallpaperSet(Context context) { 38 ParcelFileDescriptor systemWallpaperFile = 39 InjectorProvider.getInjector().getWallpaperManagerCompat(context).getWallpaperFile( 40 WallpaperManagerCompat.FLAG_SYSTEM); 41 boolean isStaticWallpaperSet = systemWallpaperFile != null; 42 43 if (systemWallpaperFile != null) { 44 try { 45 systemWallpaperFile.close(); 46 } catch (IOException e) { 47 Log.e(TAG, "Unable to close system wallpaper ParcelFileDescriptor", e); 48 } 49 } 50 51 return isStaticWallpaperSet; 52 } 53 54 @Override isLockWallpaperSet(Context context)55 public boolean isLockWallpaperSet(Context context) { 56 return WallpaperManager.getInstance(context).getWallpaperId(FLAG_LOCK) > 0; 57 } 58 } 59