• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
17 
18 import static com.google.common.base.Preconditions.checkArgument;
19 
20 import android.accounts.Account;
21 import com.google.auto.value.AutoValue;
22 import com.google.common.base.Optional;
23 import com.google.errorprone.annotations.Immutable;
24 
25 /** Request to get multiple data file groups after filtering. */
26 @AutoValue
27 @AutoValue.CopyAnnotations
28 @Immutable
29 @SuppressWarnings("Immutable")
30 public abstract class ReadDataFileGroupsByFilterRequest {
ReadDataFileGroupsByFilterRequest()31   ReadDataFileGroupsByFilterRequest() {}
32 
33   // If this value is set to true, groupName should not be set.
includeAllGroups()34   public abstract boolean includeAllGroups();
35 
36   // If this value is set to true, only groups without account will be returned, and accountOptional
37   // should be absent. The default value is false.
groupWithNoAccountOnly()38   public abstract boolean groupWithNoAccountOnly();
39 
groupNameOptional()40   public abstract Optional<String> groupNameOptional();
41 
accountOptional()42   public abstract Optional<Account> accountOptional();
43 
downloadedOptional()44   public abstract Optional<Boolean> downloadedOptional();
45 
newBuilder()46   public static Builder newBuilder() {
47     return new AutoValue_ReadDataFileGroupsByFilterRequest.Builder()
48         .setIncludeAllGroups(false)
49         .setGroupWithNoAccountOnly(false);
50   }
51 
52   /** Builder for {@link ReadDataFileGroupsByFilterRequest}. */
53   @AutoValue.Builder
54   public abstract static class Builder {
Builder()55     Builder() {}
56 
57     /** Sets the flag whether all groups are included. */
setIncludeAllGroups(boolean includeAllGroups)58     public abstract Builder setIncludeAllGroups(boolean includeAllGroups);
59 
60     /** Sets the flag whether to only return account independent groups. */
setGroupWithNoAccountOnly(boolean groupWithNoAccountOnly)61     public abstract Builder setGroupWithNoAccountOnly(boolean groupWithNoAccountOnly);
62 
63     /**
64      * Sets the name of the file group, which is optional. When groupNameOptional is absent, caller
65      * must set the includeAllGroups.
66      */
setGroupNameOptional(Optional<String> groupNameOptional)67     public abstract Builder setGroupNameOptional(Optional<String> groupNameOptional);
68 
69     /** Sets the account that is associated with the file group, which is optional. */
setAccountOptional(Optional<Account> accountOptional)70     public abstract Builder setAccountOptional(Optional<Account> accountOptional);
71 
72     /**
73      * Use setDownloaded instead.
74      *
75      * @see setDownloaded.
76      */
setDownloadedOptional(Optional<Boolean> downloadedOptional)77     abstract Builder setDownloadedOptional(Optional<Boolean> downloadedOptional);
78 
79     /**
80      * Sets whether to include only downloaded or pending file groups.
81      *
82      * @param downloaded if set to true, only downloaded file groups returned. If set to false, only
83      *     pending groups are included. If not set, all groups are returned.
84      */
setDownloaded(Boolean downloaded)85     public Builder setDownloaded(Boolean downloaded) {
86       return setDownloadedOptional(Optional.of(downloaded));
87     }
88 
autoBuild()89     abstract ReadDataFileGroupsByFilterRequest autoBuild();
90 
build()91     public final ReadDataFileGroupsByFilterRequest build() {
92       ReadDataFileGroupsByFilterRequest readDataFileGroupsByFilterRequest = autoBuild();
93 
94       if (readDataFileGroupsByFilterRequest.includeAllGroups()) {
95         checkArgument(!readDataFileGroupsByFilterRequest.groupNameOptional().isPresent());
96         checkArgument(!readDataFileGroupsByFilterRequest.accountOptional().isPresent());
97         checkArgument(!readDataFileGroupsByFilterRequest.groupWithNoAccountOnly());
98         checkArgument(!readDataFileGroupsByFilterRequest.downloadedOptional().isPresent());
99       } else {
100         checkArgument(
101             readDataFileGroupsByFilterRequest.groupNameOptional().isPresent(),
102             "Request must provide a group name or source to filter by");
103       }
104 
105       if (readDataFileGroupsByFilterRequest.groupWithNoAccountOnly()) {
106         checkArgument(!readDataFileGroupsByFilterRequest.accountOptional().isPresent());
107       }
108 
109       return readDataFileGroupsByFilterRequest;
110     }
111   }
112 }
113