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.providers.contacts.util;
18 
19 import android.net.Uri;
20 
21 public final class LogFields {
22 
23     private final int apiType;
24 
25     private final int uriType;
26 
27     // The type is from LogUtils.TaskType
28     private final int taskType;
29 
30     private final boolean callerIsSyncAdapter;
31 
32     private final long startNanos;
33 
34     private Exception exception;
35 
36     private Uri resultUri;
37 
38     private int resultCount;
39 
40     private int uid;
41 
LogFields( int apiType, int uriType, int taskType, boolean callerIsSyncAdapter, long startNanos)42     public LogFields(
43             int apiType, int uriType, int taskType, boolean callerIsSyncAdapter, long startNanos) {
44         this.apiType = apiType;
45         this.uriType = uriType;
46         this.taskType = taskType;
47         this.callerIsSyncAdapter = callerIsSyncAdapter;
48         this.startNanos = startNanos;
49     }
50 
getApiType()51     public int getApiType() {
52         return apiType;
53     }
54 
getUriType()55     public int getUriType() {
56         return uriType;
57     }
58 
getTaskType()59     public int getTaskType() {
60         return taskType;
61     }
62 
isCallerIsSyncAdapter()63     public boolean isCallerIsSyncAdapter() {
64         return callerIsSyncAdapter;
65     }
66 
getStartNanos()67     public long getStartNanos() {
68         return startNanos;
69     }
70 
getException()71     public Exception getException() {
72         return exception;
73     }
74 
getResultUri()75     public Uri getResultUri() {
76         return resultUri;
77     }
78 
getResultCount()79     public int getResultCount() {
80         return resultCount;
81     }
82 
getUid()83     public int getUid() {
84         return uid;
85     }
86 
87     public static final class Builder {
88         private int apiType;
89         private int uriType;
90         private int taskType;
91         private boolean callerIsSyncAdapter;
92         private long startNanos;
93         private Exception exception;
94         private Uri resultUri;
95         private int resultCount;
96 
97         private int uid;
98 
Builder()99         private Builder() {
100         }
101 
aLogFields()102         public static Builder aLogFields() {
103             return new Builder();
104         }
105 
setApiType(int apiType)106         public Builder setApiType(int apiType) {
107             this.apiType = apiType;
108             return this;
109         }
110 
setUriType(int uriType)111         public Builder setUriType(int uriType) {
112             this.uriType = uriType;
113             return this;
114         }
115 
setTaskType(int taskType)116         public Builder setTaskType(int taskType) {
117             this.taskType = taskType;
118             return this;
119         }
120 
setCallerIsSyncAdapter(boolean callerIsSyncAdapter)121         public Builder setCallerIsSyncAdapter(boolean callerIsSyncAdapter) {
122             this.callerIsSyncAdapter = callerIsSyncAdapter;
123             return this;
124         }
125 
setStartNanos(long startNanos)126         public Builder setStartNanos(long startNanos) {
127             this.startNanos = startNanos;
128             return this;
129         }
130 
setException(Exception exception)131         public Builder setException(Exception exception) {
132             this.exception = exception;
133             return this;
134         }
135 
setResultUri(Uri resultUri)136         public Builder setResultUri(Uri resultUri) {
137             this.resultUri = resultUri;
138             return this;
139         }
140 
setResultCount(int resultCount)141         public Builder setResultCount(int resultCount) {
142             this.resultCount = resultCount;
143             return this;
144         }
145 
setUid(int uid)146         public Builder setUid(int uid) {
147             this.uid = uid;
148             return this;
149         }
150 
build()151         public LogFields build() {
152             LogFields logFields =
153                     new LogFields(apiType, uriType, taskType, callerIsSyncAdapter, startNanos);
154             logFields.resultCount = this.resultCount;
155             logFields.exception = this.exception;
156             logFields.resultUri = this.resultUri;
157             logFields.uid = this.uid;
158             return logFields;
159         }
160     }
161 }
162