1 /* 2 * Copyright 2020 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 package com.android.server.tv.tunerresourcemanager; 17 18 import android.media.tv.tuner.frontend.FrontendSettings.Type; 19 20 import java.util.Collection; 21 import java.util.HashSet; 22 import java.util.Set; 23 24 /** 25 * A frontend resource object used by the Tuner Resource Manager to record the tuner frontend 26 * information. 27 * 28 * @hide 29 */ 30 public final class FrontendResource extends TunerResourceBasic { 31 32 /** 33 * see {@link android.media.tv.tuner.frontend.FrontendSettings.Type} 34 */ 35 @Type private final int mType; 36 37 /** 38 * The exclusive group id of the FE. FEs under the same id can't be used at the same time. 39 */ 40 private final int mExclusiveGroupId; 41 42 /** 43 * An array to save all the FE handles under the same exclisive group. 44 */ 45 private Set<Integer> mExclusiveGroupMemberHandles = new HashSet<>(); 46 FrontendResource(Builder builder)47 private FrontendResource(Builder builder) { 48 super(builder); 49 this.mType = builder.mType; 50 this.mExclusiveGroupId = builder.mExclusiveGroupId; 51 } 52 getType()53 public int getType() { 54 return mType; 55 } 56 getExclusiveGroupId()57 public int getExclusiveGroupId() { 58 return mExclusiveGroupId; 59 } 60 getExclusiveGroupMemberFeHandles()61 public Set<Integer> getExclusiveGroupMemberFeHandles() { 62 return mExclusiveGroupMemberHandles; 63 } 64 65 /** 66 * Add one handle into the exclusive group member handle collection. 67 * 68 * @param handle the handle to be added. 69 */ addExclusiveGroupMemberFeHandle(int handle)70 public void addExclusiveGroupMemberFeHandle(int handle) { 71 mExclusiveGroupMemberHandles.add(handle); 72 } 73 74 /** 75 * Add one handle collection to the exclusive group member handle collection. 76 * 77 * @param handles the handle collection to be added. 78 */ addExclusiveGroupMemberFeHandles(Collection<Integer> handles)79 public void addExclusiveGroupMemberFeHandles(Collection<Integer> handles) { 80 mExclusiveGroupMemberHandles.addAll(handles); 81 } 82 83 /** 84 * Remove one id from the exclusive group member id collection. 85 * 86 * @param id the id to be removed. 87 */ removeExclusiveGroupMemberFeId(int handle)88 public void removeExclusiveGroupMemberFeId(int handle) { 89 mExclusiveGroupMemberHandles.remove(handle); 90 } 91 92 @Override toString()93 public String toString() { 94 return "FrontendResource[handle=" + this.mHandle + ", type=" + this.mType 95 + ", exclusiveGId=" + this.mExclusiveGroupId + ", exclusiveGMemeberHandles=" 96 + this.mExclusiveGroupMemberHandles 97 + ", isInUse=" + this.mIsInUse + ", ownerClientId=" + this.mOwnerClientId + "]"; 98 } 99 100 /** 101 * Builder class for {@link FrontendResource}. 102 */ 103 public static class Builder extends TunerResourceBasic.Builder { 104 @Type private int mType; 105 private int mExclusiveGroupId; 106 Builder(int handle)107 Builder(int handle) { 108 super(handle); 109 } 110 111 /** 112 * Builder for {@link FrontendResource}. 113 * 114 * @param type the type of the frontend. See {@link Type} 115 */ type(@ype int type)116 public Builder type(@Type int type) { 117 this.mType = type; 118 return this; 119 } 120 121 /** 122 * Builder for {@link FrontendResource}. 123 * 124 * @param exclusiveGroupId the id of exclusive group. 125 */ exclusiveGroupId(int exclusiveGroupId)126 public Builder exclusiveGroupId(int exclusiveGroupId) { 127 this.mExclusiveGroupId = exclusiveGroupId; 128 return this; 129 } 130 131 /** 132 * Build a {@link FrontendResource}. 133 * 134 * @return {@link FrontendResource}. 135 */ 136 @Override build()137 public FrontendResource build() { 138 FrontendResource frontendResource = new FrontendResource(this); 139 return frontendResource; 140 } 141 } 142 } 143