1 /*
2  * Copyright (C) 2023 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 import android.hardware.input.InputManager;
20 import android.view.InputEvent;
21 
22 import com.android.adservices.service.measurement.util.Validation;
23 
24 import com.google.auto.value.AutoValue;
25 
26 /** Class for AD_SERVICES_MEASUREMENT_CLICK_VERIFICATION_STATS atom. */
27 @AutoValue
28 public abstract class MeasurementClickVerificationStats {
29     /**
30      * @return Final source type of source registered.
31      */
getSourceType()32     public abstract int getSourceType();
33 
34     /**
35      * @return true, if an InputEvent object was present at source registration (meaning the source
36      *     was intended to be a navigation).
37      */
isInputEventPresent()38     public abstract boolean isInputEventPresent();
39 
40     /**
41      * @return true, if the system could verify the InputEvent with {@link
42      *     InputManager#verifyInputEvent(InputEvent)}
43      */
isSystemClickVerificationSuccessful()44     public abstract boolean isSystemClickVerificationSuccessful();
45 
46     /**
47      * @return true, if the system click verification is enabled.
48      */
isSystemClickVerificationEnabled()49     public abstract boolean isSystemClickVerificationEnabled();
50 
51     /**
52      * @return the delay (in millis) from when the input event was created to when the
53      *     registerSource API was called.
54      */
getInputEventDelayMillis()55     public abstract long getInputEventDelayMillis();
56 
57     /**
58      * @return the max difference (in millis) between input event creation and the API cal for the
59      *     source to not get downgraded.
60      */
getValidDelayWindowMillis()61     public abstract long getValidDelayWindowMillis();
62 
63     /**
64      * @return source registrant.
65      */
getSourceRegistrant()66     public abstract String getSourceRegistrant();
67 
68     /**
69      * @return true, if click deduplication is enabled (the result is not recorded).
70      */
isClickDeduplicationEnabled()71     public abstract boolean isClickDeduplicationEnabled();
72 
73     /**
74      * @return true, if click deduplication is enforced (the result is recorded but the click is not
75      *     demoted if it fails).
76      */
isClickDeduplicationEnforced()77     public abstract boolean isClickDeduplicationEnforced();
78 
79     /**
80      * @return the current limit for the number of sources per click.
81      */
getMaxSourcesPerClick()82     public abstract long getMaxSourcesPerClick();
83 
84     /**
85      * @return whether the current registration attempt is under the limit.
86      */
isCurrentRegistrationUnderClickDeduplicationLimit()87     public abstract boolean isCurrentRegistrationUnderClickDeduplicationLimit();
88 
89     /**
90      * @return generic builder.
91      */
builder()92     public static MeasurementClickVerificationStats.Builder builder() {
93         return new AutoValue_MeasurementClickVerificationStats.Builder();
94     }
95 
96     /** Builder class for {@link MeasurementClickVerificationStats} */
97     @AutoValue.Builder
98     public abstract static class Builder {
99         /** Set sourceType. */
setSourceType(int value)100         public abstract Builder setSourceType(int value);
101 
102         /** Set to true, if an InputEvent is present at source registration. */
setInputEventPresent(boolean value)103         public abstract Builder setInputEventPresent(boolean value);
104 
105         /** Set to true, if click verification by the system is successful. */
setSystemClickVerificationSuccessful(boolean value)106         public abstract Builder setSystemClickVerificationSuccessful(boolean value);
107 
108         /** Set to true, if click verification by the system is enabled. */
setSystemClickVerificationEnabled(boolean value)109         public abstract Builder setSystemClickVerificationEnabled(boolean value);
110 
111         /**
112          * Set the delay from when the input event was created to when the registration occurred.
113          */
setInputEventDelayMillis(long value)114         public abstract Builder setInputEventDelayMillis(long value);
115 
116         /**
117          * Set the valid delay window between input event creation and the registration call time.
118          */
setValidDelayWindowMillis(long value)119         public abstract Builder setValidDelayWindowMillis(long value);
120 
121         /** Set source registrant. */
setSourceRegistrant(String value)122         public abstract Builder setSourceRegistrant(String value);
123 
124         /** Set to true, if click deduplication is enabled. */
setClickDeduplicationEnabled(boolean value)125         public abstract Builder setClickDeduplicationEnabled(boolean value);
126 
127         /** Set to true, if click deduplication is enforced. */
setClickDeduplicationEnforced(boolean value)128         public abstract Builder setClickDeduplicationEnforced(boolean value);
129 
130         /** Set the current limit for number of sources per click. */
setMaxSourcesPerClick(long value)131         public abstract Builder setMaxSourcesPerClick(long value);
132 
133         /** Set to true, if the current click is under the deduplication limit. */
setCurrentRegistrationUnderClickDeduplicationLimit(boolean value)134         public abstract Builder setCurrentRegistrationUnderClickDeduplicationLimit(boolean value);
135 
136         /** Auto build for {@link MeasurementClickVerificationStats} */
autoBuild()137         abstract MeasurementClickVerificationStats autoBuild();
138 
139         /** build for {@link MeasurementClickVerificationStats} */
build()140         public final MeasurementClickVerificationStats build() {
141             MeasurementClickVerificationStats stats = autoBuild();
142             Validation.validateNonNull(stats.getSourceRegistrant());
143             return stats;
144         }
145     }
146 }
147