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

Commit e13c17d2 authored by Joanne Chung's avatar Joanne Chung
Browse files

Add HotwordMetricsLogger for statistics logging.

This change only provide a utilility class to help hotword dection
metrics logging. The log writing will on the follow up changes.

Bug: 207717787
Test: build pass can boot success
Change-Id: If436aae1b4ebdb06c7bd5a1c0b8d6df4e94488cd
parent 1a337e9c
Loading
Loading
Loading
Loading
+69 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.server.voiceinteraction;

import com.android.internal.util.FrameworkStatsLog;

/**
 * A utility class for logging hotword statistics event.
 */
public final class HotwordMetricsLogger {

    private HotwordMetricsLogger() {
        // Class only contains static utility functions, and should not be instantiated
    }

    /**
     * Logs information related to create hotword detector.
     */
    public static void writeDetectorCreateEvent(int detectorType, boolean isCreated, int uid) {
        FrameworkStatsLog.write(FrameworkStatsLog.HOTWORD_DETECTOR_CREATE_REQUESTED, detectorType,
                isCreated, uid);
    }

    /**
     * Logs information related to hotword detection service init result.
     */
    public static void writeServiceInitResultEvent(int detectorType, int result) {
        FrameworkStatsLog.write(FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_INIT_RESULT_REPORTED,
                detectorType, result);
    }

    /**
     * Logs information related to hotword detection service restarting.
     */
    public static void writeServiceRestartEvent(int detectorType, int reason) {
        FrameworkStatsLog.write(FrameworkStatsLog.HOTWORD_DETECTION_SERVICE_RESTARTED,
                detectorType, reason);
    }

    /**
     * Logs information related to keyphrase trigger.
     */
    public static void writeKeyphraseTriggerEvent(int detectorType, int result) {
        FrameworkStatsLog.write(FrameworkStatsLog.HOTWORD_DETECTOR_KEYPHRASE_TRIGGERED,
                detectorType, result);
    }

    /**
     * Logs information related to hotword detector events.
     */
    public static void writeDetectorEvent(int detectorType, int event, int uid) {
        FrameworkStatsLog.write(FrameworkStatsLog.HOTWORD_DETECTOR_EVENTS,
                detectorType, event, uid);
    }
}