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

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

Merge "Pass the user handle for the screenshot app to the content suggestion...

Merge "Pass the user handle for the screenshot app to the content suggestion service (SysUI part)." into rvc-dev am: 71576c05 am: dc99f1cc

Change-Id: I32c3f75ee31fe4277811e198fd7105527568b7cc
parents 2d66b6e3 dc99f1cc
Loading
Loading
Loading
Loading
+3 −5
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
@@ -146,7 +145,7 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
            CompletableFuture<List<Notification.Action>> smartActionsFuture =
                    ScreenshotSmartActions.getSmartActionsFuture(
                            mScreenshotId, uri, image, mSmartActionsProvider,
                            mSmartActionsEnabled, isManagedProfile(mContext));
                            mSmartActionsEnabled, getUserHandle(mContext));

            try {
                // First, write the actual data for our screenshot
@@ -382,10 +381,9 @@ class SaveImageInBackgroundTask extends AsyncTask<Void, Void, Void> {
        }
    }

    private boolean isManagedProfile(Context context) {
    private UserHandle getUserHandle(Context context) {
        UserManager manager = UserManager.get(context);
        UserInfo info = manager.getUserInfo(getUserHandleOfForegroundApplication(context));
        return info.isManagedProfile();
        return manager.getUserInfo(getUserHandleOfForegroundApplication(context)).getUserHandle();
    }

    private List<Notification.Action> buildSmartActions(
+3 −2
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.Notification;
import android.content.ComponentName;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.UserHandle;
import android.util.Log;

import java.util.Collections;
@@ -64,14 +65,14 @@ public class ScreenshotNotificationSmartActionsProvider {
     * @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.
     * @param isManagedProfile   The screenshot was taken for a work profile app.
     * @param userHandle         The user handle of the app where the screenshot was taken.
     */
    public CompletableFuture<List<Notification.Action>> getActions(
            String screenshotId,
            Uri screenshotUri,
            Bitmap bitmap,
            ComponentName componentName,
            boolean isManagedProfile) {
            UserHandle userHandle) {
        Log.d(TAG, "Returning empty smart action list.");
        return CompletableFuture.completedFuture(Collections.emptyList());
    }
+4 −3
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Handler;
import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Slog;

import com.android.internal.annotations.VisibleForTesting;
@@ -48,7 +49,7 @@ public class ScreenshotSmartActions {
    static CompletableFuture<List<Notification.Action>> getSmartActionsFuture(
            String screenshotId, Uri screenshotUri, Bitmap image,
            ScreenshotNotificationSmartActionsProvider smartActionsProvider,
            boolean smartActionsEnabled, boolean isManagedProfile) {
            boolean smartActionsEnabled, UserHandle userHandle) {
        if (!smartActionsEnabled) {
            Slog.i(TAG, "Screenshot Intelligence not enabled, returning empty list.");
            return CompletableFuture.completedFuture(Collections.emptyList());
@@ -60,7 +61,7 @@ public class ScreenshotSmartActions {
            return CompletableFuture.completedFuture(Collections.emptyList());
        }

        Slog.d(TAG, "Screenshot from a managed profile: " + isManagedProfile);
        Slog.d(TAG, "Screenshot from user profile: " + userHandle.getIdentifier());
        CompletableFuture<List<Notification.Action>> smartActionsFuture;
        long startTimeMs = SystemClock.uptimeMillis();
        try {
@@ -71,7 +72,7 @@ public class ScreenshotSmartActions {
                            ? runningTask.topActivity
                            : new ComponentName("", "");
            smartActionsFuture = smartActionsProvider.getActions(
                    screenshotId, screenshotUri, image, componentName, isManagedProfile);
                    screenshotId, screenshotUri, image, componentName, userHandle);
        } catch (Throwable e) {
            long waitTimeMs = SystemClock.uptimeMillis() - startTimeMs;
            smartActionsFuture = CompletableFuture.completedFuture(Collections.emptyList());
+9 −12
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -37,6 +36,7 @@ import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.UserHandle;
import android.testing.AndroidTestingRunner;

import androidx.test.filters.SmallTest;
@@ -79,13 +79,12 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE);
        ScreenshotNotificationSmartActionsProvider smartActionsProvider = mock(
                ScreenshotNotificationSmartActionsProvider.class);
        when(smartActionsProvider.getActions(any(), any(), any(), any(),
                eq(false))).thenThrow(
                RuntimeException.class);
        when(smartActionsProvider.getActions(any(), any(), any(), any(), any()))
            .thenThrow(RuntimeException.class);
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                ScreenshotSmartActions.getSmartActionsFuture(
                        "", Uri.parse("content://authority/data"), bitmap, smartActionsProvider,
                        true, false);
                        true, UserHandle.getUserHandleForUid(UserHandle.myUserId()));
        assertNotNull(smartActionsFuture);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
        assertEquals(Collections.emptyList(), smartActions);
@@ -125,9 +124,8 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                ScreenshotSmartActions.getSmartActionsFuture(
                        "", Uri.parse("content://autority/data"), bitmap, mSmartActionsProvider,
                        true, true);
        verify(mSmartActionsProvider, never()).getActions(any(), any(), any(), any(),
                eq(false));
                        true, UserHandle.getUserHandleForUid(UserHandle.myUserId()));
        verify(mSmartActionsProvider, never()).getActions(any(), any(), any(), any(), any());
        assertNotNull(smartActionsFuture);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
        assertEquals(Collections.emptyList(), smartActions);
@@ -140,9 +138,8 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        when(bitmap.getConfig()).thenReturn(Bitmap.Config.HARDWARE);
        ScreenshotSmartActions.getSmartActionsFuture(
                "", Uri.parse("content://autority/data"), bitmap, mSmartActionsProvider, true,
                true);
        verify(mSmartActionsProvider, times(1))
                .getActions(any(), any(), any(), any(), eq(true));
                UserHandle.getUserHandleForUid(UserHandle.myUserId()));
        verify(mSmartActionsProvider, times(1)).getActions(any(), any(), any(), any(), any());
    }

    // Tests for a hardware bitmap, a completed future is returned.
@@ -157,7 +154,7 @@ public class ScreenshotNotificationSmartActionsTest extends SysuiTestCase {
        CompletableFuture<List<Notification.Action>> smartActionsFuture =
                ScreenshotSmartActions.getSmartActionsFuture("", null, bitmap,
                        actionsProvider,
                        true, true);
                        true, UserHandle.getUserHandleForUid(UserHandle.myUserId()));
        assertNotNull(smartActionsFuture);
        List<Notification.Action> smartActions = smartActionsFuture.get(5, TimeUnit.MILLISECONDS);
        assertEquals(smartActions.size(), 0);