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.annotation.SuppressLint; 19 import android.app.WallpaperManager; 20 import android.content.Context; 21 22 /** 23 * Default implementation of {@link LiveWallpaperStatusChecker}. 24 */ 25 @SuppressLint("ServiceCast") 26 public class DefaultLiveWallpaperStatusChecker implements LiveWallpaperStatusChecker { 27 28 private WallpaperManager mWallpaperManager; 29 DefaultLiveWallpaperStatusChecker(Context context)30 public DefaultLiveWallpaperStatusChecker(Context context) { 31 // Retrieve WallpaperManager using Context#getSystemService instead of 32 // WallpaperManager#getInstance so it can be mocked out in test. 33 mWallpaperManager = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE); 34 } 35 36 @Override isNoBackupImageWallpaperSet()37 public boolean isNoBackupImageWallpaperSet() { 38 android.app.WallpaperInfo liveWallpaper = mWallpaperManager.getWallpaperInfo(); 39 return liveWallpaper != null 40 && liveWallpaper.getServiceName().equals(NoBackupImageWallpaper.class.getName()); 41 } 42 } 43