Merge "Move bitmapSupplier.get() call to a worker thread." into tm-qpr-dev
diff --git a/quickstep/src/com/android/quickstep/ImageActionsApi.java b/quickstep/src/com/android/quickstep/ImageActionsApi.java
index 154848d..2273806 100644
--- a/quickstep/src/com/android/quickstep/ImageActionsApi.java
+++ b/quickstep/src/com/android/quickstep/ImageActionsApi.java
@@ -78,16 +78,17 @@
addImageAndSendIntent(crop, intent, true, exceptionCallback);
}
- @UiThread
private void addImageAndSendIntent(@Nullable Rect crop, Intent intent, boolean setData,
@Nullable Runnable exceptionCallback) {
- if (mBitmapSupplier.get() == null) {
- Log.e(TAG, "No snapshot available, not starting share.");
- return;
- }
- UI_HELPER_EXECUTOR.execute(() -> persistBitmapAndStartActivity(mContext,
- mBitmapSupplier.get(), crop, intent, (uri, intentForUri) -> {
+ UI_HELPER_EXECUTOR.execute(() -> {
+ Bitmap bitmap = mBitmapSupplier.get();
+ if (bitmap == null) {
+ Log.e(TAG, "No snapshot available, not starting share.");
+ return;
+ }
+ persistBitmapAndStartActivity(mContext,
+ bitmap, crop, intent, (uri, intentForUri) -> {
intentForUri.addFlags(FLAG_GRANT_READ_URI_PERMISSION);
if (setData) {
intentForUri.setData(uri);
@@ -95,7 +96,8 @@
intentForUri.putExtra(EXTRA_STREAM, uri);
}
return new Intent[]{intentForUri};
- }, TAG, exceptionCallback));
+ }, TAG, exceptionCallback);
+ });
}
/**
diff --git a/quickstep/src/com/android/quickstep/util/ImageActionUtils.java b/quickstep/src/com/android/quickstep/util/ImageActionUtils.java
index 63d5b0d..9fe24de 100644
--- a/quickstep/src/com/android/quickstep/util/ImageActionUtils.java
+++ b/quickstep/src/com/android/quickstep/util/ImageActionUtils.java
@@ -43,7 +43,6 @@
import android.util.Log;
import android.view.View;
-import androidx.annotation.UiThread;
import androidx.annotation.WorkerThread;
import androidx.core.content.FileProvider;
@@ -86,67 +85,70 @@
* Launch the activity to share image for overview sharing. This is to share cropped bitmap
* with specific share targets (with shortcutInfo and appTarget) rendered in overview.
*/
- @UiThread
public static void shareImage(Context context, Supplier<Bitmap> bitmapSupplier, RectF rectF,
ShortcutInfo shortcutInfo, AppTarget appTarget, String tag) {
- if (bitmapSupplier.get() == null) {
- return;
- }
- Rect crop = new Rect();
- rectF.round(crop);
- Intent intent = new Intent();
- Uri uri = getImageUri(bitmapSupplier.get(), crop, context, tag);
- ClipData clipdata = new ClipData(new ClipDescription("content",
- new String[]{"image/png"}),
- new ClipData.Item(uri));
- intent.setAction(Intent.ACTION_SEND)
- .setComponent(new ComponentName(appTarget.getPackageName(), appTarget.getClassName()))
- .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
- .addFlags(FLAG_GRANT_READ_URI_PERMISSION)
- .setType("image/png")
- .putExtra(Intent.EXTRA_STREAM, uri)
- .putExtra(Intent.EXTRA_SHORTCUT_ID, shortcutInfo.getId())
- .setClipData(clipdata);
+ UI_HELPER_EXECUTOR.execute(() -> {
+ Bitmap bitmap = bitmapSupplier.get();
+ if (bitmap == null) {
+ return;
+ }
+ Rect crop = new Rect();
+ rectF.round(crop);
+ Intent intent = new Intent();
+ Uri uri = getImageUri(bitmap, crop, context, tag);
+ ClipData clipdata = new ClipData(new ClipDescription("content",
+ new String[]{"image/png"}),
+ new ClipData.Item(uri));
+ intent.setAction(Intent.ACTION_SEND)
+ .setComponent(
+ new ComponentName(appTarget.getPackageName(), appTarget.getClassName()))
+ .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+ .addFlags(FLAG_GRANT_READ_URI_PERMISSION)
+ .setType("image/png")
+ .putExtra(Intent.EXTRA_STREAM, uri)
+ .putExtra(Intent.EXTRA_SHORTCUT_ID, shortcutInfo.getId())
+ .setClipData(clipdata);
- if (context.getUserId() != appTarget.getUser().getIdentifier()) {
- intent.prepareToLeaveUser(context.getUserId());
- intent.fixUris(context.getUserId());
- context.startActivityAsUser(intent, appTarget.getUser());
- } else {
- context.startActivity(intent);
- }
+ if (context.getUserId() != appTarget.getUser().getIdentifier()) {
+ intent.prepareToLeaveUser(context.getUserId());
+ intent.fixUris(context.getUserId());
+ context.startActivityAsUser(intent, appTarget.getUser());
+ } else {
+ context.startActivity(intent);
+ }
+ });
}
/**
* Launch the activity to share image.
*/
- @UiThread
public static void startShareActivity(Context context, Supplier<Bitmap> bitmapSupplier,
Rect crop, Intent intent, String tag) {
- if (bitmapSupplier.get() == null) {
- Log.e(tag, "No snapshot available, not starting share.");
- return;
- }
-
- UI_HELPER_EXECUTOR.execute(() -> persistBitmapAndStartActivity(context,
- bitmapSupplier.get(), crop, intent, ImageActionUtils::getShareIntentForImageUri,
- tag));
+ UI_HELPER_EXECUTOR.execute(() -> {
+ Bitmap bitmap = bitmapSupplier.get();
+ if (bitmap == null) {
+ Log.e(tag, "No snapshot available, not starting share.");
+ return;
+ }
+ persistBitmapAndStartActivity(context, bitmap, crop, intent,
+ ImageActionUtils::getShareIntentForImageUri, tag);
+ });
}
/**
* Launch the activity to share image with shared element transition.
*/
- @UiThread
public static void startShareActivity(Context context, Supplier<Bitmap> bitmapSupplier,
Rect crop, Intent intent, String tag, View sharedElement) {
- if (bitmapSupplier.get() == null) {
- Log.e(tag, "No snapshot available, not starting share.");
- return;
- }
-
- UI_HELPER_EXECUTOR.execute(() -> persistBitmapAndStartActivity(context,
- bitmapSupplier.get(), crop, intent, ImageActionUtils::getShareIntentForImageUri,
- tag, sharedElement));
+ UI_HELPER_EXECUTOR.execute(() -> {
+ Bitmap bitmap = bitmapSupplier.get();
+ if (bitmap == null) {
+ Log.e(tag, "No snapshot available, not starting share.");
+ return;
+ }
+ persistBitmapAndStartActivity(context, bitmap,
+ crop, intent, ImageActionUtils::getShareIntentForImageUri, tag, sharedElement);
+ });
}
/**