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 com.google.common.util.concurrent.ListenableFuture; 19 20 /** 21 * Listener for {@link MobileDataDownload#downloadFile} to respond to download events. 22 * 23 * <p>Supports registering for download progress update. Callbacks will be executed 24 * on @MddControlExecutor. If you need to do heavy work, please offload to a background task. 25 */ 26 public interface SingleFileDownloadListener { 27 /** 28 * Will be triggered periodically with the current downloaded size of the being downloaded file. 29 * This could be used to show progressbar to users. 30 */ onProgress(long currentSize)31 void onProgress(long currentSize); 32 33 /** 34 * This will be called when the download is completed successfully. MDD will keep the Foreground 35 * Download Service alive so that the onComplete can finish without being killed by Android. 36 */ onComplete()37 ListenableFuture<Void> onComplete(); 38 39 /** This will be called when the download failed. */ onFailure(Throwable t)40 void onFailure(Throwable t); 41 42 /** 43 * Callback triggered when all downloads are in a state waiting for connectivity, and no download 44 * progress is happening until connectivity resumes. 45 */ onPausedForConnectivity()46 void onPausedForConnectivity(); 47 } 48