Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b356a76d authored by Katsiaryna Naliuka's avatar Katsiaryna Naliuka Committed by Automerger Merge Worker
Browse files

Merge "Support for passing the name of the newly taken screenshot to the...

Merge "Support for passing the name of the newly taken screenshot to the content suggestion service." into rvc-dev am: 3aba4dd2

Change-Id: Ia7d1c46cd9fc7e343d9e95c3b06d5f35ce580f70
parents ae226ed9 3aba4dd2
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -130,7 +130,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        try {
            CompletableFuture<List<Notification.Action>> smartActionsFuture =
                    ScreenshotSmartActions.getSmartActionsFuture(
                            mScreenshotId, image, mSmartActionsProvider,
                            mScreenshotId, mImageFileName, image, mSmartActionsProvider,
                            mSmartActionsEnabled, isManagedProfile(mContext));

            // Save the screenshot to the MediaStore
@@ -202,7 +202,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
                        1000);
                smartActions.addAll(buildSmartActions(
                        ScreenshotSmartActions.getSmartActions(
                                mScreenshotId, smartActionsFuture, timeoutMs,
                                mScreenshotId, mImageFileName, smartActionsFuture, timeoutMs,
                                mSmartActionsProvider),
                        mContext));
            }
+10 −8
Original line number Diff line number Diff line
@@ -57,15 +57,17 @@ public class ScreenshotNotificationSmartActionsProvider {
     * This method is overridden in vendor-specific Sys UI implementation.
     *
     * @param screenshotId       A generated random unique id for the screenshot.
     * @param screenshotFileName name of the file where the screenshot will be written.
     * @param bitmap             The bitmap of the screenshot. The bitmap config must be {@link
     *                           HARDWARE}.
     * @param componentName      Contains package and activity class names where the screenshot was
     *                         taken. This is used as an additional signal to generate and rank more
     *                         relevant actions.
     *                           taken. This is used as an additional signal to generate and rank
     *                           more relevant actions.
     * @param isManagedProfile   The screenshot was taken for a work profile app.
     */
    public CompletableFuture<List<Notification.Action>> getActions(
            String screenshotId,
            String screenshotFileName,
            Bitmap bitmap,
            ComponentName componentName,
            boolean isManagedProfile) {
@@ -77,7 +79,7 @@ public class ScreenshotNotificationSmartActionsProvider {
     * Notify exceptions and latency encountered during generating smart actions.
     * This method is overridden in vendor-specific Sys UI implementation.
     *
     * @param screenshotId Unique id of the screenshot.
     * @param screenshotId unique id of the screenshot.
     * @param op           screenshot execution phase defined in {@link ScreenshotOp}
     * @param status       {@link ScreenshotOpStatus} to report success or failure.
     * @param durationMs   latency experienced in different phases of screenshots.
+6 −6
Original line number Diff line number Diff line
@@ -44,8 +44,9 @@ public class ScreenshotSmartActions {
    private static final String TAG = "ScreenshotSmartActions";

    @VisibleForTesting
    static CompletableFuture<List<Notification.Action>> getSmartActionsFuture(String screenshotId,
            Bitmap image, ScreenshotNotificationSmartActionsProvider smartActionsProvider,
    static CompletableFuture<List<Notification.Action>> getSmartActionsFuture(
            String screenshotId, String screenshotFileName, Bitmap image,
            ScreenshotNotificationSmartActionsProvider smartActionsProvider,
            boolean smartActionsEnabled, boolean isManagedProfile) {
        if (!smartActionsEnabled) {
            Slog.i(TAG, "Screenshot Intelligence not enabled, returning empty list.");
@@ -68,9 +69,8 @@ public class ScreenshotSmartActions {
                    (runningTask != null && runningTask.topActivity != null)
                            ? runningTask.topActivity
                            : new ComponentName("", "");
            smartActionsFuture = smartActionsProvider.getActions(screenshotId, image,
                    componentName,
                    isManagedProfile);
            smartActionsFuture = smartActionsProvider.getActions(
                    screenshotId, screenshotFileName, image, componentName, isManagedProfile);
        } catch (Throwable e) {
            long waitTimeMs = SystemClock.uptimeMillis() - startTimeMs;
            smartActionsFuture = CompletableFuture.completedFuture(Collections.emptyList());
@@ -84,7 +84,7 @@ public class ScreenshotSmartActions {
    }

    @VisibleForTesting
    static List<Notification.Action> getSmartActions(String screenshotId,
    static List<Notification.Action> getSmartActions(String screenshotId, String screenshotFileName,
            CompletableFuture<List<Notification.Action>> smartActionsFuture, int timeoutMs,
            ScreenshotNotificationSmartActionsProvider smartActionsProvider) {
        long startTimeMs = SystemClock.uptimeMillis();
+8 −8
Original line number Diff line number Diff line
@@ -76,11 +76,11 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE);
        ScreenshotNotificationSmartActionsProvider smartActionsProvider = mock(
                ScreenshotNotificationSmartActionsProvider.class);
        when(smartActionsProvider.getActions(any(), any(), any(),
        when(smartActionsProvider.getActions(any(), any(), any(), any(),
                eq(false))).thenThrow(
                RuntimeException.class);
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                ScreenshotSmartActions.getSmartActionsFuture("", bitmap,
                ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap,
                        smartActionsProvider, true, false);
        Assert.assertNotNull(smartActionsFuture);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
@@ -98,7 +98,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        when(smartActionsFuture.get(timeoutMs, TimeUnit.MILLISECONDS)).thenThrow(
                RuntimeException.class);
        List<Notification.Action> actions = ScreenshotSmartActions.getSmartActions(
                "", smartActionsFuture, timeoutMs, mSmartActionsProvider);
                "", "", smartActionsFuture, timeoutMs, mSmartActionsProvider);
        Assert.assertEquals(Collections.emptyList(), actions);
    }

@@ -119,9 +119,9 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        Bitmap bitmap = mock(Bitmap.class);
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.RGB_565);
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                ScreenshotSmartActions.getSmartActionsFuture("", bitmap,
                ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap,
                        mSmartActionsProvider, true, true);
        verify(mSmartActionsProvider, never()).getActions(any(), any(), any(),
        verify(mSmartActionsProvider, never()).getActions(any(), any(), any(), any(),
                eq(false));
        Assert.assertNotNull(smartActionsFuture);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
@@ -133,10 +133,10 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
    public void testScreenshotNotificationSmartActionsProviderInvokedOnce() {
        Bitmap bitmap = mock(Bitmap.class);
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE);
        ScreenshotSmartActions.getSmartActionsFuture("", bitmap, mSmartActionsProvider,
        ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap, mSmartActionsProvider,
                true, true);
        verify(mSmartActionsProvider, times(1))
                .getActions(any(), any(), any(), eq(true));
                .getActions(any(), any(), any(), any(), eq(true));
    }

    // Tests for a hardware bitmap, a completed future is returned.
@@ -149,7 +149,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
                SystemUIFactory.getInstance().createScreenshotNotificationSmartActionsProvider(
                        mContext, null, mHandler);
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                ScreenshotSmartActions.getSmartActionsFuture("", bitmap,
                ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap,
                        actionsProvider,
                        true, true);
        Assert.assertNotNull(smartActionsFuture);