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 AsJavaAnnotation(const Expression & expr)29std::string AsJavaAnnotation(const Expression& expr) { 30 if (const auto& s = std::get_if<std::string>(&expr); s) { 31 return JavaFullName(*s); 32 } 33 if (const auto& all = std::get_if<AllOf>(&expr); all) { 34 return all->JavaAnnotation(); 35 } 36 if (const auto& any = std::get_if<AnyOf>(&expr); any) { 37 return any->JavaAnnotation(); 38 } 39 return ""; 40 } 41 JavaFullName(const std::string & permission)42std::string JavaFullName(const std::string& permission) { 43 if (permission.find('.') == std::string::npos) { 44 return "android.Manifest.permission." + permission; 45 } 46 return permission; 47 } 48 49 } // namespace perm 50 } // namespace aidl 51 } // namespace android 52