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

Commit 71c42508 authored by Miranda Kephart's avatar Miranda Kephart Committed by Android (Google) Code Review
Browse files

Merge "Only register receiver for the length of a screenshot" into main

parents b6336ddc ff8c76cd
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -53,8 +53,6 @@ public class ScreenshotHelper {

    public ScreenshotHelper(Context context) {
        mContext = context;
        IntentFilter filter = new IntentFilter(ACTION_USER_SWITCHED);
        mContext.registerReceiver(mBroadcastReceiver, filter, Context.RECEIVER_EXPORTED);
    }

    /**
@@ -108,6 +106,8 @@ public class ScreenshotHelper {
    public void takeScreenshotInternal(ScreenshotRequest request, @NonNull Handler handler,
            @Nullable Consumer<Uri> completionConsumer, long timeoutMs) {
        synchronized (mScreenshotLock) {
            mContext.registerReceiver(mBroadcastReceiver,
                new IntentFilter(ACTION_USER_SWITCHED), Context.RECEIVER_EXPORTED);

            final Runnable mScreenshotTimeout = () -> {
                synchronized (mScreenshotLock) {
@@ -223,6 +223,11 @@ public class ScreenshotHelper {
            mScreenshotConnection = null;
            mScreenshotService = null;
        }
        try {
            mContext.unregisterReceiver(mBroadcastReceiver);
        } catch (IllegalArgumentException e) {
            Log.w(TAG, "Attempted to remove broadcast receiver twice");
        }
    }

    /**