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.common; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.os.Parcel; 22 import android.os.Parcelable; 23 24 /** 25 * AdServicesStates exposed to system apps/services through the enableAdServices API. The bits 26 * stored in this parcel can change frequently based on user interaction with the Ads settings page. 27 * 28 * @hide 29 */ 30 @SystemApi 31 public final class AdServicesStates implements Parcelable { 32 33 @NonNull 34 public static final Creator<AdServicesStates> CREATOR = 35 new Parcelable.Creator<>() { 36 @Override 37 public AdServicesStates createFromParcel(Parcel in) { 38 return new AdServicesStates(in); 39 } 40 41 @Override 42 public AdServicesStates[] newArray(int size) { 43 return new AdServicesStates[size]; 44 } 45 }; 46 47 private final boolean mIsPrivacySandboxUiEnabled; 48 private final boolean mIsPrivacySandboxUiRequest; 49 private final boolean mIsU18Account; 50 private final boolean mIsAdultAccount; 51 private final boolean mIsAdIdEnabled; 52 AdServicesStates( boolean isPrivacySandboxUiEnabled, boolean isPrivacySandboxUiRequest, boolean isU18Account, boolean isAdultAccount, boolean isAdIdEnabled)53 private AdServicesStates( 54 boolean isPrivacySandboxUiEnabled, 55 boolean isPrivacySandboxUiRequest, 56 boolean isU18Account, 57 boolean isAdultAccount, 58 boolean isAdIdEnabled) { 59 mIsPrivacySandboxUiEnabled = isPrivacySandboxUiEnabled; 60 mIsPrivacySandboxUiRequest = isPrivacySandboxUiRequest; 61 mIsU18Account = isU18Account; 62 mIsAdultAccount = isAdultAccount; 63 mIsAdIdEnabled = isAdIdEnabled; 64 } 65 AdServicesStates(@onNull Parcel in)66 private AdServicesStates(@NonNull Parcel in) { 67 mIsPrivacySandboxUiEnabled = in.readBoolean(); 68 mIsPrivacySandboxUiRequest = in.readBoolean(); 69 mIsU18Account = in.readBoolean(); 70 mIsAdultAccount = in.readBoolean(); 71 mIsAdIdEnabled = in.readBoolean(); 72 } 73 74 @Override describeContents()75 public int describeContents() { 76 return 0; 77 } 78 79 @Override writeToParcel(@onNull Parcel out, int flags)80 public void writeToParcel(@NonNull Parcel out, int flags) { 81 out.writeBoolean(mIsPrivacySandboxUiEnabled); 82 out.writeBoolean(mIsPrivacySandboxUiRequest); 83 out.writeBoolean(mIsU18Account); 84 out.writeBoolean(mIsAdultAccount); 85 out.writeBoolean(mIsAdIdEnabled); 86 } 87 88 /** Returns whether the privacy sandbox UI is visible from the settings app. */ 89 @NonNull isPrivacySandboxUiEnabled()90 public boolean isPrivacySandboxUiEnabled() { 91 return mIsPrivacySandboxUiEnabled; 92 } 93 94 /** 95 * Returns whether the API call was the byproduct of a privacy sandbox UI request from the 96 * settings app. 97 */ 98 @NonNull isPrivacySandboxUiRequest()99 public boolean isPrivacySandboxUiRequest() { 100 return mIsPrivacySandboxUiRequest; 101 } 102 103 /** Returns whether Advertising ID is enabled. */ 104 @NonNull isAdIdEnabled()105 public boolean isAdIdEnabled() { 106 return mIsAdIdEnabled; 107 } 108 109 /** 110 * Determines whether the user account is eligible for the U18 (under 18) privacy sandbox, in 111 * which all ads relevance personalized Ads APIs are * permanently disabled and the ad 112 * measurement API can be enabled/disabled by the user. An account is considered a U18 account 113 * if privacy sandbox has received signals that the user is a minor. 114 */ 115 @NonNull isU18Account()116 public boolean isU18Account() { 117 return mIsU18Account; 118 } 119 120 /** 121 * Determines whether the user account is eligible for the adult or full-fledged privacy 122 * sandbox, in which all Ads APIs can be * enabled/disabled by the user. An account is 123 * considered an adult account if privacy sandbox has received signals that the user is an 124 * adult. 125 */ 126 @NonNull isAdultAccount()127 public boolean isAdultAccount() { 128 return mIsAdultAccount; 129 } 130 131 /** Builder for {@link AdServicesStates} objects. */ 132 public static final class Builder { 133 private boolean mIsPrivacySandboxUiEnabled; 134 private boolean mIsPrivacySandboxUiRequest; 135 private boolean mIsU18Account; 136 private boolean mIsAdultAccount; 137 private boolean mIsAdIdEnabled; 138 Builder()139 public Builder() { 140 } 141 142 /** Set if the privacy sandbox UX entry point is enabled. */ 143 @NonNull setPrivacySandboxUiEnabled(boolean isPrivacySandboxUiEnabled)144 public Builder setPrivacySandboxUiEnabled(boolean isPrivacySandboxUiEnabled) { 145 mIsPrivacySandboxUiEnabled = isPrivacySandboxUiEnabled; 146 return this; 147 } 148 149 /** Set if the API call was the result of a privacy sandbox UX entry point request. */ 150 @NonNull setPrivacySandboxUiRequest(boolean isPrivacySandboxUiRequest)151 public Builder setPrivacySandboxUiRequest(boolean isPrivacySandboxUiRequest) { 152 mIsPrivacySandboxUiRequest = isPrivacySandboxUiRequest; 153 return this; 154 } 155 156 /** Set if the device is currently running under a U18 account. */ 157 @NonNull setU18Account(boolean isU18Account)158 public Builder setU18Account(boolean isU18Account) { 159 mIsU18Account = isU18Account; 160 return this; 161 } 162 163 /** Set if the device is currently running under an adult account. */ 164 @NonNull setAdultAccount(boolean isAdultAccount)165 public Builder setAdultAccount(boolean isAdultAccount) { 166 mIsAdultAccount = isAdultAccount; 167 return this; 168 } 169 170 /** Set if user has opt-in/out of Advertising ID. */ 171 @NonNull setAdIdEnabled(boolean isAdIdEnabled)172 public Builder setAdIdEnabled(boolean isAdIdEnabled) { 173 mIsAdIdEnabled = isAdIdEnabled; 174 return this; 175 } 176 177 /** Builds a {@link AdServicesStates} instance. */ 178 @NonNull build()179 public AdServicesStates build() { 180 return new AdServicesStates( 181 mIsPrivacySandboxUiEnabled, 182 mIsPrivacySandboxUiRequest, 183 mIsU18Account, 184 mIsAdultAccount, 185 mIsAdIdEnabled); 186 } 187 } 188 } 189