17/ Update activity tracker callback

- Immediately callback when scheduling activity tracker callback and the
  activity already exists
- Remove LauncherInitListenerEx, it was only used to update the prediction
  ui state, but not all of the callers of the launcher activity init
  listener actually needs this (ie. Go doesn't have overview predictions,
  overscroll input consumer/touch interaction service doesn't need it.)

  Instead we only call it in the places we need it LauncherSwipeHandler (for
  swipe up) and OverviewCommandHelper (for the nav bar button).

Bug: 141886704

Change-Id: I890a45e658be813e99b2a02f179fce611ede9ce8
This commit is contained in:
Winson Chung committed 2019-11-04 20:13:11 -08:00
1 parent 11aef9efdf
commit 52c57f73d2
8 files changed
+80 -44

No files matched your search

@@ -50,22 +50,41 @@ public final class ActivityTracker<T extends BaseActivity> implements Runnable {
}
}
public void schedule(SchedulerCallback<? extends T> callback) {
/**
* Schedules the callback to be notified when the activity is created.
* @return true if the activity is already created, false otherwise
*/
public boolean schedule(SchedulerCallback<? extends T> callback) {
synchronized (this) {
mPendingCallback = new WeakReference<>((SchedulerCallback<T>) callback);
}
MAIN_EXECUTOR.execute(this);
if (!notifyInitIfPending()) {
// If the activity doesn't already exist, then post and wait for the activity to start
MAIN_EXECUTOR.execute(this);
return false;
}
return true;
}
@Override
public void run() {
T activity = mCurrentActivity.get();
if (activity != null) {
initIfPending(activity, activity.isStarted());
}
notifyInitIfPending();
}
public boolean initIfPending(T activity, boolean alreadyOnHome) {
/**
* Notifies the pending callback if the activity is now created.
* @return true if the activity is now created.
*/
private boolean notifyInitIfPending() {
T activity = mCurrentActivity.get();
if (activity != null) {
notifyInitIfPending(activity, activity.isStarted());
return true;
}
return false;
}
public boolean notifyInitIfPending(T activity, boolean alreadyOnHome) {
SchedulerCallback<T> pendingCallback = mPendingCallback.get();
if (pendingCallback != null) {
if (!pendingCallback.init(activity, alreadyOnHome)) {
@@ -114,7 +133,7 @@ public final class ActivityTracker<T extends BaseActivity> implements Runnable {
}
}
if (!result && !explicitIntent) {
result = initIfPending(activity, alreadyOnHome);
result = notifyInitIfPending(activity, alreadyOnHome);
}
return result;
}