Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit cafe1949 authored by Govinda Wasserman's avatar Govinda Wasserman Committed by Automerger Merge Worker
Browse files

Merge "Adds Assistant invocation logging to statsd" into rvc-dev am: a4939de5

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11325798

Change-Id: Ibfcf3d988d88cf9b42e44a17f90117f90dbf4704
parents efaefd9b a4939de5
Loading
Loading
Loading
Loading
+40 −0
Original line number Diff line number Diff line
@@ -449,6 +449,7 @@ message Atom {
        TvTunerDvrStatus tv_tuner_dvr_status = 279 [(module) = "framework"];
        TvCasSessionOpenStatus tv_cas_session_open_status =
            280 [(module) = "framework"];
        AssistantInvocationReported assistant_invocation_reported = 281 [(module) = "framework"];

        // StatsdStats tracks platform atoms with ids upto 500.
        // Update StatsdStats::kMaxPushedAtomId when atom ids here approach that value.
@@ -9995,3 +9996,42 @@ message MediaOutputOpSwitchReported {
    // The amount of applied devices within a remote dynamic group after a switching is done.
    optional int32 applied_device_count_within_remote_group = 9;
}

/**
 * Logs when the Assistant is invoked.
 *
 * Logged from:
 *   frameworks/base/packages/SystemUI/src/com/android/systemui/assist/AssistManager.java
 */
message AssistantInvocationReported {

    // The event_id (as for UiEventReported).
    optional int32 event_id = 1;

    // The registered Assistant's uid and package (as for UiEventReported).
    optional int32 uid = 2 [(is_uid) = true];
    optional string package_name = 3;

    // An identifier used to disambiguate which logs refer to a particular invocation of the
    // Assistant  (as for UiEventReported).
    optional int32 instance_id = 4;

    // The state of the device at the time of invocation.
    enum DeviceState {
        UNKNOWN_DEVICE_STATE = 0;
        AOD1 = 1;
        AOD2 = 2;
        BOUNCER = 3;
        UNLOCKED_LOCKSCREEN = 4;
        LAUNCHER_HOME = 5;
        LAUNCHER_OVERVIEW = 6;
        LAUNCHER_ALL_APPS = 7;
        APP_DEFAULT = 8;
        APP_IMMERSIVE = 9;
        APP_FULLSCREEN = 10;
    }
    optional DeviceState device_state = 5;

    // Whether the Assistant handles were showing at the time of invocation.
    optional bool assistant_handles_showing = 6;
}
+37 −2
Original line number Diff line number Diff line
@@ -40,8 +40,11 @@ import android.widget.ImageView;
import com.android.internal.app.AssistUtils;
import com.android.internal.app.IVoiceInteractionSessionListener;
import com.android.internal.app.IVoiceInteractionSessionShowCallback;
import com.android.internal.logging.InstanceId;
import com.android.internal.logging.InstanceIdSequence;
import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.internal.util.FrameworkStatsLog;
import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.settingslib.applications.InterestingConfigChanges;
import com.android.systemui.R;
@@ -121,6 +124,7 @@ public class AssistManager {

    private static final long TIMEOUT_SERVICE = 2500;
    private static final long TIMEOUT_ACTIVITY = 1000;
    private static final int INSTANCE_ID_MAX = 1 << 20;

    protected final Context mContext;
    private final WindowManager mWindowManager;
@@ -130,6 +134,8 @@ public class AssistManager {
    private final AssistHandleBehaviorController mHandleController;
    private final UiController mUiController;
    protected final Lazy<SysUiState> mSysUiState;
    protected final InstanceIdSequence mInstanceIdSequence =
            new InstanceIdSequence(INSTANCE_ID_MAX);

    private AssistOrbContainer mView;
    private final DeviceProvisionedController mDeviceProvisionedController;
@@ -299,7 +305,8 @@ public class AssistManager {
        int phoneState = mPhoneStateMonitor.getPhoneState();
        args.putInt(INVOCATION_PHONE_STATE_KEY, phoneState);
        args.putLong(INVOCATION_TIME_MS_KEY, SystemClock.elapsedRealtime());
        logStartAssist(invocationType, phoneState);
        logStartAssist(/* instanceId = */ null, invocationType, phoneState);
        logStartAssistLegacy(invocationType, phoneState);
        startAssistInternal(args, assistComponent, isService);
    }

@@ -499,7 +506,35 @@ public class AssistManager {
        return toLoggingSubType(invocationType, mPhoneStateMonitor.getPhoneState());
    }

    protected void logStartAssist(int invocationType, int phoneState) {
    protected void logStartAssist(
            @Nullable InstanceId instanceId, int invocationType, int deviceState) {
        InstanceId currentInstanceId =
                instanceId == null ? mInstanceIdSequence.newInstanceId() : instanceId;
        ComponentName assistantComponent =
                mAssistUtils.getAssistComponentForUser(UserHandle.USER_CURRENT);
        int assistantUid = 0;
        try {
            assistantUid =
                    mContext.getPackageManager()
                            .getApplicationInfo(
                                    assistantComponent.getPackageName(),
                                    /* flags = */ 0)
                            .uid;
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "Unable to find Assistant UID", e);
        }

        FrameworkStatsLog.write(
                FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED,
                AssistantInvocationEvent.Companion.eventIdFromLegacyInvocationType(invocationType),
                assistantUid,
                assistantComponent.flattenToString(),
                currentInstanceId.getId(),
                AssistantInvocationEvent.Companion.deviceStateFromLegacyDeviceState(deviceState),
                mHandleController.areHandlesShowing());
    }

    protected void logStartAssistLegacy(int invocationType, int phoneState) {
        MetricsLogger.action(
                new LogMaker(MetricsEvent.ASSISTANT)
                        .setType(MetricsEvent.TYPE_OPEN)
+119 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.systemui.assist

import com.android.internal.logging.UiEvent
import com.android.internal.logging.UiEventLogger
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__AOD1
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__AOD2
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__APP_DEFAULT
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__APP_FULLSCREEN
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__APP_IMMERSIVE
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__BOUNCER
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__LAUNCHER_ALL_APPS
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__LAUNCHER_HOME
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__LAUNCHER_OVERVIEW
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__UNKNOWN_DEVICE_STATE
import com.android.internal.util.FrameworkStatsLog.ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__UNLOCKED_LOCKSCREEN

enum class AssistantInvocationEvent(private val id: Int) : UiEventLogger.UiEventEnum {
    @UiEvent(doc = "Assistant invoked by unknown method")
    ASSISTANT_INVOCATION_UNKNOWN(442),

    @UiEvent(doc = "Assistant invoked by touch gesture")
    ASSISTANT_INVOCATION_TOUCH_GESTURE(443),

    @UiEvent(doc = "Assistant invoked by alternate touch gesture")
    ASSISTANT_INVOCATION_TOUCH_GESTURE_ALT(444),

    @UiEvent(doc = "Assistant invoked by hotword")
    ASSISTANT_INVOCATION_HOTWORD(445),

    @UiEvent(doc = "Assistant invoked by tapping quick search bar icon")
    ASSISTANT_INVOCATION_QUICK_SEARCH_BAR(446),

    @UiEvent(doc = "Assistant invoked by home button long press")
    ASSISTANT_INVOCATION_HOME_LONG_PRESS(447),

    @UiEvent(doc = "Assistant invoked by physical gesture")
    ASSISTANT_INVOCATION_PHYSICAL_GESTURE(448);

    override fun getId(): Int {
        return id
    }

    companion object {
        fun eventIdFromLegacyInvocationType(legacyInvocationType: Int): Int {
            return when (legacyInvocationType) {
                AssistManager.INVOCATION_TYPE_GESTURE ->
                    ASSISTANT_INVOCATION_TOUCH_GESTURE

                AssistManager.INVOCATION_TYPE_OTHER ->
                    ASSISTANT_INVOCATION_PHYSICAL_GESTURE

                AssistManager.INVOCATION_TYPE_VOICE ->
                    ASSISTANT_INVOCATION_HOTWORD

                AssistManager.INVOCATION_TYPE_QUICK_SEARCH_BAR ->
                    ASSISTANT_INVOCATION_QUICK_SEARCH_BAR

                AssistManager.INVOCATION_HOME_BUTTON_LONG_PRESS ->
                    ASSISTANT_INVOCATION_HOME_LONG_PRESS

                else ->
                    ASSISTANT_INVOCATION_UNKNOWN
            }.id
        }

        fun deviceStateFromLegacyDeviceState(legacyDeviceState: Int): Int {
            return when (legacyDeviceState) {
                PhoneStateMonitor.PHONE_STATE_AOD1 ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__AOD1

                PhoneStateMonitor.PHONE_STATE_AOD2 ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__AOD2

                PhoneStateMonitor.PHONE_STATE_BOUNCER ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__BOUNCER

                PhoneStateMonitor.PHONE_STATE_UNLOCKED_LOCKSCREEN ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__UNLOCKED_LOCKSCREEN

                PhoneStateMonitor.PHONE_STATE_HOME ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__LAUNCHER_HOME

                PhoneStateMonitor.PHONE_STATE_OVERVIEW ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__LAUNCHER_OVERVIEW

                PhoneStateMonitor.PHONE_STATE_ALL_APPS ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__LAUNCHER_ALL_APPS

                PhoneStateMonitor.PHONE_STATE_APP_DEFAULT ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__APP_DEFAULT

                PhoneStateMonitor.PHONE_STATE_APP_IMMERSIVE ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__APP_IMMERSIVE

                PhoneStateMonitor.PHONE_STATE_APP_FULLSCREEN ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__APP_FULLSCREEN

                else ->
                    ASSISTANT_INVOCATION_REPORTED__DEVICE_STATE__UNKNOWN_DEVICE_STATE
            }
        }
    }
}
 No newline at end of file
+10 −10
Original line number Diff line number Diff line
@@ -50,16 +50,16 @@ import dagger.Lazy;
@Singleton
public final class PhoneStateMonitor {

    private static final int PHONE_STATE_AOD1 = 1;
    private static final int PHONE_STATE_AOD2 = 2;
    private static final int PHONE_STATE_BOUNCER = 3;
    private static final int PHONE_STATE_UNLOCKED_LOCKSCREEN = 4;
    private static final int PHONE_STATE_HOME = 5;
    private static final int PHONE_STATE_OVERVIEW = 6;
    private static final int PHONE_STATE_ALL_APPS = 7;
    private static final int PHONE_STATE_APP_DEFAULT = 8;
    private static final int PHONE_STATE_APP_IMMERSIVE = 9;
    private static final int PHONE_STATE_APP_FULLSCREEN = 10;
    public static final int PHONE_STATE_AOD1 = 1;
    public static final int PHONE_STATE_AOD2 = 2;
    public static final int PHONE_STATE_BOUNCER = 3;
    public static final int PHONE_STATE_UNLOCKED_LOCKSCREEN = 4;
    public static final int PHONE_STATE_HOME = 5;
    public static final int PHONE_STATE_OVERVIEW = 6;
    public static final int PHONE_STATE_ALL_APPS = 7;
    public static final int PHONE_STATE_APP_DEFAULT = 8;
    public static final int PHONE_STATE_APP_IMMERSIVE = 9;
    public static final int PHONE_STATE_APP_FULLSCREEN = 10;

    private static final String[] DEFAULT_HOME_CHANGE_ACTIONS = new String[] {
            PackageManagerWrapper.ACTION_PREFERRED_ACTIVITY_CHANGED,