diff options
author | Hao Liu <haoliuu@google.com> | 2023-01-17 17:46:50 +0000 |
---|---|---|
committer | Hao Liu <haoliuu@google.com> | 2023-01-17 19:45:01 +0000 |
commit | a8939013f99872bdb423c7bfb20ecb5a6af23814 (patch) | |
tree | 976cde96aa2d189863d72f66b1b25874f5c2fc8a | |
parent | c4d200e9db72ef1213d9d82f4d91a368ee82ec54 (diff) | |
download | mobile-data-download-a8939013f99872bdb423c7bfb20ecb5a6af23814.tar.gz |
Add EnabledSupplier in ManifestFileGroupPopulator
Add EnabledSupplier to provide ability to enable/disable the populator after adding it to MDD. Copied from PhFileGroupPopulator. https://source.corp.google.com/piper///depot/google3/java/com/google/android/libraries/mdi/download/populator/PhFileGroupPopulator.java;l=46;bpv=0;bpt=1;rcl=502128408
Test: local test
Bug: 265797474
Change-Id: Ife7dd6e7e3c8f8281b2ba9f0fc3ac1b515e0f037
-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); |