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.service.signals.updateprocessors;
18 
19 import com.android.adservices.data.signals.DBProtectedSignal;
20 
21 import org.json.JSONException;
22 
23 import java.nio.ByteBuffer;
24 import java.util.Map;
25 import java.util.Set;
26 
27 /** A strategy for processing an individual command from the signals update JSON. */
28 public interface UpdateProcessor {
29 
30     /**
31      * Gets the name of the processor, should match the key for it in the JSON.
32      *
33      * @return A string key for this processor to be used in parsing the update JSON.
34      */
getName()35     String getName();
36 
37     /**
38      * @param updates A JSONObject or JSONArray describing the updates to be made by this processor.
39      * @param current A map from keys to signals currently under those keys. Note that byte buffers
40      *     must have been generated with .wrap().
41      * @return An output object describing: 1. Which keys this processor has modified or could have
42      *     modified. 2. Which signals should be removed. 3. Which signals should be added.
43      * @throws JSONException In the event the passed in JSON is invalid
44      */
processUpdates(Object updates, Map<ByteBuffer, Set<DBProtectedSignal>> current)45     UpdateOutput processUpdates(Object updates, Map<ByteBuffer, Set<DBProtectedSignal>> current)
46             throws JSONException;
47 }
48