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 javax.annotation.concurrent.Immutable; 24 25 /** Request to get multiple file groups after filtering. */ 26 @AutoValue 27 @Immutable 28 public abstract class GetFileGroupsByFilterRequest { GetFileGroupsByFilterRequest()29 GetFileGroupsByFilterRequest() {} 30 31 // If this value is set to true, groupName should not be set. includeAllGroups()32 public abstract boolean includeAllGroups(); 33 34 // If this value is set to true, only groups without account will be returned, and accountOptional 35 // should be absent. The default value is false. groupWithNoAccountOnly()36 public abstract boolean groupWithNoAccountOnly(); 37 groupNameOptional()38 public abstract Optional<String> groupNameOptional(); 39 accountOptional()40 public abstract Optional<Account> accountOptional(); 41 preserveZipDirectories()42 public abstract boolean preserveZipDirectories(); 43 verifyIsolatedStructure()44 public abstract boolean verifyIsolatedStructure(); 45 newBuilder()46 public static Builder newBuilder() { 47 return new AutoValue_GetFileGroupsByFilterRequest.Builder() 48 .setIncludeAllGroups(false) 49 .setGroupWithNoAccountOnly(false) 50 .setPreserveZipDirectories(false) 51 .setVerifyIsolatedStructure(true); 52 } 53 54 /** Builder for {@link GetFileGroupsByFilterRequest}. */ 55 @AutoValue.Builder 56 public abstract static class Builder { Builder()57 Builder() {} 58 59 /** Sets the flag whether all groups are included. */ setIncludeAllGroups(boolean includeAllGroups)60 public abstract Builder setIncludeAllGroups(boolean includeAllGroups); 61 62 /** Sets the flag whether to only return account independent groups. */ setGroupWithNoAccountOnly(boolean groupWithNoAccountOnly)63 public abstract Builder setGroupWithNoAccountOnly(boolean groupWithNoAccountOnly); 64 65 /** 66 * Sets the name of the file group, which is optional. When groupNameOptional is absent, caller 67 * must set the includeAllGroups. 68 */ setGroupNameOptional(Optional<String> groupNameOptional)69 public abstract Builder setGroupNameOptional(Optional<String> groupNameOptional); 70 71 /** Sets the account that is associated with the file group, which is optional. */ setAccountOptional(Optional<Account> accountOptional)72 public abstract Builder setAccountOptional(Optional<Account> accountOptional); 73 74 /** 75 * By default, MDD will scan the directories generated by unpacking zip files in a download 76 * transform and generate a ClientDataFile for each contained file. By default, MDD also hides 77 * the root directory. Setting this to true disables that behavior, and will simply return the 78 * directories as ClientDataFiles. 79 */ setPreserveZipDirectories(boolean preserve)80 public abstract Builder setPreserveZipDirectories(boolean preserve); 81 82 /** 83 * By default, file groups will isolated structures will have this structure checked for each 84 * file when returning the file group. If the isolated structure is not correct, MDD will return 85 * a failure. 86 * 87 * <p>Setting this option to false allows clients to bypass this check, reducing the latency for 88 * critical callpaths. 89 * 90 * <p>For groups that do not have an isolated structure, this option is a no-op. 91 * 92 * <p>NOTE: All groups with isolated structures are also verified/fixed during MDD's maintenance 93 * periodic task. 94 */ setVerifyIsolatedStructure(boolean verifyIsolatedStructure)95 public abstract Builder setVerifyIsolatedStructure(boolean verifyIsolatedStructure); 96 autoBuild()97 abstract GetFileGroupsByFilterRequest autoBuild(); 98 build()99 public final GetFileGroupsByFilterRequest build() { 100 GetFileGroupsByFilterRequest getFileGroupsByFilterRequest = autoBuild(); 101 102 if (getFileGroupsByFilterRequest.includeAllGroups()) { 103 checkArgument(!getFileGroupsByFilterRequest.groupNameOptional().isPresent()); 104 checkArgument(!getFileGroupsByFilterRequest.accountOptional().isPresent()); 105 checkArgument(!getFileGroupsByFilterRequest.groupWithNoAccountOnly()); 106 } else { 107 checkArgument( 108 getFileGroupsByFilterRequest.groupNameOptional().isPresent(), 109 "Request must provide a group name or source to filter by"); 110 } 111 112 if (getFileGroupsByFilterRequest.groupWithNoAccountOnly()) { 113 checkArgument(!getFileGroupsByFilterRequest.accountOptional().isPresent()); 114 } 115 116 return getFileGroupsByFilterRequest; 117 } 118 } 119 } 120