Check device for config_enableWallpaperService before calling service.
On some devices, it is possible that config_enableWallpaperService is false, in which then there is no wallpaper service on device. Calling WallpaperManager#getWallpaperId will then result in an NPE. We should just do a check and return false. Bug: 62387789 Test: RoboSettingsTest Change-Id: I31db6845f06533d92140bf91d0f7fc7e7bedc5c5
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -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);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user