1 /* 2 * Copyright (C) 2015, 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 <limits> 20 #include <memory> 21 #include <string> 22 #include <vector> 23 24 #include "aidl_language.h" 25 #include "import_resolver.h" 26 #include "io_delegate.h" 27 #include "options.h" 28 29 namespace android { 30 namespace aidl { 31 32 enum class AidlError { 33 UNKOWN = std::numeric_limits<int32_t>::min(), 34 BAD_PRE_PROCESSED_FILE, 35 PARSE_ERROR, 36 FOUND_PARCELABLE, 37 BAD_PACKAGE, 38 BAD_IMPORT, 39 BAD_TYPE, 40 BAD_METHOD_ID, 41 GENERATION_ERROR, 42 BAD_INPUT, 43 NOT_STRUCTURED, 44 45 OK = 0, 46 }; 47 48 bool compile_aidl(const Options& options, const IoDelegate& io_delegate); 49 bool dump_mappings(const Options& options, const IoDelegate& io_delegate); 50 51 // main entry point to AIDL 52 int aidl_entry(const Options& options, const IoDelegate& io_delegate); 53 54 // Copied from android.is.IBinder.[FIRST|LAST]_CALL_TRANSACTION 55 const int kFirstCallTransaction = 1; 56 const int kLastCallTransaction = 0x00ffffff; 57 58 // Following IDs are all offsets from kFirstCallTransaction 59 60 // IDs for meta transactions. Most of the meta transactions are implemented in 61 // the framework side (Binder.java or Binder.cpp). But these are the ones that 62 // are auto-implemented by the AIDL compiler. 63 const int kFirstMetaMethodId = kLastCallTransaction - kFirstCallTransaction; 64 const int kGetInterfaceVersionId = kFirstMetaMethodId; 65 const int kGetInterfaceHashId = kFirstMetaMethodId - 1; 66 // Additional meta transactions implemented by AIDL should use 67 // kFirstMetaMethodId -1, -2, ...and so on. 68 69 // Reserve 100 IDs for meta methods, which is more than enough. If we don't reserve, 70 // in the future, a newly added meta transaction ID will have a chance to 71 // collide with the user-defined methods that were added in the past. So, 72 // let's prevent users from using IDs in this range from the beginning. 73 const int kLastMetaMethodId = kFirstMetaMethodId - 99; 74 75 // Range of IDs that is allowed for user-defined methods. 76 const int kMinUserSetMethodId = 0; 77 const int kMaxUserSetMethodId = kLastMetaMethodId - 1; 78 79 const char kPreamble[] = 80 R"(/////////////////////////////////////////////////////////////////////////////// 81 // THIS FILE IS IMMUTABLE. DO NOT EDIT IN ANY CASE. // 82 /////////////////////////////////////////////////////////////////////////////// 83 84 // This file is a snapshot of an AIDL file. Do not edit it manually. There are 85 // two cases: 86 // 1). this is a frozen version file - do not edit this in any case. 87 // 2). this is a 'current' file. If you make a backwards compatible change to 88 // the interface (from the latest frozen version), the build system will 89 // prompt you to update this file with `m <name>-update-api`. 90 // 91 // You must not make a backward incompatible change to any AIDL file built 92 // with the aidl_interface module type with versions property set. The module 93 // type is used to build AIDL files in a way that they can be used across 94 // independently updatable components of the system. If a device is shipped 95 // with such a backward incompatible change, it has a high risk of breaking 96 // later when a module using the interface is updated, e.g., Mainline modules. 97 98 )"; 99 100 const string kGetInterfaceVersion("getInterfaceVersion"); 101 const string kGetInterfaceHash("getInterfaceHash"); 102 103 namespace internals { 104 105 AidlError load_and_validate_aidl(const std::string& input_file_name, const Options& options, 106 const IoDelegate& io_delegate, AidlTypenames* typenames, 107 vector<string>* imported_files); 108 109 } // namespace internals 110 111 } // namespace aidl 112 } // namespace android 113