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

Commit 777c82d9 authored by Matt Pietal's avatar Matt Pietal
Browse files

GlobalScreenshot - Fix race condition

It is possible for the call to system windows to occur slightly after
the ChooserActivity gets launched, therefore preventing it from ever
showing. Wait on the future before attempting to launch the activity.

Bug: 134976976
Test: Screenshot, then share over and over
Change-Id: Iba98a079412f8e35643f3a1db04e749b3c654637
parent 13ee7876
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -64,6 +64,7 @@ import com.android.systemui.shared.recents.model.ThumbnailData;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Future;
import java.util.function.Consumer;

public class ActivityManagerWrapper {
@@ -380,8 +381,8 @@ public class ActivityManagerWrapper {
    /**
     * Requests that the system close any open system windows (including other SystemUI).
     */
    public void closeSystemWindows(final String reason) {
        mBackgroundExecutor.submit(new Runnable() {
    public Future<?> closeSystemWindows(final String reason) {
        return mBackgroundExecutor.submit(new Runnable() {
            @Override
            public void run() {
                try {
+17 −2
Original line number Diff line number Diff line
@@ -92,6 +92,11 @@ import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;



/**
 * POD used in the AsyncTask which saves an image in the background.
@@ -446,6 +451,8 @@ class GlobalScreenshot {
    static final String EXTRA_CANCEL_NOTIFICATION = "android:screenshot_cancel_notification";
    static final String EXTRA_DISALLOW_ENTER_PIP = "android:screenshot_disallow_enter_pip";

    private static final String TAG = "GlobalScreenshot";

    private static final int SCREENSHOT_FLASH_TO_PEAK_DURATION = 130;
    private static final int SCREENSHOT_DROP_IN_DURATION = 430;
    private static final int SCREENSHOT_DROP_OUT_DELAY = 500;
@@ -902,11 +909,19 @@ class GlobalScreenshot {
     * appropriate signals to the system (ie. to dismiss the keyguard if necessary).
     */
    public static class ActionProxyReceiver extends BroadcastReceiver {
        static final int CLOSE_WINDOWS_TIMEOUT_MILLIS = 3000;

        @Override
        public void onReceive(Context context, final Intent intent) {
            Runnable startActivityRunnable = () -> {
                try {
                    ActivityManagerWrapper.getInstance().closeSystemWindows(
                        SYSTEM_DIALOG_REASON_SCREENSHOT);
                            SYSTEM_DIALOG_REASON_SCREENSHOT).get(
                            CLOSE_WINDOWS_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
                } catch (TimeoutException | InterruptedException | ExecutionException e) {
                    Slog.e(TAG, "Unable to share screenshot", e);
                    return;
                }

                Intent actionIntent = intent.getParcelableExtra(EXTRA_ACTION_INTENT);
                if (intent.getBooleanExtra(EXTRA_CANCEL_NOTIFICATION, false)) {