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 android.adservices.adselection;
18 
19 import android.annotation.FlaggedApi;
20 import android.annotation.NonNull;
21 import android.os.Parcel;
22 import android.os.Parcelable;
23 
24 import com.android.adservices.flags.Flags;
25 
26 import java.util.Objects;
27 
28 /** Generic Decision logic that could be provided by the buyer or seller. */
29 @FlaggedApi(Flags.FLAG_FLEDGE_AD_SELECTION_FILTERING_ENABLED)
30 public final class DecisionLogic implements Parcelable {
31 
32     @NonNull private String mDecisionLogic;
33 
DecisionLogic(@onNull String buyerDecisionLogic)34     public DecisionLogic(@NonNull String buyerDecisionLogic) {
35         Objects.requireNonNull(buyerDecisionLogic);
36         mDecisionLogic = buyerDecisionLogic;
37     }
38 
DecisionLogic(@onNull Parcel in)39     private DecisionLogic(@NonNull Parcel in) {
40         this(in.readString());
41     }
42 
43     @NonNull
44     public static final Creator<DecisionLogic> CREATOR =
45             new Creator<DecisionLogic>() {
46                 @Override
47                 public DecisionLogic createFromParcel(Parcel in) {
48                     Objects.requireNonNull(in);
49                     return new DecisionLogic(in);
50                 }
51 
52                 @Override
53                 public DecisionLogic[] newArray(int size) {
54                     return new DecisionLogic[size];
55                 }
56             };
57 
58     @Override
describeContents()59     public int describeContents() {
60         return 0;
61     }
62 
63     @Override
writeToParcel(@onNull Parcel dest, int flags)64     public void writeToParcel(@NonNull Parcel dest, int flags) {
65         Objects.requireNonNull(dest);
66         dest.writeString(mDecisionLogic);
67     }
68 
69     @Override
toString()70     public String toString() {
71         return mDecisionLogic;
72     }
73 
74     @Override
hashCode()75     public int hashCode() {
76         return Objects.hash(mDecisionLogic);
77     }
78 
79     @Override
equals(Object o)80     public boolean equals(Object o) {
81         if (this == o) return true;
82         if (!(o instanceof DecisionLogic)) return false;
83         DecisionLogic decisionLogic = (DecisionLogic) o;
84         return mDecisionLogic.equals(decisionLogic.getLogic());
85     }
86 
87     @NonNull
getLogic()88     public String getLogic() {
89         return mDecisionLogic;
90     }
91 }
92