| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
package com.android.internal.logging; |
| 17 |
|
| 18 |
import android.compat.annotation.UnsupportedAppUsage; |
| 19 |
import android.content.Context; |
| 20 |
import android.metrics.LogMaker; |
| 21 |
import android.os.Build; |
| 22 |
import android.view.View; |
| 23 |
|
| 24 |
import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public class MetricsLogger { |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
private static MetricsLogger sMetricsLogger; |
| 42 |
|
| 43 |
@UnsupportedAppUsage |
| 44 |
public MetricsLogger() { |
| 45 |
} |
| 46 |
|
| 47 |
private static MetricsLogger getLogger() { |
| 48 |
if (sMetricsLogger == null) { |
| 49 |
sMetricsLogger = new MetricsLogger(); |
| 50 |
} |
| 51 |
return sMetricsLogger; |
| 52 |
} |
| 53 |
|
| 54 |
protected void saveLog(LogMaker log) { |
| 55 |
EventLogTags.writeSysuiMultiAction(log.serialize()); |
| 56 |
} |
| 57 |
|
| 58 |
public static final int VIEW_UNKNOWN = MetricsEvent.VIEW_UNKNOWN; |
| 59 |
public static final int LOGTAG = EventLogTags.SYSUI_MULTI_ACTION; |
| 60 |
|
| 61 |
|
| 62 |
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.R, trackingBug = 170729553) |
| 63 |
public void write(LogMaker content) { |
| 64 |
if (content.getType() == MetricsEvent.TYPE_UNKNOWN) { |
| 65 |
content.setType(MetricsEvent.TYPE_ACTION); |
| 66 |
} |
| 67 |
saveLog(content); |
| 68 |
} |
| 69 |
|
| 70 |
|
| 71 |
public void count(String name, int value) { |
| 72 |
saveLog(new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_COUNTER) |
| 73 |
.setCounterName(name) |
| 74 |
.setCounterValue(value)); |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
public void histogram(String name, int bucket) { |
| 79 |
|
| 80 |
saveLog(new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_HISTOGRAM) |
| 81 |
.setCounterName(name) |
| 82 |
.setCounterBucket(bucket) |
| 83 |
.setCounterValue(1)); |
| 84 |
} |
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
|
| 91 |
public void visible(int category) throws IllegalArgumentException { |
| 92 |
if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { |
| 93 |
throw new IllegalArgumentException("Must define metric category"); |
| 94 |
} |
| 95 |
saveLog(new LogMaker(category).setType(MetricsEvent.TYPE_OPEN)); |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
public void hidden(int category) throws IllegalArgumentException { |
| 101 |
if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { |
| 102 |
throw new IllegalArgumentException("Must define metric category"); |
| 103 |
} |
| 104 |
saveLog(new LogMaker(category).setType(MetricsEvent.TYPE_CLOSE)); |
| 105 |
} |
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
public void visibility(int category, boolean visible) |
| 111 |
throws IllegalArgumentException { |
| 112 |
if (visible) { |
| 113 |
visible(category); |
| 114 |
} else { |
| 115 |
hidden(category); |
| 116 |
} |
| 117 |
} |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
public void visibility(int category, int vis) |
| 124 |
throws IllegalArgumentException { |
| 125 |
visibility(category, vis == View.VISIBLE); |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
public void action(int category) { |
| 131 |
saveLog(new LogMaker(category).setType(MetricsEvent.TYPE_ACTION)); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
public void action(int category, int value) { |
| 138 |
saveLog(new LogMaker(category).setType(MetricsEvent.TYPE_ACTION).setSubtype(value)); |
| 139 |
} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
public void action(int category, boolean value) { |
| 145 |
saveLog(new LogMaker(category).setType(MetricsEvent.TYPE_ACTION).setSubtype(value ? 1 : 0)); |
| 146 |
} |
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
public void action(int category, String pkg) { |
| 152 |
if (Build.IS_DEBUGGABLE && category == VIEW_UNKNOWN) { |
| 153 |
throw new IllegalArgumentException("Must define metric category"); |
| 154 |
} |
| 155 |
saveLog(new LogMaker(category).setType(MetricsEvent.TYPE_ACTION).setPackageName(pkg)); |
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
@Deprecated |
| 160 |
public static void visible(Context context, int category) throws IllegalArgumentException { |
| 161 |
getLogger().visible(category); |
| 162 |
} |
| 163 |
|
| 164 |
|
| 165 |
@Deprecated |
| 166 |
public static void hidden(Context context, int category) throws IllegalArgumentException { |
| 167 |
getLogger().hidden(category); |
| 168 |
} |
| 169 |
|
| 170 |
|
| 171 |
@Deprecated |
| 172 |
public static void visibility(Context context, int category, boolean visibile) |
| 173 |
throws IllegalArgumentException { |
| 174 |
getLogger().visibility(category, visibile); |
| 175 |
} |
| 176 |
|
| 177 |
|
| 178 |
@Deprecated |
| 179 |
public static void visibility(Context context, int category, int vis) |
| 180 |
throws IllegalArgumentException { |
| 181 |
visibility(context, category, vis == View.VISIBLE); |
| 182 |
} |
| 183 |
|
| 184 |
|
| 185 |
@Deprecated |
| 186 |
public static void action(Context context, int category) { |
| 187 |
getLogger().action(category); |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
@Deprecated |
| 192 |
public static void action(Context context, int category, int value) { |
| 193 |
getLogger().action(category, value); |
| 194 |
} |
| 195 |
|
| 196 |
|
| 197 |
@Deprecated |
| 198 |
public static void action(Context context, int category, boolean value) { |
| 199 |
getLogger().action(category, value); |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
@Deprecated |
| 204 |
public static void action(LogMaker content) { |
| 205 |
getLogger().write(content); |
| 206 |
} |
| 207 |
|
| 208 |
|
| 209 |
@Deprecated |
| 210 |
public static void action(Context context, int category, String pkg) { |
| 211 |
getLogger().action(category, pkg); |
| 212 |
} |
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
@Deprecated |
| 219 |
public static void count(Context context, String name, int value) { |
| 220 |
getLogger().count(name, value); |
| 221 |
} |
| 222 |
|
| 223 |
|
| 224 |
|
| 225 |
|
| 226 |
|
| 227 |
@Deprecated |
| 228 |
public static void histogram(Context context, String name, int bucket) { |
| 229 |
getLogger().histogram(name, bucket); |
| 230 |
} |
| 231 |
} |