Merge "Don't rely on intent to call back from activity tracker" into sc-dev am: 1b369c4763

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14909197

Change-Id: Ic05028f7cbd58bd4312b04c32f60f31ec33a1721
This commit is contained in:
Winson Chung
2021-06-15 18:16:19 +00:00
committed by Automerger Merge Worker
10 changed files with 62 additions and 60 deletions
@@ -21,6 +21,7 @@ import android.content.Intent;
import android.os.Bundle;
import com.android.launcher3.BaseActivity;
import com.android.launcher3.Launcher;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.launcher3.util.ActivityTracker;
@@ -37,7 +38,8 @@ public class HotseatEduActivity extends Activity {
.addCategory(Intent.CATEGORY_HOME)
.setPackage(getPackageName())
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
new HotseatActivityTracker<>().addToIntent(homeIntent);
Launcher.ACTIVITY_TRACKER.registerCallback(new HotseatActivityTracker());
startActivity(homeIntent);
finish();
}
@@ -349,6 +349,13 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
}
if (mActivity != null) {
if (mStateCallback.hasStates(STATE_GESTURE_COMPLETED)) {
// If the activity has restarted between setting the page scroll settling callback
// and actually receiving the callback, just mark the gesture completed
mGestureState.setState(STATE_RECENTS_SCROLLING_FINISHED);
return true;
}
// The launcher may have been recreated as a result of device rotation.
int oldState = mStateCallback.getState() & ~LAUNCHER_UI_STATES;
initStateCallbacks();
@@ -1717,13 +1724,12 @@ public abstract class AbsSwipeUpHandler<T extends StatefulActivity<S>,
/**
* Registers a callback to run when the activity is ready.
* @param intent The intent that will be used to start the activity if it doesn't exist already.
*/
public void initWhenReady(Intent intent) {
public void initWhenReady() {
// Preload the plan
RecentsModel.INSTANCE.get(mContext).getTasks(null);
mActivityInitListener.register(intent);
mActivityInitListener.register();
}
/**
@@ -184,9 +184,7 @@ public class OverviewCommandHelper {
.newHandler(gestureState, cmd.createTime);
interactionHandler.setGestureEndCallback(
() -> onTransitionComplete(cmd, interactionHandler));
Intent intent = new Intent(interactionHandler.getLaunchIntent());
interactionHandler.initWhenReady(intent);
interactionHandler.initWhenReady();
RecentsAnimationListener recentAnimListener = new RecentsAnimationListener() {
@Override
@@ -212,6 +210,7 @@ public class OverviewCommandHelper {
cmd.mActiveCallbacks.addListener(recentAnimListener);
mTaskAnimationManager.notifyRecentsAnimationState(recentAnimListener);
} else {
Intent intent = new Intent(interactionHandler.getLaunchIntent());
intent.putExtra(INTENT_EXTRA_LOG_TRACE_ID, gestureState.getGestureId());
cmd.mActiveCallbacks = mTaskAnimationManager.startRecentsAnimation(
gestureState, intent, interactionHandler);
@@ -141,7 +141,7 @@ public final class RecentsActivity extends StatefulActivity<RecentsState> {
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
ACTIVITY_TRACKER.handleNewIntent(this, intent);
ACTIVITY_TRACKER.handleNewIntent(this);
}
/**
@@ -389,8 +389,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
mInteractionHandler = mHandlerFactory.newHandler(mGestureState, touchTimeMs);
mInteractionHandler.setGestureEndCallback(this::onInteractionGestureFinished);
mMotionPauseDetector.setOnMotionPauseListener(mInteractionHandler.getMotionPauseListener());
Intent intent = new Intent(mInteractionHandler.getLaunchIntent());
mInteractionHandler.initWhenReady(intent);
mInteractionHandler.initWhenReady();
if (mTaskAnimationManager.isRecentsAnimationRunning()) {
mActiveCallbacks = mTaskAnimationManager.continueRecentsAnimation(mGestureState);
@@ -398,6 +397,7 @@ public class OtherActivityInputConsumer extends ContextWrapper implements InputC
mTaskAnimationManager.notifyRecentsAnimationState(mInteractionHandler);
notifyGestureStarted(true /*isLikelyToStartNewTask*/);
} else {
Intent intent = new Intent(mInteractionHandler.getLaunchIntent());
intent.putExtra(INTENT_EXTRA_LOG_TRACE_ID, mGestureState.getGestureId());
mActiveCallbacks = mTaskAnimationManager.startRecentsAnimation(mGestureState, intent,
mInteractionHandler);
@@ -26,7 +26,8 @@ import com.android.launcher3.util.ActivityTracker.SchedulerCallback;
import java.util.function.BiPredicate;
public class ActivityInitListener<T extends BaseActivity> implements SchedulerCallback<T> {
public class ActivityInitListener<T extends BaseActivity> implements
SchedulerCallback<T> {
private BiPredicate<T, Boolean> mOnInitListener;
private final ActivityTracker<T> mActivityTracker;
@@ -47,6 +48,7 @@ public class ActivityInitListener<T extends BaseActivity> implements SchedulerCa
@Override
public final boolean init(T activity, boolean alreadyOnHome) {
if (!mIsRegistered) {
// Don't receive any more updates
return false;
}
return handleInit(activity, alreadyOnHome);
@@ -59,18 +61,17 @@ public class ActivityInitListener<T extends BaseActivity> implements SchedulerCa
/**
* Registers the activity-created listener. If the activity is already created, then the
* callback provided in the constructor will be called synchronously.
* @param intent The intent that will be used to initialize the activity, if the activity
* doesn't already exist. We add the callback as an extra on this intent.
*/
public void register(Intent intent) {
public void register() {
mIsRegistered = true;
mActivityTracker.runCallbackWhenActivityExists(this, intent);
mActivityTracker.registerCallback(this);
}
/**
* After calling this, we won't {@link #init} even when the activity is ready.
*/
public void unregister() {
mActivityTracker.unregisterCallback(this);
mIsRegistered = false;
mOnInitListener = null;
}
@@ -82,9 +83,9 @@ public class ActivityInitListener<T extends BaseActivity> implements SchedulerCa
*/
public void registerAndStartActivity(Intent intent, RemoteAnimationProvider animProvider,
Context context, Handler handler, long duration) {
mIsRegistered = true;
register();
Bundle options = animProvider.toActivityOptions(handler, duration, context).toBundle();
context.startActivity(addToIntent(new Intent(intent)), options);
context.startActivity(new Intent(intent), options);
}
}