Move overview component logic from OverviewCommandHelper

OverviewCommandHelper previously managed both updating the current
overview component and interfacing inputs to switch to the
overview activity. This CL splits out the former to a separate
class so that the responsibilities are more focused and the code
can be reused more easily.

Test: Manual test NexusLauncher, Launcher3QuickStepGo by switching to
overview
Change-Id: I4e90918703f351d235f3cb0a45079cbb31b753ab
This commit is contained in:
Kevin 2019-01-25 14:22:18 -08:00
parent 57f88bd0ec
commit 2a9e3a66bc
3 changed files with 180 additions and 121 deletions

View File

@ -15,17 +15,11 @@
*/
package com.android.quickstep;
import static android.content.Intent.ACTION_PACKAGE_ADDED;
import static android.content.Intent.ACTION_PACKAGE_CHANGED;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
import static com.android.launcher3.anim.Interpolators.FAST_OUT_SLOW_IN;
import static com.android.launcher3.anim.Interpolators.TOUCH_RESPONSE_INTERPOLATOR;
import static com.android.quickstep.TouchConsumer.INTERACTION_NORMAL;
import static com.android.systemui.shared.system.ActivityManagerWrapper
.CLOSE_SYSTEM_WINDOWS_REASON_RECENTS;
import static com.android.systemui.shared.system.PackageManagerWrapper
.ACTION_PREFERRED_ACTIVITY_CHANGED;
import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_CLOSING;
import static com.android.systemui.shared.system.RemoteAnimationTargetCompat.MODE_OPENING;
@ -33,15 +27,9 @@ import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ResolveInfo;
import android.graphics.Rect;
import android.os.Build;
import android.os.PatternMatcher;
import android.os.SystemClock;
import android.util.Log;
import android.view.View;
@ -56,21 +44,16 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
import com.android.quickstep.ActivityControlHelper.ActivityInitListener;
import com.android.quickstep.ActivityControlHelper.AnimationFactory;
import com.android.quickstep.ActivityControlHelper.FallbackActivityControllerHelper;
import com.android.quickstep.ActivityControlHelper.LauncherActivityControllerHelper;
import com.android.quickstep.util.ClipAnimationHelper;
import com.android.quickstep.util.TransformedRect;
import com.android.quickstep.util.RemoteAnimationTargetSet;
import com.android.quickstep.util.TransformedRect;
import com.android.quickstep.views.RecentsView;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.LatencyTrackerCompat;
import com.android.systemui.shared.system.PackageManagerWrapper;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat;
import com.android.systemui.shared.system.TransactionCompat;
import java.util.ArrayList;
/**
* Helper class to handle various atomic commands for switching between Overview.
*/
@ -85,100 +68,16 @@ public class OverviewCommandHelper {
private final ActivityManagerWrapper mAM;
private final RecentsModel mRecentsModel;
private final MainThreadExecutor mMainThreadExecutor;
private final ComponentName mMyHomeComponent;
private final BroadcastReceiver mUserPreferenceChangeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
initOverviewTargets();
}
};
private final BroadcastReceiver mOtherHomeAppUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
initOverviewTargets();
}
};
private String mUpdateRegisteredPackage;
public Intent overviewIntent;
public ComponentName overviewComponent;
private ActivityControlHelper mActivityControlHelper;
private final OverviewComponentObserver mOverviewComponentObserver;
private long mLastToggleTime;
public OverviewCommandHelper(Context context) {
public OverviewCommandHelper(Context context, OverviewComponentObserver observer) {
mContext = context;
mAM = ActivityManagerWrapper.getInstance();
mMainThreadExecutor = new MainThreadExecutor();
mRecentsModel = RecentsModel.INSTANCE.get(mContext);
Intent myHomeIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME)
.setPackage(mContext.getPackageName());
ResolveInfo info = context.getPackageManager().resolveActivity(myHomeIntent, 0);
mMyHomeComponent = new ComponentName(context.getPackageName(), info.activityInfo.name);
mContext.registerReceiver(mUserPreferenceChangeReceiver,
new IntentFilter(ACTION_PREFERRED_ACTIVITY_CHANGED));
initOverviewTargets();
}
private void initOverviewTargets() {
ComponentName defaultHome = PackageManagerWrapper.getInstance()
.getHomeActivities(new ArrayList<>());
final String overviewIntentCategory;
if (defaultHome == null || mMyHomeComponent.equals(defaultHome)) {
// User default home is same as out home app. Use Overview integrated in Launcher.
overviewComponent = mMyHomeComponent;
mActivityControlHelper = new LauncherActivityControllerHelper();
overviewIntentCategory = Intent.CATEGORY_HOME;
if (mUpdateRegisteredPackage != null) {
// Remove any update listener as we don't care about other packages.
mContext.unregisterReceiver(mOtherHomeAppUpdateReceiver);
mUpdateRegisteredPackage = null;
}
} else {
// The default home app is a different launcher. Use the fallback Overview instead.
overviewComponent = new ComponentName(mContext, RecentsActivity.class);
mActivityControlHelper = new FallbackActivityControllerHelper(defaultHome);
overviewIntentCategory = Intent.CATEGORY_DEFAULT;
// User's default home app can change as a result of package updates of this app (such
// as uninstalling the app or removing the "Launcher" feature in an update).
// Listen for package updates of this app (and remove any previously attached
// package listener).
if (!defaultHome.getPackageName().equals(mUpdateRegisteredPackage)) {
if (mUpdateRegisteredPackage != null) {
mContext.unregisterReceiver(mOtherHomeAppUpdateReceiver);
}
mUpdateRegisteredPackage = defaultHome.getPackageName();
IntentFilter updateReceiver = new IntentFilter(ACTION_PACKAGE_ADDED);
updateReceiver.addAction(ACTION_PACKAGE_CHANGED);
updateReceiver.addAction(ACTION_PACKAGE_REMOVED);
updateReceiver.addDataScheme("package");
updateReceiver.addDataSchemeSpecificPart(mUpdateRegisteredPackage,
PatternMatcher.PATTERN_LITERAL);
mContext.registerReceiver(mOtherHomeAppUpdateReceiver, updateReceiver);
}
}
overviewIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(overviewIntentCategory)
.setComponent(overviewComponent)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
public void onDestroy() {
mContext.unregisterReceiver(mUserPreferenceChangeReceiver);
if (mUpdateRegisteredPackage != null) {
mContext.unregisterReceiver(mOtherHomeAppUpdateReceiver);
mUpdateRegisteredPackage = null;
}
mOverviewComponentObserver = observer;
}
public void onOverviewToggle() {
@ -200,10 +99,6 @@ public class OverviewCommandHelper {
UserEventDispatcher.newInstance(mContext).logActionTip(actionType, viewType));
}
public ActivityControlHelper getActivityControlHelper() {
return mActivityControlHelper;
}
private class ShowRecentsCommand extends RecentsActivityCommand {
@Override
@ -225,7 +120,7 @@ public class OverviewCommandHelper {
private boolean mUserEventLogged;
public RecentsActivityCommand() {
mHelper = getActivityControlHelper();
mHelper = mOverviewComponentObserver.getActivityControlHelper();
mCreateTime = SystemClock.elapsedRealtime();
mRunningTaskId = RecentsModel.getRunningTaskId();
@ -242,8 +137,10 @@ public class OverviewCommandHelper {
// Start overview
if (!mHelper.switchToRecentsIfVisible(true)) {
mListener = mHelper.createActivityInitListener(this::onActivityReady);
mListener.registerAndStartActivity(overviewIntent, this::createWindowAnimation,
mContext, mMainThreadExecutor.getHandler(), RECENTS_LAUNCH_DURATION);
mListener.registerAndStartActivity(
mOverviewComponentObserver.getOverviewIntent(),
this::createWindowAnimation, mContext, mMainThreadExecutor.getHandler(),
RECENTS_LAUNCH_DURATION);
}
}
}

View File

@ -0,0 +1,159 @@
/*
* Copyright (C) 2019 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.quickstep;
import static android.content.Intent.ACTION_PACKAGE_ADDED;
import static android.content.Intent.ACTION_PACKAGE_CHANGED;
import static android.content.Intent.ACTION_PACKAGE_REMOVED;
import static com.android.systemui.shared.system.PackageManagerWrapper
.ACTION_PREFERRED_ACTIVITY_CHANGED;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ResolveInfo;
import android.os.PatternMatcher;
import com.android.quickstep.ActivityControlHelper.FallbackActivityControllerHelper;
import com.android.quickstep.ActivityControlHelper.LauncherActivityControllerHelper;
import com.android.systemui.shared.system.PackageManagerWrapper;
import java.util.ArrayList;
/**
* Class to keep track of the current overview component based off user preferences and app updates
* and provide callers the relevant classes.
*/
public final class OverviewComponentObserver {
private final BroadcastReceiver mUserPreferenceChangeReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateOverviewTargets();
}
};
private final BroadcastReceiver mOtherHomeAppUpdateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
updateOverviewTargets();
}
};
private final Context mContext;
private final ComponentName mMyHomeComponent;
private String mUpdateRegisteredPackage;
private ActivityControlHelper mActivityControlHelper;
private Intent mOverviewIntent;
public OverviewComponentObserver(Context context) {
mContext = context;
Intent myHomeIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(Intent.CATEGORY_HOME)
.setPackage(mContext.getPackageName());
ResolveInfo info = context.getPackageManager().resolveActivity(myHomeIntent, 0);
mMyHomeComponent = new ComponentName(context.getPackageName(), info.activityInfo.name);
mContext.registerReceiver(mUserPreferenceChangeReceiver,
new IntentFilter(ACTION_PREFERRED_ACTIVITY_CHANGED));
updateOverviewTargets();
}
/**
* Update overview intent and {@link ActivityControlHelper} based off the current launcher home
* component.
*/
private void updateOverviewTargets() {
ComponentName defaultHome = PackageManagerWrapper.getInstance()
.getHomeActivities(new ArrayList<>());
final String overviewIntentCategory;
ComponentName overviewComponent;
if (defaultHome == null || mMyHomeComponent.equals(defaultHome)) {
// User default home is same as out home app. Use Overview integrated in Launcher.
overviewComponent = mMyHomeComponent;
mActivityControlHelper = new LauncherActivityControllerHelper();
overviewIntentCategory = Intent.CATEGORY_HOME;
if (mUpdateRegisteredPackage != null) {
// Remove any update listener as we don't care about other packages.
mContext.unregisterReceiver(mOtherHomeAppUpdateReceiver);
mUpdateRegisteredPackage = null;
}
} else {
// The default home app is a different launcher. Use the fallback Overview instead.
overviewComponent = new ComponentName(mContext, RecentsActivity.class);
mActivityControlHelper = new FallbackActivityControllerHelper(defaultHome);
overviewIntentCategory = Intent.CATEGORY_DEFAULT;
// User's default home app can change as a result of package updates of this app (such
// as uninstalling the app or removing the "Launcher" feature in an update).
// Listen for package updates of this app (and remove any previously attached
// package listener).
if (!defaultHome.getPackageName().equals(mUpdateRegisteredPackage)) {
if (mUpdateRegisteredPackage != null) {
mContext.unregisterReceiver(mOtherHomeAppUpdateReceiver);
}
mUpdateRegisteredPackage = defaultHome.getPackageName();
IntentFilter updateReceiver = new IntentFilter(ACTION_PACKAGE_ADDED);
updateReceiver.addAction(ACTION_PACKAGE_CHANGED);
updateReceiver.addAction(ACTION_PACKAGE_REMOVED);
updateReceiver.addDataScheme("package");
updateReceiver.addDataSchemeSpecificPart(mUpdateRegisteredPackage,
PatternMatcher.PATTERN_LITERAL);
mContext.registerReceiver(mOtherHomeAppUpdateReceiver, updateReceiver);
}
}
mOverviewIntent = new Intent(Intent.ACTION_MAIN)
.addCategory(overviewIntentCategory)
.setComponent(overviewComponent)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
}
/**
* Clean up any registered receivers.
*/
public void onDestroy() {
mContext.unregisterReceiver(mUserPreferenceChangeReceiver);
if (mUpdateRegisteredPackage != null) {
mContext.unregisterReceiver(mOtherHomeAppUpdateReceiver);
mUpdateRegisteredPackage = null;
}
}
/**
* Get the current intent for going to the overview activity.
*
* @return the overview intent
*/
public Intent getOverviewIntent() {
return mOverviewIntent;
}
/**
* Get the current activity control helper for managing interactions to the overview activity.
*
* @return the current activity control helper
*/
public ActivityControlHelper getActivityControlHelper() {
return mActivityControlHelper;
}
}

View File

@ -183,6 +183,7 @@ public class TouchInteractionService extends Service {
private MainThreadExecutor mMainThreadExecutor;
private ISystemUiProxy mISystemUiProxy;
private OverviewCommandHelper mOverviewCommandHelper;
private OverviewComponentObserver mOverviewComponentObserver;
private OverviewInteractionState mOverviewInteractionState;
private OverviewCallbacks mOverviewCallbacks;
private TaskOverlayFactory mTaskOverlayFactory;
@ -198,7 +199,8 @@ public class TouchInteractionService extends Service {
mAM = ActivityManagerWrapper.getInstance();
mRecentsModel = RecentsModel.INSTANCE.get(this);
mMainThreadExecutor = new MainThreadExecutor();
mOverviewCommandHelper = new OverviewCommandHelper(this);
mOverviewComponentObserver = new OverviewComponentObserver(this);
mOverviewCommandHelper = new OverviewCommandHelper(this, mOverviewComponentObserver);
mMainThreadChoreographer = Choreographer.getInstance();
mEventQueue = new MotionEventQueue(mMainThreadChoreographer, TouchConsumer.NO_OP);
mOverviewInteractionState = OverviewInteractionState.INSTANCE.get(this);
@ -218,7 +220,7 @@ public class TouchInteractionService extends Service {
@Override
public void onDestroy() {
mInputConsumer.unregisterInputConsumer();
mOverviewCommandHelper.onDestroy();
mOverviewComponentObserver.onDestroy();
sConnected = false;
super.onDestroy();
}
@ -250,21 +252,22 @@ public class TouchInteractionService extends Service {
if (runningTaskInfo == null && !forceToLauncher) {
return TouchConsumer.NO_OP;
} else if (forceToLauncher ||
mOverviewCommandHelper.getActivityControlHelper().isResumed()) {
mOverviewComponentObserver.getActivityControlHelper().isResumed()) {
return OverviewTouchConsumer.newInstance(
mOverviewCommandHelper.getActivityControlHelper(), false, mTouchInteractionLog);
mOverviewComponentObserver.getActivityControlHelper(), false,
mTouchInteractionLog);
} else if (ENABLE_QUICKSTEP_LIVE_TILE.get() &&
mOverviewCommandHelper.getActivityControlHelper().isInLiveTileMode()) {
mOverviewComponentObserver.getActivityControlHelper().isInLiveTileMode()) {
return OverviewTouchConsumer.newInstance(
mOverviewCommandHelper.getActivityControlHelper(), false, mTouchInteractionLog,
false /* waitForWindowAvailable */);
mOverviewComponentObserver.getActivityControlHelper(), false,
mTouchInteractionLog, false /* waitForWindowAvailable */);
} else {
if (tracker == null) {
tracker = VelocityTracker.obtain();
}
return new OtherActivityTouchConsumer(this, runningTaskInfo, mRecentsModel,
mOverviewCommandHelper.overviewIntent,
mOverviewCommandHelper.getActivityControlHelper(), mMainThreadExecutor,
mOverviewComponentObserver.getOverviewIntent(),
mOverviewComponentObserver.getActivityControlHelper(), mMainThreadExecutor,
mBackgroundThreadChoreographer, downHitTarget, mOverviewCallbacks,
mTaskOverlayFactory, mInputConsumer, tracker, mTouchInteractionLog);
}