From 979da64d8254599c332d83bf94f3f1fc3fe45fef Mon Sep 17 00:00:00 2001 From: Riddle Hsu Date: Tue, 22 Sep 2020 21:52:40 +0800 Subject: [PATCH] Add app start source info of apps launched from launcher Bug: 166614700 Test: Enable statsd log: "adb shell cmd stats print-logs" adb logcat | grep statsd | grep "(48)" The line may contain 0x100000->1[I] 0x110000->10[I] that means 1=from launcher and 10=latency 10ms. Change-Id: Iddaff7066b66e241ba58ec87129ddbe2c531dc7e (cherry picked from commit 7bdf3574a3bff06a377b4364877687bfa7619d06) --- .../com/android/launcher3/BaseQuickstepLauncher.java | 12 ++++++++++++ src/com/android/launcher3/Launcher.java | 7 ++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java index 54c2383be9..44d43c6784 100644 --- a/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java +++ b/quickstep/src/com/android/launcher3/BaseQuickstepLauncher.java @@ -26,10 +26,12 @@ import com.android.systemui.shared.system.InteractionJankMonitorWrapper; import android.animation.AnimatorSet; import android.animation.ValueAnimator; +import android.app.ActivityOptions; import android.content.Intent; import android.content.IntentSender; import android.os.Bundle; import android.os.CancellationSignal; +import android.view.View; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.model.WellbeingModel; @@ -51,6 +53,7 @@ import com.android.quickstep.util.RemoteFadeOutAnimationListener; import com.android.quickstep.views.OverviewActionsView; import com.android.quickstep.views.RecentsView; import com.android.systemui.shared.system.ActivityManagerWrapper; +import com.android.systemui.shared.system.ActivityOptionsCompat; import com.android.systemui.shared.system.RemoteAnimationTargetCompat; import java.util.stream.Stream; @@ -306,6 +309,15 @@ public abstract class BaseQuickstepLauncher extends Launcher Stream.of(WellbeingModel.SHORTCUT_FACTORY)); } + @Override + public ActivityOptions getActivityLaunchOptions(View v) { + ActivityOptions activityOptions = super.getActivityLaunchOptions(v); + if (activityOptions != null && mLastTouchUpTime > 0) { + ActivityOptionsCompat.setLauncherSourceInfo(activityOptions, mLastTouchUpTime); + } + return activityOptions; + } + public void setHintUserWillBeActive() { addActivityFlags(ACTIVITY_STATE_USER_WILL_BE_ACTIVE); } diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 4b75a33fc1..ab8d7a5a69 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -77,6 +77,7 @@ import android.os.CancellationSignal; import android.os.Parcelable; import android.os.Process; import android.os.StrictMode; +import android.os.SystemClock; import android.text.TextUtils; import android.text.method.TextKeyListener; import android.util.Log; @@ -350,7 +351,7 @@ public class Launcher extends StatefulActivity implements Launche private boolean mDeferOverlayCallbacks; private final Runnable mDeferredOverlayCallbacks = this::checkIfOverlayStillDeferred; - private long mLastTouchUpTime = -1; + protected long mLastTouchUpTime = -1; private boolean mTouchInProgress; private SafeCloseable mUserChangedCallbackCloseable; @@ -1828,7 +1829,7 @@ public class Launcher extends StatefulActivity implements Launche mTouchInProgress = true; break; case MotionEvent.ACTION_UP: - mLastTouchUpTime = System.currentTimeMillis(); + mLastTouchUpTime = ev.getEventTime(); // Follow through case MotionEvent.ACTION_CANCEL: mTouchInProgress = false; @@ -2461,7 +2462,7 @@ public class Launcher extends StatefulActivity implements Launche if (mDragController.isDragging()) { return false; } else { - return (System.currentTimeMillis() - mLastTouchUpTime) + return (SystemClock.uptimeMillis() - mLastTouchUpTime) > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); } }