To allow apps that compiled against a pre-release SDK to continue working for a period of time after API finalization, a new tag, <staging-public-group-final>, has been added to aapt2. When finalizing the framework resource API, converting <staging-public-group> tags to <staging-public-group-final> will cause aapt2 to generate the resource table so that there is a resource entry for the old non-finalized (staged) resource ID and another entry for the finalized resource ID of newly finalized resources. This allows an application that compiled against the pre-release SDK to continue resolving resources using pre-release resource IDs. All references to pre-release resource IDs will be rewritten to their finalized resource IDs through the information stored in the new staged alias chunk. This allows applications compiled against <staging-public-group> resources to use the newly finalized resource ID without re-compilation. When an application is re-compiled against the SDK with <staging-public-group-final> tags, the application will use the finalized resource IDs. This change limits the use of the alias chunk to the framework for S. Bug: 183411356 Test: aapt2_test Change-Id: Iba1c3033c3c2f32de8e4a19b58d3921c971092c4
146 lines
6.0 KiB
C++
146 lines
6.0 KiB
C++
/*
|
|
* Copyright (C) 2015 The Android Open Source Project
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
#ifndef AAPT_RESOURCE_PARSER_H
|
|
#define AAPT_RESOURCE_PARSER_H
|
|
|
|
#include <memory>
|
|
|
|
#include "android-base/macros.h"
|
|
#include "androidfw/ConfigDescription.h"
|
|
#include "androidfw/StringPiece.h"
|
|
|
|
#include "Diagnostics.h"
|
|
#include "ResourceTable.h"
|
|
#include "ResourceValues.h"
|
|
#include "StringPool.h"
|
|
#include "util/Maybe.h"
|
|
#include "xml/XmlPullParser.h"
|
|
|
|
namespace aapt {
|
|
|
|
struct ParsedResource;
|
|
|
|
struct ResourceParserOptions {
|
|
/**
|
|
* Whether the default setting for this parser is to allow translation.
|
|
*/
|
|
bool translatable = true;
|
|
|
|
/**
|
|
* Whether positional arguments in formatted strings are treated as errors or
|
|
* warnings.
|
|
*/
|
|
bool error_on_positional_arguments = true;
|
|
|
|
/**
|
|
* If true, apply the same visibility rules for styleables as are used for
|
|
* all other resources. Otherwise, all styleables will be made public.
|
|
*/
|
|
bool preserve_visibility_of_styleables = false;
|
|
|
|
// If visibility was forced, we need to use it when creating a new resource and also error if we
|
|
// try to parse the <public>, <public-group>, <java-symbol> or <symbol> tags.
|
|
Maybe<Visibility::Level> visibility;
|
|
};
|
|
|
|
struct FlattenedXmlSubTree {
|
|
std::string raw_value;
|
|
StyleString style_string;
|
|
std::vector<UntranslatableSection> untranslatable_sections;
|
|
xml::IPackageDeclStack* namespace_resolver;
|
|
Source source;
|
|
};
|
|
|
|
/*
|
|
* Parses an XML file for resources and adds them to a ResourceTable.
|
|
*/
|
|
class ResourceParser {
|
|
public:
|
|
ResourceParser(IDiagnostics* diag, ResourceTable* table, const Source& source,
|
|
const android::ConfigDescription& config,
|
|
const ResourceParserOptions& options = {});
|
|
bool Parse(xml::XmlPullParser* parser);
|
|
|
|
static std::unique_ptr<Item> ParseXml(const FlattenedXmlSubTree& xmlsub_tree, uint32_t type_mask,
|
|
bool allow_raw_value, ResourceTable& table,
|
|
const android::ConfigDescription& config,
|
|
IDiagnostics& diag);
|
|
|
|
private:
|
|
DISALLOW_COPY_AND_ASSIGN(ResourceParser);
|
|
|
|
std::optional<FlattenedXmlSubTree> CreateFlattenSubTree(xml::XmlPullParser* parser);
|
|
|
|
// Parses the XML subtree as a StyleString (flattened XML representation for strings with
|
|
// formatting). If parsing fails, false is returned and the out parameters are left in an
|
|
// unspecified state. Otherwise,
|
|
// `out_style_string` contains the escaped and whitespace trimmed text.
|
|
// `out_raw_string` contains the un-escaped text.
|
|
// `out_untranslatable_sections` contains the sections of the string that should not be
|
|
// translated.
|
|
bool FlattenXmlSubtree(xml::XmlPullParser* parser, std::string* out_raw_string,
|
|
StyleString* out_style_string,
|
|
std::vector<UntranslatableSection>* out_untranslatable_sections);
|
|
|
|
/*
|
|
* Parses the XML subtree and returns an Item.
|
|
* The type of Item that can be parsed is denoted by the `type_mask`.
|
|
* If `allow_raw_value` is true and the subtree can not be parsed as a regular
|
|
* Item, then a
|
|
* RawString is returned. Otherwise this returns false;
|
|
*/
|
|
std::unique_ptr<Item> ParseXml(xml::XmlPullParser* parser, const uint32_t type_mask,
|
|
const bool allow_raw_value);
|
|
|
|
bool ParseResources(xml::XmlPullParser* parser);
|
|
bool ParseResource(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
|
|
bool ParseItem(xml::XmlPullParser* parser, ParsedResource* out_resource, uint32_t format);
|
|
bool ParseString(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseMacro(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParsePublic(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParsePublicGroup(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseStagingPublicGroup(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseStagingPublicGroupFinal(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseSymbolImpl(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseSymbol(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseOverlayable(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseAddResource(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseAttr(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseAttrImpl(xml::XmlPullParser* parser, ParsedResource* out_resource, bool weak);
|
|
Maybe<Attribute::Symbol> ParseEnumOrFlagItem(xml::XmlPullParser* parser,
|
|
const android::StringPiece& tag);
|
|
bool ParseStyle(ResourceType type, xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseStyleItem(xml::XmlPullParser* parser, Style* style);
|
|
bool ParseDeclareStyleable(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseArray(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseIntegerArray(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseStringArray(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
bool ParseArrayImpl(xml::XmlPullParser* parser, ParsedResource* out_resource, uint32_t typeMask);
|
|
bool ParsePlural(xml::XmlPullParser* parser, ParsedResource* out_resource);
|
|
|
|
IDiagnostics* diag_;
|
|
ResourceTable* table_;
|
|
Source source_;
|
|
android::ConfigDescription config_;
|
|
ResourceParserOptions options_;
|
|
};
|
|
|
|
} // namespace aapt
|
|
|
|
#endif // AAPT_RESOURCE_PARSER_H
|