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 com.android.adservices.spe;
18 
19 import java.util.Arrays;
20 import java.util.Map;
21 import java.util.function.Function;
22 import java.util.stream.Collectors;
23 
24 /** Enum class to store background jobs metadata. */
25 public enum AdServicesJobInfo {
26     MAINTENANCE_JOB("MAINTENANCE_JOB", 1),
27 
28     TOPICS_EPOCH_JOB("TOPICS_EPOCH_JOB", 2),
29 
30     MEASUREMENT_EVENT_MAIN_REPORTING_JOB("MEASUREMENT_EVENT_MAIN_REPORTING_JOB", 3),
31 
32     MEASUREMENT_DELETE_EXPIRED_JOB("MEASUREMENT_DELETE_EXPIRED_JOB", 4),
33 
34     MEASUREMENT_ATTRIBUTION_JOB("MEASUREMENT_ATTRIBUTION_JOB", 5),
35 
36     MEASUREMENT_EVENT_FALLBACK_REPORTING_JOB("MEASUREMENT_EVENT_FALLBACK_REPORTING_JOB", 6),
37 
38     MEASUREMENT_AGGREGATE_MAIN_REPORTING_JOB("MEASUREMENT_AGGREGATE_MAIN_REPORTING_JOB", 7),
39 
40     MEASUREMENT_AGGREGATE_FALLBACK_REPORTING_JOB("MEASUREMENT_AGGREGATE_FALLBACK_REPORTING_JOB", 8),
41 
42     FLEDGE_BACKGROUND_FETCH_JOB("FLEDGE_BACKGROUND_FETCH_JOB", 9),
43 
44     CONSENT_NOTIFICATION_JOB("CONSENT_NOTIFICATION_JOB", 10),
45 
46     MDD_MAINTENANCE_PERIODIC_TASK_JOB("MDD_MAINTENANCE_PERIODIC_TASK_JOB", 11),
47 
48     MDD_CHARGING_PERIODIC_TASK_JOB("MDD_CHARGING_PERIODIC_TASK_JOB", 12),
49 
50     MDD_CELLULAR_CHARGING_PERIODIC_TASK_JOB("MDD_CELLULAR_CHARGING_PERIODIC_TASK_JOB", 13),
51 
52     MDD_WIFI_CHARGING_PERIODIC_TASK_JOB("MDD_WIFI_CHARGING_PERIODIC_TASK_JOB", 14),
53 
54     @Deprecated
55     DEPRECATED_ASYNC_REGISTRATION_QUEUE_JOB("DEPRECATED_ASYNC_REGISTRATION_QUEUE_JOB", 15),
56 
57     MEASUREMENT_DELETE_UNINSTALLED_JOB("MEASUREMENT_DELETE_UNINSTALLED_JOB", 16),
58 
59     MEASUREMENT_DEBUG_REPORT_JOB("MEASUREMENT_DEBUG_REPORT_JOB", 17),
60 
61     MEASUREMENT_VERBOSE_DEBUG_REPORT_JOB("MEASUREMENT_VERBOSE_DEBUG_REPORT_JOB", 18),
62 
63     MEASUREMENT_ASYNC_REGISTRATION_FALLBACK_JOB("MEASUREMENT_ASYNC_REGISTRATION_FALLBACK_JOB", 19),
64 
65     MEASUREMENT_ASYNC_REGISTRATION_JOB("MEASUREMENT_ASYNC_REGISTRATION_JOB", 20),
66 
67     MEASUREMENT_ATTRIBUTION_FALLBACK_JOB("MEASUREMENT_ATTRIBUTION_FALLBACK_JOB", 21),
68 
69     FLEDGE_AD_SELECTION_ENCRYPTION_KEY_FETCH_JOB(
70             "FLEDGE_AD_SELECTION_ENCRYPTION_KEY_FETCH_JOB", 22),
71 
72     COBALT_LOGGING_JOB("COBALT_LOGGING_JOB", 23),
73     MEASUREMENT_VERBOSE_DEBUG_REPORTING_FALLBACK_JOB(
74             "MEASUREMENT_VERBOSE_DEBUG_REPORTING_FALLBACK_JOB", 24),
75     MEASUREMENT_DEBUG_REPORTING_FALLBACK_JOB("MEASUREMENT_DEBUG_REPORTING_FALLBACK_JOB", 25),
76     FLEDGE_AD_SELECTION_DEBUG_REPORT_SENDER_JOB("FLEDGE_AD_SELECTION_DEBUG_REPORT_SENDER_JOB", 26),
77 
78     EXT_APPSEARCH_DELETE_INITIAL_SCHEDULER_JOB("EXT_APPSEARCH_DELETE_INITIAL_SCHEDULER_JOB", 27),
79 
80     PERIODIC_SIGNALS_ENCODING_JOB("PERIODIC_SIGNALS_ENCODING_JOB", 29),
81 
82     ENCRYPTION_KEY_PERIODIC_JOB("ENCRYPTION_KEY_PERIODIC_JOB", 30),
83 
84     FLEDGE_KANON_SIGN_JOIN_BACKGROUND_JOB("FLEDGE_KANON_SIGN_JOIN_BACKGROUND_JOB", 31),
85 
86     SCHEDULE_CUSTOM_AUDIENCE_UPDATE_BACKGROUND_JOB(
87             "SCHEDULE_CUSTOM_AUDIENCE_UPDATE_BACKGROUND_JOB", 32),
88 
89     MEASUREMENT_IMMEDIATE_AGGREGATE_REPORTING_JOB(
90             "MEASUREMENT_IMMEDIATE_AGGREGATE_REPORTING_JOB", 33),
91 
92     MEASUREMENT_REPORTING_JOB("MEASUREMENT_REPORTING_JOB", 34);
93     private final String mJobServiceName;
94     private final int mJobId;
95 
96     // The reverse mapping to get job name by job ID.
97     // Duplicated job ID leads to an IllegalStateException, referring to Collectors.toMap().
98     private static final Map<Integer, String> JOB_ID_TO_NAME_MAP =
99             Arrays.stream(AdServicesJobInfo.values())
100                     .collect(
101                             Collectors.toMap(
102                                     AdServicesJobInfo::getJobId,
103                                     AdServicesJobInfo::getJobServiceName));
104 
105     // The reverse mapping to get job info by job ID.
106     private static final Map<Integer, AdServicesJobInfo> JOB_ID_TO_INFO_MAP =
107             Arrays.stream(AdServicesJobInfo.values())
108                     .collect(Collectors.toMap(AdServicesJobInfo::getJobId, Function.identity()));
109 
AdServicesJobInfo(String jobServiceName, int jobId)110     AdServicesJobInfo(String jobServiceName, int jobId) {
111         mJobServiceName = jobServiceName;
112         mJobId = jobId;
113     }
114 
115     /**
116      * Get the job name of a job info.
117      *
118      * @return the job name
119      */
getJobServiceName()120     public String getJobServiceName() {
121         return mJobServiceName;
122     }
123 
124     /**
125      * Get the job id of a job info.
126      *
127      * @return the job id
128      */
getJobId()129     public int getJobId() {
130         return mJobId;
131     }
132 
getJobIdToJobInfoMap()133     public static Map<Integer, AdServicesJobInfo> getJobIdToJobInfoMap() {
134         return JOB_ID_TO_INFO_MAP;
135     }
136 
getJobIdToJobNameMap()137     public static Map<Integer, String> getJobIdToJobNameMap() {
138         return JOB_ID_TO_NAME_MAP;
139     }
140 }
141