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 20 21 /** POJO for storing source and trigger fetcher status */ 22 public class AsyncFetchStatus { 23 public enum ResponseStatus { 24 UNKNOWN, 25 SUCCESS, 26 SERVER_UNAVAILABLE, 27 NETWORK_ERROR, 28 INVALID_URL, 29 HEADER_SIZE_LIMIT_EXCEEDED 30 } 31 32 public enum EntityStatus { 33 UNKNOWN, 34 SUCCESS, 35 HEADER_MISSING, 36 HEADER_ERROR, 37 PARSING_ERROR, 38 VALIDATION_ERROR, 39 INVALID_ENROLLMENT, 40 STORAGE_ERROR 41 } 42 43 private ResponseStatus mResponseStatus; 44 45 private EntityStatus mEntityStatus; 46 47 private long mResponseSize; 48 49 private long mRegistrationDelay; 50 51 private boolean mIsRedirectError; 52 private int mRetryCount; 53 private boolean mIsRedirectOnly; 54 private boolean mIsPARequest; 55 AsyncFetchStatus()56 public AsyncFetchStatus() { 57 mResponseStatus = ResponseStatus.UNKNOWN; 58 mEntityStatus = EntityStatus.UNKNOWN; 59 mIsRedirectError = false; 60 mResponseSize = 0L; 61 mRegistrationDelay = 0L; 62 mIsPARequest = false; 63 } 64 65 /** Get the status of a communication with an Ad Tech server. */ getResponseStatus()66 public ResponseStatus getResponseStatus() { 67 return mResponseStatus; 68 } 69 70 /** 71 * Set the status of a communication with an Ad Tech server. 72 * 73 * @param status a {@link ResponseStatus} that is used up the call stack to determine errors in 74 * the Ad tech server during source and trigger fetching. 75 */ setResponseStatus(ResponseStatus status)76 public void setResponseStatus(ResponseStatus status) { 77 mResponseStatus = status; 78 } 79 80 /** Get entity status */ getEntityStatus()81 public EntityStatus getEntityStatus() { 82 return mEntityStatus; 83 } 84 85 /** Set entity status */ setEntityStatus(EntityStatus entityStatus)86 public void setEntityStatus(EntityStatus entityStatus) { 87 mEntityStatus = entityStatus; 88 } 89 90 /** Get response header size. */ getResponseSize()91 public long getResponseSize() { 92 return mResponseSize; 93 } 94 95 /** Set response header size. */ setResponseSize(long responseSize)96 public void setResponseSize(long responseSize) { 97 mResponseSize = responseSize; 98 } 99 100 /** Get registration delay. */ getRegistrationDelay()101 public long getRegistrationDelay() { 102 return mRegistrationDelay; 103 } 104 105 /** Set registration delay. */ setRegistrationDelay(long registrationDelay)106 public void setRegistrationDelay(long registrationDelay) { 107 mRegistrationDelay = registrationDelay; 108 } 109 110 /** Get redirect error status. */ isRedirectError()111 public boolean isRedirectError() { 112 return mIsRedirectError; 113 } 114 115 /** Set redirect error status. */ setRedirectError(boolean isRedirectError)116 public void setRedirectError(boolean isRedirectError) { 117 mIsRedirectError = isRedirectError; 118 } 119 120 /** Get retry count. */ getRetryCount()121 public int getRetryCount() { 122 return mRetryCount; 123 } 124 125 /** Set retry count. */ setRetryCount(int retryCount)126 public void setRetryCount(int retryCount) { 127 mRetryCount = retryCount; 128 } 129 130 /** Get redirect status. */ isRedirectOnly()131 public boolean isRedirectOnly() { 132 return mIsRedirectOnly; 133 } 134 135 /** Set redirect status. */ setRedirectOnlyStatus(boolean isRedirectOnly)136 public void setRedirectOnlyStatus(boolean isRedirectOnly) { 137 mIsRedirectOnly = isRedirectOnly; 138 } 139 140 /** Get PA request status. */ isPARequest()141 public boolean isPARequest() { 142 return mIsPARequest; 143 } 144 145 /** Set PA request status. */ setPARequestStatus(boolean isPARequest)146 public void setPARequestStatus(boolean isPARequest) { 147 mIsPARequest = isPARequest; 148 } 149 150 /** Returns true if request is successful. */ isRequestSuccess()151 public boolean isRequestSuccess() { 152 return mResponseStatus == ResponseStatus.SUCCESS; 153 } 154 155 /** Returns true if request can be retried. */ canRetry()156 public boolean canRetry() { 157 return mResponseStatus == ResponseStatus.NETWORK_ERROR 158 || mResponseStatus == ResponseStatus.SERVER_UNAVAILABLE; 159 } 160 } 161