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 
22 /**
23  * Bits Settings for Section Filters.
24  *
25  * @hide
26  */
27 @SystemApi
28 public class SectionSettingsWithSectionBits extends SectionSettings {
29     private final byte[] mFilter;
30     private final byte[] mMask;
31     private final byte[] mMode;
32 
33 
SectionSettingsWithSectionBits(int mainType, boolean isCheckCrc, boolean isRepeat, boolean isRaw, byte[] filter, byte[] mask, byte[] mode)34     private SectionSettingsWithSectionBits(int mainType, boolean isCheckCrc, boolean isRepeat,
35             boolean isRaw, byte[] filter, byte[] mask, byte[] mode) {
36         super(mainType, isCheckCrc, isRepeat, isRaw);
37         mFilter = filter;
38         mMask = mask;
39         mMode = mode;
40     }
41 
42     /**
43      * Gets the bytes configured for Section Filter
44      */
45     @NonNull
getFilterBytes()46     public byte[] getFilterBytes() {
47         return mFilter;
48     }
49     /**
50      * Gets bit mask.
51      *
52      * <p>The bits in the bytes are used for filtering.
53      */
54     @NonNull
getMask()55     public byte[] getMask() {
56         return mMask;
57     }
58     /**
59      * Gets mode.
60      *
61      * <p>Do positive match at the bit position of the configured bytes when the bit at same
62      * position of the mode is 0.
63      * <p>Do negative match at the bit position of the configured bytes when the bit at same
64      * position of the mode is 1.
65      */
66     @NonNull
getMode()67     public byte[] getMode() {
68         return mMode;
69     }
70 
71     /**
72      * Creates a builder for {@link SectionSettingsWithSectionBits}.
73      *
74      * @param mainType the filter main type.
75      */
76     @NonNull
builder(@ilter.Type int mainType)77     public static Builder builder(@Filter.Type int mainType) {
78         return new Builder(mainType);
79     }
80 
81     /**
82      * Builder for {@link SectionSettingsWithSectionBits}.
83      */
84     public static class Builder extends SectionSettings.Builder<Builder> {
85         private byte[] mFilter = {};
86         private byte[] mMask = {};
87         private byte[] mMode = {};
88 
Builder(int mainType)89         private Builder(int mainType) {
90             super(mainType);
91         }
92 
93         /**
94          * Sets filter bytes.
95          *
96          * <p>Default value is an empty byte array.
97          */
98         @NonNull
setFilter(@onNull byte[] filter)99         public Builder setFilter(@NonNull byte[] filter) {
100             mFilter = filter;
101             return this;
102         }
103         /**
104          * Sets bit mask.
105          *
106          * <p>Default value is an empty byte array.
107          */
108         @NonNull
setMask(@onNull byte[] mask)109         public Builder setMask(@NonNull byte[] mask) {
110             mMask = mask;
111             return this;
112         }
113         /**
114          * Sets mode.
115          *
116          * <p>Default value is an empty byte array.
117          */
118         @NonNull
setMode(@onNull byte[] mode)119         public Builder setMode(@NonNull byte[] mode) {
120             mMode = mode;
121             return this;
122         }
123 
124         /**
125          * Builds a {@link SectionSettingsWithSectionBits} object.
126          */
127         @NonNull
build()128         public SectionSettingsWithSectionBits build() {
129             return new SectionSettingsWithSectionBits(
130                     mMainType, mCrcEnabled, mIsRepeat, mIsRaw, mFilter, mMask, mMode);
131         }
132 
133         @Override
self()134         Builder self() {
135             return this;
136         }
137     }
138 }
139