forked from CtripMobile/DynamicAPK
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
yb.wang
authored and
yb.wang
committed
Nov 5, 2015
1 parent
1f2bf81
commit e760811
Showing
69 changed files
with
27,039 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (C) 2014 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_CONFIG_H | ||
#define __AAPT_CONFIG_H | ||
|
||
#include <set> | ||
#include <utils/String8.h> | ||
|
||
#include "ConfigDescription.h" | ||
|
||
/** | ||
* Utility methods for dealing with configurations. | ||
*/ | ||
namespace AaptConfig { | ||
|
||
/** | ||
* Parse a string of the form 'fr-sw600dp-land' and fill in the | ||
* given ResTable_config with resulting configuration parameters. | ||
* | ||
* The resulting configuration has the appropriate sdkVersion defined | ||
* for backwards compatibility. | ||
*/ | ||
bool parse(const android::String8& str, ConfigDescription* out = NULL); | ||
|
||
/** | ||
* Parse a comma separated list of configuration strings. Duplicate configurations | ||
* will be removed. | ||
* | ||
* Example input: "fr,de-land,fr-sw600dp-land" | ||
*/ | ||
bool parseCommaSeparatedList(const android::String8& str, std::set<ConfigDescription>* outSet); | ||
|
||
/** | ||
* If the configuration uses an axis that was added after | ||
* the original Android release, make sure the SDK version | ||
* is set accordingly. | ||
*/ | ||
void applyVersionForCompatibility(ConfigDescription* config); | ||
|
||
// Individual axis | ||
bool parseMcc(const char* str, android::ResTable_config* out = NULL); | ||
bool parseMnc(const char* str, android::ResTable_config* out = NULL); | ||
bool parseLayoutDirection(const char* str, android::ResTable_config* out = NULL); | ||
bool parseSmallestScreenWidthDp(const char* str, android::ResTable_config* out = NULL); | ||
bool parseScreenWidthDp(const char* str, android::ResTable_config* out = NULL); | ||
bool parseScreenHeightDp(const char* str, android::ResTable_config* out = NULL); | ||
bool parseScreenLayoutSize(const char* str, android::ResTable_config* out = NULL); | ||
bool parseScreenLayoutLong(const char* str, android::ResTable_config* out = NULL); | ||
bool parseOrientation(const char* str, android::ResTable_config* out = NULL); | ||
bool parseUiModeType(const char* str, android::ResTable_config* out = NULL); | ||
bool parseUiModeNight(const char* str, android::ResTable_config* out = NULL); | ||
bool parseDensity(const char* str, android::ResTable_config* out = NULL); | ||
bool parseTouchscreen(const char* str, android::ResTable_config* out = NULL); | ||
bool parseKeysHidden(const char* str, android::ResTable_config* out = NULL); | ||
bool parseKeyboard(const char* str, android::ResTable_config* out = NULL); | ||
bool parseNavHidden(const char* str, android::ResTable_config* out = NULL); | ||
bool parseNavigation(const char* str, android::ResTable_config* out = NULL); | ||
bool parseScreenSize(const char* str, android::ResTable_config* out = NULL); | ||
bool parseVersion(const char* str, android::ResTable_config* out = NULL); | ||
|
||
android::String8 getVersion(const android::ResTable_config& config); | ||
|
||
/** | ||
* Returns true if the two configurations only differ by the specified axis. | ||
* The axis mask is a bitmask of CONFIG_* constants. | ||
*/ | ||
bool isSameExcept(const android::ResTable_config& a, const android::ResTable_config& b, int configMask); | ||
|
||
} // namespace AaptConfig | ||
|
||
#endif // __AAPT_CONFIG_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* Copyright (C) 2014 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 "AaptUtil.h" | ||
|
||
using android::Vector; | ||
using android::String8; | ||
|
||
namespace AaptUtil { | ||
|
||
Vector<String8> split(const String8& str, const char sep) { | ||
Vector<String8> parts; | ||
const char* p = str.string(); | ||
const char* q; | ||
|
||
while (true) { | ||
q = strchr(p, sep); | ||
if (q == NULL) { | ||
parts.add(String8(p, strlen(p))); | ||
return parts; | ||
} | ||
|
||
parts.add(String8(p, q-p)); | ||
p = q + 1; | ||
} | ||
return parts; | ||
} | ||
|
||
Vector<String8> splitAndLowerCase(const String8& str, const char sep) { | ||
Vector<String8> parts; | ||
const char* p = str.string(); | ||
const char* q; | ||
|
||
while (true) { | ||
q = strchr(p, sep); | ||
if (q == NULL) { | ||
String8 val(p, strlen(p)); | ||
val.toLower(); | ||
parts.add(val); | ||
return parts; | ||
} | ||
|
||
String8 val(p, q-p); | ||
val.toLower(); | ||
parts.add(val); | ||
p = q + 1; | ||
} | ||
return parts; | ||
} | ||
|
||
} // namespace AaptUtil |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2014 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_UTIL_H | ||
#define __AAPT_UTIL_H | ||
|
||
#include <utils/String8.h> | ||
#include <utils/Vector.h> | ||
|
||
namespace AaptUtil { | ||
|
||
android::Vector<android::String8> split(const android::String8& str, const char sep); | ||
android::Vector<android::String8> splitAndLowerCase(const android::String8& str, const char sep); | ||
|
||
} // namespace AaptUtil | ||
|
||
#endif // __AAPT_UTIL_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
/* | ||
* Copyright (C) 2014 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 <androidfw/ResourceTypes.h> | ||
#include <utils/String8.h> | ||
|
||
#include "AaptXml.h" | ||
|
||
using namespace android; | ||
|
||
namespace AaptXml { | ||
|
||
static String8 getStringAttributeAtIndex(const ResXMLTree& tree, ssize_t attrIndex, | ||
String8* outError) { | ||
Res_value value; | ||
if (tree.getAttributeValue(attrIndex, &value) < 0) { | ||
if (outError != NULL) { | ||
*outError = "could not find attribute at index"; | ||
} | ||
return String8(); | ||
} | ||
|
||
if (value.dataType != Res_value::TYPE_STRING) { | ||
if (outError != NULL) { | ||
*outError = "attribute is not a string value"; | ||
} | ||
return String8(); | ||
} | ||
|
||
size_t len; | ||
const uint16_t* str = tree.getAttributeStringValue(attrIndex, &len); | ||
return str ? String8(str, len) : String8(); | ||
} | ||
|
||
static int32_t getIntegerAttributeAtIndex(const ResXMLTree& tree, ssize_t attrIndex, | ||
int32_t defValue, String8* outError) { | ||
Res_value value; | ||
if (tree.getAttributeValue(attrIndex, &value) < 0) { | ||
if (outError != NULL) { | ||
*outError = "could not find attribute at index"; | ||
} | ||
return defValue; | ||
} | ||
|
||
if (value.dataType < Res_value::TYPE_FIRST_INT | ||
|| value.dataType > Res_value::TYPE_LAST_INT) { | ||
if (outError != NULL) { | ||
*outError = "attribute is not an integer value"; | ||
} | ||
return defValue; | ||
} | ||
return value.data; | ||
} | ||
|
||
|
||
ssize_t indexOfAttribute(const ResXMLTree& tree, uint32_t attrRes) { | ||
size_t attrCount = tree.getAttributeCount(); | ||
for (size_t i = 0; i < attrCount; i++) { | ||
if (tree.getAttributeNameResID(i) == attrRes) { | ||
return (ssize_t)i; | ||
} | ||
} | ||
return -1; | ||
} | ||
|
||
String8 getAttribute(const ResXMLTree& tree, const char* ns, | ||
const char* attr, String8* outError) { | ||
ssize_t idx = tree.indexOfAttribute(ns, attr); | ||
if (idx < 0) { | ||
return String8(); | ||
} | ||
return getStringAttributeAtIndex(tree, idx, outError); | ||
} | ||
|
||
String8 getAttribute(const ResXMLTree& tree, uint32_t attrRes, String8* outError) { | ||
ssize_t idx = indexOfAttribute(tree, attrRes); | ||
if (idx < 0) { | ||
return String8(); | ||
} | ||
return getStringAttributeAtIndex(tree, idx, outError); | ||
} | ||
|
||
String8 getResolvedAttribute(const ResTable& resTable, const ResXMLTree& tree, | ||
uint32_t attrRes, String8* outError) { | ||
ssize_t idx = indexOfAttribute(tree, attrRes); | ||
if (idx < 0) { | ||
return String8(); | ||
} | ||
Res_value value; | ||
if (tree.getAttributeValue(idx, &value) != NO_ERROR) { | ||
if (value.dataType == Res_value::TYPE_STRING) { | ||
size_t len; | ||
const uint16_t* str = tree.getAttributeStringValue(idx, &len); | ||
return str ? String8(str, len) : String8(); | ||
} | ||
resTable.resolveReference(&value, 0); | ||
if (value.dataType != Res_value::TYPE_STRING) { | ||
if (outError != NULL) { | ||
*outError = "attribute is not a string value"; | ||
} | ||
return String8(); | ||
} | ||
} | ||
size_t len; | ||
const Res_value* value2 = &value; | ||
const char16_t* str = resTable.valueToString(value2, 0, NULL, &len); | ||
return str ? String8(str, len) : String8(); | ||
} | ||
|
||
int32_t getIntegerAttribute(const ResXMLTree& tree, const char* ns, | ||
const char* attr, int32_t defValue, String8* outError) { | ||
ssize_t idx = tree.indexOfAttribute(ns, attr); | ||
if (idx < 0) { | ||
return defValue; | ||
} | ||
return getIntegerAttributeAtIndex(tree, idx, defValue, outError); | ||
} | ||
|
||
int32_t getIntegerAttribute(const ResXMLTree& tree, uint32_t attrRes, int32_t defValue, | ||
String8* outError) { | ||
ssize_t idx = indexOfAttribute(tree, attrRes); | ||
if (idx < 0) { | ||
return defValue; | ||
} | ||
return getIntegerAttributeAtIndex(tree, idx, defValue, outError); | ||
} | ||
|
||
int32_t getResolvedIntegerAttribute(const ResTable& resTable, const ResXMLTree& tree, | ||
uint32_t attrRes, int32_t defValue, String8* outError) { | ||
ssize_t idx = indexOfAttribute(tree, attrRes); | ||
if (idx < 0) { | ||
return defValue; | ||
} | ||
Res_value value; | ||
if (tree.getAttributeValue(idx, &value) != NO_ERROR) { | ||
if (value.dataType == Res_value::TYPE_REFERENCE) { | ||
resTable.resolveReference(&value, 0); | ||
} | ||
if (value.dataType < Res_value::TYPE_FIRST_INT | ||
|| value.dataType > Res_value::TYPE_LAST_INT) { | ||
if (outError != NULL) { | ||
*outError = "attribute is not an integer value"; | ||
} | ||
return defValue; | ||
} | ||
} | ||
return value.data; | ||
} | ||
|
||
void getResolvedResourceAttribute(const ResTable& resTable, const ResXMLTree& tree, | ||
uint32_t attrRes, Res_value* outValue, String8* outError) { | ||
ssize_t idx = indexOfAttribute(tree, attrRes); | ||
if (idx < 0) { | ||
if (outError != NULL) { | ||
*outError = "attribute could not be found"; | ||
} | ||
return; | ||
} | ||
if (tree.getAttributeValue(idx, outValue) != NO_ERROR) { | ||
if (outValue->dataType == Res_value::TYPE_REFERENCE) { | ||
resTable.resolveReference(outValue, 0); | ||
} | ||
// The attribute was found and was resolved if need be. | ||
return; | ||
} | ||
if (outError != NULL) { | ||
*outError = "error getting resolved resource attribute"; | ||
} | ||
} | ||
|
||
} // namespace AaptXml |
Oops, something went wrong.