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.IntDef; 21 22 import com.android.adservices.flags.Flags; 23 24 import java.lang.annotation.Retention; 25 import java.lang.annotation.RetentionPolicy; 26 27 /** 28 * Represents AdServices Module type. 29 * 30 * <p>This class is used to identify the adservices feature that we want to turn on/off or set user 31 * consent. 32 * 33 * @hide 34 */ 35 @FlaggedApi(Flags.FLAG_ADSERVICES_ENABLE_PER_MODULE_OVERRIDES_API) 36 public final class Module { 37 38 /** Measurement module. */ 39 public static final int MEASUREMENT = AdServicesCommonManager.MODULE_MEASUREMENT; 40 41 /** Privacy Sandbox module. */ 42 public static final int PROTECTED_AUDIENCE = AdServicesCommonManager.MODULE_PROTECTED_AUDIENCE; 43 44 /** Privacy Sandbox Attribution module. */ 45 public static final int PROTECTED_APP_SIGNALS = 46 AdServicesCommonManager.MODULE_PROTECTED_APP_SIGNALS; 47 48 /** Topics module. */ 49 public static final int TOPICS = AdServicesCommonManager.MODULE_TOPICS; 50 51 /** On-device Personalization(ODP) module. */ 52 public static final int ON_DEVICE_PERSONALIZATION = 53 AdServicesCommonManager.MODULE_ON_DEVICE_PERSONALIZATION; 54 55 /** ADID module. */ 56 public static final int ADID = AdServicesCommonManager.MODULE_ADID; 57 58 /** Default Contractor, make it private so that it won't show in the system-current.txt */ Module()59 private Module() {} 60 61 /** 62 * ModuleCode IntDef. 63 * 64 * @hide 65 */ 66 @IntDef( 67 value = { 68 MEASUREMENT, 69 PROTECTED_AUDIENCE, 70 PROTECTED_APP_SIGNALS, 71 TOPICS, 72 ON_DEVICE_PERSONALIZATION, 73 ADID 74 }) 75 @Retention(RetentionPolicy.SOURCE) 76 public @interface ModuleCode {} 77 78 /** 79 * Validates a module. 80 * 81 * @param module module to validate 82 * @return module 83 */ 84 @ModuleCode validate(@oduleCode int module)85 static int validate(@ModuleCode int module) { 86 return switch (module) { 87 case ADID, 88 MEASUREMENT, 89 ON_DEVICE_PERSONALIZATION, 90 PROTECTED_APP_SIGNALS, 91 PROTECTED_AUDIENCE, 92 TOPICS -> 93 module; 94 default -> throw new IllegalArgumentException("Invalid Module Code:" + module); 95 }; 96 } 97 } 98