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

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

Merge "Additional refactoring interface between component and activity."

parents c982b407 412e1805
Loading
Loading
Loading
Loading
+51 −76
Original line number Diff line number Diff line
@@ -39,6 +39,9 @@ import com.android.internal.logging.MetricsLogger;
import com.android.systemui.R;
import com.android.systemui.recents.events.EventBus;
import com.android.systemui.recents.events.activity.AppWidgetProviderChangedEvent;
import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationStartedEvent;
import com.android.systemui.recents.events.activity.HideRecentsEvent;
import com.android.systemui.recents.events.activity.ToggleRecentsEvent;
import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent;
import com.android.systemui.recents.events.component.ScreenPinningRequestEvent;
import com.android.systemui.recents.events.ui.DismissTaskEvent;
@@ -122,36 +125,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        }
    }

    /**
     * Broadcast receiver to handle messages from AlternateRecentsComponent.
     */
    final BroadcastReceiver mServiceBroadcastReceiver = new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            String action = intent.getAction();
            if (action.equals(RecentsImpl.ACTION_HIDE_RECENTS_ACTIVITY)) {
                if (intent.getBooleanExtra(RecentsImpl.EXTRA_TRIGGERED_FROM_ALT_TAB, false)) {
                    // If we are hiding from releasing Alt-Tab, dismiss Recents to the focused app
                    dismissRecentsToFocusedTaskOrHome(false);
                } else if (intent.getBooleanExtra(RecentsImpl.EXTRA_TRIGGERED_FROM_HOME_KEY, false)) {
                    // Otherwise, dismiss Recents to Home
                    dismissRecentsToHome(true);
                } else {
                    // Do nothing
                }
            } else if (action.equals(RecentsImpl.ACTION_TOGGLE_RECENTS_ACTIVITY)) {
                // If we are toggling Recents, then first unfilter any filtered stacks first
                dismissRecentsToFocusedTaskOrHome(true);
            } else if (action.equals(RecentsImpl.ACTION_START_ENTER_ANIMATION)) {
                // Trigger the enter animation
                onEnterAnimationTriggered();
                // Notify the fallback receiver that we have successfully got the broadcast
                // See AlternateRecentsComponent.onAnimationStarted()
                setResultCode(Activity.RESULT_OK);
            }
        }
    };

    /**
     * Broadcast receiver to handle messages from the system
     */
@@ -298,7 +271,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
                    null, mFinishLaunchHomeRunnable, null);
            mRecentsView.startExitToHomeAnimation(
                    new ViewAnimation.TaskViewExitContext(exitTrigger));
            mScrimViews.startExitRecentsAnimation();
        } else {
            mFinishLaunchHomeRunnable.run();
        }
@@ -377,13 +349,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        // Notify that recents is now visible
        EventBus.getDefault().send(new RecentsVisibilityChangedEvent(this, ssp, true));

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

        // Register any broadcast receivers for the task loader
        mPackageMonitor.register(this);

@@ -396,7 +361,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        boolean wasLaunchedByAm = !launchState.launchedFromHome &&
                !launchState.launchedFromAppWithThumbnail;
        if (launchState.launchedHasConfigurationChanged || wasLaunchedByAm) {
            onEnterAnimationTriggered();
            EventBus.getDefault().send(new EnterRecentsWindowAnimationStartedEvent());
        }

        if (!launchState.launchedHasConfigurationChanged) {
@@ -426,9 +391,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        // Notify the views that we are no longer visible
        mRecentsView.onRecentsHidden();

        // Unregister the RecentsService receiver
        unregisterReceiver(mServiceBroadcastReceiver);

        // Unregister any broadcast receivers for the task loader
        mPackageMonitor.unregister();

@@ -456,26 +418,16 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        EventBus.getDefault().unregister(this);
    }

    public void onEnterAnimationTriggered() {
        // Try and start the enter animation (or restart it on configuration changed)
        ReferenceCountedTrigger t = new ReferenceCountedTrigger(this, null, null, null);
        ViewAnimation.TaskViewEnterContext ctx = new ViewAnimation.TaskViewEnterContext(t);
        mRecentsView.startEnterRecentsAnimation(ctx);

        if (mSearchWidgetInfo != null) {
            ctx.postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
    @Override
                public void run() {
                    // Start listening for widget package changes if there is one bound
                    if (mAppWidgetHost != null) {
                        mAppWidgetHost.startListening();
                    }
                }
            });
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        EventBus.getDefault().register(mScrimViews, EVENT_BUS_PRIORITY);
    }

        // Animate the SystemUI scrim views
        mScrimViews.startEnterRecentsAnimation();
    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        EventBus.getDefault().unregister(mScrimViews);
    }

    @Override
@@ -545,12 +497,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView

    /**** RecentsView.RecentsViewCallbacks Implementation ****/

    @Override
    public void onExitToHomeAnimationTriggered() {
        // Animate the SystemUI scrim views out
        mScrimViews.startExitRecentsAnimation();
    }

    @Override
    public void onTaskViewClicked() {
    }
@@ -566,15 +512,6 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        mFinishLaunchHomeRunnable.run();
    }

    @Override
    public void onScreenPinningRequest() {
        RecentsTaskLoader loader = RecentsTaskLoader.getInstance();
        SystemServicesProxy ssp = loader.getSystemServicesProxy();
        EventBus.getDefault().send(new ScreenPinningRequestEvent(this, ssp));

        MetricsLogger.count(this, "overview_screen_pinned", 1);
    }

    @Override
    public void runAfterPause(Runnable r) {
        mAfterPauseRunnable = r;
@@ -582,6 +519,40 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView

    /**** EventBus events ****/

    public final void onBusEvent(ToggleRecentsEvent event) {
        dismissRecentsToFocusedTaskOrHome(true /* checkFilteredStackState */);
    }

    public final void onBusEvent(HideRecentsEvent event) {
        if (event.triggeredFromAltTab) {
            // If we are hiding from releasing Alt-Tab, dismiss Recents to the focused app
            dismissRecentsToFocusedTaskOrHome(false /* checkFilteredStackState */);
        } else if (event.triggeredFromHomeKey) {
            // Otherwise, dismiss Recents to Home
            dismissRecentsToHome(true /* checkFilteredStackState */);
        } else {
            // Do nothing
        }
    }

    public final void onBusEvent(EnterRecentsWindowAnimationStartedEvent event) {
        // Try and start the enter animation (or restart it on configuration changed)
        ReferenceCountedTrigger t = new ReferenceCountedTrigger(this, null, null, null);
        ViewAnimation.TaskViewEnterContext ctx = new ViewAnimation.TaskViewEnterContext(t);
        mRecentsView.startEnterRecentsAnimation(ctx);
        if (mSearchWidgetInfo != null) {
            ctx.postAnimationTrigger.addLastDecrementRunnable(new Runnable() {
                @Override
                public void run() {
                    // Start listening for widget package changes if there is one bound
                    if (mAppWidgetHost != null) {
                        mAppWidgetHost.startListening();
                    }
                }
            });
        }
    }

    public final void onBusEvent(AppWidgetProviderChangedEvent event) {
        refreshSearchWidgetView();
    }
@@ -625,6 +596,10 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_BEHIND);
    }

    public final void onBusEvent(ScreenPinningRequestEvent event) {
        MetricsLogger.count(this, "overview_screen_pinned", 1);
    }

    private void refreshSearchWidgetView() {
        if (mSearchWidgetInfo != null) {
            SystemServicesProxy ssp = RecentsTaskLoader.getInstance().getSystemServicesProxy();
+0 −1
Original line number Diff line number Diff line
@@ -22,7 +22,6 @@ import android.graphics.Rect;
import android.provider.Settings;
import com.android.systemui.R;
import com.android.systemui.recents.misc.SystemServicesProxy;
import com.android.systemui.recents.model.RecentsTaskLoader;

/**
 * Application resources that can be retrieved from the application context and are not specifically
+10 −55
Original line number Diff line number Diff line
@@ -16,12 +16,10 @@

package com.android.systemui.recents;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.ActivityOptions;
import android.app.ITaskStackListener;
import android.content.ActivityNotFoundException;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
@@ -39,6 +37,10 @@ import com.android.internal.logging.MetricsLogger;
import com.android.systemui.Prefs;
import com.android.systemui.R;
import com.android.systemui.SystemUIApplication;
import com.android.systemui.recents.events.EventBus;
import com.android.systemui.recents.events.activity.EnterRecentsWindowAnimationStartedEvent;
import com.android.systemui.recents.events.activity.HideRecentsEvent;
import com.android.systemui.recents.events.activity.ToggleRecentsEvent;
import com.android.systemui.recents.events.component.RecentsVisibilityChangedEvent;
import com.android.systemui.recents.events.component.ScreenPinningRequestEvent;
import com.android.systemui.recents.misc.Console;
@@ -65,14 +67,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub

    private final static String TAG = "RecentsImpl";

    final public static String EXTRA_TRIGGERED_FROM_ALT_TAB = "triggeredFromAltTab";
    final public static String EXTRA_TRIGGERED_FROM_HOME_KEY = "triggeredFromHomeKey";

    final public static String ACTION_START_ENTER_ANIMATION = "action_start_enter_animation";
    final public static String ACTION_TOGGLE_RECENTS_ACTIVITY = "action_toggle_recents_activity";
    final public static String ACTION_HIDE_RECENTS_ACTIVITY = "action_hide_recents_activity";

    final static int sMinToggleDelay = 350;
    private final static int sMinToggleDelay = 350;

    public final static String RECENTS_PACKAGE = "com.android.systemui";
    public final static String RECENTS_ACTIVITY = "com.android.systemui.recents.RecentsActivity";
@@ -256,10 +251,8 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
        if (mBootCompleted) {
            // Defer to the activity to handle hiding recents, if it handles it, then it must still
            // be visible
            Intent intent = createLocalBroadcastIntent(mContext, ACTION_HIDE_RECENTS_ACTIVITY);
            intent.putExtra(EXTRA_TRIGGERED_FROM_ALT_TAB, triggeredFromAltTab);
            intent.putExtra(EXTRA_TRIGGERED_FROM_HOME_KEY, triggeredFromHomeKey);
            mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
            EventBus.getDefault().send(new HideRecentsEvent(triggeredFromAltTab,
                    triggeredFromHomeKey));
        }
    }

@@ -281,8 +274,7 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
            MutableBoolean isTopTaskHome = new MutableBoolean(true);
            if (topTask != null && mSystemServicesProxy.isRecentsTopMost(topTask, isTopTaskHome)) {
                // Notify recents to toggle itself
                Intent intent = createLocalBroadcastIntent(mContext, ACTION_TOGGLE_RECENTS_ACTIVITY);
                mContext.sendBroadcastAsUser(intent, UserHandle.CURRENT);
                EventBus.getDefault().send(new ToggleRecentsEvent());
                mLastToggleTime = SystemClock.elapsedRealtime();
                return;
            } else {
@@ -719,51 +711,14 @@ public class RecentsImpl extends IRecentsNonSystemUserCallbacks.Stub
        mCanReuseTaskStackViews = true;
    }

    /**
     * Creates a new broadcast intent to send to the Recents activity.
     * TODO: Use EventBus
     */
    private Intent createLocalBroadcastIntent(Context context, String action) {
        Intent intent = new Intent(action);
        intent.setPackage(context.getPackageName());
        intent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY_BEFORE_BOOT |
                Intent.FLAG_RECEIVER_FOREGROUND);
        return intent;
    }

    /**** OnAnimationStartedListener Implementation ****/

    @Override
    public void onAnimationStarted() {
        // Notify recents to start the enter animation
        // TODO: Use EventBus
        if (!mStartAnimationTriggered) {
            // There can be a race condition between the start animation callback and
            // the start of the new activity (where we register the receiver that listens
            // to this broadcast, so we add our own receiver and if that gets called, then
            // we know the activity has not yet started and we can retry sending the broadcast.
            BroadcastReceiver fallbackReceiver = new BroadcastReceiver() {
                @Override
                public void onReceive(Context context, Intent intent) {
                    if (getResultCode() == Activity.RESULT_OK) {
            mStartAnimationTriggered = true;
                        return;
                    }

                    // Schedule for the broadcast to be sent again after some time
                    mHandler.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            onAnimationStarted();
                        }
                    }, 25);
                }
            };

            // Send the broadcast to notify Recents that the animation has started
            Intent intent = createLocalBroadcastIntent(mContext, ACTION_START_ENTER_ANIMATION);
            mContext.sendOrderedBroadcastAsUser(intent, UserHandle.CURRENT, null,
                    fallbackReceiver, null, Activity.RESULT_CANCELED, null, null);
            EventBus.getDefault().send(new EnterRecentsWindowAnimationStartedEvent());
        }
    }
}
+3 −3
Original line number Diff line number Diff line
@@ -16,9 +16,6 @@

package com.android.systemui.recents;

import static android.app.ActivityManager.DOCKED_STACK_ID;
import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID;

import android.app.ActivityManager;
import android.app.AlertDialog;
import android.app.Dialog;
@@ -37,6 +34,9 @@ import com.android.systemui.recents.model.RecentsTaskLoader;
import com.android.systemui.recents.model.Task;
import com.android.systemui.recents.views.RecentsView;

import static android.app.ActivityManager.DOCKED_STACK_ID;
import static android.app.ActivityManager.FREEFORM_WORKSPACE_STACK_ID;

/**
 * A helper for the dialogs that show when task debugging is on.
 */
+26 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.systemui.recents.events.activity;

import com.android.systemui.recents.events.EventBus;

/**
 * This is sent when the task animation when dismissing Recents starts.
 */
public class DismissRecentsToHomeAnimationStarted extends EventBus.Event {
    // Simple event
}
Loading