• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.content.Context;
19 import android.os.ParcelFileDescriptor;
20 import android.util.Log;
21 
22 import com.android.wallpaper.compat.BuildCompat;
23 import com.android.wallpaper.compat.WallpaperManagerCompat;
24 
25 import java.io.IOException;
26 
27 /**
28  * Checks whether an explicit lock wallpaper is set to the device (i.e., independently shown under
29  * the keyguard and separate from the wallpaper shown under the user's launcher).
30  */
31 public class LockWallpaperStatusChecker {
32 
33     private static final String TAG = "LockWPStatusChecker";
34 
35     /**
36      * Returns whether a lock screen wallpaper is independently set to the device.
37      */
isLockWallpaperSet(Context context)38     public static boolean isLockWallpaperSet(Context context) {
39         // Lock screen wallpapers are not supported until Android N.
40         if (!BuildCompat.isAtLeastN()) {
41             return false;
42         }
43 
44         WallpaperManagerCompat wallpaperManagerCompat = InjectorProvider.getInjector()
45                 .getWallpaperManagerCompat(context);
46         ParcelFileDescriptor parcelFd =
47                 wallpaperManagerCompat.getWallpaperFile(WallpaperManagerCompat.FLAG_LOCK);
48         boolean isSet = parcelFd != null;
49         if (isSet) {
50             try {
51                 // Close the ParcelFileDescriptor if it's not null to avoid a resource leak.
52                 parcelFd.close();
53             } catch (IOException e) {
54                 Log.e(TAG, "IO exception when closing the lock screen wallpaper file descriptor.");
55             }
56         }
57         return isSet;
58     }
59 }
60