Merge "Rename WallpaperColorExtractor to WallpaperLocalColorExtractor" into tm-qpr-dev

This commit is contained in:
Aurélien Pomini
2022-10-26 14:50:56 +00:00
committed by Android (Google) Code Review
3 changed files with 68 additions and 68 deletions

View File

@@ -47,7 +47,7 @@ import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.dagger.qualifiers.Main; import com.android.systemui.dagger.qualifiers.Main;
import com.android.systemui.flags.FeatureFlags; import com.android.systemui.flags.FeatureFlags;
import com.android.systemui.util.concurrency.DelayableExecutor; import com.android.systemui.util.concurrency.DelayableExecutor;
import com.android.systemui.wallpapers.canvas.WallpaperColorExtractor; import com.android.systemui.wallpapers.canvas.WallpaperLocalColorExtractor;
import com.android.systemui.wallpapers.gl.EglHelper; import com.android.systemui.wallpapers.gl.EglHelper;
import com.android.systemui.wallpapers.gl.ImageWallpaperRenderer; import com.android.systemui.wallpapers.gl.ImageWallpaperRenderer;
@@ -521,7 +521,7 @@ public class ImageWallpaper extends WallpaperService {
class CanvasEngine extends WallpaperService.Engine implements DisplayListener { class CanvasEngine extends WallpaperService.Engine implements DisplayListener {
private WallpaperManager mWallpaperManager; private WallpaperManager mWallpaperManager;
private final WallpaperColorExtractor mWallpaperColorExtractor; private final WallpaperLocalColorExtractor mWallpaperLocalColorExtractor;
private SurfaceHolder mSurfaceHolder; private SurfaceHolder mSurfaceHolder;
@VisibleForTesting @VisibleForTesting
static final int MIN_SURFACE_WIDTH = 128; static final int MIN_SURFACE_WIDTH = 128;
@@ -543,9 +543,9 @@ public class ImageWallpaper extends WallpaperService {
super(); super();
setFixedSizeAllowed(true); setFixedSizeAllowed(true);
setShowForAllUsers(true); setShowForAllUsers(true);
mWallpaperColorExtractor = new WallpaperColorExtractor( mWallpaperLocalColorExtractor = new WallpaperLocalColorExtractor(
mBackgroundExecutor, mBackgroundExecutor,
new WallpaperColorExtractor.WallpaperColorExtractorCallback() { new WallpaperLocalColorExtractor.WallpaperLocalColorExtractorCallback() {
@Override @Override
public void onColorsProcessed(List<RectF> regions, public void onColorsProcessed(List<RectF> regions,
List<WallpaperColors> colors) { List<WallpaperColors> colors) {
@@ -570,7 +570,7 @@ public class ImageWallpaper extends WallpaperService {
// if the number of pages is already computed, transmit it to the color extractor // if the number of pages is already computed, transmit it to the color extractor
if (mPagesComputed) { if (mPagesComputed) {
mWallpaperColorExtractor.onPageChanged(mPages); mWallpaperLocalColorExtractor.onPageChanged(mPages);
} }
} }
@@ -597,7 +597,7 @@ public class ImageWallpaper extends WallpaperService {
public void onDestroy() { public void onDestroy() {
getDisplayContext().getSystemService(DisplayManager.class) getDisplayContext().getSystemService(DisplayManager.class)
.unregisterDisplayListener(this); .unregisterDisplayListener(this);
mWallpaperColorExtractor.cleanUp(); mWallpaperLocalColorExtractor.cleanUp();
unloadBitmap(); unloadBitmap();
} }
@@ -813,7 +813,7 @@ public class ImageWallpaper extends WallpaperService {
@VisibleForTesting @VisibleForTesting
void recomputeColorExtractorMiniBitmap() { void recomputeColorExtractorMiniBitmap() {
mWallpaperColorExtractor.onBitmapChanged(mBitmap); mWallpaperLocalColorExtractor.onBitmapChanged(mBitmap);
} }
@VisibleForTesting @VisibleForTesting
@@ -830,14 +830,14 @@ public class ImageWallpaper extends WallpaperService {
public void addLocalColorsAreas(@NonNull List<RectF> regions) { public void addLocalColorsAreas(@NonNull List<RectF> regions) {
// this call will activate the offset notifications // this call will activate the offset notifications
// if no colors were being processed before // if no colors were being processed before
mWallpaperColorExtractor.addLocalColorsAreas(regions); mWallpaperLocalColorExtractor.addLocalColorsAreas(regions);
} }
@Override @Override
public void removeLocalColorsAreas(@NonNull List<RectF> regions) { public void removeLocalColorsAreas(@NonNull List<RectF> regions) {
// this call will deactivate the offset notifications // this call will deactivate the offset notifications
// if we are no longer processing colors // if we are no longer processing colors
mWallpaperColorExtractor.removeLocalColorAreas(regions); mWallpaperLocalColorExtractor.removeLocalColorAreas(regions);
} }
@Override @Override
@@ -853,7 +853,7 @@ public class ImageWallpaper extends WallpaperService {
if (pages != mPages || !mPagesComputed) { if (pages != mPages || !mPagesComputed) {
mPages = pages; mPages = pages;
mPagesComputed = true; mPagesComputed = true;
mWallpaperColorExtractor.onPageChanged(mPages); mWallpaperLocalColorExtractor.onPageChanged(mPages);
} }
} }
@@ -881,7 +881,7 @@ public class ImageWallpaper extends WallpaperService {
.getSystemService(WindowManager.class) .getSystemService(WindowManager.class)
.getCurrentWindowMetrics() .getCurrentWindowMetrics()
.getBounds(); .getBounds();
mWallpaperColorExtractor.setDisplayDimensions(window.width(), window.height()); mWallpaperLocalColorExtractor.setDisplayDimensions(window.width(), window.height());
} }
@@ -902,7 +902,7 @@ public class ImageWallpaper extends WallpaperService {
: mBitmap.isRecycled() ? "recycled" : mBitmap.isRecycled() ? "recycled"
: mBitmap.getWidth() + "x" + mBitmap.getHeight()); : mBitmap.getWidth() + "x" + mBitmap.getHeight());
mWallpaperColorExtractor.dump(prefix, fd, out, args); mWallpaperLocalColorExtractor.dump(prefix, fd, out, args);
} }
} }
} }

View File

@@ -45,14 +45,14 @@ import java.util.concurrent.Executor;
* It uses a background executor, and uses callbacks to inform that the work is done. * It uses a background executor, and uses callbacks to inform that the work is done.
* It uses a downscaled version of the wallpaper to extract the colors. * It uses a downscaled version of the wallpaper to extract the colors.
*/ */
public class WallpaperColorExtractor { public class WallpaperLocalColorExtractor {
private Bitmap mMiniBitmap; private Bitmap mMiniBitmap;
@VisibleForTesting @VisibleForTesting
static final int SMALL_SIDE = 128; static final int SMALL_SIDE = 128;
private static final String TAG = WallpaperColorExtractor.class.getSimpleName(); private static final String TAG = WallpaperLocalColorExtractor.class.getSimpleName();
private static final @NonNull RectF LOCAL_COLOR_BOUNDS = private static final @NonNull RectF LOCAL_COLOR_BOUNDS =
new RectF(0, 0, 1, 1); new RectF(0, 0, 1, 1);
@@ -70,12 +70,12 @@ public class WallpaperColorExtractor {
@Background @Background
private final Executor mBackgroundExecutor; private final Executor mBackgroundExecutor;
private final WallpaperColorExtractorCallback mWallpaperColorExtractorCallback; private final WallpaperLocalColorExtractorCallback mWallpaperLocalColorExtractorCallback;
/** /**
* Interface to handle the callbacks after the different steps of the color extraction * Interface to handle the callbacks after the different steps of the color extraction
*/ */
public interface WallpaperColorExtractorCallback { public interface WallpaperLocalColorExtractorCallback {
/** /**
* Callback after the colors of new regions have been extracted * Callback after the colors of new regions have been extracted
* @param regions the list of new regions that have been processed * @param regions the list of new regions that have been processed
@@ -103,13 +103,13 @@ public class WallpaperColorExtractor {
/** /**
* Creates a new color extractor. * Creates a new color extractor.
* @param backgroundExecutor the executor on which the color extraction will be performed * @param backgroundExecutor the executor on which the color extraction will be performed
* @param wallpaperColorExtractorCallback an interface to handle the callbacks from * @param wallpaperLocalColorExtractorCallback an interface to handle the callbacks from
* the color extractor. * the color extractor.
*/ */
public WallpaperColorExtractor(@Background Executor backgroundExecutor, public WallpaperLocalColorExtractor(@Background Executor backgroundExecutor,
WallpaperColorExtractorCallback wallpaperColorExtractorCallback) { WallpaperLocalColorExtractorCallback wallpaperLocalColorExtractorCallback) {
mBackgroundExecutor = backgroundExecutor; mBackgroundExecutor = backgroundExecutor;
mWallpaperColorExtractorCallback = wallpaperColorExtractorCallback; mWallpaperLocalColorExtractorCallback = wallpaperLocalColorExtractorCallback;
} }
/** /**
@@ -157,7 +157,7 @@ public class WallpaperColorExtractor {
mBitmapWidth = bitmap.getWidth(); mBitmapWidth = bitmap.getWidth();
mBitmapHeight = bitmap.getHeight(); mBitmapHeight = bitmap.getHeight();
mMiniBitmap = createMiniBitmap(bitmap); mMiniBitmap = createMiniBitmap(bitmap);
mWallpaperColorExtractorCallback.onMiniBitmapUpdated(); mWallpaperLocalColorExtractorCallback.onMiniBitmapUpdated();
recomputeColors(); recomputeColors();
} }
} }
@@ -206,7 +206,7 @@ public class WallpaperColorExtractor {
boolean wasActive = isActive(); boolean wasActive = isActive();
mPendingRegions.addAll(regions); mPendingRegions.addAll(regions);
if (!wasActive && isActive()) { if (!wasActive && isActive()) {
mWallpaperColorExtractorCallback.onActivated(); mWallpaperLocalColorExtractorCallback.onActivated();
} }
processColorsInternal(); processColorsInternal();
} }
@@ -228,7 +228,7 @@ public class WallpaperColorExtractor {
mPendingRegions.removeAll(regions); mPendingRegions.removeAll(regions);
regions.forEach(mProcessedRegions::remove); regions.forEach(mProcessedRegions::remove);
if (wasActive && !isActive()) { if (wasActive && !isActive()) {
mWallpaperColorExtractorCallback.onDeactivated(); mWallpaperLocalColorExtractorCallback.onDeactivated();
} }
} }
} }
@@ -252,7 +252,7 @@ public class WallpaperColorExtractor {
} }
private Bitmap createMiniBitmap(@NonNull Bitmap bitmap) { private Bitmap createMiniBitmap(@NonNull Bitmap bitmap) {
Trace.beginSection("WallpaperColorExtractor#createMiniBitmap"); Trace.beginSection("WallpaperLocalColorExtractor#createMiniBitmap");
// if both sides of the image are larger than SMALL_SIDE, downscale the bitmap. // if both sides of the image are larger than SMALL_SIDE, downscale the bitmap.
int smallestSide = Math.min(bitmap.getWidth(), bitmap.getHeight()); int smallestSide = Math.min(bitmap.getWidth(), bitmap.getHeight());
float scale = Math.min(1.0f, (float) SMALL_SIDE / smallestSide); float scale = Math.min(1.0f, (float) SMALL_SIDE / smallestSide);
@@ -359,7 +359,7 @@ public class WallpaperColorExtractor {
*/ */
if (mDisplayWidth < 0 || mDisplayHeight < 0 || mPages < 0) return; if (mDisplayWidth < 0 || mDisplayHeight < 0 || mPages < 0) return;
Trace.beginSection("WallpaperColorExtractor#processColorsInternal"); Trace.beginSection("WallpaperLocalColorExtractor#processColorsInternal");
List<WallpaperColors> processedColors = new ArrayList<>(); List<WallpaperColors> processedColors = new ArrayList<>();
for (int i = 0; i < mPendingRegions.size(); i++) { for (int i = 0; i < mPendingRegions.size(); i++) {
RectF nextArea = mPendingRegions.get(i); RectF nextArea = mPendingRegions.get(i);
@@ -372,7 +372,7 @@ public class WallpaperColorExtractor {
mPendingRegions.clear(); mPendingRegions.clear();
Trace.endSection(); Trace.endSection();
mWallpaperColorExtractorCallback.onColorsProcessed(processedRegions, processedColors); mWallpaperLocalColorExtractorCallback.onColorsProcessed(processedRegions, processedColors);
} }
/** /**

View File

@@ -54,7 +54,7 @@ import java.util.concurrent.Executor;
@SmallTest @SmallTest
@RunWith(AndroidTestingRunner.class) @RunWith(AndroidTestingRunner.class)
@TestableLooper.RunWithLooper @TestableLooper.RunWithLooper
public class WallpaperColorExtractorTest extends SysuiTestCase { public class WallpaperLocalColorExtractorTest extends SysuiTestCase {
private static final int LOW_BMP_WIDTH = 128; private static final int LOW_BMP_WIDTH = 128;
private static final int LOW_BMP_HEIGHT = 128; private static final int LOW_BMP_HEIGHT = 128;
private static final int HIGH_BMP_WIDTH = 3000; private static final int HIGH_BMP_WIDTH = 3000;
@@ -105,11 +105,11 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
return bitmap; return bitmap;
} }
private WallpaperColorExtractor getSpyWallpaperColorExtractor() { private WallpaperLocalColorExtractor getSpyWallpaperLocalColorExtractor() {
WallpaperColorExtractor wallpaperColorExtractor = new WallpaperColorExtractor( WallpaperLocalColorExtractor colorExtractor = new WallpaperLocalColorExtractor(
mBackgroundExecutor, mBackgroundExecutor,
new WallpaperColorExtractor.WallpaperColorExtractorCallback() { new WallpaperLocalColorExtractor.WallpaperLocalColorExtractorCallback() {
@Override @Override
public void onColorsProcessed(List<RectF> regions, public void onColorsProcessed(List<RectF> regions,
List<WallpaperColors> colors) { List<WallpaperColors> colors) {
@@ -132,25 +132,25 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
mDeactivatedCount++; mDeactivatedCount++;
} }
}); });
WallpaperColorExtractor spyWallpaperColorExtractor = spy(wallpaperColorExtractor); WallpaperLocalColorExtractor spyColorExtractor = spy(colorExtractor);
doAnswer(invocation -> { doAnswer(invocation -> {
mMiniBitmapWidth = invocation.getArgument(1); mMiniBitmapWidth = invocation.getArgument(1);
mMiniBitmapHeight = invocation.getArgument(2); mMiniBitmapHeight = invocation.getArgument(2);
return getMockBitmap(mMiniBitmapWidth, mMiniBitmapHeight); return getMockBitmap(mMiniBitmapWidth, mMiniBitmapHeight);
}).when(spyWallpaperColorExtractor).createMiniBitmap(any(Bitmap.class), anyInt(), anyInt()); }).when(spyColorExtractor).createMiniBitmap(any(Bitmap.class), anyInt(), anyInt());
doAnswer(invocation -> getMockBitmap( doAnswer(invocation -> getMockBitmap(
invocation.getArgument(1), invocation.getArgument(1),
invocation.getArgument(2))) invocation.getArgument(2)))
.when(spyWallpaperColorExtractor) .when(spyColorExtractor)
.createMiniBitmap(any(Bitmap.class), anyInt(), anyInt()); .createMiniBitmap(any(Bitmap.class), anyInt(), anyInt());
doReturn(new WallpaperColors(Color.valueOf(0), Color.valueOf(0), Color.valueOf(0))) doReturn(new WallpaperColors(Color.valueOf(0), Color.valueOf(0), Color.valueOf(0)))
.when(spyWallpaperColorExtractor).getLocalWallpaperColors(any(Rect.class)); .when(spyColorExtractor).getLocalWallpaperColors(any(Rect.class));
return spyWallpaperColorExtractor; return spyColorExtractor;
} }
private RectF randomArea() { private RectF randomArea() {
@@ -180,18 +180,18 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
*/ */
@Test @Test
public void testMiniBitmapCreation() { public void testMiniBitmapCreation() {
WallpaperColorExtractor spyWallpaperColorExtractor = getSpyWallpaperColorExtractor(); WallpaperLocalColorExtractor spyColorExtractor = getSpyWallpaperLocalColorExtractor();
int nSimulations = 10; int nSimulations = 10;
for (int i = 0; i < nSimulations; i++) { for (int i = 0; i < nSimulations; i++) {
resetCounters(); resetCounters();
int width = randomBetween(LOW_BMP_WIDTH, HIGH_BMP_WIDTH); int width = randomBetween(LOW_BMP_WIDTH, HIGH_BMP_WIDTH);
int height = randomBetween(LOW_BMP_HEIGHT, HIGH_BMP_HEIGHT); int height = randomBetween(LOW_BMP_HEIGHT, HIGH_BMP_HEIGHT);
Bitmap bitmap = getMockBitmap(width, height); Bitmap bitmap = getMockBitmap(width, height);
spyWallpaperColorExtractor.onBitmapChanged(bitmap); spyColorExtractor.onBitmapChanged(bitmap);
assertThat(mMiniBitmapUpdatedCount).isEqualTo(1); assertThat(mMiniBitmapUpdatedCount).isEqualTo(1);
assertThat(Math.min(mMiniBitmapWidth, mMiniBitmapHeight)) assertThat(Math.min(mMiniBitmapWidth, mMiniBitmapHeight))
.isAtMost(WallpaperColorExtractor.SMALL_SIDE); .isAtMost(WallpaperLocalColorExtractor.SMALL_SIDE);
} }
} }
@@ -201,18 +201,18 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
*/ */
@Test @Test
public void testSmallMiniBitmapCreation() { public void testSmallMiniBitmapCreation() {
WallpaperColorExtractor spyWallpaperColorExtractor = getSpyWallpaperColorExtractor(); WallpaperLocalColorExtractor spyColorExtractor = getSpyWallpaperLocalColorExtractor();
int nSimulations = 10; int nSimulations = 10;
for (int i = 0; i < nSimulations; i++) { for (int i = 0; i < nSimulations; i++) {
resetCounters(); resetCounters();
int width = randomBetween(VERY_LOW_BMP_WIDTH, LOW_BMP_WIDTH); int width = randomBetween(VERY_LOW_BMP_WIDTH, LOW_BMP_WIDTH);
int height = randomBetween(VERY_LOW_BMP_HEIGHT, LOW_BMP_HEIGHT); int height = randomBetween(VERY_LOW_BMP_HEIGHT, LOW_BMP_HEIGHT);
Bitmap bitmap = getMockBitmap(width, height); Bitmap bitmap = getMockBitmap(width, height);
spyWallpaperColorExtractor.onBitmapChanged(bitmap); spyColorExtractor.onBitmapChanged(bitmap);
assertThat(mMiniBitmapUpdatedCount).isEqualTo(1); assertThat(mMiniBitmapUpdatedCount).isEqualTo(1);
assertThat(Math.max(mMiniBitmapWidth, mMiniBitmapHeight)) assertThat(Math.max(mMiniBitmapWidth, mMiniBitmapHeight))
.isAtMost(WallpaperColorExtractor.SMALL_SIDE); .isAtMost(WallpaperLocalColorExtractor.SMALL_SIDE);
} }
} }
@@ -228,15 +228,15 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
int nSimulations = 10; int nSimulations = 10;
for (int i = 0; i < nSimulations; i++) { for (int i = 0; i < nSimulations; i++) {
resetCounters(); resetCounters();
WallpaperColorExtractor spyWallpaperColorExtractor = getSpyWallpaperColorExtractor(); WallpaperLocalColorExtractor spyColorExtractor = getSpyWallpaperLocalColorExtractor();
List<RectF> regions = listOfRandomAreas(MIN_AREAS, MAX_AREAS); List<RectF> regions = listOfRandomAreas(MIN_AREAS, MAX_AREAS);
int nPages = randomBetween(PAGES_LOW, PAGES_HIGH); int nPages = randomBetween(PAGES_LOW, PAGES_HIGH);
List<Runnable> tasks = Arrays.asList( List<Runnable> tasks = Arrays.asList(
() -> spyWallpaperColorExtractor.onPageChanged(nPages), () -> spyColorExtractor.onPageChanged(nPages),
() -> spyWallpaperColorExtractor.onBitmapChanged(bitmap), () -> spyColorExtractor.onBitmapChanged(bitmap),
() -> spyWallpaperColorExtractor.setDisplayDimensions( () -> spyColorExtractor.setDisplayDimensions(
DISPLAY_WIDTH, DISPLAY_HEIGHT), DISPLAY_WIDTH, DISPLAY_HEIGHT),
() -> spyWallpaperColorExtractor.addLocalColorsAreas( () -> spyColorExtractor.addLocalColorsAreas(
regions)); regions));
Collections.shuffle(tasks); Collections.shuffle(tasks);
tasks.forEach(Runnable::run); tasks.forEach(Runnable::run);
@@ -245,7 +245,7 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
assertThat(mMiniBitmapUpdatedCount).isEqualTo(1); assertThat(mMiniBitmapUpdatedCount).isEqualTo(1);
assertThat(mColorsProcessed).isEqualTo(regions.size()); assertThat(mColorsProcessed).isEqualTo(regions.size());
spyWallpaperColorExtractor.removeLocalColorAreas(regions); spyColorExtractor.removeLocalColorAreas(regions);
assertThat(mDeactivatedCount).isEqualTo(1); assertThat(mDeactivatedCount).isEqualTo(1);
} }
} }
@@ -260,7 +260,7 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
int nSimulations = 10; int nSimulations = 10;
for (int i = 0; i < nSimulations; i++) { for (int i = 0; i < nSimulations; i++) {
resetCounters(); resetCounters();
WallpaperColorExtractor spyWallpaperColorExtractor = getSpyWallpaperColorExtractor(); WallpaperLocalColorExtractor spyColorExtractor = getSpyWallpaperLocalColorExtractor();
List<RectF> regions1 = listOfRandomAreas(MIN_AREAS / 2, MAX_AREAS / 2); List<RectF> regions1 = listOfRandomAreas(MIN_AREAS / 2, MAX_AREAS / 2);
List<RectF> regions2 = listOfRandomAreas(MIN_AREAS / 2, MAX_AREAS / 2); List<RectF> regions2 = listOfRandomAreas(MIN_AREAS / 2, MAX_AREAS / 2);
List<RectF> regions = new ArrayList<>(); List<RectF> regions = new ArrayList<>();
@@ -268,20 +268,20 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
regions.addAll(regions2); regions.addAll(regions2);
int nPages = randomBetween(PAGES_LOW, PAGES_HIGH); int nPages = randomBetween(PAGES_LOW, PAGES_HIGH);
List<Runnable> tasks = Arrays.asList( List<Runnable> tasks = Arrays.asList(
() -> spyWallpaperColorExtractor.onPageChanged(nPages), () -> spyColorExtractor.onPageChanged(nPages),
() -> spyWallpaperColorExtractor.onBitmapChanged(bitmap), () -> spyColorExtractor.onBitmapChanged(bitmap),
() -> spyWallpaperColorExtractor.setDisplayDimensions( () -> spyColorExtractor.setDisplayDimensions(
DISPLAY_WIDTH, DISPLAY_HEIGHT), DISPLAY_WIDTH, DISPLAY_HEIGHT),
() -> spyWallpaperColorExtractor.removeLocalColorAreas(regions1)); () -> spyColorExtractor.removeLocalColorAreas(regions1));
spyWallpaperColorExtractor.addLocalColorsAreas(regions); spyColorExtractor.addLocalColorsAreas(regions);
assertThat(mActivatedCount).isEqualTo(1); assertThat(mActivatedCount).isEqualTo(1);
Collections.shuffle(tasks); Collections.shuffle(tasks);
tasks.forEach(Runnable::run); tasks.forEach(Runnable::run);
assertThat(mMiniBitmapUpdatedCount).isEqualTo(1); assertThat(mMiniBitmapUpdatedCount).isEqualTo(1);
assertThat(mDeactivatedCount).isEqualTo(0); assertThat(mDeactivatedCount).isEqualTo(0);
spyWallpaperColorExtractor.removeLocalColorAreas(regions2); spyColorExtractor.removeLocalColorAreas(regions2);
assertThat(mDeactivatedCount).isEqualTo(1); assertThat(mDeactivatedCount).isEqualTo(1);
} }
} }
@@ -295,18 +295,18 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
@Test @Test
public void testRecomputeColorExtraction() { public void testRecomputeColorExtraction() {
Bitmap bitmap = getMockBitmap(HIGH_BMP_WIDTH, HIGH_BMP_HEIGHT); Bitmap bitmap = getMockBitmap(HIGH_BMP_WIDTH, HIGH_BMP_HEIGHT);
WallpaperColorExtractor spyWallpaperColorExtractor = getSpyWallpaperColorExtractor(); WallpaperLocalColorExtractor spyColorExtractor = getSpyWallpaperLocalColorExtractor();
List<RectF> regions1 = listOfRandomAreas(MIN_AREAS / 2, MAX_AREAS / 2); List<RectF> regions1 = listOfRandomAreas(MIN_AREAS / 2, MAX_AREAS / 2);
List<RectF> regions2 = listOfRandomAreas(MIN_AREAS / 2, MAX_AREAS / 2); List<RectF> regions2 = listOfRandomAreas(MIN_AREAS / 2, MAX_AREAS / 2);
List<RectF> regions = new ArrayList<>(); List<RectF> regions = new ArrayList<>();
regions.addAll(regions1); regions.addAll(regions1);
regions.addAll(regions2); regions.addAll(regions2);
spyWallpaperColorExtractor.addLocalColorsAreas(regions); spyColorExtractor.addLocalColorsAreas(regions);
assertThat(mActivatedCount).isEqualTo(1); assertThat(mActivatedCount).isEqualTo(1);
int nPages = PAGES_LOW; int nPages = PAGES_LOW;
spyWallpaperColorExtractor.onBitmapChanged(bitmap); spyColorExtractor.onBitmapChanged(bitmap);
spyWallpaperColorExtractor.onPageChanged(nPages); spyColorExtractor.onPageChanged(nPages);
spyWallpaperColorExtractor.setDisplayDimensions(DISPLAY_WIDTH, DISPLAY_HEIGHT); spyColorExtractor.setDisplayDimensions(DISPLAY_WIDTH, DISPLAY_HEIGHT);
int nSimulations = 20; int nSimulations = 20;
for (int i = 0; i < nSimulations; i++) { for (int i = 0; i < nSimulations; i++) {
@@ -315,22 +315,22 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
// verify that if we remove some regions, they are not recomputed after other changes // verify that if we remove some regions, they are not recomputed after other changes
if (i == nSimulations / 2) { if (i == nSimulations / 2) {
regions.removeAll(regions2); regions.removeAll(regions2);
spyWallpaperColorExtractor.removeLocalColorAreas(regions2); spyColorExtractor.removeLocalColorAreas(regions2);
} }
if (Math.random() >= 0.5) { if (Math.random() >= 0.5) {
int nPagesNew = randomBetween(PAGES_LOW, PAGES_HIGH); int nPagesNew = randomBetween(PAGES_LOW, PAGES_HIGH);
if (nPagesNew == nPages) continue; if (nPagesNew == nPages) continue;
nPages = nPagesNew; nPages = nPagesNew;
spyWallpaperColorExtractor.onPageChanged(nPagesNew); spyColorExtractor.onPageChanged(nPagesNew);
} else { } else {
Bitmap newBitmap = getMockBitmap(HIGH_BMP_WIDTH, HIGH_BMP_HEIGHT); Bitmap newBitmap = getMockBitmap(HIGH_BMP_WIDTH, HIGH_BMP_HEIGHT);
spyWallpaperColorExtractor.onBitmapChanged(newBitmap); spyColorExtractor.onBitmapChanged(newBitmap);
assertThat(mMiniBitmapUpdatedCount).isEqualTo(1); assertThat(mMiniBitmapUpdatedCount).isEqualTo(1);
} }
assertThat(mColorsProcessed).isEqualTo(regions.size()); assertThat(mColorsProcessed).isEqualTo(regions.size());
} }
spyWallpaperColorExtractor.removeLocalColorAreas(regions); spyColorExtractor.removeLocalColorAreas(regions);
assertThat(mDeactivatedCount).isEqualTo(1); assertThat(mDeactivatedCount).isEqualTo(1);
} }
@@ -339,12 +339,12 @@ public class WallpaperColorExtractorTest extends SysuiTestCase {
resetCounters(); resetCounters();
Bitmap bitmap = getMockBitmap(HIGH_BMP_WIDTH, HIGH_BMP_HEIGHT); Bitmap bitmap = getMockBitmap(HIGH_BMP_WIDTH, HIGH_BMP_HEIGHT);
doNothing().when(bitmap).recycle(); doNothing().when(bitmap).recycle();
WallpaperColorExtractor spyWallpaperColorExtractor = getSpyWallpaperColorExtractor(); WallpaperLocalColorExtractor spyColorExtractor = getSpyWallpaperLocalColorExtractor();
spyWallpaperColorExtractor.onPageChanged(PAGES_LOW); spyColorExtractor.onPageChanged(PAGES_LOW);
spyWallpaperColorExtractor.onBitmapChanged(bitmap); spyColorExtractor.onBitmapChanged(bitmap);
assertThat(mMiniBitmapUpdatedCount).isEqualTo(1); assertThat(mMiniBitmapUpdatedCount).isEqualTo(1);
spyWallpaperColorExtractor.cleanUp(); spyColorExtractor.cleanUp();
spyWallpaperColorExtractor.addLocalColorsAreas(listOfRandomAreas(MIN_AREAS, MAX_AREAS)); spyColorExtractor.addLocalColorsAreas(listOfRandomAreas(MIN_AREAS, MAX_AREAS));
assertThat(mColorsProcessed).isEqualTo(0); assertThat(mColorsProcessed).isEqualTo(0);
} }
} }