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

Commit 8f5cb67e authored by /e/ robot's avatar /e/ robot
Browse files

Merge remote-tracking branch 'origin/lineage-20.0' into v1-t

parents 101d4aa8 def5583b
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -191,7 +191,7 @@ class SaveImageInBackgroundTask extends AsyncTask<String, Void, Void> {
            mImageData.quickShareAction = createQuickShareAction(
                    mQuickShareData.quickShareAction, mScreenshotId, uri, mImageTime, image,
                    user);
            mImageData.subject = getSubjectString();
            mImageData.subject = getSubjectString(mImageTime);

            mParams.mActionsReadyListener.onActionsReady(mImageData);
            if (DEBUG_CALLBACK) {
@@ -314,7 +314,7 @@ class SaveImageInBackgroundTask extends AsyncTask<String, Void, Void> {
                    new String[]{ClipDescription.MIMETYPE_TEXT_PLAIN}),
                    new ClipData.Item(uri));
            sharingIntent.setClipData(clipdata);
            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, getSubjectString());
            sharingIntent.putExtra(Intent.EXTRA_SUBJECT, getSubjectString(mImageTime));
            sharingIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
                    .addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

@@ -524,9 +524,7 @@ class SaveImageInBackgroundTask extends AsyncTask<String, Void, Void> {
        Intent fillIn = new Intent();
        fillIn.setType("image/png");
        fillIn.putExtra(Intent.EXTRA_STREAM, uri);
        String subjectDate = DateFormat.getDateTimeInstance().format(new Date(imageTime));
        String subject = String.format(SCREENSHOT_SHARE_SUBJECT_TEMPLATE, subjectDate);
        fillIn.putExtra(Intent.EXTRA_SUBJECT, subject);
        fillIn.putExtra(Intent.EXTRA_SUBJECT, getSubjectString(imageTime));
        // Include URI in ClipData also, so that grantPermission picks it up.
        // We don't use setData here because some apps interpret this as "to:".
        ClipData clipData = new ClipData(
@@ -566,8 +564,8 @@ class SaveImageInBackgroundTask extends AsyncTask<String, Void, Void> {
        return null;
    }

    private String getSubjectString() {
        String subjectDate = DateFormat.getDateTimeInstance().format(new Date(mImageTime));
    private static String getSubjectString(long imageTime) {
        String subjectDate = DateFormat.getDateTimeInstance().format(new Date(imageTime));
        return String.format(SCREENSHOT_SHARE_SUBJECT_TEMPLATE, subjectDate);
    }
}
+1 −4
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import android.os.SystemClock;
import android.os.UserHandle;
import android.util.Log;

import com.android.internal.annotations.VisibleForTesting;
import com.android.systemui.dagger.SysUISingleton;
import com.android.systemui.shared.system.ActivityManagerWrapper;

@@ -61,7 +60,6 @@ public class ScreenshotSmartActions {
                screenshotNotificationSmartActionsProviderProvider;
    }

    @VisibleForTesting
    CompletableFuture<List<Notification.Action>> getSmartActionsFuture(
            String screenshotId, Uri screenshotUri, Bitmap image,
            ScreenshotNotificationSmartActionsProvider smartActionsProvider,
@@ -112,7 +110,6 @@ public class ScreenshotSmartActions {
        return smartActionsFuture;
    }

    @VisibleForTesting
    List<Notification.Action> getSmartActions(String screenshotId,
            CompletableFuture<List<Notification.Action>> smartActionsFuture, int timeoutMs,
            ScreenshotNotificationSmartActionsProvider smartActionsProvider,
+8 −9
Original line number Diff line number Diff line
@@ -99,6 +99,7 @@ class MediaResumeListenerTest : SysuiTestCase() {
    @Captor lateinit var actionCaptor: ArgumentCaptor<Runnable>
    @Captor lateinit var componentCaptor: ArgumentCaptor<String>
    @Captor lateinit var userIdCaptor: ArgumentCaptor<Int>
    @Captor lateinit var userCallbackCaptor: ArgumentCaptor<UserTracker.Callback>

    private lateinit var executor: FakeExecutor
    private lateinit var data: MediaData
@@ -615,8 +616,8 @@ class MediaResumeListenerTest : SysuiTestCase() {

    @Test
    fun testUserUnlocked_userChangeWhileQuerying() {
        val firstUserId = context.userId
        val secondUserId = firstUserId + 1
        val firstUserId = 1
        val secondUserId = 2
        val description = MediaDescription.Builder().setTitle(TITLE).build()
        val component = ComponentName(PACKAGE_NAME, CLASS_NAME)

@@ -628,18 +629,16 @@ class MediaResumeListenerTest : SysuiTestCase() {
            Intent(Intent.ACTION_USER_UNLOCKED).apply {
                putExtra(Intent.EXTRA_USER_HANDLE, firstUserId)
            }
        verify(userTracker).addCallback(capture(userCallbackCaptor), any())

        // When the first user unlocks and we query their recent media
        resumeListener.userChangeReceiver.onReceive(context, unlockIntent)
        userCallbackCaptor.value.onUserChanged(firstUserId, context)
        resumeListener.userUnlockReceiver.onReceive(context, unlockIntent)
        whenever(resumeBrowser.userId).thenReturn(userIdCaptor.value)
        verify(resumeBrowser, times(3)).findRecentMedia()

        // And the user changes before the MBS response is received
        val changeIntent =
            Intent(Intent.ACTION_USER_SWITCHED).apply {
                putExtra(Intent.EXTRA_USER_HANDLE, secondUserId)
            }
        resumeListener.userChangeReceiver.onReceive(context, changeIntent)
        userCallbackCaptor.value.onUserChanged(secondUserId, context)
        callbackCaptor.value.addTrack(description, component, resumeBrowser)

        // Then the loaded media is correctly associated with the first user
@@ -669,7 +668,7 @@ class MediaResumeListenerTest : SysuiTestCase() {
            }

        // When the user is unlocked, but does not have the component installed
        resumeListener.userChangeReceiver.onReceive(context, unlockIntent)
        resumeListener.userUnlockReceiver.onReceive(context, unlockIntent)

        // Then we never attempt to connect to it
        verify(resumeBrowser, never()).findRecentMedia()
+2 −2
Original line number Diff line number Diff line
@@ -94,7 +94,7 @@ public class ResumeMediaBrowserTest : SysuiTestCase() {
                browserFactory,
                logger,
                mediaController,
                context.userId
                context.userId,
            )
    }

@@ -383,7 +383,7 @@ public class ResumeMediaBrowserTest : SysuiTestCase() {
        browserFactory: MediaBrowserFactory,
        logger: ResumeMediaBrowserLogger,
        private val fakeController: MediaController,
        userId: Int
        userId: Int,
    ) : ResumeMediaBrowser(context, callback, componentName, browserFactory, logger, userId) {

        override fun createMediaController(token: MediaSession.Token): MediaController {
+20 −19
Original line number Diff line number Diff line
@@ -24,29 +24,27 @@ import android.graphics.Bitmap
import android.graphics.drawable.Icon
import android.net.Uri
import android.os.UserHandle
import android.testing.AndroidTestingRunner
import androidx.test.filters.SmallTest

import com.android.systemui.SysuiTestCase
import com.android.systemui.flags.FakeFeatureFlags
import com.android.systemui.screenshot.ScreenshotController.SaveImageInBackgroundData
import com.android.systemui.screenshot.ScreenshotNotificationSmartActionsProvider.ScreenshotSmartActionType
import com.android.systemui.util.mockito.any
import com.android.systemui.util.mockito.eq
import com.android.systemui.util.mockito.mock
import com.android.systemui.util.mockito.whenever
import java.util.concurrent.CompletableFuture
import java.util.function.Supplier
import org.junit.Assert.assertEquals
import org.junit.Assert.assertNull
import org.junit.Before
import org.junit.runner.RunWith
import org.junit.Test
import org.mockito.Mockito

@SmallTest
@RunWith(AndroidTestingRunner::class)
class SaveImageInBackgroundTaskTest : SysuiTestCase() {
    private val imageExporter = mock<ImageExporter>()
    private val smartActions = mock<ScreenshotSmartActions>()
    private val smartActionsProvider = mock<ScreenshotNotificationSmartActionsProvider>()
    private val saveImageData = SaveImageInBackgroundData()
    private val sharedTransitionSupplier =
        mock<Supplier<ScreenshotController.SavedImageData.ActionTransition>>()
@@ -55,6 +53,7 @@ class SaveImageInBackgroundTaskTest : SysuiTestCase() {
    private val testUser = UserHandle.getUserHandleForUid(0)
    private val testIcon = mock<Icon>()
    private val testImageTime = 1234.toLong()
    private val flags = FakeFeatureFlags()

    private val smartActionsUriFuture = mock<CompletableFuture<List<Notification.Action>>>()
    private val smartActionsFuture = mock<CompletableFuture<List<Notification.Action>>>()
@@ -85,32 +84,34 @@ class SaveImageInBackgroundTaskTest : SysuiTestCase() {
    private val saveImageTask =
        SaveImageInBackgroundTask(
            mContext,
            flags,
            imageExporter,
            smartActions,
            saveImageData,
            sharedTransitionSupplier,
            smartActionsProvider,
        )

    @Before
    fun setup() {
        Mockito.`when`(
        whenever(
                smartActions.getSmartActionsFuture(
                    eq(testScreenshotId),
                    any(Uri::class.java),
                    eq(testBitmap),
                    any(ScreenshotNotificationSmartActionsProvider::class.java),
                    eq(smartActionsProvider),
                    any(ScreenshotSmartActionType::class.java),
                    any(Boolean::class.java),
                    eq(testUser)
                )
            )
            .thenReturn(smartActionsUriFuture)
        Mockito.`when`(
        whenever(
                smartActions.getSmartActionsFuture(
                    eq(testScreenshotId),
                    eq(null),
                    eq(testBitmap),
                    any(ScreenshotNotificationSmartActionsProvider::class.java),
                    eq(smartActionsProvider),
                    any(ScreenshotSmartActionType::class.java),
                    any(Boolean::class.java),
                    eq(testUser)
@@ -121,12 +122,12 @@ class SaveImageInBackgroundTaskTest : SysuiTestCase() {

    @Test
    fun testQueryQuickShare_noAction() {
        Mockito.`when`(
        whenever(
                smartActions.getSmartActions(
                    eq(testScreenshotId),
                    eq(smartActionsFuture),
                    any(Int::class.java),
                    any(ScreenshotNotificationSmartActionsProvider::class.java),
                    eq(smartActionsProvider),
                    eq(ScreenshotSmartActionType.QUICK_SHARE_ACTION)
                )
            )
@@ -143,12 +144,12 @@ class SaveImageInBackgroundTaskTest : SysuiTestCase() {
        val actions = ArrayList<Notification.Action>()
        actions.add(constructAction("Action One", mutablePendingIntent))
        actions.add(constructAction("Action Two", mutablePendingIntent))
        Mockito.`when`(
        whenever(
                smartActions.getSmartActions(
                    eq(testScreenshotId),
                    eq(smartActionsUriFuture),
                    any(Int::class.java),
                    any(ScreenshotNotificationSmartActionsProvider::class.java),
                    eq(smartActionsProvider),
                    eq(ScreenshotSmartActionType.QUICK_SHARE_ACTION)
                )
            )
@@ -180,12 +181,12 @@ class SaveImageInBackgroundTaskTest : SysuiTestCase() {
    fun testCreateQuickShareAction_immutableIntentDifferentAction_returnsNull() {
        val actions = ArrayList<Notification.Action>()
        actions.add(constructAction("New Test Action", immutablePendingIntent))
        Mockito.`when`(
        whenever(
                smartActions.getSmartActions(
                    eq(testScreenshotId),
                    eq(smartActionsUriFuture),
                    any(Int::class.java),
                    any(ScreenshotNotificationSmartActionsProvider::class.java),
                    eq(smartActionsProvider),
                    eq(ScreenshotSmartActionType.QUICK_SHARE_ACTION)
                )
            )
@@ -210,12 +211,12 @@ class SaveImageInBackgroundTaskTest : SysuiTestCase() {
        val actions = ArrayList<Notification.Action>()
        val action = constructAction("Action One", mutablePendingIntent)
        actions.add(action)
        Mockito.`when`(
        whenever(
                smartActions.getSmartActions(
                    eq(testScreenshotId),
                    eq(smartActionsUriFuture),
                    any(Int::class.java),
                    any(ScreenshotNotificationSmartActionsProvider::class.java),
                    eq(smartActionsProvider),
                    eq(ScreenshotSmartActionType.QUICK_SHARE_ACTION)
                )
            )
@@ -245,12 +246,12 @@ class SaveImageInBackgroundTaskTest : SysuiTestCase() {
        val actions = ArrayList<Notification.Action>()
        val action = constructAction("Test Action", immutablePendingIntent)
        actions.add(action)
        Mockito.`when`(
        whenever(
                smartActions.getSmartActions(
                    eq(testScreenshotId),
                    eq(smartActionsUriFuture),
                    any(Int::class.java),
                    any(ScreenshotNotificationSmartActionsProvider::class.java),
                    eq(smartActionsProvider),
                    eq(ScreenshotSmartActionType.QUICK_SHARE_ACTION)
                )
            )