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

Commit 32137e44 authored by Gustav Sennton's avatar Gustav Sennton
Browse files

Run pending-intent-sent callback on UI thread.

Before this CL the callback passed to
StatusBar.startPendingIntentDismissingKeyguard() was being run on a
background thread otherwise used to run the pending intent. This is not
obvious to the caller of startPendingIntentDismissingKeyguard(), so with
this CL we call the callback to the UI thread and make it clear that's
the case.

Bug: 120894295
Test: atest SystemUITests
Test: manual - ensure HUN is removed when pressing HUN smart action.
Change-Id: If106b697527843dd74e37d14de882d5f08187285
parent 407396e3
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -32,10 +32,11 @@ public interface ActivityStarter {
    void startPendingIntentDismissingKeyguard(PendingIntent intent);

    /**
     * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent, Runnable)}, but
     * allow you to specify the callback that is executed after the intent is sent.
     * Similar to {@link #startPendingIntentDismissingKeyguard(PendingIntent, Runnable)}, but allows
     * you to specify the callback that is executed on the UI thread after the intent is sent.
     */
    void startPendingIntentDismissingKeyguard(PendingIntent intent, Runnable intentSentCallback);
    void startPendingIntentDismissingKeyguard(PendingIntent intent,
            Runnable intentSentUiThreadCallback);
    void startActivity(Intent intent, boolean dismissShade);
    void startActivity(Intent intent, boolean onlyProvisioned, boolean dismissShade);
    void startActivity(Intent intent, boolean dismissShade, Callback callback);
+9 −3
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.os.Message;
import android.os.PowerManager;
import android.os.RemoteException;
@@ -568,6 +569,7 @@ public class StatusBar extends SystemUI implements DemoMode,
                    mEntryManager.updateNotifications();
                }
            };
    private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());

    protected DisplayManager mDisplayManager;

@@ -4353,7 +4355,7 @@ public class StatusBar extends SystemUI implements DemoMode,

    @Override
    public void startPendingIntentDismissingKeyguard(
            final PendingIntent intent, @Nullable final Runnable intentSentCallback) {
            final PendingIntent intent, @Nullable final Runnable intentSentUiThreadCallback) {
        final boolean afterKeyguardGone = intent.isActivity()
                && PreviewInflater.wouldLaunchResolverActivity(mContext, intent.getIntent(),
                mLockscreenUserManager.getCurrentUserId());
@@ -4372,12 +4374,16 @@ public class StatusBar extends SystemUI implements DemoMode,
            if (intent.isActivity()) {
                mAssistManager.hideAssist();
            }
            if (intentSentCallback != null) {
                intentSentCallback.run();
            if (intentSentUiThreadCallback != null) {
                postOnUiThread(intentSentUiThreadCallback);
            }
        }, afterKeyguardGone);
    }

    private void postOnUiThread(Runnable runnable) {
        mMainThreadHandler.post(runnable);
    }

    public static Bundle getActivityOptions(@Nullable RemoteAnimationAdapter animationAdapter) {
        ActivityOptions options;
        if (animationAdapter != null) {
+1 −9
Original line number Diff line number Diff line
@@ -16,8 +16,6 @@ import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.InsetDrawable;
import android.graphics.drawable.RippleDrawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.Layout;
import android.text.TextPaint;
import android.text.method.TransformationMethod;
@@ -65,7 +63,6 @@ public class SmartReplyView extends ViewGroup {
    private final SmartReplyConstants mConstants;
    private final KeyguardDismissUtil mKeyguardDismissUtil;
    private final NotificationRemoteInputManager mRemoteInputManager;
    private final Handler mMainThreadHandler = new Handler(Looper.getMainLooper());

    /**
     * The upper bound for the height of this view in pixels. Notifications are automatically
@@ -311,8 +308,7 @@ public class SmartReplyView extends ViewGroup {
                        () -> {
                            smartReplyController.smartActionClicked(
                                    entry, actionIndex, action, smartActions.fromAssistant);
                            postOnUiThread(() ->
                                    headsUpManager.removeNotification(entry.key, true));
                            headsUpManager.removeNotification(entry.key, true);
                        }));

        // TODO(b/119010281): handle accessibility
@@ -323,10 +319,6 @@ public class SmartReplyView extends ViewGroup {
        return button;
    }

    private void postOnUiThread(Runnable runnable) {
        mMainThreadHandler.post(runnable);
    }

    @Override
    public LayoutParams generateLayoutParams(AttributeSet attrs) {
        return new LayoutParams(mContext, attrs);