Merge "Check device for config_enableWallpaperService before calling service."

This commit is contained in:
TreeHugger Robot
2018-02-06 20:27:20 +00:00
committed by Android (Google) Code Review
3 changed files with 41 additions and 6 deletions

View File

@@ -59,7 +59,8 @@ public class WallpaperSuggestionActivity extends Activity {
@VisibleForTesting
public static boolean isSuggestionComplete(Context context) {
final WallpaperManagerWrapper manager = new WallpaperManagerWrapper(context);
return manager.getWallpaperId(WallpaperManager.FLAG_SYSTEM) > 0;
return manager.isWallpaperServiceEnabled() ? manager.getWallpaperId(
WallpaperManager.FLAG_SYSTEM) > 0 : false;
}
}

View File

@@ -22,12 +22,23 @@ import android.content.Context;
public class WallpaperManagerWrapper {
private final WallpaperManager mWallpaperManager;
private final boolean mWallpaperServiceEnabled;
public WallpaperManagerWrapper(Context context) {
mWallpaperManager = (WallpaperManager) context.getSystemService(Context.WALLPAPER_SERVICE);
mWallpaperServiceEnabled = context.getResources().getBoolean(
com.android.internal.R.bool.config_enableWallpaperService);
mWallpaperManager = mWallpaperServiceEnabled ? (WallpaperManager) context.getSystemService(
Context.WALLPAPER_SERVICE) : null;
}
public boolean isWallpaperServiceEnabled() {
return mWallpaperServiceEnabled;
}
public int getWallpaperId(int which) {
if (!mWallpaperServiceEnabled) {
throw new RuntimeException("This device does not have wallpaper service enabled.");
}
return mWallpaperManager.getWallpaperId(which);
}
}