• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.consent;
18 
19 import android.app.adservices.consent.ConsentParcel;
20 
21 import com.android.internal.annotations.VisibleForTesting;
22 
23 /** Represents a PP API type. */
24 public enum AdServicesApiType {
25     TOPICS,
26     FLEDGE,
27     MEASUREMENTS;
28 
29     // to support scenario when GA UX is on but the consent is server from PP API
30     @VisibleForTesting static final String CONSENT_FLEDGE = "CONSENT-FLEDGE";
31     @VisibleForTesting static final String CONSENT_MEASUREMENT = "CONSENT-MEASUREMENT";
32     @VisibleForTesting static final String CONSENT_TOPICS = "CONSENT-TOPICS";
33 
34     /** Map the {@link AdServicesApiType} to Consent API type integer. */
toConsentApiType()35     public int toConsentApiType() {
36         switch (this) {
37             case TOPICS:
38                 return ConsentParcel.TOPICS;
39             case FLEDGE:
40                 return ConsentParcel.FLEDGE;
41             case MEASUREMENTS:
42                 return ConsentParcel.MEASUREMENT;
43             default:
44                 return ConsentParcel.UNKNOWN;
45         }
46     }
47 
48     /**
49      * Map the {@link AdServicesApiType} to {@link String} which represents the key in the PP API
50      * datastore.
51      *
52      * @return key which can be used to retrieved data for {@link AdServicesApiType} from PP API
53      *     datastore.
54      */
toPpApiDatastoreKey()55     public String toPpApiDatastoreKey() {
56         switch (this) {
57             case TOPICS:
58                 return CONSENT_TOPICS;
59             case FLEDGE:
60                 return CONSENT_FLEDGE;
61             case MEASUREMENTS:
62                 return CONSENT_MEASUREMENT;
63             default:
64                 throw new IllegalStateException("AdServicesApiType doesn't exist.");
65         }
66     }
67 }
68