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