• 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 android.accounts.Account;
19 import com.google.auto.value.AutoValue;
20 import com.google.common.base.Optional;
21 import com.google.mobiledatadownload.DownloadConfigProto.DownloadConditions;
22 import javax.annotation.concurrent.Immutable;
23 
24 /** Request to download file group in MDD. */
25 @AutoValue
26 @Immutable
27 public abstract class DownloadFileGroupRequest {
28 
29   /** Defines notifiction behavior for foreground download requests. */
30   public enum ShowNotifications {
31     NONE,
32     ALL,
33   }
34 
DownloadFileGroupRequest()35   DownloadFileGroupRequest() {}
36 
groupName()37   public abstract String groupName();
38 
accountOptional()39   public abstract Optional<Account> accountOptional();
40 
variantIdOptional()41   public abstract Optional<String> variantIdOptional();
42 
43   /**
44    * If present, title text to display in notification when using foreground downloads. Otherwise,
45    * the file group name will be used.
46    *
47    * <p>See <internal> for an example of the notification.
48    */
contentTitleOptional()49   public abstract Optional<String> contentTitleOptional();
50 
51   /**
52    * If present, content text to display in notification when using foreground downloads. Otherwise,
53    * the file group name will be used.
54    *
55    * <p>See <internal> for an example of the notification.
56    */
contentTextOptional()57   public abstract Optional<String> contentTextOptional();
58 
59   /**
60    * The conditions for the download. If absent, MDD will use the download conditions from the
61    * server config.
62    */
downloadConditionsOptional()63   public abstract Optional<DownloadConditions> downloadConditionsOptional();
64 
65   /** If present, will receive download progress update. */
listenerOptional()66   public abstract Optional<DownloadListener> listenerOptional();
67 
68   // The size of the being downloaded file in bytes.
69   // This is used to display the progressbar.
70   // If not specified, an indeterminate progressbar will be displayed.
71   // https://developer.android.com/reference/android/app/Notification.Builder.html#setProgress(int,%20int,%20boolean)
groupSizeBytes()72   public abstract int groupSizeBytes();
73 
74   /**
75    * If {@link ShowNotifications.NONE}, will not create notifications for this foreground download
76    * request.
77    */
showNotifications()78   public abstract ShowNotifications showNotifications();
79 
preserveZipDirectories()80   public abstract boolean preserveZipDirectories();
81 
verifyIsolatedStructure()82   public abstract boolean verifyIsolatedStructure();
83 
toBuilder()84   public abstract Builder toBuilder();
85 
newBuilder()86   public static Builder newBuilder() {
87     return new AutoValue_DownloadFileGroupRequest.Builder()
88         .setGroupSizeBytes(0)
89         .setShowNotifications(ShowNotifications.ALL)
90         .setPreserveZipDirectories(false)
91         .setVerifyIsolatedStructure(true);
92   }
93 
94   /** Builder for {@link DownloadFileGroupRequest}. */
95   @AutoValue.Builder
96   public abstract static class Builder {
Builder()97     Builder() {}
98 
99     /** Sets the name of the file group. */
setGroupName(String groupName)100     public abstract Builder setGroupName(String groupName);
101 
102     /** Sets the optional account that is associated to the file group. */
setAccountOptional(Optional<Account> accountOptional)103     public abstract Builder setAccountOptional(Optional<Account> accountOptional);
104 
105     /**
106      * Sets the variant id that is associated to the file group.
107      *
108      * <p>This parameter is only required to download a group that was added to MDD with a variantId
109      * specified (see {@link AddFileGroupRequest.Builder#setVariantIdOptional}).
110      *
111      * <p>If a variantId was specified when adding the group to MDD and is not included here, the
112      * request will fail with a {@link DownloadException} and a GROUP_NOT_FOUND result code.
113      *
114      * <p>Similarly, if a variantId was <em>not</em> specified when adding the group to MDD and
115      * <em>is</em> included here, the request will also fail with the same exception.
116      */
setVariantIdOptional(Optional<String> variantIdOptional)117     public abstract Builder setVariantIdOptional(Optional<String> variantIdOptional);
118 
119     /** Sets the optional title text for a notification when using foreground downloads. */
setContentTitleOptional(Optional<String> contentTitleOptional)120     public abstract Builder setContentTitleOptional(Optional<String> contentTitleOptional);
121 
122     /** Sets the optional content text for a notification when using foreground downloads. */
setContentTextOptional(Optional<String> contentTextOptional)123     public abstract Builder setContentTextOptional(Optional<String> contentTextOptional);
124 
125     /**
126      * Sets the optional download conditions. If absent, MDD will use the download conditions from
127      * the server config.
128      */
setDownloadConditionsOptional( Optional<DownloadConditions> downloadConditionsOptional)129     public abstract Builder setDownloadConditionsOptional(
130         Optional<DownloadConditions> downloadConditionsOptional);
131 
132     /**
133      * Sets the optional download listener when using foreground downloads. If present, will receive
134      * download progress update.
135      */
setListenerOptional(Optional<DownloadListener> listenerOptional)136     public abstract Builder setListenerOptional(Optional<DownloadListener> listenerOptional);
137 
138     /**
139      * Sets size of the being downloaded group in bytes when using foreground downloads. This is
140      * used to display the progressbar. If not specified, a indeterminate progressbar will be
141      * displayed.
142      * https://developer.android.com/reference/android/app/Notification.Builder.html#setProgress(int,%20int,%20boolean)
143      */
setGroupSizeBytes(int groupSizeBytes)144     public abstract Builder setGroupSizeBytes(int groupSizeBytes);
145 
146     /**
147      * Controls if notifications should be created for this download request when using foreground
148      * downloads. Defaults to true.
149      */
setShowNotifications(ShowNotifications notifications)150     public abstract Builder setShowNotifications(ShowNotifications notifications);
151 
152     /**
153      * By default, MDD will scan the directories generated by unpacking zip files in a download
154      * transform and generate a ClientDataFile for each contained file. By default, MDD also hides
155      * the root directory. Setting this to true disables that behavior, and will simply return the
156      * directories as ClientDataFiles.
157      */
setPreserveZipDirectories(boolean preserve)158     public abstract Builder setPreserveZipDirectories(boolean preserve);
159 
160     /**
161      * By default, file groups will isolated structures will have this structure checked for each
162      * file when returning the file group. If the isolated structure is not correct, MDD will return
163      * a failure.
164      *
165      * <p>Setting this option to false allows clients to bypass this check, reducing the latency for
166      * critical callpaths.
167      *
168      * <p>For groups that do not have an isolated structure, this option is a no-op.
169      *
170      * <p>NOTE: All groups with isolated structures are also verified/fixed during MDD's maintenance
171      * periodic task.
172      */
setVerifyIsolatedStructure(boolean verifyIsolatedStructure)173     public abstract Builder setVerifyIsolatedStructure(boolean verifyIsolatedStructure);
174 
build()175     public abstract DownloadFileGroupRequest build();
176   }
177 }
178