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

Commit 82d386f2 authored by Winson Chung's avatar Winson Chung Committed by Automerger Merge Worker
Browse files

Merge "8/ Updating bubbles to run on shell thread" into sc-dev am: 9330a9ac

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/13429215

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I98fbab81b462e977118754069cdb5495b41c694e
parents 264a7e92 9330a9ac
Loading
Loading
Loading
Loading
+13 −4
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import java.io.FileDescriptor;
import java.io.PrintWriter;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;

/**
 * Encapsulates the data and UI elements of a bubble.
@@ -58,6 +59,7 @@ public class Bubble implements BubbleViewProvider {
    private static final String TAG = "Bubble";

    private final String mKey;
    private final Executor mMainExecutor;

    private long mLastUpdated;
    private long mLastAccessed;
@@ -156,7 +158,8 @@ public class Bubble implements BubbleViewProvider {
     * Note: Currently this is only being used when the bubble is persisted to disk.
     */
    Bubble(@NonNull final String key, @NonNull final ShortcutInfo shortcutInfo,
            final int desiredHeight, final int desiredHeightResId, @Nullable final String title) {
            final int desiredHeight, final int desiredHeightResId, @Nullable final String title,
            Executor mainExecutor) {
        Objects.requireNonNull(key);
        Objects.requireNonNull(shortcutInfo);
        mMetadataShortcutId = shortcutInfo.getId();
@@ -170,20 +173,25 @@ public class Bubble implements BubbleViewProvider {
        mDesiredHeightResId = desiredHeightResId;
        mTitle = title;
        mShowBubbleUpdateDot = false;
        mMainExecutor = mainExecutor;
    }

    @VisibleForTesting(visibility = PRIVATE)
    Bubble(@NonNull final BubbleEntry entry,
            @Nullable final Bubbles.NotificationSuppressionChangedListener listener,
            final Bubbles.PendingIntentCanceledListener intentCancelListener) {
            final Bubbles.PendingIntentCanceledListener intentCancelListener,
            Executor mainExecutor) {
        mKey = entry.getKey();
        mSuppressionListener = listener;
        mIntentCancelListener = intent -> {
            if (mIntent != null) {
                mIntent.unregisterCancelListener(mIntentCancelListener);
            }
            mainExecutor.execute(() -> {
                intentCancelListener.onPendingIntentCanceled(this);
            });
        };
        mMainExecutor = mainExecutor;
        setEntry(entry);
    }

@@ -329,7 +337,8 @@ public class Bubble implements BubbleViewProvider {
                stackView,
                iconFactory,
                skipInflation,
                callback);
                callback,
                mMainExecutor);
        if (mInflateSynchronously) {
            mInflationTask.onPostExecute(mInflationTask.doInBackground());
        } else {
+247 −66

File changed.

Preview size limit exceeded, changes collapsed.

+7 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.function.Consumer;
import java.util.function.Predicate;

@@ -117,6 +118,7 @@ public class BubbleData {

    private final Context mContext;
    private final BubblePositioner mPositioner;
    private final Executor mMainExecutor;
    /** Bubbles that are actively in the stack. */
    private final List<Bubble> mBubbles;
    /** Bubbles that aged out to overflow. */
@@ -155,10 +157,12 @@ public class BubbleData {
     */
    private HashMap<String, String> mSuppressedGroupKeys = new HashMap<>();

    public BubbleData(Context context, BubbleLogger bubbleLogger, BubblePositioner positioner) {
    public BubbleData(Context context, BubbleLogger bubbleLogger, BubblePositioner positioner,
            Executor mainExecutor) {
        mContext = context;
        mLogger = bubbleLogger;
        mPositioner = positioner;
        mMainExecutor = mainExecutor;
        mOverflow = new BubbleOverflow(context, positioner);
        mBubbles = new ArrayList<>();
        mOverflowBubbles = new ArrayList<>();
@@ -264,7 +268,8 @@ public class BubbleData {
                bubbleToReturn = mPendingBubbles.get(key);
            } else if (entry != null) {
                // New bubble
                bubbleToReturn = new Bubble(entry, mSuppressionListener, mCancelledListener);
                bubbleToReturn = new Bubble(entry, mSuppressionListener, mCancelledListener,
                        mMainExecutor);
            } else {
                // Persisted bubble being promoted
                bubbleToReturn = persistedBubble;
+9 −4
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ import android.util.Log
import com.android.wm.shell.bubbles.storage.BubbleEntity
import com.android.wm.shell.bubbles.storage.BubblePersistentRepository
import com.android.wm.shell.bubbles.storage.BubbleVolatileRepository
import com.android.wm.shell.common.ShellExecutor
import com.android.wm.shell.common.annotations.ExternalThread
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
@@ -34,12 +36,12 @@ import kotlinx.coroutines.cancelAndJoin
import kotlinx.coroutines.launch
import kotlinx.coroutines.yield

internal class BubbleDataRepository(context: Context, private val launcherApps: LauncherApps) {
internal class BubbleDataRepository(context: Context, private val launcherApps: LauncherApps,
        private val mainExecutor : ShellExecutor) {
    private val volatileRepository = BubbleVolatileRepository(launcherApps)
    private val persistentRepository = BubblePersistentRepository(context)

    private val ioScope = CoroutineScope(Dispatchers.IO)
    private val uiScope = CoroutineScope(Dispatchers.Main)
    private var job: Job? = null

    /**
@@ -109,6 +111,8 @@ internal class BubbleDataRepository(context: Context, private val launcherApps:

    /**
     * Load bubbles from disk.
     * @param cb The callback to be run after the bubbles are loaded.  This callback is always made
     *           on the main thread of the hosting process.
     */
    @SuppressLint("WrongConstant")
    fun loadBubbles(cb: (List<Bubble>) -> Unit) = ioScope.launch {
@@ -163,10 +167,11 @@ internal class BubbleDataRepository(context: Context, private val launcherApps:
                            shortcutInfo,
                            entity.desiredHeight,
                            entity.desiredHeightResId,
                            entity.title
                            entity.title,
                            mainExecutor
                    ) }
        }
        uiScope.launch { cb(bubbles) }
        mainExecutor.execute { cb(bubbles) }
    }
}

+16 −11

File changed.

Preview size limit exceeded, changes collapsed.

Loading