Merge "Move ImageWallpaper tasks to its own thread" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1467c855e2
@@ -114,6 +114,17 @@ public abstract class SysUIConcurrencyModule {
|
|||||||
return new ExecutorImpl(looper);
|
return new ExecutorImpl(looper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide a Long running Executor.
|
||||||
|
*/
|
||||||
|
@Provides
|
||||||
|
@SysUISingleton
|
||||||
|
@LongRunning
|
||||||
|
public static DelayableExecutor provideLongRunningDelayableExecutor(
|
||||||
|
@LongRunning Looper looper) {
|
||||||
|
return new ExecutorImpl(looper);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provide a Background-Thread Executor.
|
* Provide a Background-Thread Executor.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ import android.view.WindowManager;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
import com.android.internal.annotations.VisibleForTesting;
|
import com.android.internal.annotations.VisibleForTesting;
|
||||||
import com.android.systemui.dagger.qualifiers.Background;
|
import com.android.systemui.dagger.qualifiers.LongRunning;
|
||||||
import com.android.systemui.settings.UserTracker;
|
import com.android.systemui.settings.UserTracker;
|
||||||
import com.android.systemui.util.concurrency.DelayableExecutor;
|
import com.android.systemui.util.concurrency.DelayableExecutor;
|
||||||
|
|
||||||
@@ -61,17 +61,16 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
private final UserTracker mUserTracker;
|
private final UserTracker mUserTracker;
|
||||||
|
|
||||||
// used for most tasks (call canvas.drawBitmap, load/unload the bitmap)
|
// used for most tasks (call canvas.drawBitmap, load/unload the bitmap)
|
||||||
@Background
|
@LongRunning
|
||||||
private final DelayableExecutor mBackgroundExecutor;
|
private final DelayableExecutor mLongExecutor;
|
||||||
|
|
||||||
// wait at least this duration before unloading the bitmap
|
// wait at least this duration before unloading the bitmap
|
||||||
private static final int DELAY_UNLOAD_BITMAP = 2000;
|
private static final int DELAY_UNLOAD_BITMAP = 2000;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
public ImageWallpaper(@Background DelayableExecutor backgroundExecutor,
|
public ImageWallpaper(@LongRunning DelayableExecutor longExecutor, UserTracker userTracker) {
|
||||||
UserTracker userTracker) {
|
|
||||||
super();
|
super();
|
||||||
mBackgroundExecutor = backgroundExecutor;
|
mLongExecutor = longExecutor;
|
||||||
mUserTracker = userTracker;
|
mUserTracker = userTracker;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,7 +104,7 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
setFixedSizeAllowed(true);
|
setFixedSizeAllowed(true);
|
||||||
setShowForAllUsers(true);
|
setShowForAllUsers(true);
|
||||||
mWallpaperLocalColorExtractor = new WallpaperLocalColorExtractor(
|
mWallpaperLocalColorExtractor = new WallpaperLocalColorExtractor(
|
||||||
mBackgroundExecutor,
|
mLongExecutor,
|
||||||
new WallpaperLocalColorExtractor.WallpaperLocalColorExtractorCallback() {
|
new WallpaperLocalColorExtractor.WallpaperLocalColorExtractorCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onColorsProcessed(List<RectF> regions,
|
public void onColorsProcessed(List<RectF> regions,
|
||||||
@@ -202,7 +201,7 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void drawFrame() {
|
private void drawFrame() {
|
||||||
mBackgroundExecutor.execute(this::drawFrameSynchronized);
|
mLongExecutor.execute(this::drawFrameSynchronized);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawFrameSynchronized() {
|
private void drawFrameSynchronized() {
|
||||||
@@ -257,7 +256,7 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void unloadBitmapIfNotUsed() {
|
private void unloadBitmapIfNotUsed() {
|
||||||
mBackgroundExecutor.execute(this::unloadBitmapIfNotUsedSynchronized);
|
mLongExecutor.execute(this::unloadBitmapIfNotUsedSynchronized);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void unloadBitmapIfNotUsedSynchronized() {
|
private void unloadBitmapIfNotUsedSynchronized() {
|
||||||
@@ -341,7 +340,7 @@ public class ImageWallpaper extends WallpaperService {
|
|||||||
* - the mini bitmap from color extractor is recomputed
|
* - the mini bitmap from color extractor is recomputed
|
||||||
* - the DELAY_UNLOAD_BITMAP has passed
|
* - the DELAY_UNLOAD_BITMAP has passed
|
||||||
*/
|
*/
|
||||||
mBackgroundExecutor.executeDelayed(
|
mLongExecutor.executeDelayed(
|
||||||
this::unloadBitmapIfNotUsedSynchronized, DELAY_UNLOAD_BITMAP);
|
this::unloadBitmapIfNotUsedSynchronized, DELAY_UNLOAD_BITMAP);
|
||||||
}
|
}
|
||||||
// even if the bitmap cannot be loaded, call reportEngineShown
|
// even if the bitmap cannot be loaded, call reportEngineShown
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import android.util.MathUtils;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.VisibleForTesting;
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
import com.android.systemui.dagger.qualifiers.Background;
|
import com.android.systemui.dagger.qualifiers.LongRunning;
|
||||||
import com.android.systemui.util.Assert;
|
import com.android.systemui.util.Assert;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
@@ -66,8 +66,8 @@ public class WallpaperLocalColorExtractor {
|
|||||||
private final List<RectF> mPendingRegions = new ArrayList<>();
|
private final List<RectF> mPendingRegions = new ArrayList<>();
|
||||||
private final Set<RectF> mProcessedRegions = new ArraySet<>();
|
private final Set<RectF> mProcessedRegions = new ArraySet<>();
|
||||||
|
|
||||||
@Background
|
@LongRunning
|
||||||
private final Executor mBackgroundExecutor;
|
private final Executor mLongExecutor;
|
||||||
|
|
||||||
private final WallpaperLocalColorExtractorCallback mWallpaperLocalColorExtractorCallback;
|
private final WallpaperLocalColorExtractorCallback mWallpaperLocalColorExtractorCallback;
|
||||||
|
|
||||||
@@ -101,13 +101,13 @@ public class WallpaperLocalColorExtractor {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new color extractor.
|
* Creates a new color extractor.
|
||||||
* @param backgroundExecutor the executor on which the color extraction will be performed
|
* @param longExecutor the executor on which the color extraction will be performed
|
||||||
* @param wallpaperLocalColorExtractorCallback an interface to handle the callbacks from
|
* @param wallpaperLocalColorExtractorCallback an interface to handle the callbacks from
|
||||||
* the color extractor.
|
* the color extractor.
|
||||||
*/
|
*/
|
||||||
public WallpaperLocalColorExtractor(@Background Executor backgroundExecutor,
|
public WallpaperLocalColorExtractor(@LongRunning Executor longExecutor,
|
||||||
WallpaperLocalColorExtractorCallback wallpaperLocalColorExtractorCallback) {
|
WallpaperLocalColorExtractorCallback wallpaperLocalColorExtractorCallback) {
|
||||||
mBackgroundExecutor = backgroundExecutor;
|
mLongExecutor = longExecutor;
|
||||||
mWallpaperLocalColorExtractorCallback = wallpaperLocalColorExtractorCallback;
|
mWallpaperLocalColorExtractorCallback = wallpaperLocalColorExtractorCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ public class WallpaperLocalColorExtractor {
|
|||||||
* not recomputed.
|
* not recomputed.
|
||||||
*/
|
*/
|
||||||
public void setDisplayDimensions(int displayWidth, int displayHeight) {
|
public void setDisplayDimensions(int displayWidth, int displayHeight) {
|
||||||
mBackgroundExecutor.execute(() ->
|
mLongExecutor.execute(() ->
|
||||||
setDisplayDimensionsSynchronized(displayWidth, displayHeight));
|
setDisplayDimensionsSynchronized(displayWidth, displayHeight));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -144,7 +144,7 @@ public class WallpaperLocalColorExtractor {
|
|||||||
* @param bitmap the new wallpaper
|
* @param bitmap the new wallpaper
|
||||||
*/
|
*/
|
||||||
public void onBitmapChanged(@NonNull Bitmap bitmap) {
|
public void onBitmapChanged(@NonNull Bitmap bitmap) {
|
||||||
mBackgroundExecutor.execute(() -> onBitmapChangedSynchronized(bitmap));
|
mLongExecutor.execute(() -> onBitmapChangedSynchronized(bitmap));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onBitmapChangedSynchronized(@NonNull Bitmap bitmap) {
|
private void onBitmapChangedSynchronized(@NonNull Bitmap bitmap) {
|
||||||
@@ -167,7 +167,7 @@ public class WallpaperLocalColorExtractor {
|
|||||||
* @param pages the total number of pages of the launcher
|
* @param pages the total number of pages of the launcher
|
||||||
*/
|
*/
|
||||||
public void onPageChanged(int pages) {
|
public void onPageChanged(int pages) {
|
||||||
mBackgroundExecutor.execute(() -> onPageChangedSynchronized(pages));
|
mLongExecutor.execute(() -> onPageChangedSynchronized(pages));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onPageChangedSynchronized(int pages) {
|
private void onPageChangedSynchronized(int pages) {
|
||||||
@@ -194,7 +194,7 @@ public class WallpaperLocalColorExtractor {
|
|||||||
*/
|
*/
|
||||||
public void addLocalColorsAreas(@NonNull List<RectF> regions) {
|
public void addLocalColorsAreas(@NonNull List<RectF> regions) {
|
||||||
if (regions.size() > 0) {
|
if (regions.size() > 0) {
|
||||||
mBackgroundExecutor.execute(() -> addLocalColorsAreasSynchronized(regions));
|
mLongExecutor.execute(() -> addLocalColorsAreasSynchronized(regions));
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Attempt to add colors with an empty list");
|
Log.w(TAG, "Attempt to add colors with an empty list");
|
||||||
}
|
}
|
||||||
@@ -218,7 +218,7 @@ public class WallpaperLocalColorExtractor {
|
|||||||
* @param regions The areas of interest in our wallpaper (in screen pixel coordinates)
|
* @param regions The areas of interest in our wallpaper (in screen pixel coordinates)
|
||||||
*/
|
*/
|
||||||
public void removeLocalColorAreas(@NonNull List<RectF> regions) {
|
public void removeLocalColorAreas(@NonNull List<RectF> regions) {
|
||||||
mBackgroundExecutor.execute(() -> removeLocalColorAreasSynchronized(regions));
|
mLongExecutor.execute(() -> removeLocalColorAreasSynchronized(regions));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void removeLocalColorAreasSynchronized(@NonNull List<RectF> regions) {
|
private void removeLocalColorAreasSynchronized(@NonNull List<RectF> regions) {
|
||||||
@@ -236,7 +236,7 @@ public class WallpaperLocalColorExtractor {
|
|||||||
* Clean up the memory (in particular, the mini bitmap) used by this class.
|
* Clean up the memory (in particular, the mini bitmap) used by this class.
|
||||||
*/
|
*/
|
||||||
public void cleanUp() {
|
public void cleanUp() {
|
||||||
mBackgroundExecutor.execute(this::cleanUpSynchronized);
|
mLongExecutor.execute(this::cleanUpSynchronized);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cleanUpSynchronized() {
|
private void cleanUpSynchronized() {
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
|||||||
@Mock
|
@Mock
|
||||||
private Bitmap mWallpaperBitmap;
|
private Bitmap mWallpaperBitmap;
|
||||||
FakeSystemClock mFakeSystemClock = new FakeSystemClock();
|
FakeSystemClock mFakeSystemClock = new FakeSystemClock();
|
||||||
FakeExecutor mFakeBackgroundExecutor = new FakeExecutor(mFakeSystemClock);
|
FakeExecutor mFakeExecutor = new FakeExecutor(mFakeSystemClock);
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
@@ -125,7 +125,7 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBitmapWallpaper_normal() {
|
public void testBitmapWallpaper_normal() {
|
||||||
// Will use a image wallpaper with dimensions DISPLAY_WIDTH x DISPLAY_WIDTH.
|
// Will use an image wallpaper with dimensions DISPLAY_WIDTH x DISPLAY_WIDTH.
|
||||||
// Then we expect the surface size will be also DISPLAY_WIDTH x DISPLAY_WIDTH.
|
// Then we expect the surface size will be also DISPLAY_WIDTH x DISPLAY_WIDTH.
|
||||||
int bitmapSide = DISPLAY_WIDTH;
|
int bitmapSide = DISPLAY_WIDTH;
|
||||||
testSurfaceHelper(
|
testSurfaceHelper(
|
||||||
@@ -137,7 +137,7 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testBitmapWallpaper_low_resolution() {
|
public void testBitmapWallpaper_low_resolution() {
|
||||||
// Will use a image wallpaper with dimensions BMP_WIDTH x BMP_HEIGHT.
|
// Will use an image wallpaper with dimensions BMP_WIDTH x BMP_HEIGHT.
|
||||||
// Then we expect the surface size will be also BMP_WIDTH x BMP_HEIGHT.
|
// Then we expect the surface size will be also BMP_WIDTH x BMP_HEIGHT.
|
||||||
testSurfaceHelper(LOW_BMP_WIDTH /* bitmapWidth */,
|
testSurfaceHelper(LOW_BMP_WIDTH /* bitmapWidth */,
|
||||||
LOW_BMP_HEIGHT /* bitmapHeight */,
|
LOW_BMP_HEIGHT /* bitmapHeight */,
|
||||||
@@ -161,13 +161,13 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
|||||||
ImageWallpaper.CanvasEngine spyEngine = getSpyEngine();
|
ImageWallpaper.CanvasEngine spyEngine = getSpyEngine();
|
||||||
spyEngine.onCreate(mSurfaceHolder);
|
spyEngine.onCreate(mSurfaceHolder);
|
||||||
spyEngine.onSurfaceRedrawNeeded(mSurfaceHolder);
|
spyEngine.onSurfaceRedrawNeeded(mSurfaceHolder);
|
||||||
assertThat(mFakeBackgroundExecutor.numPending()).isAtLeast(1);
|
assertThat(mFakeExecutor.numPending()).isAtLeast(1);
|
||||||
|
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (mFakeBackgroundExecutor.numPending() >= 1) {
|
while (mFakeExecutor.numPending() >= 1) {
|
||||||
n++;
|
n++;
|
||||||
assertThat(n).isAtMost(10);
|
assertThat(n).isAtMost(10);
|
||||||
mFakeBackgroundExecutor.runNextReady();
|
mFakeExecutor.runNextReady();
|
||||||
mFakeSystemClock.advanceTime(1000);
|
mFakeSystemClock.advanceTime(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ public class ImageWallpaperTest extends SysuiTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ImageWallpaper createImageWallpaper() {
|
private ImageWallpaper createImageWallpaper() {
|
||||||
return new ImageWallpaper(mFakeBackgroundExecutor, mUserTracker) {
|
return new ImageWallpaper(mFakeExecutor, mUserTracker) {
|
||||||
@Override
|
@Override
|
||||||
public Engine onCreateEngine() {
|
public Engine onCreateEngine() {
|
||||||
return new CanvasEngine() {
|
return new CanvasEngine() {
|
||||||
|
|||||||
Reference in New Issue
Block a user