OSDN Git Service

Fix SysUI-Assistant metrics logging
authorGovinda Wasserman <gwasserman@google.com>
Fri, 31 May 2019 15:59:19 +0000 (11:59 -0400)
committerGovinda Wasserman <gwasserman@google.com>
Fri, 31 May 2019 22:25:20 +0000 (18:25 -0400)
Logging was broken by a refactor, this fixes it so that it works
correctly again. Also adds handle, phone state, and dismiss reason
logging to the metrics as they were never being logged.

Test: Tested locally
BUG:128982146
BUG:133407447
BUG:133247164
Change-Id: I3d925243f9826439c6acb718e8436ccdd1d27564

packages/SystemUI/src/com/android/systemui/assist/AssistHandleBehaviorController.java
packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
packages/SystemUI/src/com/android/systemui/assist/ui/DefaultUiController.java

index 01deb03..6d109fb 100644 (file)
@@ -142,6 +142,10 @@ public final class AssistHandleBehaviorController implements AssistHandleCallbac
         mHandler.post(() -> maybeShowHandles(/* ignoreThreshold = */ true));
     }
 
+    boolean areHandlesShowing() {
+        return mHandlesShowing;
+    }
+
     void onAssistantGesturePerformed() {
         mBehaviorMap.get(mCurrentBehavior).onAssistantGesturePerformed();
     }
index 2fc79d6..67fcd68 100644 (file)
@@ -104,6 +104,11 @@ public class AssistManager implements ConfigurationChangedReceiver {
     public static final int INVOCATION_TYPE_QUICK_SEARCH_BAR = 4;
     public static final int INVOCATION_HOME_BUTTON_LONG_PRESS = 5;
 
+    public static final int DISMISS_REASON_INVOCATION_CANCELLED = 1;
+    public static final int DISMISS_REASON_TAP = 2;
+    public static final int DISMISS_REASON_BACK = 3;
+    public static final int DISMISS_REASON_TIMEOUT = 4;
+
     private static final long TIMEOUT_SERVICE = 2500;
     private static final long TIMEOUT_ACTIVITY = 1000;
 
@@ -251,13 +256,14 @@ public class AssistManager implements ConfigurationChangedReceiver {
         if (invocationType == INVOCATION_TYPE_GESTURE) {
             mHandleController.onAssistantGesturePerformed();
         }
-        args.putInt(INVOCATION_PHONE_STATE_KEY, mPhoneStateMonitor.getPhoneState());
+        int phoneState = mPhoneStateMonitor.getPhoneState();
+        args.putInt(INVOCATION_PHONE_STATE_KEY, phoneState);
         args.putLong(INVOCATION_TIME_MS_KEY, SystemClock.uptimeMillis());
         // Logs assistant start with invocation type.
         MetricsLogger.action(
                 new LogMaker(MetricsEvent.ASSISTANT)
-                        .setType(MetricsEvent.TYPE_OPEN).setSubtype(
-                        invocationType));
+                        .setType(MetricsEvent.TYPE_OPEN)
+                        .setSubtype(toLoggingSubType(invocationType, phoneState)));
         startAssistInternal(args, assistComponent, isService);
     }
 
@@ -437,4 +443,19 @@ public class AssistManager implements ConfigurationChangedReceiver {
     public void onLockscreenShown() {
         mAssistUtils.onLockscreenShown();
     }
+
+    /** Returns the logging flags for the given Assistant invocation type. */
+    public int toLoggingSubType(int invocationType) {
+        return toLoggingSubType(invocationType, mPhoneStateMonitor.getPhoneState());
+    }
+
+    private int toLoggingSubType(int invocationType, int phoneState) {
+        // Note that this logic will break if the number of Assistant invocation types exceeds 7.
+        // There are currently 5 invocation types, but we will be migrating to the new logging
+        // framework in the next update.
+        int subType = mHandleController.areHandlesShowing() ? 0 : 1;
+        subType |= invocationType << 1;
+        subType |= phoneState << 4;
+        return subType;
+    }
 }
index b1be811..95c136f 100644 (file)
@@ -16,6 +16,8 @@
 
 package com.android.systemui.assist.ui;
 
+import static com.android.systemui.assist.AssistManager.DISMISS_REASON_INVOCATION_CANCELLED;
+
 import android.animation.Animator;
 import android.animation.AnimatorListenerAdapter;
 import android.animation.ValueAnimator;
@@ -91,6 +93,8 @@ public class DefaultUiController implements AssistManager.UiController {
 
     @Override // AssistManager.UiController
     public void onInvocationProgress(int type, float progress) {
+        boolean invocationWasInProgress = mInvocationInProgress;
+
         if (progress == 1) {
             animateInvocationCompletion(type, 0);
         } else if (progress == 0) {
@@ -105,16 +109,7 @@ public class DefaultUiController implements AssistManager.UiController {
         }
         mLastInvocationProgress = progress;
 
-        // Logs assistant invocation start.
-        if (!mInvocationInProgress && progress > 0.f) {
-            MetricsLogger.action(new LogMaker(MetricsEvent.ASSISTANT)
-                    .setType(MetricsEvent.TYPE_ACTION));
-        }
-        // Logs assistant invocation cancelled.
-        if (mInvocationInProgress && progress == 0f) {
-            MetricsLogger.action(new LogMaker(MetricsEvent.ASSISTANT)
-                    .setType(MetricsEvent.TYPE_DISMISS).setSubtype(0));
-        }
+        logInvocationProgressMetrics(type, progress, invocationWasInProgress);
     }
 
     @Override // AssistManager.UiController
@@ -142,6 +137,22 @@ public class DefaultUiController implements AssistManager.UiController {
         mInvocationLightsView.setColors(color1, color2, color3, color4);
     }
 
+    protected static void logInvocationProgressMetrics(
+            int type, float progress, boolean invocationWasInProgress) {
+        // Logs assistant invocation start.
+        if (!invocationWasInProgress && progress > 0.f) {
+            MetricsLogger.action(new LogMaker(MetricsEvent.ASSISTANT)
+                    .setType(MetricsEvent.TYPE_ACTION)
+                    .setSubtype(Dependency.get(AssistManager.class).toLoggingSubType(type)));
+        }
+        // Logs assistant invocation cancelled.
+        if (invocationWasInProgress && progress == 0f) {
+            MetricsLogger.action(new LogMaker(MetricsEvent.ASSISTANT)
+                    .setType(MetricsEvent.TYPE_DISMISS)
+                    .setSubtype(DISMISS_REASON_INVOCATION_CANCELLED));
+        }
+    }
+
     private void updateAssistHandleVisibility() {
         ScreenDecorations decorations = SysUiServiceProvider.getComponent(mRoot.getContext(),
                 ScreenDecorations.class);