Merge "Check device for config_enableWallpaperService before calling service."
This commit is contained in:
committed by
Android (Google) Code Review
commit
def55bf102
@@ -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);
|
||||
}
|
||||
}
|
||||
|
@@ -17,12 +17,14 @@
|
||||
package com.android.settings.wallpaper;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.robolectric.Shadows.shadowOf;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
|
||||
import com.android.settings.SubSettings;
|
||||
import com.android.settings.TestConfig;
|
||||
@@ -42,16 +44,16 @@ import org.robolectric.annotation.Implements;
|
||||
import org.robolectric.shadows.ShadowActivity;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION,
|
||||
shadows = {
|
||||
WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class
|
||||
})
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class WallpaperSuggestionActivityTest {
|
||||
|
||||
@Mock
|
||||
private Context mContext;
|
||||
@Mock
|
||||
private PackageManager mPackageManager;
|
||||
@Mock
|
||||
private Resources mResources;
|
||||
|
||||
private ActivityController<WallpaperSuggestionActivity> mController;
|
||||
|
||||
@Before
|
||||
@@ -72,6 +74,17 @@ public class WallpaperSuggestionActivityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wallpaperServiceEnabled_no_shouldReturnFalse() {
|
||||
when(mContext.getResources()).thenReturn(mResources);
|
||||
when(mResources.getBoolean(
|
||||
com.android.internal.R.bool.config_enableWallpaperService)).thenReturn(false);
|
||||
|
||||
assertThat(WallpaperSuggestionActivity.isSuggestionComplete(mContext))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class)
|
||||
public void hasWallpaperSet_no_shouldReturnFalse() {
|
||||
ShadowWallpaperManagerWrapper.setWallpaperId(0);
|
||||
|
||||
@@ -80,6 +93,7 @@ public class WallpaperSuggestionActivityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@Config(shadows = WallpaperSuggestionActivityTest.ShadowWallpaperManagerWrapper.class)
|
||||
public void hasWallpaperSet_yes_shouldReturnTrue() {
|
||||
ShadowWallpaperManagerWrapper.setWallpaperId(100);
|
||||
|
||||
@@ -100,6 +114,15 @@ public class WallpaperSuggestionActivityTest {
|
||||
sWallpaperId = 0;
|
||||
}
|
||||
|
||||
public void __constructor__(Context context) {
|
||||
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public boolean isWallpaperServiceEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Implementation
|
||||
public int getWallpaperId(int which) {
|
||||
return sWallpaperId;
|
||||
|
Reference in New Issue
Block a user