diff options
author | Presubmit Automerger Backend <android-build-presubmit-automerger-backend@system.gserviceaccount.com> | 2023-01-17 19:45:14 +0000 |
---|---|---|
committer | Presubmit Automerger Backend <android-build-presubmit-automerger-backend@system.gserviceaccount.com> | 2023-01-17 19:45:14 +0000 |
commit | 892a6ecb5404bcfb4905f5573a38ff58b1e1b995 (patch) | |
tree | 2b23cbec9c218318d30909d19ec130a4d0f37d7b | |
parent | f26ea610f89c738ea04ef30596db04f63195dcac (diff) | |
parent | a8939013f99872bdb423c7bfb20ecb5a6af23814 (diff) | |
download | mobile-data-download-892a6ecb5404bcfb4905f5573a38ff58b1e1b995.tar.gz |
[automerge] Add EnabledSupplier in ManifestFileGroupPopulator 2p: a8939013f9
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/mobile-data-download/+/21019686
Bug: 265797474
Change-Id: I918531d763bcc588dff493e05e7a83a6d78feadb
-rw-r--r-- | java/com/google/android/libraries/mobiledatadownload/populator/ManifestFileGroupPopulator.java | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/java/com/google/android/libraries/mobiledatadownload/populator/ManifestFileGroupPopulator.java b/java/com/google/android/libraries/mobiledatadownload/populator/ManifestFileGroupPopulator.java index 422470e..27dc5f3 100644 --- a/java/com/google/android/libraries/mobiledatadownload/populator/ManifestFileGroupPopulator.java +++ b/java/com/google/android/libraries/mobiledatadownload/populator/ManifestFileGroupPopulator.java @@ -109,6 +109,11 @@ public final class ManifestFileGroupPopulator implements FileGroupPopulator { ListenableFuture<ManifestConfig> parse(Uri fileUri); } + /** Client-provided supplier of a condition whether the populator should be enabled. */ + public interface EnabledSupplier { + boolean isEnabled(); + } + /** Builder for {@link ManifestFileGroupPopulator}. */ public static final class Builder { private boolean allowsInsecureHttp = false; @@ -124,6 +129,8 @@ public final class ManifestFileGroupPopulator implements FileGroupPopulator { private Optional<ManifestConfigOverrider> overriderOptional = Optional.absent(); private Optional<String> instanceIdOptional = Optional.absent(); private Flags flags = new Flags() {}; + // Enabled the populator if no EnabledSupplier is provided. + private EnabledSupplier enabledSupplier = () -> true; /** * Sets the flag that allows insecure http. @@ -211,6 +218,15 @@ public final class ManifestFileGroupPopulator implements FileGroupPopulator { return this; } + /** + * Sets the condition to check whether the populator should be enabled. If the value, returned + * by the condition is {@code false}, {@code refreshFileGroups} should do nothing. + */ + public Builder setEnabledSupplier(EnabledSupplier enabledSupplier) { + this.enabledSupplier = enabledSupplier; + return this; + } + public ManifestFileGroupPopulator build() { Preconditions.checkNotNull(context, "Must call setContext() before build()."); Preconditions.checkNotNull( @@ -242,6 +258,7 @@ public final class ManifestFileGroupPopulator implements FileGroupPopulator { private final FileGroupPopulatorLogger eventLogger; // We use futureSerializer for synchronization. private final ExecutionSequencer futureSerializer = ExecutionSequencer.create(); + private final EnabledSupplier enabledSupplier; /** Returns a Builder for {@link ManifestFileGroupPopulator}. */ public static Builder builder() { @@ -262,6 +279,7 @@ public final class ManifestFileGroupPopulator implements FileGroupPopulator { this.overriderOptional = builder.overriderOptional; this.eventLogger = new FileGroupPopulatorLogger(builder.logger, builder.flags); this.manifestFileMetadataStore = builder.manifestFileMetadataStore; + this.enabledSupplier = builder.enabledSupplier; } @Override @@ -288,6 +306,10 @@ public final class ManifestFileGroupPopulator implements FileGroupPopulator { private ListenableFuture<Void> refreshFileGroups( MobileDataDownload mobileDataDownload, ManifestFileFlag manifestFileFlag) { + if(!enabledSupplier.isEnabled()){ + LogUtil.d("%s: The populator was disabled by enabledSupplier", TAG); + return immediateVoidFuture(); + } if (!validate(manifestFileFlag)) { logRefreshResult(0, manifestFileFlag); |