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

Commit b2b84372 authored by Fan Zhang's avatar Fan Zhang
Browse files

Add a new logger for StatsLog

Bug: 117860032
Test: robotests
Change-Id: I4f3f5b1fb47df9427140a22f1e78126ad391ff68
parent 367f122d
Loading
Loading
Loading
Loading
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.settings.core.instrumentation;

import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;

public class SettingsMetricsFeatureProvider extends MetricsFeatureProvider {
    @Override
    protected void installLogWriters() {
        super.installLogWriters();
        mLoggerWriters.add(new StatsLogWriter());
    }
}
+118 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 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.settings.core.instrumentation;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.util.Pair;
import android.util.StatsLog;

import com.android.settingslib.core.instrumentation.LogWriter;

public class StatsLogWriter implements LogWriter {

    @Override
    public void visible(Context context, int attribution, int pageId) {
        StatsLog.write(StatsLog.SETTINGS_UI_CHANGED /* Atom name */,
                attribution,
                SettingsEnums.PAGE_VISIBLE /* action */,
                pageId,
                null /* changedPreferenceKey */,
                0 /* changedPreferenceIntValue */);
    }

    @Override
    public void hidden(Context context, int pageId) {
        StatsLog.write(StatsLog.SETTINGS_UI_CHANGED /* Atom name */,
                SettingsEnums.PAGE_UNKNOWN /* attribution */,
                SettingsEnums.PAGE_HIDE /* action */,
                pageId,
                null /* changedPreferenceKey */,
                0 /* changedPreferenceIntValue */);
    }

    @Override
    public void action(int category, int value, Pair<Integer, Object>... taggedData) {

    }

    @Override
    public void action(int category, boolean value, Pair<Integer, Object>... taggedData) {

    }

    @Override
    public void action(Context context, int action, Pair<Integer, Object>... taggedData) {
        action(SettingsEnums.PAGE_UNKNOWN /* attribution */,
                action,
                SettingsEnums.PAGE_UNKNOWN /* pageId */,
                null /* changedPreferenceKey */,
                0 /* changedPreferenceIntValue */);
    }

    @Override
    public void actionWithSource(Context context, int pageId, int action) {
        action(SettingsEnums.PAGE_UNKNOWN /* attribution */,
                action,
                pageId /* pageId */,
                null /* changedPreferenceKey */,
                0 /* changedPreferenceIntValue */);
    }

    @Override
    public void action(Context context, int action, int value) {
        action(SettingsEnums.PAGE_UNKNOWN /* attribution */,
                action,
                SettingsEnums.PAGE_UNKNOWN /* pageId */,
                null /* changedPreferenceKey */,
                value /* changedPreferenceIntValue */);
    }

    @Override
    public void action(Context context, int action, boolean value) {
        action(SettingsEnums.PAGE_UNKNOWN /* attribution */,
                action,
                SettingsEnums.PAGE_UNKNOWN /* pageId */,
                null /* changedPreferenceKey */,
                value ? 1 : 0 /* changedPreferenceIntValue */);
    }

    @Override
    public void action(Context context, int action, String pkg,
            Pair<Integer, Object>... taggedData) {
        action(SettingsEnums.PAGE_UNKNOWN /* attribution */,
                action,
                SettingsEnums.PAGE_UNKNOWN /* pageId */,
                pkg /* changedPreferenceKey */,
                1 /* changedPreferenceIntValue */);
    }

    @Override
    public void count(Context context, String name, int value) {
        // No-op
    }

    @Override
    public void action(int attribution, int action, int pageId, String key, int value) {
        StatsLog.write(StatsLog.SETTINGS_UI_CHANGED /* atomName */,
                attribution,
                action,
                pageId,
                key,
                value);
    }
}
+2 −6
Original line number Diff line number Diff line
@@ -16,16 +16,12 @@

package com.android.settings.gestures;

import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.SharedPreferences;
import android.provider.SearchIndexableResource;

import com.android.internal.hardware.AmbientDisplayConfiguration;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settings.R;
import com.android.settings.dashboard.DashboardFragment;
import com.android.settings.dashboard.suggestions.SuggestionFeatureProvider;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settingslib.search.SearchIndexable;

@@ -42,7 +38,7 @@ public class WakeScreenGestureSettings extends DashboardFragment {

    @Override
    public int getMetricsCategory() {
        return MetricsProto.MetricsEvent.SETTINGS_GESTURE_WAKE_SCREEN;
        return SettingsEnums.SETTINGS_GESTURE_WAKE_SCREEN;
    }

    @Override
+2 −2
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settings.homepage.contextualcards;

import static com.android.settings.homepage.contextualcards.ContextualCardsAdapter.SPAN_COUNT;

import android.app.settings.SettingsEnums;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
@@ -26,7 +27,6 @@ import android.view.ViewGroup;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;

@@ -69,6 +69,6 @@ public class ContextualCardsFragment extends InstrumentedFragment {

    @Override
    public int getMetricsCategory() {
        return MetricsEvent.SETTINGS_HOMEPAGE;
        return SettingsEnums.SETTINGS_HOMEPAGE;
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settings.network.telephony;

import android.app.Activity;
import android.app.settings.SettingsEnums;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
@@ -31,7 +32,6 @@ import android.util.Log;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;

import com.android.internal.logging.nano.MetricsProto;
import com.android.internal.telephony.TelephonyIntents;
import com.android.settings.R;
import com.android.settings.dashboard.RestrictedDashboardFragment;
@@ -75,7 +75,7 @@ public class MobileNetworkSettings extends RestrictedDashboardFragment {

    @Override
    public int getMetricsCategory() {
        return MetricsProto.MetricsEvent.MOBILE_NETWORK;
        return SettingsEnums.MOBILE_NETWORK;
    }

    /**
Loading