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

Commit 66aa586b authored by Mark Renouf's avatar Mark Renouf
Browse files

Log additional UiEvents for long screenshots, include packageName

Bug: 195013652
Test: atest ScrollCaptureControllerTest
Change-Id: Ief6578b33bb3361980ebd73a803a87f21f985a47
parent 71bc80de
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -660,7 +660,7 @@ public class ScreenshotController {
                    + mLastScrollCaptureResponse.getWindowTitle() + "]");

            final ScrollCaptureResponse response = mLastScrollCaptureResponse;
            mScreenshotView.showScrollChip(/* onClick */ () -> {
            mScreenshotView.showScrollChip(response.getPackageName(), /* onClick */ () -> {
                DisplayMetrics displayMetrics = new DisplayMetrics();
                getDefaultDisplay().getRealMetrics(displayMetrics);
                Bitmap newScreenshot = captureScreenshot(
+7 −1
Original line number Diff line number Diff line
@@ -71,7 +71,13 @@ public enum ScreenshotEvent implements UiEventLogger.UiEventEnum {
    @UiEvent(doc = "User has shared a long screenshot")
    SCREENSHOT_LONG_SCREENSHOT_SHARE(689),
    @UiEvent(doc = "User has sent a long screenshot to the editor")
    SCREENSHOT_LONG_SCREENSHOT_EDIT(690);
    SCREENSHOT_LONG_SCREENSHOT_EDIT(690),
    @UiEvent(doc = "A long screenshot capture has started")
    SCREENSHOT_LONG_SCREENSHOT_STARTED(880),
    @UiEvent(doc = "The long screenshot capture failed")
    SCREENSHOT_LONG_SCREENSHOT_FAILURE(881),
    @UiEvent(doc = "The long screenshot capture completed successfully")
    SCREENSHOT_LONG_SCREENSHOT_COMPLETED(882);

    private final int mId;

+5 −3
Original line number Diff line number Diff line
@@ -242,19 +242,21 @@ public class ScreenshotView extends FrameLayout implements
    /**
     * Called to display the scroll action chip when support is detected.
     *
     * @param packageName the owning package of the window to be captured
     * @param onClick the action to take when the chip is clicked.
     */
    public void showScrollChip(Runnable onClick) {
    public void showScrollChip(String packageName, Runnable onClick) {
        if (DEBUG_SCROLL) {
            Log.d(TAG, "Showing Scroll option");
        }
        mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_IMPRESSION);
        mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_IMPRESSION, 0, packageName);
        mScrollChip.setVisibility(VISIBLE);
        mScrollChip.setOnClickListener((v) -> {
            if (DEBUG_INPUT) {
                Log.d(TAG, "scroll chip tapped");
            }
            mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_REQUESTED);
            mUiEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_REQUESTED, 0,
                    packageName);
            onClick.run();
        });
    }
+13 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import androidx.concurrent.futures.CallbackToFutureAdapter;
import androidx.concurrent.futures.CallbackToFutureAdapter.Completer;

import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.logging.UiEventLogger;
import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.screenshot.ScrollCaptureClient.CaptureResult;
import com.android.systemui.screenshot.ScrollCaptureClient.Session;
@@ -61,6 +62,7 @@ public class ScrollCaptureController {
    private final Context mContext;
    private final Executor mBgExecutor;
    private final ImageTileSet mImageTileSet;
    private final UiEventLogger mEventLogger;
    private final ScrollCaptureClient mClient;

    private Completer<LongScreenshot> mCaptureCompleter;
@@ -69,6 +71,7 @@ public class ScrollCaptureController {
    private Session mSession;
    private ListenableFuture<CaptureResult> mTileFuture;
    private ListenableFuture<Void> mEndFuture;
    private String mWindowOwner;

    static class LongScreenshot {
        private final ImageTileSet mImageTileSet;
@@ -135,11 +138,12 @@ public class ScrollCaptureController {

    @Inject
    ScrollCaptureController(Context context, @Background Executor bgExecutor,
            ScrollCaptureClient client, ImageTileSet imageTileSet) {
            ScrollCaptureClient client, ImageTileSet imageTileSet, UiEventLogger logger) {
        mContext = context;
        mBgExecutor = bgExecutor;
        mClient = client;
        mImageTileSet = imageTileSet;
        mEventLogger = logger;
    }

    @VisibleForTesting
@@ -157,6 +161,7 @@ public class ScrollCaptureController {
    ListenableFuture<LongScreenshot> run(ScrollCaptureResponse response) {
        return CallbackToFutureAdapter.getFuture(completer -> {
            mCaptureCompleter = completer;
            mWindowOwner = response.getPackageName();
            mBgExecutor.execute(() -> {
                float maxPages = Settings.Secure.getFloat(mContext.getContentResolver(),
                        SETTING_KEY_MAX_PAGES, MAX_PAGES_DEFAULT);
@@ -173,11 +178,13 @@ public class ScrollCaptureController {
            if (LogConfig.DEBUG_SCROLL) {
                Log.d(TAG, "got session " + mSession);
            }
            mEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_STARTED, 0, mWindowOwner);
            requestNextTile(0);
        } catch (InterruptedException | ExecutionException e) {
            // Failure to start, propagate to caller
            Log.e(TAG, "session start failed!");
            mCaptureCompleter.setException(e);
            mEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_FAILURE, 0, mWindowOwner);
        }
    }

@@ -297,6 +304,11 @@ public class ScrollCaptureController {
        if (LogConfig.DEBUG_SCROLL) {
            Log.d(TAG, "finishCapture()");
        }
        if (mImageTileSet.getHeight() > 0) {
            mEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_COMPLETED, 0, mWindowOwner);
        } else {
            mEventLogger.log(ScreenshotEvent.SCREENSHOT_LONG_SCREENSHOT_FAILURE, 0, mWindowOwner);
        }
        mEndFuture = mSession.end();
        mEndFuture.addListener(() -> {
            if (LogConfig.DEBUG_SCROLL) {
+3 −1
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@ import android.view.ScrollCaptureResponse;

import androidx.test.filters.SmallTest;

import com.android.internal.logging.testing.UiEventLoggerFake;
import com.android.systemui.SysuiTestCase;
import com.android.systemui.screenshot.ScrollCaptureClient.Session;

@@ -274,7 +275,8 @@ public class ScrollCaptureControllerTest extends SysuiTestCase {
            when(client.start(/* response */ any(), /* maxPages */ anyFloat()))
                    .thenReturn(immediateFuture(session));
            return new ScrollCaptureController(context, context.getMainExecutor(),
                    client, new ImageTileSet(context.getMainThreadHandler()));
                    client, new ImageTileSet(context.getMainThreadHandler()),
                    new UiEventLoggerFake());
        }
    }
}