diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java b/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java index 23139382c6e07..09fab4b92dde3 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/SaveImageInBackgroundTask.java @@ -130,11 +130,6 @@ class SaveImageInBackgroundTask extends AsyncTask { Resources r = mContext.getResources(); try { - CompletableFuture> smartActionsFuture = - ScreenshotSmartActions.getSmartActionsFuture( - mScreenshotId, mImageFileName, image, mSmartActionsProvider, - mSmartActionsEnabled, isManagedProfile(mContext)); - // Save the screenshot to the MediaStore final ContentValues values = new ContentValues(); values.put(MediaColumns.RELATIVE_PATH, Environment.DIRECTORY_PICTURES @@ -148,6 +143,11 @@ class SaveImageInBackgroundTask extends AsyncTask { final Uri uri = resolver.insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); + CompletableFuture> smartActionsFuture = + ScreenshotSmartActions.getSmartActionsFuture( + mScreenshotId, uri, image, mSmartActionsProvider, + mSmartActionsEnabled, isManagedProfile(mContext)); + try { // First, write the actual data for our screenshot try (OutputStream out = resolver.openOutputStream(uri)) { @@ -203,7 +203,7 @@ class SaveImageInBackgroundTask extends AsyncTask { 1000); smartActions.addAll(buildSmartActions( ScreenshotSmartActions.getSmartActions( - mScreenshotId, mImageFileName, smartActionsFuture, timeoutMs, + mScreenshotId, smartActionsFuture, timeoutMs, mSmartActionsProvider), mContext)); } diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsProvider.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsProvider.java index 09a0644159e2a..3edb33da9cd0f 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsProvider.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsProvider.java @@ -19,6 +19,7 @@ package com.android.systemui.screenshot; import android.app.Notification; import android.content.ComponentName; import android.graphics.Bitmap; +import android.net.Uri; import android.util.Log; import java.util.Collections; @@ -67,7 +68,7 @@ public class ScreenshotNotificationSmartActionsProvider { */ public CompletableFuture> getActions( String screenshotId, - String screenshotFileName, + Uri screenshotUri, Bitmap bitmap, ComponentName componentName, boolean isManagedProfile) { diff --git a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSmartActions.java b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSmartActions.java index d31344446fac9..c228fe2c4334e 100644 --- a/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSmartActions.java +++ b/packages/SystemUI/src/com/android/systemui/screenshot/ScreenshotSmartActions.java @@ -23,6 +23,7 @@ import android.app.Notification; import android.content.ComponentName; import android.content.Context; import android.graphics.Bitmap; +import android.net.Uri; import android.os.Handler; import android.os.SystemClock; import android.util.Slog; @@ -45,7 +46,7 @@ public class ScreenshotSmartActions { @VisibleForTesting static CompletableFuture> getSmartActionsFuture( - String screenshotId, String screenshotFileName, Bitmap image, + String screenshotId, Uri screenshotUri, Bitmap image, ScreenshotNotificationSmartActionsProvider smartActionsProvider, boolean smartActionsEnabled, boolean isManagedProfile) { if (!smartActionsEnabled) { @@ -70,7 +71,7 @@ public class ScreenshotSmartActions { ? runningTask.topActivity : new ComponentName("", ""); smartActionsFuture = smartActionsProvider.getActions( - screenshotId, screenshotFileName, image, componentName, isManagedProfile); + screenshotId, screenshotUri, image, componentName, isManagedProfile); } catch (Throwable e) { long waitTimeMs = SystemClock.uptimeMillis() - startTimeMs; smartActionsFuture = CompletableFuture.completedFuture(Collections.emptyList()); @@ -84,7 +85,7 @@ public class ScreenshotSmartActions { } @VisibleForTesting - static List getSmartActions(String screenshotId, String screenshotFileName, + static List getSmartActions(String screenshotId, CompletableFuture> smartActionsFuture, int timeoutMs, ScreenshotNotificationSmartActionsProvider smartActionsProvider) { long startTimeMs = SystemClock.uptimeMillis(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsTest.java b/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsTest.java index ffe3cd5bd5044..2c4304d51720a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/screenshot/ScreenshotNotificationSmartActionsTest.java @@ -83,8 +83,9 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase { eq(false))).thenThrow( RuntimeException.class); CompletableFuture> smartActionsFuture = - ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap, - smartActionsProvider, true, false); + ScreenshotSmartActions.getSmartActionsFuture( + "", Uri.parse("content://authority/data"), bitmap, smartActionsProvider, + true, false); assertNotNull(smartActionsFuture); List smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS); assertEquals(Collections.emptyList(), smartActions); @@ -101,7 +102,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase { when(smartActionsFuture.get(timeoutMs, TimeUnit.MILLISECONDS)).thenThrow( RuntimeException.class); List actions = ScreenshotSmartActions.getSmartActions( - "", "", smartActionsFuture, timeoutMs, mSmartActionsProvider); + "", smartActionsFuture, timeoutMs, mSmartActionsProvider); assertEquals(Collections.emptyList(), actions); } @@ -122,8 +123,9 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase { Bitmap bitmap = mock(Bitmap.class); when(bitmap.getConfig()).thenReturn(Bitmap.Config.RGB_565); CompletableFuture> smartActionsFuture = - ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap, - mSmartActionsProvider, true, true); + ScreenshotSmartActions.getSmartActionsFuture( + "", Uri.parse("content://autority/data"), bitmap, mSmartActionsProvider, + true, true); verify(mSmartActionsProvider, never()).getActions(any(), any(), any(), any(), eq(false)); assertNotNull(smartActionsFuture); @@ -136,8 +138,9 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase { public void testScreenshotNotificationSmartActionsProviderInvokedOnce() { Bitmap bitmap = mock(Bitmap.class); when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE); - ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap, mSmartActionsProvider, - true, true); + ScreenshotSmartActions.getSmartActionsFuture( + "", Uri.parse("content://autority/data"), bitmap, mSmartActionsProvider, true, + true); verify(mSmartActionsProvider, times(1)) .getActions(any(), any(), any(), any(), eq(true)); } @@ -152,7 +155,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase { SystemUIFactory.getInstance().createScreenshotNotificationSmartActionsProvider( mContext, null, mHandler); CompletableFuture> smartActionsFuture = - ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap, + ScreenshotSmartActions.getSmartActionsFuture("", null, bitmap, actionsProvider, true, true); assertNotNull(smartActionsFuture);