HELLO·Android
系统源代码
IT资讯
技术文章
我的收藏
注册
登录
-
我收藏的文章
创建代码块
我的代码块
我的账号
Nougat 7.1
|
7.1.1_r28
下载
查看原文件
收藏
根目录
frameworks
base
tools
aapt2
link
AutoVersioner.cpp
/* * 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. */ #include "ConfigDescription.h" #include "ResourceTable.h" #include "SdkConstants.h" #include "ValueVisitor.h" #include "link/Linkers.h" #include
#include
namespace aapt { bool shouldGenerateVersionedResource(const ResourceEntry* entry, const ConfigDescription& config, const int sdkVersionToGenerate) { assert(sdkVersionToGenerate > config.sdkVersion); const auto endIter = entry->values.end(); auto iter = entry->values.begin(); for (; iter != endIter; ++iter) { if ((*iter)->config == config) { break; } } // The source config came from this list, so it should be here. assert(iter != entry->values.end()); ++iter; // The next configuration either only varies in sdkVersion, or it is completely different // and therefore incompatible. If it is incompatible, we must generate the versioned resource. // NOTE: The ordering of configurations takes sdkVersion as higher precedence than other // qualifiers, so we need to iterate through the entire list to be sure there // are no higher sdk level versions of this resource. ConfigDescription tempConfig(config); for (; iter != endIter; ++iter) { tempConfig.sdkVersion = (*iter)->config.sdkVersion; if (tempConfig == (*iter)->config) { // The two configs are the same, check the sdk version. return sdkVersionToGenerate < (*iter)->config.sdkVersion; } } // No match was found, so we should generate the versioned resource. return true; } bool AutoVersioner::consume(IAaptContext* context, ResourceTable* table) { for (auto& package : table->packages) { for (auto& type : package->types) { if (type->type != ResourceType::kStyle) { continue; } for (auto& entry : type->entries) { for (size_t i = 0; i < entry->values.size(); i++) { ResourceConfigValue* configValue = entry->values[i].get(); if (configValue->config.sdkVersion >= SDK_LOLLIPOP_MR1) { // If this configuration is only used on L-MR1 then we don't need // to do anything since we use private attributes since that version. continue; } if (Style* style = valueCast