blob: 1209e4d8dc8ce4af1007eacbeedc2227a099b002 [file] [log] [blame]
Chris Wren26ca65d2016-11-29 10:43:28 -05001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.internal.logging.legacy;
17
Chris Wrenb6237142017-01-23 16:42:58 -050018import android.metrics.LogMaker;
Chris Wren26ca65d2016-11-29 10:43:28 -050019import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
20
21import java.util.HashMap;
22import java.util.LinkedList;
23import java.util.Queue;
24
25/** @hide */
26public class LegacyConversionLogger implements TronLogger {
Chris Wrenb6237142017-01-23 16:42:58 -050027 private final Queue<LogMaker> mQueue;
Chris Wren26ca65d2016-11-29 10:43:28 -050028 private HashMap<String, Boolean> mConfig;
29
30 public LegacyConversionLogger() {
31 mQueue = new LinkedList<>();
32 }
33
Chris Wrenb6237142017-01-23 16:42:58 -050034 public Queue<LogMaker> getEvents() {
Chris Wren26ca65d2016-11-29 10:43:28 -050035 return mQueue;
36 }
37
38 @Override
39 public void increment(String counterName) {
Chris Wrenb6237142017-01-23 16:42:58 -050040 LogMaker b = new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_COUNTER)
Chris Wren26ca65d2016-11-29 10:43:28 -050041 .setCounterName(counterName)
42 .setCounterValue(1);
43 mQueue.add(b);
44 }
45
46 @Override
47 public void incrementBy(String counterName, int value) {
Chris Wrenb6237142017-01-23 16:42:58 -050048 LogMaker b = new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_COUNTER)
Chris Wren26ca65d2016-11-29 10:43:28 -050049 .setCounterName(counterName)
50 .setCounterValue(value);
51 mQueue.add(b);
52 }
53
54 @Override
55 public void incrementIntHistogram(String counterName, int bucket) {
Chris Wrenb6237142017-01-23 16:42:58 -050056 LogMaker b = new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_HISTOGRAM)
Chris Wren26ca65d2016-11-29 10:43:28 -050057 .setCounterName(counterName)
58 .setCounterBucket(bucket)
59 .setCounterValue(1);
60 mQueue.add(b);
61 }
62
63 @Override
64 public void incrementLongHistogram(String counterName, long bucket) {
Chris Wrenb6237142017-01-23 16:42:58 -050065 LogMaker b = new LogMaker(MetricsEvent.RESERVED_FOR_LOGBUILDER_HISTOGRAM)
Chris Wren26ca65d2016-11-29 10:43:28 -050066 .setCounterName(counterName)
67 .setCounterBucket(bucket)
68 .setCounterValue(1);
69 mQueue.add(b);
70 }
71
72 @Override
Chris Wrenb6237142017-01-23 16:42:58 -050073 public LogMaker obtain() {
74 return new LogMaker(MetricsEvent.VIEW_UNKNOWN);
Chris Wren26ca65d2016-11-29 10:43:28 -050075 }
76
77 @Override
Chris Wrenb6237142017-01-23 16:42:58 -050078 public void dispose(LogMaker proto) {
Chris Wren26ca65d2016-11-29 10:43:28 -050079 }
80
81 @Override
Chris Wrenb6237142017-01-23 16:42:58 -050082 public void addEvent(LogMaker proto) {
Chris Wren26ca65d2016-11-29 10:43:28 -050083 mQueue.add(proto);
84 }
85
86 @Override
87 public boolean getConfig(String configName) {
88 if (mConfig != null && mConfig.containsKey(configName)) {
89 return mConfig.get(configName);
90 }
91 return false;
92 }
93
94 @Override
95 public void setConfig(String configName, boolean newValue) {
96 if (mConfig == null) {
97 mConfig = new HashMap<>();
98 }
99 mConfig.put(configName, newValue);
100 }
101}