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 #ifndef AAPT_XML_FLATTENER_H 18 #define AAPT_XML_FLATTENER_H 19 20 #include "BigBuffer.h" 21 #include "Maybe.h" 22 #include "Resolver.h" 23 #include "Source.h" 24 #include "XmlDom.h" 25 26 #include <string> 27 28 namespace aapt { 29 namespace xml { 30 31 /** 32 * Flattens an XML file into a binary representation parseable by 33 * the Android resource system. 34 */ 35 bool flatten(Node* root, const std::u16string& defaultPackage, BigBuffer* outBuffer); 36 37 /** 38 * Options for flattenAndLink. 39 */ 40 struct FlattenOptions { 41 /** 42 * Keep attribute raw string values along with typed values. 43 */ 44 bool keepRawValues = false; 45 46 /** 47 * If set, any attribute introduced in a later SDK will not be encoded. 48 */ 49 Maybe<size_t> maxSdkAttribute; 50 }; 51 52 /** 53 * Like flatten(Node*,BigBuffer*), but references to resources are checked 54 * and string values are transformed to typed data where possible. 55 * 56 * `defaultPackage` is used when a reference has no package or the namespace URI 57 * "http://schemas.android.com/apk/res-auto" is used. 58 * 59 * `resolver` is used to resolve references to resources. 60 */ 61 Maybe<size_t> flattenAndLink(const Source& source, Node* root, 62 const std::u16string& defaultPackage, 63 const std::shared_ptr<IResolver>& resolver, 64 const FlattenOptions& options, BigBuffer* outBuffer); 65 66 } // namespace xml 67 } // namespace aapt 68 69 #endif // AAPT_XML_FLATTENER_H 70