1 /*
2  * Copyright (C) 2017 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 #ifndef ANDROID_VINTF_SEPOLICY_H
18 #define ANDROID_VINTF_SEPOLICY_H
19 
20 
21 namespace android {
22 namespace vintf {
23 
24 struct KernelSepolicyVersion {
25     size_t value;
KernelSepolicyVersionKernelSepolicyVersion26     inline KernelSepolicyVersion() : KernelSepolicyVersion(0u) {}
KernelSepolicyVersionKernelSepolicyVersion27     inline KernelSepolicyVersion(size_t v) : value(v) {}
size_tKernelSepolicyVersion28     inline operator size_t() const {
29         return value;
30     }
31 };
32 
33 // Sepolicy section in compatibility matrix.
34 struct Sepolicy {
35 
SepolicySepolicy36     Sepolicy() : Sepolicy(0u, {}) {}
SepolicySepolicy37     Sepolicy(KernelSepolicyVersion kernelSepolicyVersion,
38             std::vector<VersionRange> &&sepolicyVersions) :
39             mKernelSepolicyVersion(kernelSepolicyVersion),
40             mSepolicyVersionRanges(std::move(sepolicyVersions)) {}
41 
kernelSepolicyVersionSepolicy42     inline size_t kernelSepolicyVersion() const { return mKernelSepolicyVersion.value; }
sepolicyVersionsSepolicy43     inline const std::vector<VersionRange> &sepolicyVersions() const {
44         return mSepolicyVersionRanges;
45     }
46 
47    private:
48     friend class AssembleVintfImpl;
49     friend struct SepolicyConverter;
50     KernelSepolicyVersion mKernelSepolicyVersion;
51     std::vector<VersionRange> mSepolicyVersionRanges;
52 };
53 
54 inline bool operator==(const Sepolicy &lft, const Sepolicy &rgt) {
55     return lft.kernelSepolicyVersion() == rgt.kernelSepolicyVersion() &&
56            lft.sepolicyVersions() == rgt.sepolicyVersions();
57 }
58 
59 } // namespace vintf
60 } // namespace android
61 
62 #endif // ANDROID_VINTF_SEPOLICY_H
63