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

Commit f64c5d07 authored by Santiago Etchebehere's avatar Santiago Etchebehere
Browse files

Add infrastructure for logging in TP

This CL only adds the logger, it's not being called
from anywhere yet. That will come in a follow-up CL.

StatsLogEventLogger for now only logs to logcat,
StatsLogCompat calls are currently commented out as
it's not fully working.

Bug: 129365634
Change-Id: I81eba2956c07c5a59831a2805171200d6b1174cd
parent cb118bd6
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ public class Clockface implements CustomizationOption<Clockface> {
        return mPreview;
    }

    String getId() {
    public String getId() {
        return mId;
    }

+3 −3
Original line number Diff line number Diff line
@@ -34,7 +34,7 @@ import com.android.wallpaper.picker.PreviewFragment;
public class DefaultCustomizationInjector extends BaseWallpaperInjector
        implements CustomizationInjector {
    private CategoryProvider mCategoryProvider;
    private UserEventLogger mUserEventLogger;
    private ThemesUserEventLogger mUserEventLogger;
    private WallpaperRotationRefresher mWallpaperRotationRefresher;
    private PerformanceMonitor mPerformanceMonitor;
    private WallpaperPreferences mPrefs;
@@ -62,9 +62,9 @@ public class DefaultCustomizationInjector extends BaseWallpaperInjector
    }

    @Override
    public synchronized UserEventLogger getUserEventLogger(Context context) {
    public synchronized ThemesUserEventLogger getUserEventLogger(Context context) {
        if (mUserEventLogger == null) {
            mUserEventLogger = new NoOpUserEventLogger();
            mUserEventLogger = new StatsLogUserEventLogger();
        }
        return mUserEventLogger;
    }
+197 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.customization.module;

import android.stats.style.nano.StyleEnums;
import android.util.Log;

import androidx.annotation.Nullable;

import com.android.customization.model.clock.Clockface;
import com.android.customization.model.grid.GridOption;
import com.android.customization.model.theme.ThemeBundle;
import com.android.wallpaper.module.NoOpUserEventLogger;

import java.util.Map;
import java.util.Objects;

import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_FONT;
import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SHAPE;

/**
 * StatsLog-backed implementation of {@link ThemesUserEventLogger}.
 */
public class StatsLogUserEventLogger extends NoOpUserEventLogger implements ThemesUserEventLogger {

    private static final String TAG = "StatsLogUserEventLogger";

    @Override
    public void logResumed() {
        Log.d(TAG, String.format("logResumed: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.ONRESUME,
                0, 0, 0, 0, 0, 0, 0));
//        StatsLogCompat.write(StyleEnums.ONRESUME,
//                0, 0, 0, 0, 0, 0, 0);
    }

    @Override
    public void logStopped() {
        Log.d(TAG, String.format("logStopped: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.ONSTOP,
                0, 0, 0, 0, 0, 0, 0));
//        StatsLogCompat.write(StyleEnums.ONSTOP,
//                0, 0, 0, 0, 0, 0, 0);
    }

    @Override
    public void logActionClicked(String collectionId, int actionLabelResId) {
        Log.d(TAG, String.format("logActionClicked: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.WALLPAPER_EXPLORE,
                0, 0, 0, 0, 0,
                collectionId.hashCode(),
                0));
//        StatsLogCompat.write(StyleEnums.WALLPAPER_EXPLORE,
//                0, 0, 0, 0, 0,
//                collectionId.hashCode(),
//                0));
    }

    @Override
    public void logIndividualWallpaperSelected(String collectionId) {
        Log.d(TAG, String.format("logIndividualWallpaperSelected: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.WALLPAPER_SELECT,
                0, 0, 0, 0, 0, 0,
                collectionId.hashCode()));
//        StatsLogCompat.write(StyleEnums.WALLPAPER_SELECT,
//                0, 0, 0, 0, 0, 0,
//                collectionId.hashCode());
    }

    @Override
    public void logCategorySelected(String collectionId) {
        Log.d(TAG, String.format("logCategorySelected: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.WALLPAPER_SELECT,
                0, 0, 0, 0, 0,
                collectionId.hashCode(),
                0));
//        StatsLogCompat.write(StyleEnums.WALLPAPER_SELECT,
//                0, 0, 0, 0, 0,
//                collectionId.hashCode(),
//                0);
    }

    @Override
    public void logWallpaperSet(String collectionId, @Nullable String wallpaperId) {
        Log.d(TAG, String.format("logWallpaperSet: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.WALLPAPER_APPLIED,
                0, 0, 0, 0, 0,
                collectionId.hashCode(),
                Objects.hashCode(wallpaperId)));
//        StatsLogCompat.write(StyleEnums.WALLPAPER_SELECT,
//                0, 0, 0, 0, 0,
//                collectionId.hashCode(),
//                0);
    }

    @Nullable
    private String getThemePackage(ThemeBundle theme, String category) {
        Map<String, String> packages = theme.getPackagesByCategory();
        return packages.get(category);
    }

    @Override
    public void logThemeSelected(ThemeBundle theme, boolean isCustomTheme) {
        Log.d(TAG, String.format("logThemeSelected: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.PICKER_SELECT,
                Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_COLOR)),
                Objects.hashCode(getThemePackage(theme,OVERLAY_CATEGORY_FONT)),
                Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_SHAPE)),
                0, 0, 0, 0));
//        StatsLogCompat.write(StyleEnums.PICKER_SELECT,
//                Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_COLOR)),
//                Objects.hashCode(getThemePackage(theme,OVERLAY_CATEGORY_FONT)),
//                Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_SHAPE)),
//                0, 0, 0, 0);
    }

    @Override
    public void logThemeApplied(ThemeBundle theme, boolean isCustomTheme) {
        Log.d(TAG, String.format("logThemeApplied: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.PICKER_APPLIED,
                Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_COLOR)),
                Objects.hashCode(getThemePackage(theme,OVERLAY_CATEGORY_FONT)),
                Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_SHAPE)),
                0, 0, 0, 0));
//        StatsLogCompat.write(StyleEnums.PICKER_APPLIED,
//        Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_COLOR)),
//        Objects.hashCode(getThemePackage(theme,OVERLAY_CATEGORY_FONT)),
//        Objects.hashCode(getThemePackage(theme, OVERLAY_CATEGORY_SHAPE)),
//                0, 0, 0, 0);
    }

    @Override
    public void logClockSelected(Clockface clock) {
        Log.d(TAG, String.format("logClockSelected: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.PICKER_SELECT,
                0, 0, 0,
                Objects.hashCode(clock.getId()),
                0, 0, 0));
//        StatsLogCompat.write(StyleEnums.PICKER_SELECT,
//        0, 0, 0,
//        Objects.hashCode(clock.getId()),
//        0, 0, 0));
    }

    @Override
    public void logClockApplied(Clockface clock) {
        Log.d(TAG, String.format("logClockApplied: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.PICKER_APPLIED,
                0, 0, 0,
                Objects.hashCode(clock.getId()),
                0, 0, 0));
//        StatsLogCompat.write(StyleEnums.PICKER_APPLIED,
//        0, 0, 0,
//        Objects.hashCode(clock.getId()),
//        0, 0, 0));
    }

    @Override
    public void logGridSelected(GridOption grid) {
        Log.d(TAG, String.format("logGridSelected: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.PICKER_SELECT,
                0, 0, 0, 0,
                grid.cols,
                0, 0));
//        StatsLogCompat.write(StyleEnums.PICKER_SELECT,
//        0, 0, 0, 0,
//        Objects.hashCode(clock.getId()),
//        0, 0));
    }

    @Override
    public void logGridApplied(GridOption grid) {
        Log.d(TAG, String.format("logGridApplied: %d, %d, %d, %d, %d, %d, %d, %d",
                StyleEnums.PICKER_APPLIED,
                0, 0, 0, 0,
                grid.cols,
                0, 0));
//        StatsLogCompat.write(StyleEnums.PICKER_APPLIED,
//        0, 0, 0, 0,
//        Objects.hashCode(clock.getId()),
//        0, 0));
    }
}
+40 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2019 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.customization.module;

import com.android.customization.model.clock.Clockface;
import com.android.customization.model.grid.GridOption;
import com.android.customization.model.theme.ThemeBundle;
import com.android.wallpaper.module.UserEventLogger;

/**
 * Extension of {@link UserEventLogger} that adds ThemePicker specific events.
 */
public interface ThemesUserEventLogger extends UserEventLogger {

    void logThemeSelected(ThemeBundle theme, boolean isCustomTheme);

    void logThemeApplied(ThemeBundle theme, boolean isCustomTheme);

    void logClockSelected(Clockface clock);

    void logClockApplied(Clockface clock);

    void logGridSelected(GridOption grid);

    void logGridApplied(GridOption grid);

}