Debian Codegraph @

core/java/android/content/integrity/RuleSet.java

raw symbols SCIP
1 /*
2 * Copyright (C) 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.content.integrity;
18
19 import android.annotation.NonNull;
20 import android.annotation.SystemApi;
21
22 import java.util.ArrayList;
23 import java.util.Collections;
24 import java.util.List;
25 import java.util.Objects;
26
27 /**
28 * Immutable data class encapsulating all parameters of a rule set.
29 *
30 * @hide
31 */
32 @SystemApi
33 public class RuleSet {
34 private final String mVersion;
35 private final List<Rule> mRules;
36
37 private RuleSet(String version, List<Rule> rules) {
38 mVersion = version;
39 mRules = Collections.unmodifiableList(rules);
40 }
41
42 /** @see Builder#setVersion(String). */
43 @NonNull
44 public String getVersion() {
45 return mVersion;
46 }
47
48 /** @see Builder#addRules(List). */
49 @NonNull
50 public List<Rule> getRules() {
51 return mRules;
52 }
53
54 /** Builder class for RuleSetUpdateRequest. */
55 public static class Builder {
56 private String mVersion;
57 private List<Rule> mRules;
58
59 public Builder() {
60 mRules = new ArrayList<>();
61 }
62
63 /**
64 * Set a version string to identify this rule set. This can be retrieved by {@link
65 * AppIntegrityManager#getCurrentRuleSetVersion()}.
66 */
67 @NonNull
68 public Builder setVersion(@NonNull String version) {
69 mVersion = version;
70 return this;
71 }
72
73 /** Add the rules to include. */
74 @NonNull
75 public Builder addRules(@NonNull List<Rule> rules) {
76 mRules.addAll(rules);
77 return this;
78 }
79
80 /**
81 * Builds a {@link RuleSet}.
82 *
83 * @throws IllegalArgumentException if version is null
84 */
85 @NonNull
86 public RuleSet build() {
87 Objects.requireNonNull(mVersion);
88 return new RuleSet(mVersion, mRules);
89 }
90 }
91 }