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

Commit 083baf99 authored by Winson Chung's avatar Winson Chung
Browse files

Fixing a few potential crashes, preparing for Task affiliations framework changes.

- Deferring widget host listening to speed up startup
- Ensuring that we animate to the right task position in the stack and not just the front-most
- Removing assumption that we can only get screenshots for the most recent task
parent a2295e65
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -23,12 +23,10 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Handler;
import android.os.SystemClock;
import android.os.UserHandle;
import android.view.View;
import com.android.systemui.R;
@@ -317,6 +315,11 @@ public class AlternateRecentsComponent implements ActivityOptions.OnAnimationSta
    Rect getThumbnailTransitionRect(int runningTaskId) {
        // Get the stack of tasks that we are animating into
        TaskStack stack = RecentsTaskLoader.getShallowTaskStack(mSystemServicesProxy);
        if (stack.getTaskCount() == 0) {
            return new Rect();
        }

        // Get the stack
        TaskStackView tsv = new TaskStackView(mContext, stack);
        TaskStackViewLayoutAlgorithm algo = tsv.getStackAlgorithm();
        tsv.computeRects(mTaskStackBounds.width(), mTaskStackBounds.height() - mStatusBarHeight, 0, 0);
+18 −6
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.systemui.recents.views.RecentsView;
import com.android.systemui.recents.views.SystemBarScrimViews;
import com.android.systemui.recents.views.ViewAnimation;

import java.lang.ref.WeakReference;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;

@@ -125,7 +126,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        }
    }

    // Broadcast receiver to handle messages from our RecentsService
    // Broadcast receiver to handle messages from AlternateRecentsComponent
    final BroadcastReceiver mServiceBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
@@ -458,11 +459,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        filter.addAction(ACTION_START_ENTER_ANIMATION);
        registerReceiver(mServiceBroadcastReceiver, filter);

        // Start listening for widget package changes if there is one bound
        if (mConfig.searchBarAppWidgetId >= 0) {
            mAppWidgetHost.startListening(this);
        }

        mVisible = true;
    }

@@ -473,6 +469,22 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
                    Console.AnsiRed);
        }
        super.onResume();

        // Start listening for widget package changes if there is one bound, post it since we don't
        // want it stalling the startup
        if (mConfig.searchBarAppWidgetId >= 0) {
            final WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks> callback =
                    new WeakReference<RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks>(this);
            mRecentsView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    RecentsAppWidgetHost.RecentsAppWidgetHostCallbacks cb = callback.get();
                    if (cb != null) {
                        mAppWidgetHost.startListening(cb);
                    }
                }
            }, 1);
        }
    }

    @Override
+3 −3
Original line number Diff line number Diff line
@@ -396,7 +396,7 @@ public class RecentsTaskLoader {
        Resources res = context.getResources();
        ArrayList<Task> tasksToForceLoad = new ArrayList<Task>();
        TaskStack stack = new TaskStack();
        SpaceNode root = new SpaceNode(context);
        SpaceNode root = new SpaceNode();
        root.setStack(stack);

        // Get the recent tasks
@@ -428,7 +428,7 @@ public class RecentsTaskLoader {
            boolean isForemostTask = (i == (taskCount - 1));

            // Create a new task
            Task task = new Task(t.persistentId, (t.id > -1), t.baseIntent, activityLabel,
            Task task = new Task(t.persistentId, (t.id > -1), t.baseIntent, 0, activityLabel,
                    activityIcon, activityColor, t.userId, t.firstActiveTime, t.lastActiveTime);

            // Preload the specified number of apps
@@ -522,7 +522,7 @@ public class RecentsTaskLoader {
            ActivityInfo info = ssp.getActivityInfo(t.baseIntent.getComponent(), t.userId);
            if (info == null) continue;

            stack.addTask(new Task(t.persistentId, true, t.baseIntent, null, null, 0, 0,
            stack.addTask(new Task(t.persistentId, true, t.baseIntent, 0, null, null, 0, 0,
                    t.firstActiveTime, t.lastActiveTime));
        }
        stack.createSimulatedAffiliatedGroupings();
+2 −5
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.systemui.recents.model;

import android.content.Context;
import android.graphics.Rect;

import java.util.ArrayList;
@@ -35,15 +34,13 @@ public class SpaceNode {
        public void onSpaceNodeMeasured(SpaceNode node, Rect rect);
    }

    Context mContext;

    SpaceNode mStartNode;
    SpaceNode mEndNode;

    TaskStack mStack;

    public SpaceNode(Context context) {
        mContext = context;
    public SpaceNode() {
        // Do nothing
    }

    /** Sets the current stack for this space node */
+6 −4
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ public class Task {

    public TaskKey key;
    public TaskGrouping group;
    public int taskAffiliation;
    public Drawable applicationIcon;
    public Drawable activityIcon;
    public String activityLabel;
@@ -94,10 +95,11 @@ public class Task {
        // Only used by RecentsService for task rect calculations.
    }

    public Task(int id, boolean isActive, Intent intent, String activityTitle,
                Drawable activityIcon, int colorPrimary, int userId, long firstActiveTime,
                long lastActiveTime) {
    public Task(int id, boolean isActive, Intent intent, int taskAffiliation, String activityTitle,
                Drawable activityIcon, int colorPrimary, int userId,
                long firstActiveTime, long lastActiveTime) {
        this.key = new TaskKey(id, intent, userId, firstActiveTime, lastActiveTime);
        this.taskAffiliation = taskAffiliation;
        this.activityLabel = activityTitle;
        this.activityIcon = activityIcon;
        this.colorPrimary = colorPrimary;
@@ -148,7 +150,7 @@ public class Task {
    public String toString() {
        String groupAffiliation = "no group";
        if (group != null) {
            groupAffiliation = group.affiliation;
            groupAffiliation = Integer.toString(group.affiliation);
        }
        return "Task (" + groupAffiliation + "): " + key.baseIntent.getComponent().getPackageName() +
                " [" + super.toString() + "]";
Loading