1 /* 2 * Copyright 2022 Google LLC 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.google.android.libraries.mobiledatadownload.populator; 17 18 import static com.google.common.util.concurrent.Futures.immediateFuture; 19 20 import com.google.common.base.Supplier; 21 import com.google.common.util.concurrent.ListenableFuture; 22 import com.google.mobiledatadownload.DownloadConfigProto.DataFileGroup; 23 import com.google.mobiledatadownload.DownloadConfigProto.ManifestConfig; 24 import java.util.ArrayList; 25 import java.util.List; 26 27 /** 28 * Proxy overrider used in the migration of ManifestFileGroupPopulator. 29 * 30 * <p>{@code flagSupplier} is used to determine whether the ManifestFileGroupPopulator is enabled. 31 * It is called every time a client calls refreshFileGroups. When it returns true, it calls {@code 32 * localeOverrider.override()}; when it returns false, it returns an empty list which makes the 33 * ManifestFileGroupPopulator not add any data file group to MDD. 34 */ 35 public final class MigrationProxyLocaleOverrider implements ManifestConfigOverrider { 36 private static final String TAG = "MigrationProxyLocaleOverrider"; 37 38 private final Supplier<Boolean> flagSupplier; 39 private final LocaleOverrider localeOverrider; 40 MigrationProxyLocaleOverrider( LocaleOverrider localeOverrider, Supplier<Boolean> flagSupplier)41 public MigrationProxyLocaleOverrider( 42 LocaleOverrider localeOverrider, Supplier<Boolean> flagSupplier) { 43 this.flagSupplier = flagSupplier; 44 this.localeOverrider = localeOverrider; 45 } 46 47 @Override override(ManifestConfig manifestConfig)48 public ListenableFuture<List<DataFileGroup>> override(ManifestConfig manifestConfig) { 49 if (flagSupplier.get()) { 50 return localeOverrider.override(manifestConfig); 51 } else { 52 return immediateFuture(new ArrayList<>()); 53 } 54 } 55 } 56