summaryrefslogtreecommitdiff
path: root/src/com/android/customization/module/WallpaperStatsLog.java
blob: 9f5761f800669ac46422ee9fd738978d646dbde4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
// This file is autogenerated

package com.android.customization.module;

import static java.nio.charset.StandardCharsets.UTF_8;

import android.util.StatsLog;
import android.os.SystemClock;

import java.util.ArrayList;


/**
 * Utility class for logging statistics events.
 */
public class WallpaperStatsLog {
    private static final int LOGGER_ENTRY_MAX_PAYLOAD = 4068;
    private static final int MAX_EVENT_PAYLOAD = LOGGER_ENTRY_MAX_PAYLOAD - 4;
    private static final byte INT_TYPE = 0;
    private static final byte LONG_TYPE = 1;
    private static final byte STRING_TYPE = 2;
    private static final byte LIST_TYPE = 3;
    private static final byte FLOAT_TYPE = 4;
    private static final int INT_TYPE_SIZE = 5;
    private static final int FLOAT_TYPE_SIZE = 5;
    private static final int LONG_TYPE_SIZE = 9;
    private static final int STRING_TYPE_OVERHEAD = 5;
    private static final int LIST_TYPE_OVERHEAD = 2;
    // Constants for atom codes.

    /**
     * StyleUIChanged style_ui_changed<br>
     * Usage: StatsLog.write(StatsLog.STYLE_UI_CHANGED, int action, int color_package_hash, int font_package_hash, int shape_package_hash, int clock_package_hash, int launcher_grid, int wallpaper_category_hash, int wallpaper_id_hash, int color_preference, int location_preference);<br>
     */
    public static final int STYLE_UI_CHANGED = 179;

    // Constants for enum values.

    // Values for StyleUIChanged.action
    public static final int STYLE_UICHANGED__ACTION__DEFAULT_ACTION = 0;
    public static final int STYLE_UICHANGED__ACTION__ONRESUME = 1;
    public static final int STYLE_UICHANGED__ACTION__ONSTOP = 2;
    public static final int STYLE_UICHANGED__ACTION__PICKER_SELECT = 3;
    public static final int STYLE_UICHANGED__ACTION__PICKER_APPLIED = 4;
    public static final int STYLE_UICHANGED__ACTION__WALLPAPER_OPEN_CATEGORY = 5;
    public static final int STYLE_UICHANGED__ACTION__WALLPAPER_SELECT = 6;
    public static final int STYLE_UICHANGED__ACTION__WALLPAPER_APPLIED = 7;
    public static final int STYLE_UICHANGED__ACTION__WALLPAPER_EXPLORE = 8;
    public static final int STYLE_UICHANGED__ACTION__WALLPAPER_DOWNLOAD = 9;
    public static final int STYLE_UICHANGED__ACTION__WALLPAPER_REMOVE = 10;
    public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DOWNLOAD_SUCCESS = 11;
    public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DOWNLOAD_FAILED = 12;
    public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DOWNLOAD_CANCELLED = 13;
    public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DELETE_SUCCESS = 14;
    public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DELETE_FAILED = 15;
    public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_APPLIED = 16;

    // Values for StyleUIChanged.location_preference
    public static final int STYLE_UICHANGED__LOCATION_PREFERENCE__LOCATION_PREFERENCE_UNSPECIFIED = 0;
    public static final int STYLE_UICHANGED__LOCATION_PREFERENCE__LOCATION_UNAVAILABLE = 1;
    public static final int STYLE_UICHANGED__LOCATION_PREFERENCE__LOCATION_CURRENT = 2;
    public static final int STYLE_UICHANGED__LOCATION_PREFERENCE__LOCATION_MANUAL = 3;

    // Write methods
    public static void write(int code, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10) {
        // Initial overhead of the list, timestamp, and atom tag.
        int needed = LIST_TYPE_OVERHEAD + LONG_TYPE_SIZE + INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        needed += INT_TYPE_SIZE;
        if (needed > MAX_EVENT_PAYLOAD) {
            return;
        }
        byte[] buff = new byte[needed];
        int pos = 0;
        buff[pos] = LIST_TYPE;
        buff[pos + 1] = 12;
        pos += LIST_TYPE_OVERHEAD;
        long elapsedRealtime = SystemClock.elapsedRealtimeNanos();
        buff[pos] = LONG_TYPE;
        copyLong(buff, pos + 1, elapsedRealtime);
        pos += LONG_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, code);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg1);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg2);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg3);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg4);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg5);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg6);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg7);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg8);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg9);
        pos += INT_TYPE_SIZE;
        buff[pos] = INT_TYPE;
        copyInt(buff, pos + 1, arg10);
        pos += INT_TYPE_SIZE;
        StatsLog.writeRaw(buff, pos);
    }

    // Helper methods for copying primitives
    private static void copyInt(byte[] buff, int pos, int val) {
        buff[pos] = (byte) (val);
        buff[pos + 1] = (byte) (val >> 8);
        buff[pos + 2] = (byte) (val >> 16);
        buff[pos + 3] = (byte) (val >> 24);
        return;
    }

    private static void copyLong(byte[] buff, int pos, long val) {
        buff[pos] = (byte) (val);
        buff[pos + 1] = (byte) (val >> 8);
        buff[pos + 2] = (byte) (val >> 16);
        buff[pos + 3] = (byte) (val >> 24);
        buff[pos + 4] = (byte) (val >> 32);
        buff[pos + 5] = (byte) (val >> 40);
        buff[pos + 6] = (byte) (val >> 48);
        buff[pos + 7] = (byte) (val >> 56);
        return;
    }

}