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

Commit 7b5d857e authored by Winson Chung's avatar Winson Chung Committed by Android (Google) Code Review
Browse files

Merge "Using the RecentsService connection to toggle recents"

parents edb67190 47c4c695
Loading
Loading
Loading
Loading
+41 −1
Original line number Diff line number Diff line
@@ -107,8 +107,10 @@ public class Recents extends SystemUI implements RecentsComponent {
    final static int MSG_UPDATE_TASK_THUMBNAIL = 1;
    final static int MSG_PRELOAD_TASKS = 2;
    final static int MSG_CANCEL_PRELOAD_TASKS = 3;
    final static int MSG_CLOSE_RECENTS = 4;
    final static int MSG_TOGGLE_RECENTS = 5;

    final static String sToggleRecentsAction = "com.android.systemui.recents.TOGGLE_RECENTS";
    final static String sToggleRecentsAction = "com.android.systemui.recents.SHOW_RECENTS";
    final static String sRecentsPackage = "com.android.systemui";
    final static String sRecentsActivity = "com.android.systemui.recents.RecentsActivity";
    final static String sRecentsService = "com.android.systemui.recents.RecentsService";
@@ -419,6 +421,33 @@ public class Recents extends SystemUI implements RecentsComponent {

    /** Starts the recents activity */
    void startAlternateRecentsActivity() {
        // If Recents is the front most activity, then we should just communicate with it directly
        // to launch the first task or dismiss itself
        ActivityManager am = (ActivityManager) mContext.getSystemService(Context.ACTIVITY_SERVICE);
        List<ActivityManager.RunningTaskInfo> tasks = am.getRunningTasks(1);
        if (!tasks.isEmpty()) {
            ComponentName topActivity = tasks.get(0).topActivity;
            Log.d(TAG, "[RecentsComponent|topActivity] " + topActivity);

            // Check if the front most activity is recents
            if (topActivity.getPackageName().equals(sRecentsPackage) &&
                    topActivity.getClassName().equals(sRecentsActivity)) {
                // Notify Recents to toggle itself
                try {
                    Bundle data = new Bundle();
                    Message msg = Message.obtain(null, MSG_TOGGLE_RECENTS, 0, 0);
                    msg.setData(data);
                    mService.send(msg);
                } catch (RemoteException re) {
                    re.printStackTrace();
                }
                return;
            }
        }

        // XXX: If window transitions are currently happening, then we should eat up the event here

        // Otherwise, Recents is not the front-most activity and we should animate into it
        Rect taskRect = mFirstTaskRect;
        if (taskRect != null && taskRect.width() > 0 && taskRect.height() > 0 && hasFirstTask()) {
            // Loading from thumbnail
@@ -511,6 +540,17 @@ public class Recents extends SystemUI implements RecentsComponent {
    public void closeRecents() {
        if (mUseAlternateRecents) {
            Log.d(TAG, "[RecentsComponent|closeRecents]");
            if (mServiceIsBound) {
                // Try and update the recents configuration
                try {
                    Bundle data = new Bundle();
                    Message msg = Message.obtain(null, MSG_CLOSE_RECENTS, 0, 0);
                    msg.setData(data);
                    mService.send(msg);
                } catch (RemoteException re) {
                    re.printStackTrace();
                }
            }
        } else {
            Intent intent = new Intent(RecentsActivity.CLOSE_RECENTS_INTENT);
            intent.setPackage("com.android.systemui");
+6 −7
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ public class Constants {
        public static class App {
            public static final boolean EnableTaskFiltering = false;
            public static final boolean EnableTaskStackClipping = false;
            public static final boolean EnableToggleNewRecentsActivity = false;
            // This disables the bitmap and icon caches to
            public static final boolean DisableBackgroundCache = false;

@@ -76,6 +77,8 @@ public class Constants {
                public static final int SnapScrollBackDuration = 650;
            }

            public static final int TaskStackOverscrollRange = 150;

            // The padding will be applied to the smallest dimension, and then applied to all sides
            public static final float StackPaddingPct = 0.15f;
            // The overlap height relative to the task height
@@ -91,12 +94,13 @@ public class Constants {
        public static class TaskView {
            public static class Animation {
                public static final int TaskDataUpdatedFadeDuration = 250;
                public static final int TaskIconCircularClipInDuration = 225;
                public static final int TaskIconCircularClipOutDuration = 85;
                public static final int TaskIconOnEnterDuration = 175;
                public static final int TaskIconOnLeavingDuration = 75;
            }

            public static final boolean AnimateFrontTaskIconOnEnterRecents = true;
            public static final boolean AnimateFrontTaskIconOnLeavingRecents = true;
            public static final boolean AnimateFrontTaskIconOnEnterUseClip = false;
            public static final boolean AnimateFrontTaskIconOnLeavingUseClip = false;
            public static final boolean DrawColoredTaskBars = false;
            public static final boolean UseRoundedCorners = true;
@@ -106,9 +110,4 @@ public class Constants {
            public static final float TaskIconSizeDps = 60;
        }
    }

    // UNMIGRATED CONSTANTS:

    /** Determines whether to layout the stack vertically in landscape mode */
    public static final boolean LANDSCAPE_LAYOUT_VERTICAL_STACK = true;
}
 No newline at end of file
+61 −19
Original line number Diff line number Diff line
@@ -17,27 +17,48 @@
package com.android.systemui.recents;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import com.android.systemui.recent.RecentTasksLoader;
import com.android.systemui.R;
import com.android.systemui.recents.model.SpaceNode;
import com.android.systemui.recents.model.TaskStack;
import com.android.systemui.recents.views.RecentsView;
import com.android.systemui.R;

import java.util.ArrayList;


/* Activity */
public class RecentsActivity extends Activity {
public class RecentsActivity extends Activity implements RecentsView.RecentsViewCallbacks {
    FrameLayout mContainerView;
    RecentsView mRecentsView;
    View mEmptyView;

    boolean mVisible;
    boolean mTaskLaunched;

    BroadcastReceiver mServiceBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            Console.log(Constants.DebugFlags.App.SystemUIHandshake,
                    "[RecentsActivity|serviceBroadcast]", action, Console.AnsiRed);
            if (action.equals(RecentsService.ACTION_FINISH_RECENTS_ACTIVITY)) {
                if (Constants.DebugFlags.App.EnableToggleNewRecentsActivity) {
                    finish();
                }
            } else if (action.equals(RecentsService.ACTION_TOGGLE_RECENTS_ACTIVITY)) {
                // Dismiss recents and launch the first task if possible
                dismissRecentsIfVisible();
            }
        }
    };

    /** Updates the set of recent tasks */
    void updateRecentsTasks() {
@@ -63,15 +84,13 @@ public class RecentsActivity extends Activity {
    }

    /** Dismisses recents if we are already visible and the intent is to toggle the recents view */
    boolean dismissRecentsIfVisible(Intent intent) {
        if ("com.android.systemui.recents.TOGGLE_RECENTS".equals(intent.getAction())) {
    boolean dismissRecentsIfVisible() {
        if (mVisible) {
            if (!mRecentsView.launchFirstTask()) {
                finish();
            }
            return true;
        }
        }
        return false;
    }

@@ -87,9 +106,6 @@ public class RecentsActivity extends Activity {
        RecentsTaskLoader.initialize(this);
        RecentsConfiguration.reinitialize(this);

        // Dismiss recents if it is visible and we are toggling
        if (dismissRecentsIfVisible(getIntent())) return;

        // Set the background dim
        WindowManager.LayoutParams wlp = getWindow().getAttributes();
        wlp.dimAmount = Constants.Values.Window.BackgroundDim;
@@ -98,6 +114,7 @@ public class RecentsActivity extends Activity {

        // Create the view hierarchy
        mRecentsView = new RecentsView(this);
        mRecentsView.setCallbacks(this);
        mRecentsView.setLayoutParams(new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.MATCH_PARENT));
@@ -118,13 +135,14 @@ public class RecentsActivity extends Activity {
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);

        // Reset the task launched flag if we encounter an onNewIntent() before onStop()
        mTaskLaunched = false;

        Console.logDivider(Constants.DebugFlags.App.SystemUIHandshake);
        Console.log(Constants.DebugFlags.App.SystemUIHandshake, "[RecentsActivity|onNewIntent]",
                intent.getAction() + " visible: " + mVisible, Console.AnsiRed);

        // Dismiss recents if it is visible and we are toggling
        if (dismissRecentsIfVisible(intent)) return;

        // Initialize the loader and the configuration
        RecentsTaskLoader.initialize(this);
        RecentsConfiguration.reinitialize(this);
@@ -146,6 +164,12 @@ public class RecentsActivity extends Activity {
        Console.log(Constants.DebugFlags.App.SystemUIHandshake, "[RecentsActivity|onResume]", "",
                Console.AnsiRed);
        super.onResume();

        // Register the broadcast receiver to handle messages from our service
        IntentFilter filter = new IntentFilter();
        filter.addAction(RecentsService.ACTION_TOGGLE_RECENTS_ACTIVITY);
        filter.addAction(RecentsService.ACTION_FINISH_RECENTS_ACTIVITY);
        registerReceiver(mServiceBroadcastReceiver, filter);
    }

    @Override
@@ -154,9 +178,8 @@ public class RecentsActivity extends Activity {
                Console.AnsiRed);
        super.onPause();

        // Stop the loader immediately when we leave Recents
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
        loader.stopLoader();
        // Unregister any broadcast receivers we have registered
        unregisterReceiver(mServiceBroadcastReceiver);
    }

    @Override
@@ -164,7 +187,21 @@ public class RecentsActivity extends Activity {
        Console.log(Constants.DebugFlags.App.SystemUIHandshake, "[RecentsActivity|onStop]", "",
                Console.AnsiRed);
        super.onStop();

        // Finish the current recents activity after we have launched a task
        if (mTaskLaunched && Constants.DebugFlags.App.EnableToggleNewRecentsActivity) {
            finish();
        }

        mVisible = false;
        mTaskLaunched = false;
    }

    @Override
    protected void onDestroy() {
        Console.log(Constants.DebugFlags.App.SystemUIHandshake, "[RecentsActivity|onDestroy]", "",
                Console.AnsiRed);
        super.onDestroy();
    }

    @Override
@@ -181,4 +218,9 @@ public class RecentsActivity extends Activity {
            super.onBackPressed();
        }
    }

    @Override
    public void onTaskLaunching() {
        mTaskLaunched = true;
    }
}
+60 −46
Original line number Diff line number Diff line
@@ -33,16 +33,11 @@ import com.android.systemui.recents.views.TaskViewTransform;
import java.lang.ref.WeakReference;


/* Service */
public class RecentsService extends Service {
    // XXX: This should be getting the message from recents definition
    final static int MSG_UPDATE_RECENTS_FOR_CONFIGURATION = 0;

    /** This Handler should be static to prevent holding onto a reference to the service. */
    static class MessageHandler extends Handler {
/** The message handler to process Recents SysUI messages */
class SystemUIMessageHandler extends Handler {
    WeakReference<Context> mContext;

        MessageHandler(Context context) {
    SystemUIMessageHandler(Context context) {
        // Keep a weak ref to the context instead of a strong ref
        mContext = new WeakReference<Context>(context);
    }
@@ -51,10 +46,11 @@ public class RecentsService extends Service {
    public void handleMessage(Message msg) {
        Console.log(Constants.DebugFlags.App.SystemUIHandshake,
                "[RecentsService|handleMessage]", msg);
            if (msg.what == MSG_UPDATE_RECENTS_FOR_CONFIGURATION) {

        Context context = mContext.get();
        if (context == null) return;

        if (msg.what == RecentsService.MSG_UPDATE_RECENTS_FOR_CONFIGURATION) {
            RecentsTaskLoader.initialize(context);
            RecentsConfiguration.reinitialize(context);

@@ -73,17 +69,35 @@ public class RecentsService extends Service {
                Rect taskRect = new Rect(transform.rect);

                data.putParcelable("taskRect", taskRect);
                    Message reply = Message.obtain(null, MSG_UPDATE_RECENTS_FOR_CONFIGURATION, 0, 0);
                Message reply = Message.obtain(null,
                        RecentsService.MSG_UPDATE_RECENTS_FOR_CONFIGURATION, 0, 0);
                reply.setData(data);
                msg.replyTo.send(reply);
            } catch (RemoteException re) {
                re.printStackTrace();
            }
        } else if (msg.what == RecentsService.MSG_CLOSE_RECENTS) {
            // Do nothing
        } else if (msg.what == RecentsService.MSG_TOGGLE_RECENTS) {
            // Send a broadcast to toggle recents
            Intent intent = new Intent(RecentsService.ACTION_TOGGLE_RECENTS_ACTIVITY);
            intent.setPackage(context.getPackageName());
            context.sendBroadcast(intent);
        }
    }
}

    Messenger mMessenger = new Messenger(new MessageHandler(this));
/* Service */
public class RecentsService extends Service {
    final static String ACTION_FINISH_RECENTS_ACTIVITY = "action_finish_recents_activity";
    final static String ACTION_TOGGLE_RECENTS_ACTIVITY = "action_toggle_recents_activity";

    // XXX: This should be getting the message from recents definition
    final static int MSG_UPDATE_RECENTS_FOR_CONFIGURATION = 0;
    final static int MSG_CLOSE_RECENTS = 4;
    final static int MSG_TOGGLE_RECENTS = 5;

    Messenger mSystemUIMessenger = new Messenger(new SystemUIMessageHandler(this));

    @Override
    public void onCreate() {
@@ -94,7 +108,7 @@ public class RecentsService extends Service {
    @Override
    public IBinder onBind(Intent intent) {
        Console.log(Constants.DebugFlags.App.SystemUIHandshake, "[RecentsService|onBind]");
        return mMessenger.getBinder();
        return mSystemUIMessenger.getBinder();
    }

    @Override
+2 −1
Original line number Diff line number Diff line
@@ -511,7 +511,8 @@ public class RecentsTaskLoader {

        switch (level) {
            case ComponentCallbacks2.TRIM_MEMORY_UI_HIDDEN:
                // Do nothing
                // Stop the loader immediately when the UI is no longer visible
                stopLoader();
                break;
            case ComponentCallbacks2.TRIM_MEMORY_RUNNING_MODERATE:
            case ComponentCallbacks2.TRIM_MEMORY_BACKGROUND:
Loading