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.frontend; 18 19 import android.annotation.NonNull; 20 import android.annotation.SystemApi; 21 import android.media.tv.tuner.frontend.FrontendSettings.Type; 22 import android.media.tv.tuner.frontend.FrontendStatus.FrontendStatusType; 23 import android.util.Range; 24 25 import java.util.Arrays; 26 import java.util.Objects; 27 28 /** 29 * This class is used to specify meta information of a frontend. 30 * 31 * @hide 32 */ 33 @SystemApi 34 public class FrontendInfo { 35 private final int mId; 36 private final int mType; 37 private final Range<Long> mFrequencyRange; 38 private final Range<Integer> mSymbolRateRange; 39 private final long mAcquireRange; 40 private final int mExclusiveGroupId; 41 private final int[] mStatusCaps; 42 private final FrontendCapabilities mFrontendCap; 43 FrontendInfo(int id, int type, long minFrequency, long maxFrequency, int minSymbolRate, int maxSymbolRate, long acquireRange, int exclusiveGroupId, int[] statusCaps, FrontendCapabilities frontendCap)44 private FrontendInfo(int id, int type, long minFrequency, long maxFrequency, int minSymbolRate, 45 int maxSymbolRate, long acquireRange, int exclusiveGroupId, int[] statusCaps, 46 FrontendCapabilities frontendCap) { 47 mId = id; 48 mType = type; 49 // if max Frequency is negative, we set it as max value of the Integer. 50 if (maxFrequency < 0) { 51 maxFrequency = Integer.MAX_VALUE; 52 } 53 mFrequencyRange = new Range<>(minFrequency, maxFrequency); 54 mSymbolRateRange = new Range<>(minSymbolRate, maxSymbolRate); 55 mAcquireRange = acquireRange; 56 mExclusiveGroupId = exclusiveGroupId; 57 mStatusCaps = statusCaps; 58 mFrontendCap = frontendCap; 59 } 60 61 /** 62 * Gets frontend ID. 63 * 64 * @return the frontend ID or {@link android.media.tv.tuner.Tuner#INVALID_FRONTEND_ID} 65 * if invalid 66 */ getId()67 public int getId() { 68 return mId; 69 } 70 /** 71 * Gets frontend type. 72 */ 73 @Type getType()74 public int getType() { 75 return mType; 76 } 77 78 /** 79 * Gets supported frequency range in Hz. 80 * 81 * @deprecated Use {@link #getFrequencyRangeLong()} 82 */ 83 @Deprecated 84 @NonNull getFrequencyRange()85 public Range<Integer> getFrequencyRange() { 86 return new Range<>( 87 (int) (long) mFrequencyRange.getLower(), (int) (long) mFrequencyRange.getUpper()); 88 } 89 90 /** 91 * Gets supported frequency range in Hz. 92 */ 93 @NonNull getFrequencyRangeLong()94 public Range<Long> getFrequencyRangeLong() { 95 return mFrequencyRange; 96 } 97 98 /** 99 * Gets symbol rate range in symbols per second. 100 */ 101 @NonNull getSymbolRateRange()102 public Range<Integer> getSymbolRateRange() { 103 return mSymbolRateRange; 104 } 105 106 /** 107 * Gets acquire range in Hz. 108 * 109 * <p>The maximum frequency difference the frontend can detect. 110 @deprecated Use {@link #getAcquireRangeLong(long)} 111 */ 112 @Deprecated getAcquireRange()113 public int getAcquireRange() { 114 return (int) getAcquireRangeLong(); 115 } 116 117 /** 118 * Gets acquire range in Hz. 119 * 120 * <p>The maximum frequency difference the frontend can detect. 121 */ getAcquireRangeLong()122 public long getAcquireRangeLong() { 123 return mAcquireRange; 124 } 125 126 /** 127 * Gets exclusive group ID. 128 * 129 * <p>Frontends with the same exclusive group ID indicates they can't function at same time. For 130 * instance, they share some hardware modules. 131 */ getExclusiveGroupId()132 public int getExclusiveGroupId() { 133 return mExclusiveGroupId; 134 } 135 136 /** 137 * Gets status capabilities. 138 * 139 * @return An array of supported status types. 140 */ 141 @FrontendStatusType 142 @NonNull getStatusCapabilities()143 public int[] getStatusCapabilities() { 144 return mStatusCaps; 145 } 146 147 /** 148 * Gets frontend capabilities. 149 */ 150 @NonNull getFrontendCapabilities()151 public FrontendCapabilities getFrontendCapabilities() { 152 return mFrontendCap; 153 } 154 155 /** @hide */ 156 @Override equals(Object o)157 public boolean equals(Object o) { 158 if (this == o) { 159 return true; 160 } 161 if (o == null || !(o instanceof FrontendInfo)) { 162 return false; 163 } 164 // TODO: compare FrontendCapabilities 165 FrontendInfo info = (FrontendInfo) o; 166 return mId == info.getId() && mType == info.getType() 167 && Objects.equals(mFrequencyRange, info.getFrequencyRangeLong()) 168 && Objects.equals(mSymbolRateRange, info.getSymbolRateRange()) 169 && mAcquireRange == info.getAcquireRangeLong() 170 && mExclusiveGroupId == info.getExclusiveGroupId() 171 && Arrays.equals(mStatusCaps, info.getStatusCapabilities()); 172 } 173 174 /** @hide */ 175 @Override hashCode()176 public int hashCode() { 177 return mId; 178 } 179 } 180