Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 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 | |
Thiébaud Weksteen | c6770e9 | 2021-12-20 12:58:57 +1100 | [diff] [blame] | 30 | struct AnyOf; |
| 31 | struct AllOf; |
| 32 | |
| 33 | typedef std::variant<std::string, AnyOf, AllOf> Expression; |
Greg Kaiser | 874fcea | 2022-01-10 09:55:52 -0800 | [diff] [blame] | 34 | std::string AsJavaAnnotation(const Expression& expr); |
Thiébaud Weksteen | fd413f7 | 2022-03-08 14:41:23 +1100 | [diff] [blame] | 35 | std::string JavaFullName(const std::string& permission); |
Thiébaud Weksteen | c6770e9 | 2021-12-20 12:58:57 +1100 | [diff] [blame] | 36 | |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 37 | struct AnyOf { |
| 38 | std::vector<std::string> operands; |
| 39 | |
Greg Kaiser | 874fcea | 2022-01-10 09:55:52 -0800 | [diff] [blame] | 40 | std::string JavaAnnotation() const { |
Thiébaud Weksteen | c6770e9 | 2021-12-20 12:58:57 +1100 | [diff] [blame] | 41 | std::string ret("anyOf = {"); |
| 42 | for (size_t i = 0; i < operands.size(); i++) { |
Thiébaud Weksteen | fd413f7 | 2022-03-08 14:41:23 +1100 | [diff] [blame] | 43 | ret += android::aidl::perm::JavaFullName(operands[i]); |
Thiébaud Weksteen | c6770e9 | 2021-12-20 12:58:57 +1100 | [diff] [blame] | 44 | if (i != operands.size() - 1) { |
| 45 | ret += ", "; |
| 46 | } |
| 47 | } |
| 48 | return ret + "}"; |
| 49 | } |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 50 | }; |
| 51 | |
| 52 | struct AllOf { |
| 53 | std::vector<std::string> operands; |
| 54 | |
Greg Kaiser | 874fcea | 2022-01-10 09:55:52 -0800 | [diff] [blame] | 55 | std::string JavaAnnotation() const { |
Thiébaud Weksteen | c6770e9 | 2021-12-20 12:58:57 +1100 | [diff] [blame] | 56 | std::string ret("allOf = {"); |
| 57 | for (size_t i = 0; i < operands.size(); i++) { |
Thiébaud Weksteen | fd413f7 | 2022-03-08 14:41:23 +1100 | [diff] [blame] | 58 | ret += android::aidl::perm::JavaFullName(operands[i]); |
Thiébaud Weksteen | c6770e9 | 2021-12-20 12:58:57 +1100 | [diff] [blame] | 59 | if (i != operands.size() - 1) { |
| 60 | ret += ", "; |
| 61 | } |
| 62 | } |
| 63 | return ret + "}"; |
| 64 | } |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 65 | }; |
| 66 | |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 67 | |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 68 | |
| 69 | } // namespace perm |
| 70 | } // namespace aidl |
| 71 | } // namespace android |