1 /* 2 * Copyright (C) 2016 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 android.telephony.mbms; 18 19 import android.annotation.IntDef; 20 import android.telephony.MbmsDownloadSession; 21 22 import java.lang.annotation.Retention; 23 import java.lang.annotation.RetentionPolicy; 24 25 /** 26 * A optional listener class used by download clients to track progress. Apps should extend this 27 * class and pass an instance into 28 * {@link MbmsDownloadSession#download(DownloadRequest)} 29 * 30 * This is optionally specified when requesting a download and will only be called while the app 31 * is running. 32 * @hide 33 */ 34 public class DownloadStateCallback { 35 36 /** 37 * Bitmask flags used for filtering out callback methods. Used when constructing the 38 * DownloadStateCallback as an optional parameter. 39 * @hide 40 */ 41 @Retention(RetentionPolicy.SOURCE) 42 @IntDef({ALL_UPDATES, PROGRESS_UPDATES, STATE_UPDATES}) 43 public @interface FilterFlag {} 44 45 /** 46 * Receive all callbacks. 47 * Default value. 48 */ 49 public static final int ALL_UPDATES = 0x00; 50 /** 51 * Receive callbacks for {@link #onProgressUpdated}. 52 */ 53 public static final int PROGRESS_UPDATES = 0x01; 54 /** 55 * Receive callbacks for {@link #onStateUpdated}. 56 */ 57 public static final int STATE_UPDATES = 0x02; 58 59 private final int mCallbackFilterFlags; 60 61 /** 62 * Creates a DownloadStateCallback that will receive all callbacks. 63 */ 64 public DownloadStateCallback() { 65 mCallbackFilterFlags = ALL_UPDATES; 66 } 67 68 /** 69 * Creates a DownloadStateCallback that will only receive callbacks for the methods specified 70 * via the filterFlags parameter. 71 * @param filterFlags A bitmask of filter flags that will specify which callback this instance 72 * is interested in. 73 */ 74 public DownloadStateCallback(int filterFlags) { 75 mCallbackFilterFlags = filterFlags; 76 } 77 78 /** 79 * Return the currently set filter flags. 80 * @return An integer containing the bitmask of flags that this instance is interested in. 81 * @hide 82 */ 83 public int getCallbackFilterFlags() { 84 return mCallbackFilterFlags; 85 } 86 87 /** 88 * Returns true if a filter flag is set for a particular callback method. If the flag is set, 89 * the callback will be delivered to the listening process. 90 * @param flag A filter flag specifying whether or not a callback method is registered to 91 * receive callbacks. 92 * @return true if registered to receive callbacks in the listening process, false if not. 93 */ 94 public final boolean isFilterFlagSet(@FilterFlag int flag) { 95 if (mCallbackFilterFlags == ALL_UPDATES) { 96 return true; 97 } 98 return (mCallbackFilterFlags & flag) > 0; 99 } 100 101 /** 102 * Called when the middleware wants to report progress for a file in a {@link DownloadRequest}. 103 * 104 * @param request a {@link DownloadRequest}, indicating which download is being referenced. 105 * @param fileInfo a {@link FileInfo} specifying the file to report progress on. Note that 106 * the request may result in many files being downloaded and the client 107 * may not have been able to get a list of them in advance. 108 * @param currentDownloadSize is the current amount downloaded. 109 * @param fullDownloadSize is the total number of bytes that make up the downloaded content. 110 * This may be different from the decoded final size, but is useful in gauging download 111 * progress. 112 * @param currentDecodedSize is the number of bytes that have been decoded. 113 * @param fullDecodedSize is the total number of bytes that make up the final decoded content. 114 */ 115 public void onProgressUpdated(DownloadRequest request, FileInfo fileInfo, 116 int currentDownloadSize, int fullDownloadSize, 117 int currentDecodedSize, int fullDecodedSize) { 118 } 119 120 /** 121 * Gives download state callbacks for a file in a {@link DownloadRequest}. 122 * 123 * @param request a {@link DownloadRequest}, indicating which download is being referenced. 124 * @param fileInfo a {@link FileInfo} specifying the file to report progress on. Note that 125 * the request may result in many files being downloaded and the client 126 * may not have been able to get a list of them in advance. 127 * @param state The current state of the download. 128 */ 129 public void onStateUpdated(DownloadRequest request, FileInfo fileInfo, 130 @MbmsDownloadSession.DownloadStatus int state) { 131 } 132 } 133