blob: 9f730da261bc1580a941b4f8194c2f38f4cf7aea [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#include "permission.h"
18#include <memory>
19#include <string>
20#include <variant>
21#include <vector>
22
23#include <android-base/strings.h>
24
25namespace android {
26namespace aidl {
27namespace perm {
28
Greg Kaiser874fcea2022-01-10 09:55:52 -080029std::string AsJavaAnnotation(const Expression& expr) {
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110030 if (const auto& s = std::get_if<std::string>(&expr); s) {
Thiébaud Weksteenfd413f72022-03-08 14:41:23 +110031 return JavaFullName(*s);
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110032 }
33 if (const auto& all = std::get_if<AllOf>(&expr); all) {
Thiébaud Weksteenc6770e92021-12-20 12:58:57 +110034 return all->JavaAnnotation();
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110035 }
36 if (const auto& any = std::get_if<AnyOf>(&expr); any) {
Thiébaud Weksteenc6770e92021-12-20 12:58:57 +110037 return any->JavaAnnotation();
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110038 }
39 return "";
40}
41
Thiébaud Weksteenfd413f72022-03-08 14:41:23 +110042std::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 Weksteenc6770e92021-12-20 12:58:57 +110047}
48
Thiébaud Weksteen65281c42021-12-15 10:07:10 +110049} // namespace perm
50} // namespace aidl
51} // namespace android