1 // This file is autogenerated
2 
3 package com.android.customization.module;
4 
5 import static java.nio.charset.StandardCharsets.UTF_8;
6 
7 import android.util.StatsLog;
8 import android.os.SystemClock;
9 
10 import java.util.ArrayList;
11 
12 
13 /**
14  * Utility class for logging statistics events.
15  */
16 public class WallpaperStatsLog {
17     private static final int LOGGER_ENTRY_MAX_PAYLOAD = 4068;
18     private static final int MAX_EVENT_PAYLOAD = LOGGER_ENTRY_MAX_PAYLOAD - 4;
19     private static final byte INT_TYPE = 0;
20     private static final byte LONG_TYPE = 1;
21     private static final byte STRING_TYPE = 2;
22     private static final byte LIST_TYPE = 3;
23     private static final byte FLOAT_TYPE = 4;
24     private static final int INT_TYPE_SIZE = 5;
25     private static final int FLOAT_TYPE_SIZE = 5;
26     private static final int LONG_TYPE_SIZE = 9;
27     private static final int STRING_TYPE_OVERHEAD = 5;
28     private static final int LIST_TYPE_OVERHEAD = 2;
29     // Constants for atom codes.
30 
31     /**
32      * StyleUIChanged style_ui_changed<br>
33      * 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>
34      */
35     public static final int STYLE_UI_CHANGED = 179;
36 
37     // Constants for enum values.
38 
39     // Values for StyleUIChanged.action
40     public static final int STYLE_UICHANGED__ACTION__DEFAULT_ACTION = 0;
41     public static final int STYLE_UICHANGED__ACTION__ONRESUME = 1;
42     public static final int STYLE_UICHANGED__ACTION__ONSTOP = 2;
43     public static final int STYLE_UICHANGED__ACTION__PICKER_SELECT = 3;
44     public static final int STYLE_UICHANGED__ACTION__PICKER_APPLIED = 4;
45     public static final int STYLE_UICHANGED__ACTION__WALLPAPER_OPEN_CATEGORY = 5;
46     public static final int STYLE_UICHANGED__ACTION__WALLPAPER_SELECT = 6;
47     public static final int STYLE_UICHANGED__ACTION__WALLPAPER_APPLIED = 7;
48     public static final int STYLE_UICHANGED__ACTION__WALLPAPER_EXPLORE = 8;
49     public static final int STYLE_UICHANGED__ACTION__WALLPAPER_DOWNLOAD = 9;
50     public static final int STYLE_UICHANGED__ACTION__WALLPAPER_REMOVE = 10;
51     public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DOWNLOAD_SUCCESS = 11;
52     public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DOWNLOAD_FAILED = 12;
53     public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DOWNLOAD_CANCELLED = 13;
54     public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DELETE_SUCCESS = 14;
55     public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_DELETE_FAILED = 15;
56     public static final int STYLE_UICHANGED__ACTION__LIVE_WALLPAPER_APPLIED = 16;
57 
58     // Values for StyleUIChanged.location_preference
59     public static final int STYLE_UICHANGED__LOCATION_PREFERENCE__LOCATION_PREFERENCE_UNSPECIFIED = 0;
60     public static final int STYLE_UICHANGED__LOCATION_PREFERENCE__LOCATION_UNAVAILABLE = 1;
61     public static final int STYLE_UICHANGED__LOCATION_PREFERENCE__LOCATION_CURRENT = 2;
62     public static final int STYLE_UICHANGED__LOCATION_PREFERENCE__LOCATION_MANUAL = 3;
63 
64     // Write methods
write(int code, int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7, int arg8, int arg9, int arg10)65     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) {
66         // Initial overhead of the list, timestamp, and atom tag.
67         int needed = LIST_TYPE_OVERHEAD + LONG_TYPE_SIZE + INT_TYPE_SIZE;
68         needed += INT_TYPE_SIZE;
69         needed += INT_TYPE_SIZE;
70         needed += INT_TYPE_SIZE;
71         needed += INT_TYPE_SIZE;
72         needed += INT_TYPE_SIZE;
73         needed += INT_TYPE_SIZE;
74         needed += INT_TYPE_SIZE;
75         needed += INT_TYPE_SIZE;
76         needed += INT_TYPE_SIZE;
77         needed += INT_TYPE_SIZE;
78         if (needed > MAX_EVENT_PAYLOAD) {
79             return;
80         }
81         byte[] buff = new byte[needed];
82         int pos = 0;
83         buff[pos] = LIST_TYPE;
84         buff[pos + 1] = 12;
85         pos += LIST_TYPE_OVERHEAD;
86         long elapsedRealtime = SystemClock.elapsedRealtimeNanos();
87         buff[pos] = LONG_TYPE;
88         copyLong(buff, pos + 1, elapsedRealtime);
89         pos += LONG_TYPE_SIZE;
90         buff[pos] = INT_TYPE;
91         copyInt(buff, pos + 1, code);
92         pos += INT_TYPE_SIZE;
93         buff[pos] = INT_TYPE;
94         copyInt(buff, pos + 1, arg1);
95         pos += INT_TYPE_SIZE;
96         buff[pos] = INT_TYPE;
97         copyInt(buff, pos + 1, arg2);
98         pos += INT_TYPE_SIZE;
99         buff[pos] = INT_TYPE;
100         copyInt(buff, pos + 1, arg3);
101         pos += INT_TYPE_SIZE;
102         buff[pos] = INT_TYPE;
103         copyInt(buff, pos + 1, arg4);
104         pos += INT_TYPE_SIZE;
105         buff[pos] = INT_TYPE;
106         copyInt(buff, pos + 1, arg5);
107         pos += INT_TYPE_SIZE;
108         buff[pos] = INT_TYPE;
109         copyInt(buff, pos + 1, arg6);
110         pos += INT_TYPE_SIZE;
111         buff[pos] = INT_TYPE;
112         copyInt(buff, pos + 1, arg7);
113         pos += INT_TYPE_SIZE;
114         buff[pos] = INT_TYPE;
115         copyInt(buff, pos + 1, arg8);
116         pos += INT_TYPE_SIZE;
117         buff[pos] = INT_TYPE;
118         copyInt(buff, pos + 1, arg9);
119         pos += INT_TYPE_SIZE;
120         buff[pos] = INT_TYPE;
121         copyInt(buff, pos + 1, arg10);
122         pos += INT_TYPE_SIZE;
123         StatsLog.writeRaw(buff, pos);
124     }
125 
126     // Helper methods for copying primitives
copyInt(byte[] buff, int pos, int val)127     private static void copyInt(byte[] buff, int pos, int val) {
128         buff[pos] = (byte) (val);
129         buff[pos + 1] = (byte) (val >> 8);
130         buff[pos + 2] = (byte) (val >> 16);
131         buff[pos + 3] = (byte) (val >> 24);
132         return;
133     }
134 
copyLong(byte[] buff, int pos, long val)135     private static void copyLong(byte[] buff, int pos, long val) {
136         buff[pos] = (byte) (val);
137         buff[pos + 1] = (byte) (val >> 8);
138         buff[pos + 2] = (byte) (val >> 16);
139         buff[pos + 3] = (byte) (val >> 24);
140         buff[pos + 4] = (byte) (val >> 32);
141         buff[pos + 5] = (byte) (val >> 40);
142         buff[pos + 6] = (byte) (val >> 48);
143         buff[pos + 7] = (byte) (val >> 56);
144         return;
145     }
146 
147 }
148