1 // Copyright 2021 The Android Open Source Project 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package com.google.android.downloader; 16 17 import com.google.auto.value.AutoValue; 18 19 /** 20 * Value interface for representing download metadata in-memory. Note that this is generalized so 21 * that the exact serialization mechanism used by a {@link DownloadDestination} implementation can 22 * be hidden from the downloader, as there are contexts where for example using a protocol buffer 23 * isn't desirable for dependency purposes. 24 */ 25 @AutoValue 26 public abstract class DownloadMetadata { 27 /** The HTTP content tag of the download, or the empty string if none was returned. */ getContentTag()28 abstract String getContentTag(); 29 30 /** 31 * The last modification timestamp of the download, in seconds since the UNIX epoch, or 0 if none 32 * was returned. 33 */ getLastModifiedTimeSeconds()34 abstract long getLastModifiedTimeSeconds(); 35 36 /** Creates an empty instance of {@link DownloadMetadata}. */ create()37 public static DownloadMetadata create() { 38 return new AutoValue_DownloadMetadata("", 0L); 39 } 40 41 /** 42 * Creates an instance of {@link DownloadMetadata} with the provided content tag and modified 43 * timestamp. 44 */ create(String contentTag, long lastModifiedTimeSeconds)45 public static DownloadMetadata create(String contentTag, long lastModifiedTimeSeconds) { 46 return new AutoValue_DownloadMetadata(contentTag, lastModifiedTimeSeconds); 47 } 48 } 49