1 /*
2  * Copyright (C) 2020 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  */
16 
17 package com.android.server.notification;
18 
19 import android.util.StatsEvent;
20 
21 /**
22  * Wrapper for StatsEvent that enables unit testing.
23  */
24 public class SysUiStatsEvent {
25 
26     static class Builder {
27         private final StatsEvent.Builder mBuilder;
28 
Builder(StatsEvent.Builder builder)29         protected Builder(StatsEvent.Builder builder) {
30             mBuilder = builder;
31         }
32 
build()33         public StatsEvent build() {
34             return mBuilder.build();
35         }
36 
setAtomId(int atomId)37         public Builder setAtomId(int atomId) {
38             mBuilder.setAtomId(atomId);
39             return this;
40         }
41 
writeInt(int value)42         public Builder writeInt(int value) {
43             mBuilder.writeInt(value);
44             return this;
45         }
46 
addBooleanAnnotation(byte annotation, boolean value)47         public Builder addBooleanAnnotation(byte annotation, boolean value) {
48             mBuilder.addBooleanAnnotation(annotation, value);
49             return this;
50         }
51 
writeString(String value)52         public Builder writeString(String value) {
53             mBuilder.writeString(value);
54             return this;
55         }
56 
writeBoolean(boolean value)57         public Builder writeBoolean(boolean value) {
58             mBuilder.writeBoolean(value);
59             return this;
60         }
61 
writeByteArray(byte[] value)62         public Builder writeByteArray(byte[] value) {
63             mBuilder.writeByteArray(value);
64             return this;
65         }
66     }
67 
68     static class BuilderFactory {
newBuilder()69         Builder newBuilder() {
70             return new Builder(StatsEvent.newBuilder());
71         }
72     }
73 }
74