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.JSONArray; 22 import org.json.JSONException; 23 24 import java.nio.ByteBuffer; 25 import java.util.Map; 26 import java.util.Set; 27 28 /** 29 * Removes the signal for a key. 30 * 31 * <p>The value of this is a list of base 64 strings corresponding to the keys of the signals that 32 * should be deleted. 33 */ 34 public class Remove implements UpdateProcessor { 35 36 private static final String REMOVE = "remove"; 37 38 @Override getName()39 public String getName() { 40 return REMOVE; 41 } 42 43 @Override processUpdates( Object updates, Map<ByteBuffer, Set<DBProtectedSignal>> current)44 public UpdateOutput processUpdates( 45 Object updates, Map<ByteBuffer, Set<DBProtectedSignal>> current) throws JSONException { 46 UpdateOutput toReturn = new UpdateOutput(); 47 JSONArray updatesArray = UpdateProcessorUtils.castToJSONArray(REMOVE, updates); 48 for (int i = 0; i < updatesArray.length(); i++) { 49 ByteBuffer key = UpdateProcessorUtils.decodeKey(REMOVE, updatesArray.getString(i)); 50 UpdateProcessorUtils.touchKey(key, toReturn.getKeysTouched()); 51 // Remove all signals for the key 52 if (current.containsKey(key)) { 53 toReturn.getToRemove().addAll(current.get(key)); 54 } 55 } 56 return toReturn; 57 } 58 } 59