1 /* 2 * Copyright (C) 2024 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 android.adservices.common; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.annotation.SystemApi; 22 import android.os.Parcel; 23 import android.os.Parcelable; 24 25 import com.android.adservices.flags.Flags; 26 27 import java.util.Objects; 28 29 /** 30 * Response parcel of the getAdservicesCommonStates API. 31 * 32 * @hide 33 */ 34 @SystemApi 35 @FlaggedApi(Flags.FLAG_GET_ADSERVICES_COMMON_STATES_API_ENABLED) 36 public final class AdServicesCommonStatesResponse implements Parcelable { 37 38 private AdServicesCommonStates mAdServicesCommonStates; 39 AdServicesCommonStatesResponse(AdServicesCommonStates adservicesCommonStates)40 private AdServicesCommonStatesResponse(AdServicesCommonStates adservicesCommonStates) { 41 mAdServicesCommonStates = adservicesCommonStates; 42 } 43 AdServicesCommonStatesResponse(@onNull Parcel in)44 private AdServicesCommonStatesResponse(@NonNull Parcel in) { 45 mAdServicesCommonStates = in.readParcelable(AdServicesCommonStates.class.getClassLoader()); 46 } 47 48 @NonNull getAdServicesCommonStates()49 public AdServicesCommonStates getAdServicesCommonStates() { 50 return mAdServicesCommonStates; 51 } 52 53 @NonNull 54 public static final Creator<AdServicesCommonStatesResponse> CREATOR = 55 new Creator<AdServicesCommonStatesResponse>() { 56 @Override 57 public AdServicesCommonStatesResponse createFromParcel(@NonNull Parcel in) { 58 Objects.requireNonNull(in); 59 return new AdServicesCommonStatesResponse(in); 60 } 61 62 @Override 63 public AdServicesCommonStatesResponse[] newArray(int size) { 64 return new AdServicesCommonStatesResponse[size]; 65 } 66 }; 67 68 @Override describeContents()69 public int describeContents() { 70 return 0; 71 } 72 73 /** @hide */ 74 @Override writeToParcel(@onNull Parcel dest, int flags)75 public void writeToParcel(@NonNull Parcel dest, int flags) { 76 Objects.requireNonNull(dest); 77 78 dest.writeParcelable(mAdServicesCommonStates, flags); 79 } 80 81 @Override toString()82 public String toString() { 83 return "EnableAdServicesResponse{" 84 + "mAdservicesCommonStates=" 85 + mAdServicesCommonStates 86 + "'}"; 87 } 88 89 /** 90 * Builder for {@link AdServicesCommonStatesResponse} objects. 91 * 92 * @hide 93 */ 94 public static final class Builder { 95 private AdServicesCommonStates mAdServicesCommonStates; 96 Builder(@onNull AdServicesCommonStates adservicesCommonStates)97 public Builder(@NonNull AdServicesCommonStates adservicesCommonStates) { 98 mAdServicesCommonStates = adservicesCommonStates; 99 } 100 101 /** Set the enableAdServices API response status Code. */ 102 @NonNull setAdservicesCommonStates( AdServicesCommonStates adservicesCommonStates)103 public AdServicesCommonStatesResponse.Builder setAdservicesCommonStates( 104 AdServicesCommonStates adservicesCommonStates) { 105 mAdServicesCommonStates = adservicesCommonStates; 106 return this; 107 } 108 109 /** 110 * Builds a {@link AdServicesCommonStatesResponse} instance. 111 * 112 * <p>throws IllegalArgumentException if any of the status code is null or error message is 113 * not set for an unsuccessful status. 114 */ 115 @NonNull build()116 public AdServicesCommonStatesResponse build() { 117 return new AdServicesCommonStatesResponse(mAdServicesCommonStates); 118 } 119 } 120 } 121