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

Commit b5733832 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: Ia9d3b97ddfecc05631a27cdcb40a84b1b611979e
parents d80f5fc7 3aba4dd2
Loading
Loading
Loading
Loading
+2 −2
Original line number Original line Diff line number Diff line
@@ -130,7 +130,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        try {
        try {
            CompletableFuture<List<Notification.Action>> smartActionsFuture =
            CompletableFuture<List<Notification.Action>> smartActionsFuture =
                    ScreenshotSmartActions.getSmartActionsFuture(
                    ScreenshotSmartActions.getSmartActionsFuture(
                            mScreenshotId, image, mSmartActionsProvider,
                            mScreenshotId, mImageFileName, image, mSmartActionsProvider,
                            mSmartActionsEnabled, isManagedProfile(mContext));
                            mSmartActionsEnabled, isManagedProfile(mContext));


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


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


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


@@ -119,9 +119,9 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        Bitmap bitmap = mock(Bitmap.class);
        Bitmap bitmap = mock(Bitmap.class);
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.RGB_565);
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.RGB_565);
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                ScreenshotSmartActions.getSmartActionsFuture("", bitmap,
                ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap,
                        mSmartActionsProvider, true, true);
                        mSmartActionsProvider, true, true);
        verify(mSmartActionsProvider, never()).getActions(any(), any(), any(),
        verify(mSmartActionsProvider, never()).getActions(any(), any(), any(), any(),
                eq(false));
                eq(false));
        Assert.assertNotNull(smartActionsFuture);
        Assert.assertNotNull(smartActionsFuture);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
@@ -133,10 +133,10 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
    public void testScreenshotNotificationSmartActionsProviderInvokedOnce() {
    public void testScreenshotNotificationSmartActionsProviderInvokedOnce() {
        Bitmap bitmap = mock(Bitmap.class);
        Bitmap bitmap = mock(Bitmap.class);
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE);
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE);
        ScreenshotSmartActions.getSmartActionsFuture("", bitmap, mSmartActionsProvider,
        ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap, mSmartActionsProvider,
                true, true);
                true, true);
        verify(mSmartActionsProvider, times(1))
        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.
    // Tests for a hardware bitmap, a completed future is returned.
@@ -149,7 +149,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
                SystemUIFactory.getInstance().createScreenshotNotificationSmartActionsProvider(
                SystemUIFactory.getInstance().createScreenshotNotificationSmartActionsProvider(
                        mContext, null, mHandler);
                        mContext, null, mHandler);
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                ScreenshotSmartActions.getSmartActionsFuture("", bitmap,
                ScreenshotSmartActions.getSmartActionsFuture("", "", bitmap,
                        actionsProvider,
                        actionsProvider,
                        true, true);
                        true, true);
        Assert.assertNotNull(smartActionsFuture);
        Assert.assertNotNull(smartActionsFuture);