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 static android.media.tv.tunerresourcemanager.TunerResourceManager.INVALID_OWNER_ID;
19 
20 /**
21  * A Tuner resource basic object used by the Tuner Resource Manager to record the resource
22  * information.
23  *
24  * @hide
25  */
26 public class TunerResourceBasic {
27     /**
28      * Handle of the current resource. Should not be changed and should be aligned with the driver
29      * level implementation.
30      */
31     final int mHandle;
32 
33     /**
34      * If the current resource is in use.
35      */
36     boolean mIsInUse;
37 
38     /**
39      * The owner client's id if this resource is occupied.
40      */
41     int mOwnerClientId = INVALID_OWNER_ID;
42 
TunerResourceBasic(Builder builder)43     TunerResourceBasic(Builder builder) {
44         this.mHandle = builder.mHandle;
45     }
46 
getHandle()47     public int getHandle() {
48         return mHandle;
49     }
50 
isInUse()51     public boolean isInUse() {
52         return mIsInUse;
53     }
54 
getOwnerClientId()55     public int getOwnerClientId() {
56         return mOwnerClientId;
57     }
58 
59     /**
60      * Set an owner client on the resource.
61      *
62      * @param ownerClientId the id of the owner client.
63      */
setOwner(int ownerClientId)64     public void setOwner(int ownerClientId) {
65         mIsInUse = true;
66         mOwnerClientId = ownerClientId;
67     }
68 
69     /**
70      * Remove an owner client from the resource.
71      */
removeOwner()72     public void removeOwner() {
73         mIsInUse = false;
74         mOwnerClientId = INVALID_OWNER_ID;
75     }
76 
77     /**
78      * Builder class for {@link TunerResourceBasic}.
79      */
80     public static class Builder {
81         private final int mHandle;
82 
Builder(int handle)83         Builder(int handle) {
84             this.mHandle = handle;
85         }
86 
87         /**
88          * Build a {@link TunerResourceBasic}.
89          *
90          * @return {@link TunerResourceBasic}.
91          */
build()92         public TunerResourceBasic build() {
93             TunerResourceBasic resource = new TunerResourceBasic(this);
94             return resource;
95         }
96     }
97 }
98