1 /* 2 * Copyright 2019 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.media.tv.tuner.filter; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.media.tv.tuner.TunerUtils; 22 import android.media.tv.tuner.TunerVersionChecker; 23 24 /** 25 * Filter Settings for a Download. 26 * 27 * @hide 28 */ 29 @SystemApi 30 public class DownloadSettings extends Settings { 31 private final boolean mUseDownloadId; 32 private final int mDownloadId; 33 DownloadSettings(int mainType, boolean useDownloadId, int downloadId)34 private DownloadSettings(int mainType, boolean useDownloadId, int downloadId) { 35 super(TunerUtils.getFilterSubtype(mainType, Filter.SUBTYPE_DOWNLOAD)); 36 mUseDownloadId = useDownloadId; 37 mDownloadId = downloadId; 38 } 39 40 /** 41 * Gets download ID. 42 */ getDownloadId()43 public int getDownloadId() { 44 return mDownloadId; 45 } 46 47 /** 48 * Gets whether download ID is used. 49 * 50 * If it's set to false, HAL will begin to send data before it knows downloadId and document 51 * structures. 52 * 53 * <p>This query is only supported in Tuner 2.0 or higher version. Unsupported version will 54 * return {@code false}. Use {@link TunerVersionChecker#getTunerVersion()} to get the version 55 * information. 56 */ useDownloadId()57 public boolean useDownloadId() { return mUseDownloadId; } 58 59 /** 60 * Creates a builder for {@link DownloadSettings}. 61 * 62 * @param mainType the filter main type. 63 */ 64 @NonNull builder(@ilter.Type int mainType)65 public static Builder builder(@Filter.Type int mainType) { 66 return new Builder(mainType); 67 } 68 69 /** 70 * Builder for {@link DownloadSettings}. 71 */ 72 public static class Builder { 73 private final int mMainType; 74 private boolean mUseDownloadId = false; 75 private int mDownloadId; 76 Builder(int mainType)77 private Builder(int mainType) { 78 mMainType = mainType; 79 } 80 81 /** 82 * Sets whether download ID is used or not. 83 * 84 * If it's set to false, HAL will begin to send data before it knows downloadId and document 85 * structures. 86 * 87 * <p>This configuration is only supported in Tuner 2.0 or higher version. Unsupported 88 * version will cause no-op. Use {@link TunerVersionChecker#getTunerVersion()} to get the 89 * version information. 90 * 91 * <p>Default value is {@code false}. 92 */ 93 @NonNull setUseDownloadId(boolean useDownloadId)94 public Builder setUseDownloadId(boolean useDownloadId) { 95 if (TunerVersionChecker.checkHigherOrEqualVersionTo( 96 TunerVersionChecker.TUNER_VERSION_2_0, "setUseDownloadId")) { 97 mUseDownloadId = useDownloadId; 98 } 99 return this; 100 } 101 102 /** 103 * Sets download ID. 104 */ 105 @NonNull setDownloadId(int downloadId)106 public Builder setDownloadId(int downloadId) { 107 mDownloadId = downloadId; 108 return this; 109 } 110 111 /** 112 * Builds a {@link DownloadSettings} object. 113 */ 114 @NonNull build()115 public DownloadSettings build() { 116 return new DownloadSettings(mMainType, mUseDownloadId, mDownloadId); 117 } 118 } 119 } 120