Loading core/java/com/android/internal/util/ScreenshotHelper.java +6 −5 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.os.Message; Loading Loading @@ -58,7 +59,7 @@ public class ScreenshotHelper { */ public void takeScreenshot(final int screenshotType, final boolean hasStatus, final boolean hasNav, @NonNull Handler handler, @Nullable Consumer<Boolean> completionConsumer) { @Nullable Consumer<Uri> completionConsumer) { takeScreenshot(screenshotType, hasStatus, hasNav, SCREENSHOT_TIMEOUT_MS, handler, completionConsumer); } Loading Loading @@ -88,7 +89,7 @@ public class ScreenshotHelper { */ public void takeScreenshot(final int screenshotType, final boolean hasStatus, final boolean hasNav, long timeoutMs, @NonNull Handler handler, @Nullable Consumer<Boolean> completionConsumer) { @Nullable Consumer<Uri> completionConsumer) { synchronized (mScreenshotLock) { if (mScreenshotConnection != null) { return; Loading @@ -108,7 +109,7 @@ public class ScreenshotHelper { } } if (completionConsumer != null) { completionConsumer.accept(false); completionConsumer.accept(null); } } }; Loading @@ -135,7 +136,7 @@ public class ScreenshotHelper { } } if (completionConsumer != null) { completionConsumer.accept(true); completionConsumer.accept((Uri) msg.obj); } } }; Loading @@ -148,7 +149,7 @@ public class ScreenshotHelper { } catch (RemoteException e) { Log.e(TAG, "Couldn't take screenshot: " + e); if (completionConsumer != null) { completionConsumer.accept(false); completionConsumer.accept(null); } } } Loading core/tests/screenshothelpertests/src/com/android/internal/util/ScreenshotHelperTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package com.android.internal.util; import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN; import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.fail; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -80,8 +80,8 @@ public final class ScreenshotHelperTest { CountDownLatch lock = new CountDownLatch(1); mScreenshotHelper.takeScreenshot(TAKE_SCREENSHOT_FULLSCREEN, false, false, timeoutMs, mHandler, worked -> { assertFalse(worked); uri -> { assertNull(uri); lock.countDown(); }); Loading packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +11 −10 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Consumer; import java.util.function.Function; import javax.inject.Inject; Loading @@ -107,7 +108,7 @@ public class GlobalScreenshot { public Context context; public Bitmap image; public Uri imageUri; public Runnable finisher; public Consumer<Uri> finisher; public Function<PendingIntent, Void> onEditReady; public int iconSize; public int previewWidth; Loading Loading @@ -260,7 +261,7 @@ public class GlobalScreenshot { * Creates a new worker thread and saves the screenshot to the media store. */ private void saveScreenshotInWorkerThread( Runnable finisher, @Nullable Function<PendingIntent, Void> onEditReady) { Consumer<Uri> finisher, @Nullable Function<PendingIntent, Void> onEditReady) { SaveImageInBackgroundData data = new SaveImageInBackgroundData(); data.context = mContext; data.image = mScreenBitmap; Loading @@ -276,15 +277,15 @@ public class GlobalScreenshot { .execute(); } private void saveScreenshotInWorkerThread(Runnable finisher) { private void saveScreenshotInWorkerThread(Consumer<Uri> finisher) { saveScreenshotInWorkerThread(finisher, null); } /** * Takes a screenshot of the current display and shows an animation. */ private void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, Rect crop) { private void takeScreenshot(Consumer<Uri> finisher, boolean statusBarVisible, boolean navBarVisible, Rect crop) { int rot = mDisplay.getRotation(); int width = crop.width(); int height = crop.height(); Loading @@ -294,7 +295,7 @@ public class GlobalScreenshot { if (mScreenBitmap == null) { notifyScreenshotError(mContext, mNotificationManager, R.string.screenshot_failed_to_capture_text); finisher.run(); finisher.accept(null); return; } Loading @@ -307,7 +308,7 @@ public class GlobalScreenshot { statusBarVisible, navBarVisible); } void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) { void takeScreenshot(Consumer<Uri> finisher, boolean statusBarVisible, boolean navBarVisible) { mDisplay.getRealMetrics(mDisplayMetrics); takeScreenshot(finisher, statusBarVisible, navBarVisible, new Rect(0, 0, mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels)); Loading @@ -316,7 +317,7 @@ public class GlobalScreenshot { /** * Displays a screenshot selector */ void takeScreenshotPartial(final Runnable finisher, final boolean statusBarVisible, void takeScreenshotPartial(final Consumer<Uri> finisher, final boolean statusBarVisible, final boolean navBarVisible) { mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams); mScreenshotSelectorView.setOnTouchListener(new View.OnTouchListener() { Loading Loading @@ -392,8 +393,8 @@ public class GlobalScreenshot { /** * Starts the animation after taking the screenshot */ private void startAnimation(final Runnable finisher, int w, int h, boolean statusBarVisible, boolean navBarVisible) { private void startAnimation(final Consumer<Uri> finisher, int w, int h, boolean statusBarVisible, boolean navBarVisible) { // If power save is on, show a toast so there is some visual indication that a screenshot // has been taken. PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); Loading packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java +2 −2 Original line number Diff line number Diff line Loading @@ -453,7 +453,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { mNotificationBuilder.build()); } } mParams.finisher.run(); mParams.finisher.accept(mParams.imageUri); mParams.clearContext(); } Loading @@ -462,7 +462,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { // If we are cancelled while the task is running in the background, we may get null // params. The finisher is expected to always be called back, so just use the baked-in // params from the ctor in any case. mParams.finisher.run(); mParams.finisher.accept(null); mParams.clearImage(); mParams.clearContext(); Loading packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java +7 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.screenshot; import android.app.Service; import android.content.Intent; import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.os.Message; Loading @@ -27,6 +28,8 @@ import android.os.UserManager; import android.util.Log; import android.view.WindowManager; import java.util.function.Consumer; import javax.inject.Inject; public class TakeScreenshotService extends Service { Loading @@ -39,10 +42,10 @@ public class TakeScreenshotService extends Service { @Override public void handleMessage(Message msg) { final Messenger callback = msg.replyTo; Runnable finisher = new Runnable() { Consumer<Uri> finisher = new Consumer<Uri>() { @Override public void run() { Message reply = Message.obtain(null, 1); public void accept(Uri uri) { Message reply = Message.obtain(null, 1, uri); try { callback.send(reply); } catch (RemoteException e) { Loading @@ -55,7 +58,7 @@ public class TakeScreenshotService extends Service { // animation and error notification. if (!mUserManager.isUserUnlocked()) { Log.w(TAG, "Skipping screenshot because storage is locked!"); post(finisher); post(() -> finisher.accept(null)); return; } Loading Loading
core/java/com/android/internal/util/ScreenshotHelper.java +6 −5 Original line number Diff line number Diff line Loading @@ -6,6 +6,7 @@ import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.os.Message; Loading Loading @@ -58,7 +59,7 @@ public class ScreenshotHelper { */ public void takeScreenshot(final int screenshotType, final boolean hasStatus, final boolean hasNav, @NonNull Handler handler, @Nullable Consumer<Boolean> completionConsumer) { @Nullable Consumer<Uri> completionConsumer) { takeScreenshot(screenshotType, hasStatus, hasNav, SCREENSHOT_TIMEOUT_MS, handler, completionConsumer); } Loading Loading @@ -88,7 +89,7 @@ public class ScreenshotHelper { */ public void takeScreenshot(final int screenshotType, final boolean hasStatus, final boolean hasNav, long timeoutMs, @NonNull Handler handler, @Nullable Consumer<Boolean> completionConsumer) { @Nullable Consumer<Uri> completionConsumer) { synchronized (mScreenshotLock) { if (mScreenshotConnection != null) { return; Loading @@ -108,7 +109,7 @@ public class ScreenshotHelper { } } if (completionConsumer != null) { completionConsumer.accept(false); completionConsumer.accept(null); } } }; Loading @@ -135,7 +136,7 @@ public class ScreenshotHelper { } } if (completionConsumer != null) { completionConsumer.accept(true); completionConsumer.accept((Uri) msg.obj); } } }; Loading @@ -148,7 +149,7 @@ public class ScreenshotHelper { } catch (RemoteException e) { Log.e(TAG, "Couldn't take screenshot: " + e); if (completionConsumer != null) { completionConsumer.accept(false); completionConsumer.accept(null); } } } Loading
core/tests/screenshothelpertests/src/com/android/internal/util/ScreenshotHelperTest.java +3 −3 Original line number Diff line number Diff line Loading @@ -19,7 +19,7 @@ package com.android.internal.util; import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN; import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION; import static junit.framework.Assert.assertFalse; import static junit.framework.Assert.assertNull; import static junit.framework.Assert.fail; import static org.mockito.ArgumentMatchers.any; Loading Loading @@ -80,8 +80,8 @@ public final class ScreenshotHelperTest { CountDownLatch lock = new CountDownLatch(1); mScreenshotHelper.takeScreenshot(TAKE_SCREENSHOT_FULLSCREEN, false, false, timeoutMs, mHandler, worked -> { assertFalse(worked); uri -> { assertNull(uri); lock.countDown(); }); Loading
packages/SystemUI/src/com/android/systemui/screenshot/GlobalScreenshot.java +11 −10 Original line number Diff line number Diff line Loading @@ -87,6 +87,7 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.function.Consumer; import java.util.function.Function; import javax.inject.Inject; Loading @@ -107,7 +108,7 @@ public class GlobalScreenshot { public Context context; public Bitmap image; public Uri imageUri; public Runnable finisher; public Consumer<Uri> finisher; public Function<PendingIntent, Void> onEditReady; public int iconSize; public int previewWidth; Loading Loading @@ -260,7 +261,7 @@ public class GlobalScreenshot { * Creates a new worker thread and saves the screenshot to the media store. */ private void saveScreenshotInWorkerThread( Runnable finisher, @Nullable Function<PendingIntent, Void> onEditReady) { Consumer<Uri> finisher, @Nullable Function<PendingIntent, Void> onEditReady) { SaveImageInBackgroundData data = new SaveImageInBackgroundData(); data.context = mContext; data.image = mScreenBitmap; Loading @@ -276,15 +277,15 @@ public class GlobalScreenshot { .execute(); } private void saveScreenshotInWorkerThread(Runnable finisher) { private void saveScreenshotInWorkerThread(Consumer<Uri> finisher) { saveScreenshotInWorkerThread(finisher, null); } /** * Takes a screenshot of the current display and shows an animation. */ private void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible, Rect crop) { private void takeScreenshot(Consumer<Uri> finisher, boolean statusBarVisible, boolean navBarVisible, Rect crop) { int rot = mDisplay.getRotation(); int width = crop.width(); int height = crop.height(); Loading @@ -294,7 +295,7 @@ public class GlobalScreenshot { if (mScreenBitmap == null) { notifyScreenshotError(mContext, mNotificationManager, R.string.screenshot_failed_to_capture_text); finisher.run(); finisher.accept(null); return; } Loading @@ -307,7 +308,7 @@ public class GlobalScreenshot { statusBarVisible, navBarVisible); } void takeScreenshot(Runnable finisher, boolean statusBarVisible, boolean navBarVisible) { void takeScreenshot(Consumer<Uri> finisher, boolean statusBarVisible, boolean navBarVisible) { mDisplay.getRealMetrics(mDisplayMetrics); takeScreenshot(finisher, statusBarVisible, navBarVisible, new Rect(0, 0, mDisplayMetrics.widthPixels, mDisplayMetrics.heightPixels)); Loading @@ -316,7 +317,7 @@ public class GlobalScreenshot { /** * Displays a screenshot selector */ void takeScreenshotPartial(final Runnable finisher, final boolean statusBarVisible, void takeScreenshotPartial(final Consumer<Uri> finisher, final boolean statusBarVisible, final boolean navBarVisible) { mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams); mScreenshotSelectorView.setOnTouchListener(new View.OnTouchListener() { Loading Loading @@ -392,8 +393,8 @@ public class GlobalScreenshot { /** * Starts the animation after taking the screenshot */ private void startAnimation(final Runnable finisher, int w, int h, boolean statusBarVisible, boolean navBarVisible) { private void startAnimation(final Consumer<Uri> finisher, int w, int h, boolean statusBarVisible, boolean navBarVisible) { // If power save is on, show a toast so there is some visual indication that a screenshot // has been taken. PowerManager powerManager = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); Loading
packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java +2 −2 Original line number Diff line number Diff line Loading @@ -453,7 +453,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { mNotificationBuilder.build()); } } mParams.finisher.run(); mParams.finisher.accept(mParams.imageUri); mParams.clearContext(); } Loading @@ -462,7 +462,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> { // If we are cancelled while the task is running in the background, we may get null // params. The finisher is expected to always be called back, so just use the baked-in // params from the ctor in any case. mParams.finisher.run(); mParams.finisher.accept(null); mParams.clearImage(); mParams.clearContext(); Loading
packages/SystemUI/src/com/android/systemui/screenshot/TakeScreenshotService.java +7 −4 Original line number Diff line number Diff line Loading @@ -18,6 +18,7 @@ package com.android.systemui.screenshot; import android.app.Service; import android.content.Intent; import android.net.Uri; import android.os.Handler; import android.os.IBinder; import android.os.Message; Loading @@ -27,6 +28,8 @@ import android.os.UserManager; import android.util.Log; import android.view.WindowManager; import java.util.function.Consumer; import javax.inject.Inject; public class TakeScreenshotService extends Service { Loading @@ -39,10 +42,10 @@ public class TakeScreenshotService extends Service { @Override public void handleMessage(Message msg) { final Messenger callback = msg.replyTo; Runnable finisher = new Runnable() { Consumer<Uri> finisher = new Consumer<Uri>() { @Override public void run() { Message reply = Message.obtain(null, 1); public void accept(Uri uri) { Message reply = Message.obtain(null, 1, uri); try { callback.send(reply); } catch (RemoteException e) { Loading @@ -55,7 +58,7 @@ public class TakeScreenshotService extends Service { // animation and error notification. if (!mUserManager.isUserUnlocked()) { Log.w(TAG, "Skipping screenshot because storage is locked!"); post(finisher); post(() -> finisher.accept(null)); return; } Loading