• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.adservices.service.stats;
18 
19 
20 
21 import android.adservices.common.AdServicesStatusUtils.StatusCode;
22 
23 import java.util.Objects;
24 
25 /** Class for Api Call Stats. */
26 public final class ApiCallStats {
27     private int mCode;
28     private int mApiClass;
29     private int mApiName;
30     private String mAppPackageName;
31     private String mSdkPackageName;
32     private int mLatencyMillisecond;
33 
34     private @StatusCode int mResultCode;
35 
ApiCallStats()36     private ApiCallStats() {}
37 
38     @Override
equals(Object obj)39     public boolean equals(Object obj) {
40         if (!(obj instanceof ApiCallStats)) {
41             return false;
42         }
43         ApiCallStats apiCallStats = (ApiCallStats) obj;
44         return mCode == apiCallStats.mCode
45                 && mApiClass == apiCallStats.mApiClass
46                 && mApiName == apiCallStats.mApiName
47                 && Objects.equals(mAppPackageName, apiCallStats.mAppPackageName)
48                 && Objects.equals(mSdkPackageName, apiCallStats.mSdkPackageName)
49                 && mLatencyMillisecond == apiCallStats.mLatencyMillisecond
50                 && mResultCode == apiCallStats.mResultCode;
51     }
52 
53     @Override
hashCode()54     public int hashCode() {
55         return Objects.hash(
56                 mCode,
57                 mApiClass,
58                 mApiName,
59                 mAppPackageName,
60                 mSdkPackageName,
61                 mLatencyMillisecond,
62                 mResultCode);
63     }
64 
getCode()65     public int getCode() {
66         return mCode;
67     }
68 
getApiClass()69     public int getApiClass() {
70         return mApiClass;
71     }
72 
getApiName()73     public int getApiName() {
74         return mApiName;
75     }
76 
getAppPackageName()77     public String getAppPackageName() {
78         return mAppPackageName;
79     }
80 
getSdkPackageName()81     public String getSdkPackageName() {
82         return mSdkPackageName;
83     }
84 
getLatencyMillisecond()85     public int getLatencyMillisecond() {
86         return mLatencyMillisecond;
87     }
88 
getResultCode()89     public @StatusCode int getResultCode() {
90         return mResultCode;
91     }
92 
93     @Override
toString()94     public String toString() {
95         return "ApiCallStats{"
96                 + "mCode="
97                 + mCode
98                 + ", mApiClass="
99                 + mApiClass
100                 + ", mApiName="
101                 + mApiName
102                 + ", mAppPackageName='"
103                 + mAppPackageName
104                 + '\''
105                 + ", mSdkPackageName='"
106                 + mSdkPackageName
107                 + '\''
108                 + ", mLatencyMillisecond="
109                 + mLatencyMillisecond
110                 + ", mResultCode="
111                 + mResultCode
112                 + '}';
113     }
114 
115     /** Builder for {@link ApiCallStats}. */
116     public static final class Builder {
117         private final ApiCallStats mBuilding = new ApiCallStats();
118 
Builder()119         public Builder() {
120         }
121 
122         /** See {@link ApiCallStats#getCode()} . */
setCode(int code)123         public Builder setCode(int code) {
124             mBuilding.mCode = code;
125             return this;
126         }
127 
128         /** See {@link ApiCallStats#getApiClass()} . */
setApiClass(int apiClass)129         public Builder setApiClass(int apiClass) {
130             mBuilding.mApiClass = apiClass;
131             return this;
132         }
133 
134         /** See {@link ApiCallStats#getApiName()} . */
setApiName(int apiName)135         public Builder setApiName(int apiName) {
136             mBuilding.mApiName = apiName;
137             return this;
138         }
139 
140         /** See {@link ApiCallStats#getAppPackageName()} . */
setAppPackageName(String appPackageName)141         public Builder setAppPackageName(String appPackageName) {
142             mBuilding.mAppPackageName = Objects.requireNonNull(appPackageName);
143             return this;
144         }
145 
146         /** See {@link ApiCallStats#getSdkPackageName()}. */
setSdkPackageName(String sdkPackageName)147         public Builder setSdkPackageName(String sdkPackageName) {
148             mBuilding.mSdkPackageName = Objects.requireNonNull(sdkPackageName);
149             return this;
150         }
151 
152         /** See {@link ApiCallStats#getLatencyMillisecond()}. */
setLatencyMillisecond(int latencyMillisecond)153         public Builder setLatencyMillisecond(int latencyMillisecond) {
154             mBuilding.mLatencyMillisecond = latencyMillisecond;
155             return this;
156         }
157 
158         /** See {@link ApiCallStats#getResultCode()}. */
setResultCode(@tatusCode int resultCode)159         public Builder setResultCode(@StatusCode int resultCode) {
160             mBuilding.mResultCode = resultCode;
161             return this;
162         }
163 
164         /** Build the {@link ApiCallStats}. */
build()165         public ApiCallStats build() {
166             if (mBuilding.mAppPackageName == null) {
167                 throw new IllegalStateException("must call setAppPackageName()");
168             }
169             if (mBuilding.mSdkPackageName == null) {
170                 throw new IllegalStateException("must call setSdkPackageName()");
171             }
172             return mBuilding;
173         }
174     }
175 }
176