1 /* 2 * Copyright (C) 2018 The Android Open Source Project 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 17 package com.android.textclassifier.downloader; 18 19 import com.google.common.util.concurrent.ListenableFuture; 20 import java.io.File; 21 22 /** Interface for downloading files from certain URI. */ 23 interface ModelDownloader { 24 25 /** 26 * Downloads a manifest file from given url, parse it and return the proto. 27 * 28 * <p>The downloaded file should be deleted no matter the download succeeds or not. 29 * 30 * @param manifestUrl url to download manifest file from 31 * @return listenable future of ModelManifest proto 32 */ downloadManifest(String manifestUrl)33 ListenableFuture<ModelManifest> downloadManifest(String manifestUrl); 34 35 /** 36 * Downloads a model file and validate it based on given model info. 37 * 38 * <p>The file should be in the target folder. Returns the File if succeed. If the download or 39 * validation fails, the unfinished model file should be cleaned up. Failures should be wrapped 40 * inside a {@link ModelDownloadException} and throw. 41 * 42 * @param targetDir the target directory for the downloaded model 43 * @param modelInfo the model information in manifest used for downloading and validation 44 * @return the downloaded model file 45 */ downloadModel(File targetDir, ModelManifest.Model modelInfo)46 ListenableFuture<File> downloadModel(File targetDir, ModelManifest.Model modelInfo); 47 } 48