1 /* 2 * Copyright (C) 2022 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 package com.android.server.adservices; 17 18 import static com.android.server.adservices.BinderFlagReader.readFlag; 19 20 import android.annotation.NonNull; 21 import android.provider.DeviceConfig; 22 23 /** 24 * Flags Implementation that delegates to DeviceConfig. 25 * 26 * @hide 27 */ 28 public final class PhFlags implements Flags { 29 30 private static final PhFlags sSingleton = new PhFlags(); 31 32 /** Returns the singleton instance of the PhFlags. */ 33 @NonNull getInstance()34 static PhFlags getInstance() { 35 return sSingleton; 36 } 37 38 /* 39 * Keys for ALL the flags stored in DeviceConfig. 40 */ 41 // Adservices System Service enable status keys. 42 static final String KEY_ADSERVICES_SYSTEM_SERVICE_ENABLED = "adservice_system_service_enabled"; 43 44 static final String KEY_CLIENT_ERROR_LOGGING__ENABLE_CEL_FOR_SYSTEM_SERVER = 45 "ClientErrorLogging__enable_cel_for_system_server"; 46 47 /** Key to enable AtomicFileDataStore update API for adservices system service. */ 48 public static final String KEY_ENABLE_BATCH_UPDATE_API_IN_SYSTEM_SERVER = 49 "AtomicFileDatastore__enable_batch_update_api_in_system_server"; 50 51 @Override getAdServicesSystemServiceEnabled()52 public boolean getAdServicesSystemServiceEnabled() { 53 return getFlag(KEY_ADSERVICES_SYSTEM_SERVICE_ENABLED, ADSERVICES_SYSTEM_SERVICE_ENABLED); 54 } 55 56 @Override getEnableCelForSystemServer()57 public boolean getEnableCelForSystemServer() { 58 return getFlag( 59 KEY_CLIENT_ERROR_LOGGING__ENABLE_CEL_FOR_SYSTEM_SERVER, 60 CLIENT_ERROR_LOGGING__ENABLE_CEL_FOR_SYSTEM_SERVER); 61 } 62 63 @Override getEnableAtomicFileDatastoreBatchUpdateApiInSystemServer()64 public boolean getEnableAtomicFileDatastoreBatchUpdateApiInSystemServer() { 65 return getFlag( 66 KEY_ENABLE_BATCH_UPDATE_API_IN_SYSTEM_SERVER, 67 ENABLE_ATOMIC_FILE_DATASTORE_BATCH_UPDATE_API_IN_SYSTEM_SERVER); 68 } 69 70 @SuppressWarnings("AvoidDeviceConfigUsage") // Helper / infra method getFlag(String name, boolean defaultValue)71 private boolean getFlag(String name, boolean defaultValue) { 72 return readFlag( 73 () -> 74 DeviceConfig.getBoolean( 75 DeviceConfig.NAMESPACE_ADSERVICES, name, defaultValue)); 76 } 77 } 78