• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021, 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 #pragma once
18 
19 #include <memory>
20 #include <string>
21 #include <variant>
22 #include <vector>
23 
24 #include <android-base/strings.h>
25 
26 namespace android {
27 namespace aidl {
28 namespace perm {
29 
30 struct AnyOf;
31 struct AllOf;
32 
33 typedef std::variant<std::string, AnyOf, AllOf> Expression;
34 std::string AsJavaAnnotation(const Expression& expr);
35 std::string JavaFullName(const std::string& permission);
36 
37 struct AnyOf {
38   std::vector<std::string> operands;
39 
JavaAnnotationAnyOf40   std::string JavaAnnotation() const {
41     std::string ret("anyOf = {");
42     for (size_t i = 0; i < operands.size(); i++) {
43       ret += android::aidl::perm::JavaFullName(operands[i]);
44       if (i != operands.size() - 1) {
45         ret += ", ";
46       }
47     }
48     return ret + "}";
49   }
50 };
51 
52 struct AllOf {
53   std::vector<std::string> operands;
54 
JavaAnnotationAllOf55   std::string JavaAnnotation() const {
56     std::string ret("allOf = {");
57     for (size_t i = 0; i < operands.size(); i++) {
58       ret += android::aidl::perm::JavaFullName(operands[i]);
59       if (i != operands.size() - 1) {
60         ret += ", ";
61       }
62     }
63     return ret + "}";
64   }
65 };
66 
67 
68 
69 }  // namespace perm
70 }  // namespace aidl
71 }  // namespace android
72