• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 static com.android.adservices.service.stats.AdServicesLoggerUtil.FIELD_UNSET;
20 
21 import android.adservices.adselection.ReportEventRequest;
22 
23 import com.google.auto.value.AutoValue;
24 import com.google.common.collect.ImmutableList;
25 
26 import java.util.ArrayList;
27 import java.util.List;
28 import java.util.Set;
29 
30 /** Class for destinationRegisteredBeacon reported stats. */
31 @AutoValue
32 public abstract class DestinationRegisteredBeaconsReportedStats {
33     /** @return the entity who registered the beacons. */
34     @ReportEventRequest.ReportingDestination
getBeaconReportingDestinationType()35     public abstract int getBeaconReportingDestinationType();
36 
37     /** @return number of beacons ad-tech tries to register during reportImpression. */
getAttemptedRegisteredBeacons()38     public abstract int getAttemptedRegisteredBeacons();
39 
40     /** @return key size range for interactionKey in every registerAdBeacon call. */
getAttemptedKeySizesRangeType()41     public abstract ImmutableList<InteractionKeySizeRangeType> getAttemptedKeySizesRangeType();
42 
43     /** @return size of registered_ad_interactions database after each update to it. */
getTableNumRows()44     public abstract int getTableNumRows();
45 
46     /** @return the status response code in AdServices. */
getAdServicesStatusCode()47     public abstract int getAdServicesStatusCode();
48 
49     // The range of key size for interaction key.
50     public enum InteractionKeySizeRangeType {
51         UNSET_TYPE(0),
52         // The key size is smaller than 50% maximum key size.
53         MUCH_SMALLER_THAN_MAXIMUM_KEY_SIZE(1),
54         // The key size is equal or greater than 50% maximum key size
55         // but smaller than maximum key size.
56         SMALLER_THAN_MAXIMUM_KEY_SIZE(2),
57         // The key size is equal to maximum key size.
58         EQUAL_TO_MAXIMUM_KEY_SIZE(3),
59         // The key size is greater than maximum key size.
60         LARGER_THAN_MAXIMUM_KEY_SIZE(4);
61 
62         private final int mValue;
63 
InteractionKeySizeRangeType(int value)64         InteractionKeySizeRangeType(int value) {
65             mValue = value;
66         }
67 
getValue()68         public int getValue() {
69             return mValue;
70         }
71     }
72 
73     /** @return generic builder */
builder()74     public static Builder builder() {
75         return new AutoValue_DestinationRegisteredBeaconsReportedStats.Builder()
76                 .setAdServicesStatusCode(FIELD_UNSET);
77     }
78 
79     /** Builder class for DestinationRegisteredBeaconsReportedStats. */
80     @AutoValue.Builder
81     public abstract static class Builder {
setBeaconReportingDestinationType( @eportEventRequest.ReportingDestination int value)82         public abstract Builder setBeaconReportingDestinationType(
83                 @ReportEventRequest.ReportingDestination int value);
84 
setAttemptedRegisteredBeacons(int value)85         public abstract Builder setAttemptedRegisteredBeacons(int value);
86 
setAttemptedKeySizesRangeType( List<InteractionKeySizeRangeType> value)87         public abstract Builder setAttemptedKeySizesRangeType(
88                 List<InteractionKeySizeRangeType> value);
89 
setTableNumRows(int value)90         public abstract Builder setTableNumRows(int value);
91 
setAdServicesStatusCode(int value)92         public abstract Builder setAdServicesStatusCode(int value);
93 
build()94         public abstract DestinationRegisteredBeaconsReportedStats build();
95     }
96 
97     /**
98      * Converts set of interaction keys to list of interaction key size range type.
99      *
100      * @param interactionKeys The list of interaction keys.
101      * @param maxInteractionKeySize The maximum size of interaction key.
102      * @return The list of interaction key size range type.
103      */
getInteractionKeySizeRangeTypeList( Set<String> interactionKeys, long maxInteractionKeySize)104     public static List<InteractionKeySizeRangeType> getInteractionKeySizeRangeTypeList(
105             Set<String> interactionKeys,
106             long maxInteractionKeySize) {
107         List<InteractionKeySizeRangeType> results = new ArrayList<>();
108         if (interactionKeys == null || maxInteractionKeySize <= 0) {
109             return results;
110         }
111         for (String interactionKey : interactionKeys) {
112             if (interactionKey == null) {
113                 results.add(InteractionKeySizeRangeType.UNSET_TYPE);
114             } else if (interactionKey.length() < 0.5 * maxInteractionKeySize) {
115                 results.add(InteractionKeySizeRangeType.MUCH_SMALLER_THAN_MAXIMUM_KEY_SIZE);
116             } else if (interactionKey.length() < maxInteractionKeySize) {
117                 results.add(InteractionKeySizeRangeType.SMALLER_THAN_MAXIMUM_KEY_SIZE);
118             } else if (interactionKey.length() == maxInteractionKeySize) {
119                 results.add(InteractionKeySizeRangeType.EQUAL_TO_MAXIMUM_KEY_SIZE);
120             } else {
121                 results.add(InteractionKeySizeRangeType.LARGER_THAN_MAXIMUM_KEY_SIZE);
122             }
123         }
124         return results;
125     }
126 }
127