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 | #include "permission.h" |
| 18 | #include <memory> |
| 19 | #include <string> |
| 20 | #include <variant> |
| 21 | #include <vector> |
| 22 | |
| 23 | #include <android-base/strings.h> |
| 24 | |
| 25 | namespace android { |
| 26 | namespace aidl { |
| 27 | namespace perm { |
| 28 | |
Greg Kaiser | 874fcea | 2022-01-10 09:55:52 -0800 | [diff] [blame] | 29 | std::string AsJavaAnnotation(const Expression& expr) { |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 30 | if (const auto& s = std::get_if<std::string>(&expr); s) { |
Thiébaud Weksteen | fd413f7 | 2022-03-08 14:41:23 +1100 | [diff] [blame] | 31 | return JavaFullName(*s); |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 32 | } |
| 33 | if (const auto& all = std::get_if<AllOf>(&expr); all) { |
Thiébaud Weksteen | c6770e9 | 2021-12-20 12:58:57 +1100 | [diff] [blame] | 34 | return all->JavaAnnotation(); |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 35 | } |
| 36 | if (const auto& any = std::get_if<AnyOf>(&expr); any) { |
Thiébaud Weksteen | c6770e9 | 2021-12-20 12:58:57 +1100 | [diff] [blame] | 37 | return any->JavaAnnotation(); |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 38 | } |
| 39 | return ""; |
| 40 | } |
| 41 | |
Thiébaud Weksteen | fd413f7 | 2022-03-08 14:41:23 +1100 | [diff] [blame] | 42 | std::string JavaFullName(const std::string& permission) { |
| 43 | if (permission.find('.') == std::string::npos) { |
| 44 | return "android.Manifest.permission." + permission; |
| 45 | } |
| 46 | return permission; |
Thiébaud Weksteen | c6770e9 | 2021-12-20 12:58:57 +1100 | [diff] [blame] | 47 | } |
| 48 | |
Thiébaud Weksteen | 65281c4 | 2021-12-15 10:07:10 +1100 | [diff] [blame] | 49 | } // namespace perm |
| 50 | } // namespace aidl |
| 51 | } // namespace android |