blob: 590a00c0ab4984fa65dd2a00b625ff3bbb6be9b5 [file] [log] [blame]
Thiébaud Weksteen65281c42021-12-15 10:07:10 +11001/*
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
26namespace android {
27namespace aidl {
28namespace perm {
29
Thiébaud Weksteenc6770e92021-12-20 12:58:57 +110030struct AnyOf;
31struct AllOf;
32
33typedef std::variant<std::string, AnyOf, AllOf> Expression;
Greg Kaiser874fcea2022-01-10 09:55:52 -080034std::string AsJavaAnnotation(const Expression& expr);
Thiébaud Weksteenfd413f72022-03-08 14:41:23 +110035std::string JavaFullName(const std::string& permission);
Thiébaud Weksteenc6770e92021-12-20 12:58:57 +110036
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110037struct AnyOf {
38 std::vector<std::string> operands;
39
Greg Kaiser874fcea2022-01-10 09:55:52 -080040 std::string JavaAnnotation() const {
Thiébaud Weksteenc6770e92021-12-20 12:58:57 +110041 std::string ret("anyOf = {");
42 for (size_t i = 0; i < operands.size(); i++) {
Thiébaud Weksteenfd413f72022-03-08 14:41:23 +110043 ret += android::aidl::perm::JavaFullName(operands[i]);
Thiébaud Weksteenc6770e92021-12-20 12:58:57 +110044 if (i != operands.size() - 1) {
45 ret += ", ";
46 }
47 }
48 return ret + "}";
49 }
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110050};
51
52struct AllOf {
53 std::vector<std::string> operands;
54
Greg Kaiser874fcea2022-01-10 09:55:52 -080055 std::string JavaAnnotation() const {
Thiébaud Weksteenc6770e92021-12-20 12:58:57 +110056 std::string ret("allOf = {");
57 for (size_t i = 0; i < operands.size(); i++) {
Thiébaud Weksteenfd413f72022-03-08 14:41:23 +110058 ret += android::aidl::perm::JavaFullName(operands[i]);
Thiébaud Weksteenc6770e92021-12-20 12:58:57 +110059 if (i != operands.size() - 1) {
60 ret += ", ";
61 }
62 }
63 return ret + "}";
64 }
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110065};
66
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110067
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110068
69} // namespace perm
70} // namespace aidl
71} // namespace android