• 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.measurement.attribution;
18 
19 import com.android.adservices.service.measurement.EventSurfaceType;
20 import com.android.adservices.service.measurement.Source;
21 import com.android.adservices.service.measurement.Trigger;
22 
23 import java.util.Optional;
24 
25 import javax.annotation.Nullable;
26 
27 /** POJO for storing attribution status */
28 public class AttributionStatus {
29     /** Enums are tied to the AdservicesMeasurementAttributionStatus atom */
30     public enum SourceType {
31         UNKNOWN,
32         NAVIGATION,
33         EVENT
34     }
35 
36     public enum AttributionSurface {
37         UNKNOWN,
38         APP_APP,
39         APP_WEB,
40         WEB_APP,
41         WEB_WEB,
42     }
43 
44     public enum AttributionResult {
45         UNKNOWN,
46         SUCCESS,
47         FAILURE
48     }
49 
50     public enum FailureType {
51         UNKNOWN,
52         TRIGGER_IGNORED,
53         TRIGGER_ALREADY_ATTRIBUTED,
54         TRIGGER_MARKED_FOR_DELETION,
55         NO_MATCHING_SOURCE,
56         TOP_LEVEL_FILTER_MATCH_FAILURE,
57         RATE_LIMIT_EXCEEDED,
58         NO_REPORTS_GENERATED
59     }
60 
61     private SourceType mSourceType;
62     private AttributionSurface mAttributionSurface;
63     private AttributionResult mAttributionResult;
64     private FailureType mFailureType;
65     private boolean mIsSourceDerived;
66     private boolean mIsInstallAttribution;
67     @Nullable private Long mAttributionDelay;
68 
AttributionStatus()69     public AttributionStatus() {
70         mSourceType = SourceType.UNKNOWN;
71         mAttributionSurface = AttributionSurface.UNKNOWN;
72         mAttributionResult = AttributionResult.UNKNOWN;
73         mFailureType = FailureType.UNKNOWN;
74         mIsSourceDerived = false;
75         mIsInstallAttribution = false;
76     }
77 
78     /** Get the type of the source that is getting attributed. */
getSourceType()79     public SourceType getSourceType() {
80         return mSourceType;
81     }
82 
83     /** Set the type of the source that is getting attributed. */
setSourceType(SourceType type)84     public void setSourceType(SourceType type) {
85         mSourceType = type;
86     }
87 
88     /** Set the type of the source that is getting attributed using Source.SourceType. */
setSourceType(Source.SourceType type)89     public void setSourceType(Source.SourceType type) {
90         if (type == Source.SourceType.EVENT) {
91             setSourceType(SourceType.EVENT);
92         } else if (type == Source.SourceType.NAVIGATION) {
93             setSourceType(SourceType.NAVIGATION);
94         }
95     }
96 
97     /** Get the surface type for the attributed source and trigger. */
getAttributionSurface()98     public AttributionSurface getAttributionSurface() {
99         return mAttributionSurface;
100     }
101 
102     /** Set the surface type for the attributed source and trigger. */
setAttributionSurface(AttributionSurface attributionSurface)103     public void setAttributionSurface(AttributionSurface attributionSurface) {
104         mAttributionSurface = attributionSurface;
105     }
106 
107     /** Set the surface type for the attributed source and trigger using Source and Trigger. */
setSurfaceTypeFromSourceAndTrigger(Source source, Trigger trigger)108     public void setSurfaceTypeFromSourceAndTrigger(Source source, Trigger trigger) {
109         if (source.getPublisherType() == EventSurfaceType.APP
110                 && trigger.getDestinationType() == EventSurfaceType.APP) {
111             setAttributionSurface(AttributionSurface.APP_APP);
112         } else if (source.getPublisherType() == EventSurfaceType.APP
113                 && trigger.getDestinationType() == EventSurfaceType.WEB) {
114             setAttributionSurface(AttributionSurface.APP_WEB);
115         } else if (source.getPublisherType() == EventSurfaceType.WEB
116                 && trigger.getDestinationType() == EventSurfaceType.APP) {
117             setAttributionSurface(AttributionSurface.WEB_APP);
118         } else if (source.getPublisherType() == EventSurfaceType.WEB
119                 && trigger.getDestinationType() == EventSurfaceType.WEB) {
120             setAttributionSurface(AttributionSurface.WEB_WEB);
121         }
122     }
123 
124     /** Get the result of attribution. */
getAttributionResult()125     public AttributionResult getAttributionResult() {
126         return mAttributionResult;
127     }
128 
129     /** Set the result of attribution. */
setAttributionResult(AttributionResult attributionResult)130     public void setAttributionResult(AttributionResult attributionResult) {
131         mAttributionResult = attributionResult;
132     }
133 
134     /** Get failure type. */
getFailureType()135     public FailureType getFailureType() {
136         return mFailureType;
137     }
138 
139     /** Set failure type. */
setFailureType(FailureType failureType)140     public void setFailureType(FailureType failureType) {
141         mFailureType = failureType;
142     }
143 
144     /** Set failure type using Trigger.Status. */
setFailureTypeFromTriggerStatus(int triggerStatus)145     public void setFailureTypeFromTriggerStatus(int triggerStatus) {
146         if (triggerStatus == Trigger.Status.IGNORED) {
147             setFailureType(FailureType.TRIGGER_IGNORED);
148         } else if (triggerStatus == Trigger.Status.ATTRIBUTED) {
149             setFailureType(FailureType.TRIGGER_ALREADY_ATTRIBUTED);
150         } else if (triggerStatus == Trigger.Status.MARKED_TO_DELETE) {
151             setFailureType(FailureType.TRIGGER_MARKED_FOR_DELETION);
152         }
153     }
154 
155     /** See if source is derived. */
isSourceDerived()156     public boolean isSourceDerived() {
157         return mIsSourceDerived;
158     }
159 
160     /** Set source derived status */
setSourceDerived(boolean isSourceDerived)161     public void setSourceDerived(boolean isSourceDerived) {
162         mIsSourceDerived = isSourceDerived;
163     }
164 
165     /** See if attribution is an install attribution */
isInstallAttribution()166     public boolean isInstallAttribution() {
167         return mIsInstallAttribution;
168     }
169 
170     /** Set install attribution status */
setInstallAttribution(boolean installAttribution)171     public void setInstallAttribution(boolean installAttribution) {
172         mIsInstallAttribution = installAttribution;
173     }
174 
175     /** Get attribution delay. */
getAttributionDelay()176     public Optional<Long> getAttributionDelay() {
177         return Optional.ofNullable(mAttributionDelay);
178     }
179 
180     /** Set attribution delay. */
setAttributionDelay(Long attributionDelay)181     public void setAttributionDelay(Long attributionDelay) {
182         mAttributionDelay = attributionDelay;
183     }
184 }
185