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

Commit ef3b519c authored by Matt Casey's avatar Matt Casey
Browse files

Follow-on fixes for long screenshot activity

- Add takeScrollCaptureConnection() instead of accessing the static var
    directly.
- Re-enable action buttons in the activity after export completes (fixes
    the flow where you go to share and then back out).
- Fix share intent to properly used EXTRA_STREAM.

Bug: 180756221
Bug: 180755704

Test: Take long screenshot, share and return to long screenshot
  activity, verify buttons still work. Share output to printer target,
  verify that content arrives properly.
Change-Id: I1a0b20df50e7a7b6415d623920b84b07cddb0c80
parent d2191dba
Loading
Loading
Loading
Loading
+23 −14
Original line number Original line Diff line number Diff line
@@ -46,6 +46,7 @@ public class LongScreenshotActivity extends Activity {


    private final UiEventLogger mUiEventLogger;
    private final UiEventLogger mUiEventLogger;
    private final ScrollCaptureController mScrollCaptureController;
    private final ScrollCaptureController mScrollCaptureController;
    private final ScrollCaptureClient.Connection mConnection;


    private ImageView mPreview;
    private ImageView mPreview;
    private View mSave;
    private View mSave;
@@ -69,8 +70,10 @@ public class LongScreenshotActivity extends Activity {
            Context context) {
            Context context) {
        mUiEventLogger = uiEventLogger;
        mUiEventLogger = uiEventLogger;


        mScrollCaptureController = new ScrollCaptureController(context,
        mScrollCaptureController = new ScrollCaptureController(context, mainExecutor, bgExecutor,
                ScreenshotController.sScrollConnection, mainExecutor, bgExecutor, imageExporter);
                imageExporter);

        mConnection = ScreenshotController.takeScrollCaptureConnection();
    }
    }


    @Override
    @Override
@@ -98,15 +101,20 @@ public class LongScreenshotActivity extends Activity {
    public void onStart() {
    public void onStart() {
        super.onStart();
        super.onStart();
        if (mPreview.getDrawable() == null) {
        if (mPreview.getDrawable() == null) {
            if (mConnection == null) {
                Log.e(TAG, "Failed to get scroll capture connection, bailing out");
                finishAndRemoveTask();
                return;
            }
            doCapture();
            doCapture();
        }
        }
    }
    }


    private void disableButtons() {
    private void setButtonsEnabled(boolean enabled) {
        mSave.setEnabled(false);
        mSave.setEnabled(enabled);
        mCancel.setEnabled(false);
        mCancel.setEnabled(enabled);
        mEdit.setEnabled(false);
        mEdit.setEnabled(enabled);
        mShare.setEnabled(false);
        mShare.setEnabled(enabled);
    }
    }


    private void doEdit(Uri uri) {
    private void doEdit(Uri uri) {
@@ -115,8 +123,7 @@ public class LongScreenshotActivity extends Activity {
        if (!TextUtils.isEmpty(editorPackage)) {
        if (!TextUtils.isEmpty(editorPackage)) {
            intent.setComponent(ComponentName.unflattenFromString(editorPackage));
            intent.setComponent(ComponentName.unflattenFromString(editorPackage));
        }
        }
        intent.setType("image/png");
        intent.setDataAndType(uri, "image/png");
        intent.setData(uri);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
                | Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);


@@ -127,12 +134,11 @@ public class LongScreenshotActivity extends Activity {
    private void doShare(Uri uri) {
    private void doShare(Uri uri) {
        Intent intent = new Intent(Intent.ACTION_SEND);
        Intent intent = new Intent(Intent.ACTION_SEND);
        intent.setType("image/png");
        intent.setType("image/png");
        intent.setData(uri);
        intent.putExtra(Intent.EXTRA_STREAM, uri);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
                | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                | Intent.FLAG_GRANT_READ_URI_PERMISSION);
        Intent sharingChooserIntent = Intent.createChooser(intent, null)
        Intent sharingChooserIntent = Intent.createChooser(intent, null)
                .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK
                .addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                        | Intent.FLAG_GRANT_READ_URI_PERMISSION);


        startActivityAsUser(sharingChooserIntent, UserHandle.CURRENT);
        startActivityAsUser(sharingChooserIntent, UserHandle.CURRENT);
    }
    }
@@ -140,7 +146,7 @@ public class LongScreenshotActivity extends Activity {
    private void onClicked(View v) {
    private void onClicked(View v) {
        int id = v.getId();
        int id = v.getId();
        v.setPressed(true);
        v.setPressed(true);
        disableButtons();
        setButtonsEnabled(false);
        if (id == R.id.save) {
        if (id == R.id.save) {
            startExport(PendingAction.SAVE);
            startExport(PendingAction.SAVE);
        } else if (id == R.id.cancel) {
        } else if (id == R.id.cancel) {
@@ -160,10 +166,12 @@ public class LongScreenshotActivity extends Activity {
                    @Override
                    @Override
                    public void onError() {
                    public void onError() {
                        Log.e(TAG, "Error exporting image data.");
                        Log.e(TAG, "Error exporting image data.");
                        setButtonsEnabled(true);
                    }
                    }


                    @Override
                    @Override
                    public void onExportComplete(Uri outputUri) {
                    public void onExportComplete(Uri outputUri) {
                        setButtonsEnabled(true);
                        switch (action) {
                        switch (action) {
                            case EDIT:
                            case EDIT:
                                doEdit(outputUri);
                                doEdit(outputUri);
@@ -181,7 +189,8 @@ public class LongScreenshotActivity extends Activity {
    }
    }


    private void doCapture() {
    private void doCapture() {
        mScrollCaptureController.start(new ScrollCaptureController.ScrollCaptureCallback() {
        mScrollCaptureController.start(mConnection,
                new ScrollCaptureController.ScrollCaptureCallback() {
            @Override
            @Override
            public void onError() {
            public void onError() {
                Log.e(TAG, "Error!");
                Log.e(TAG, "Error!");
+7 −1
Original line number Original line Diff line number Diff line
@@ -101,7 +101,7 @@ import javax.inject.Inject;
public class ScreenshotController {
public class ScreenshotController {
    private static final String TAG = logTag(ScreenshotController.class);
    private static final String TAG = logTag(ScreenshotController.class);


    public static ScrollCaptureClient.Connection sScrollConnection;
    private static ScrollCaptureClient.Connection sScrollConnection;


    /**
    /**
     * POD used in the AsyncTask which saves an image in the background.
     * POD used in the AsyncTask which saves an image in the background.
@@ -222,6 +222,12 @@ public class ScreenshotController {
                    | ActivityInfo.CONFIG_SCREEN_LAYOUT
                    | ActivityInfo.CONFIG_SCREEN_LAYOUT
                    | ActivityInfo.CONFIG_ASSETS_PATHS);
                    | ActivityInfo.CONFIG_ASSETS_PATHS);


    public static @Nullable ScrollCaptureClient.Connection takeScrollCaptureConnection() {
        ScrollCaptureClient.Connection connection = sScrollConnection;
        sScrollConnection = null;
        return connection;
    }

    @Inject
    @Inject
    ScreenshotController(
    ScreenshotController(
            Context context,
            Context context,
+5 −6
Original line number Original line Diff line number Diff line
@@ -53,7 +53,6 @@ public class ScrollCaptureController {


    public static final int MAX_HEIGHT = 12000;
    public static final int MAX_HEIGHT = 12000;


    private final Connection mConnection;
    private final Context mContext;
    private final Context mContext;


    private final Executor mUiExecutor;
    private final Executor mUiExecutor;
@@ -65,10 +64,9 @@ public class ScrollCaptureController {
    private UUID mRequestId;
    private UUID mRequestId;
    private ScrollCaptureCallback mCaptureCallback;
    private ScrollCaptureCallback mCaptureCallback;


    public ScrollCaptureController(Context context, Connection connection, Executor uiExecutor,
    public ScrollCaptureController(Context context, Executor uiExecutor, Executor bgExecutor,
            Executor bgExecutor, ImageExporter exporter) {
            ImageExporter exporter) {
        mContext = context;
        mContext = context;
        mConnection = connection;
        mUiExecutor = uiExecutor;
        mUiExecutor = uiExecutor;
        mBgExecutor = bgExecutor;
        mBgExecutor = bgExecutor;
        mImageExporter = exporter;
        mImageExporter = exporter;
@@ -78,16 +76,17 @@ public class ScrollCaptureController {
    /**
    /**
     * Run scroll capture!
     * Run scroll capture!
     *
     *
     * @param connection connection to the remote window to be used
     * @param callback request callback to report back to the service
     * @param callback request callback to report back to the service
     */
     */
    public void start(ScrollCaptureCallback callback) {
    public void start(Connection connection, ScrollCaptureCallback callback) {
        mCaptureTime = ZonedDateTime.now();
        mCaptureTime = ZonedDateTime.now();
        mRequestId = UUID.randomUUID();
        mRequestId = UUID.randomUUID();
        mCaptureCallback = callback;
        mCaptureCallback = callback;


        float maxPages = Settings.Secure.getFloat(mContext.getContentResolver(),
        float maxPages = Settings.Secure.getFloat(mContext.getContentResolver(),
                SETTING_KEY_MAX_PAGES, MAX_PAGES_DEFAULT);
                SETTING_KEY_MAX_PAGES, MAX_PAGES_DEFAULT);
        mConnection.start(this::startCapture, maxPages);
        connection.start(this::startCapture, maxPages);
    }
    }


    /**
    /**