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 android.adservices.ondevicepersonalization; 18 19 import android.annotation.FlaggedApi; 20 import android.annotation.NonNull; 21 import android.annotation.Nullable; 22 import android.annotation.WorkerThread; 23 24 import com.android.adservices.ondevicepersonalization.flags.Flags; 25 26 import java.util.Set; 27 28 /** 29 * An interface to a read-only key-value store. 30 * 31 * Used as a Data Access Object for the REMOTE_DATA table. 32 * 33 * @see IsolatedService#getRemoteData(RequestToken) 34 * 35 */ 36 @FlaggedApi(Flags.FLAG_ON_DEVICE_PERSONALIZATION_APIS_ENABLED) 37 public interface KeyValueStore { 38 /** 39 * Looks up a key in a read-only store. 40 * 41 * @param key The key to look up. 42 * @return the value to which the specified key is mapped, 43 * or null if there contains no mapping for the key. 44 * 45 */ 46 @WorkerThread get(@onNull String key)47 @Nullable byte[] get(@NonNull String key); 48 49 /** 50 * Returns a Set view of the keys contained in the REMOTE_DATA table. 51 */ 52 @WorkerThread keySet()53 @NonNull Set<String> keySet(); 54 55 /** 56 * Returns the table id {@link ModelId.TableId} of KeyValueStore implementation. 57 * 58 * @hide 59 */ getTableId()60 default int getTableId(){ 61 return 0; 62 } 63 } 64