• 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.registration;
18 
19 import java.util.Optional;
20 
21 import javax.annotation.Nullable;
22 
23 /** POJO for storing source and trigger fetcher status */
24 public class AsyncFetchStatus {
25     public enum ResponseStatus {
26         UNKNOWN,
27         SUCCESS,
28         SERVER_UNAVAILABLE,
29         NETWORK_ERROR,
30         INVALID_URL
31     }
32 
33     public enum EntityStatus {
34         UNKNOWN,
35         SUCCESS,
36         HEADER_MISSING,
37         HEADER_ERROR,
38         PARSING_ERROR,
39         VALIDATION_ERROR,
40         INVALID_ENROLLMENT,
41         STORAGE_ERROR
42     }
43 
44     private ResponseStatus mResponseStatus;
45 
46     private EntityStatus mEntityStatus;
47 
48     @Nullable private Long mResponseSize;
49 
50     @Nullable private Long mRegistrationDelay;
51 
52     private boolean mIsRedirectError;
53 
AsyncFetchStatus()54     public AsyncFetchStatus() {
55         mResponseStatus = ResponseStatus.UNKNOWN;
56         mEntityStatus = EntityStatus.UNKNOWN;
57         mIsRedirectError = false;
58     }
59 
60     /** Get the status of a communication with an Ad Tech server. */
getResponseStatus()61     public ResponseStatus getResponseStatus() {
62         return mResponseStatus;
63     }
64 
65     /**
66      * Set the status of a communication with an Ad Tech server.
67      *
68      * @param status a {@link ResponseStatus} that is used up the call stack to determine errors in
69      *     the Ad tech server during source and trigger fetching.
70      */
setResponseStatus(ResponseStatus status)71     public void setResponseStatus(ResponseStatus status) {
72         mResponseStatus = status;
73     }
74 
75     /** Get entity status */
getEntityStatus()76     public EntityStatus getEntityStatus() {
77         return mEntityStatus;
78     }
79 
80     /** Set entity status */
setEntityStatus(EntityStatus entityStatus)81     public void setEntityStatus(EntityStatus entityStatus) {
82         mEntityStatus = entityStatus;
83     }
84 
85     /** Get response header size. */
getResponseSize()86     public Optional<Long> getResponseSize() {
87         return Optional.ofNullable(mResponseSize);
88     }
89 
90     /** Set response header size. */
setResponseSize(Long responseSize)91     public void setResponseSize(Long responseSize) {
92         mResponseSize = responseSize;
93     }
94 
95     /** Get registration delay. */
getRegistrationDelay()96     public Optional<Long> getRegistrationDelay() {
97         return Optional.ofNullable(mRegistrationDelay);
98     }
99 
100     /** Set registration delay. */
setRegistrationDelay(Long registrationDelay)101     public void setRegistrationDelay(Long registrationDelay) {
102         mRegistrationDelay = registrationDelay;
103     }
104 
105     /** Get redirect error status. */
isRedirectError()106     public boolean isRedirectError() {
107         return mIsRedirectError;
108     }
109 
110     /** Set redirect error status. */
setRedirectError(boolean isRedirectError)111     public void setRedirectError(boolean isRedirectError) {
112         mIsRedirectError = isRedirectError;
113     }
114 
115     /** Returns true if request is successful. */
isRequestSuccess()116     public boolean isRequestSuccess() {
117         return mResponseStatus == ResponseStatus.SUCCESS;
118     }
119 
120     /** Returns true if request can be retried. */
canRetry()121     public boolean canRetry() {
122         return mResponseStatus == ResponseStatus.NETWORK_ERROR
123                 || mResponseStatus == ResponseStatus.SERVER_UNAVAILABLE;
124     }
125 }
126