Fix dump badging parity issue
Correct the target SDK version for follow-up attribute checking when dump badging, and add the check if platformBuildVersionName/Code is integer. Besides, replace target SDK int by SdkConstants for both aapt and aapt2. Fix: 164447047 Test: atest libaapt_tests aapt2_tests Test: manually compare the output result between aapt and aapt2 Change-Id: I154264721c362ef9e45d9869900d50f07819cdf0
This commit is contained in:
@@ -769,7 +769,7 @@ int doDump(Bundle* bundle)
|
||||
config.country[1] = 'S';
|
||||
config.orientation = ResTable_config::ORIENTATION_PORT;
|
||||
config.density = ResTable_config::DENSITY_MEDIUM;
|
||||
config.sdkVersion = 10000; // Very high.
|
||||
config.sdkVersion = SDK_CUR_DEVELOPMENT; // Very high.
|
||||
config.screenWidthDp = 320;
|
||||
config.screenHeightDp = 480;
|
||||
config.smallestScreenWidthDp = 320;
|
||||
@@ -1306,16 +1306,30 @@ int doDump(Bundle* bundle)
|
||||
splitName.string()).string());
|
||||
}
|
||||
|
||||
// For 'platformBuildVersionName', using both string and int type as a fallback
|
||||
// since it may be the code name of Android or the API level.
|
||||
String8 platformBuildVersionName = AaptXml::getAttribute(tree, NULL,
|
||||
"platformBuildVersionName");
|
||||
int32_t platformBuildVersionNameInt =
|
||||
AaptXml::getIntegerAttribute(tree, NULL, "platformBuildVersionName", 0,
|
||||
NULL);
|
||||
if (platformBuildVersionName != "") {
|
||||
printf(" platformBuildVersionName='%s'", platformBuildVersionName.string());
|
||||
} else if (platformBuildVersionNameInt > 0) {
|
||||
printf(" platformBuildVersionName='%d'", platformBuildVersionNameInt);
|
||||
}
|
||||
|
||||
// For 'platformBuildVersionCode', using both string and int type as a fallback
|
||||
// since it may be the code name of Android or the API level.
|
||||
String8 platformBuildVersionCode = AaptXml::getAttribute(tree, NULL,
|
||||
"platformBuildVersionCode");
|
||||
int32_t platformBuildVersionCodeInt =
|
||||
AaptXml::getIntegerAttribute(tree, NULL, "platformBuildVersionCode", 0,
|
||||
NULL);
|
||||
if (platformBuildVersionCode != "") {
|
||||
printf(" platformBuildVersionCode='%s'", platformBuildVersionCode.string());
|
||||
} else if (platformBuildVersionCodeInt > 0) {
|
||||
printf(" platformBuildVersionCode='%d'", platformBuildVersionCodeInt);
|
||||
}
|
||||
|
||||
int32_t compileSdkVersion = AaptXml::getIntegerAttribute(tree,
|
||||
@@ -1490,7 +1504,7 @@ int doDump(Bundle* bundle)
|
||||
error.string());
|
||||
goto bail;
|
||||
}
|
||||
if (name == "Donut") targetSdk = 4;
|
||||
if (name == "Donut") targetSdk = SDK_DONUT;
|
||||
printf("sdkVersion:'%s'\n",
|
||||
ResTable::normalizeForOutput(name.string()).string());
|
||||
} else if (code != -1) {
|
||||
@@ -1512,7 +1526,12 @@ int doDump(Bundle* bundle)
|
||||
error.string());
|
||||
goto bail;
|
||||
}
|
||||
if (name == "Donut" && targetSdk < 4) targetSdk = 4;
|
||||
if (name == "Donut" && targetSdk < SDK_DONUT) {
|
||||
targetSdk = SDK_DONUT;
|
||||
} else if (name != "" && targetSdk == 0) {
|
||||
// Bump to current development version
|
||||
targetSdk = SDK_CUR_DEVELOPMENT;
|
||||
}
|
||||
printf("targetSdkVersion:'%s'\n",
|
||||
ResTable::normalizeForOutput(name.string()).string());
|
||||
} else if (code != -1) {
|
||||
@@ -2122,7 +2141,7 @@ int doDump(Bundle* bundle)
|
||||
}
|
||||
|
||||
// Pre-1.6 implicitly granted permission compatibility logic
|
||||
if (targetSdk < 4) {
|
||||
if (targetSdk < SDK_DONUT) {
|
||||
if (!hasWriteExternalStoragePermission) {
|
||||
printUsesPermission(String8("android.permission.WRITE_EXTERNAL_STORAGE"));
|
||||
printUsesImpliedPermission(String8("android.permission.WRITE_EXTERNAL_STORAGE"),
|
||||
@@ -2149,7 +2168,7 @@ int doDump(Bundle* bundle)
|
||||
}
|
||||
|
||||
// Pre-JellyBean call log permission compatibility.
|
||||
if (targetSdk < 16) {
|
||||
if (targetSdk < SDK_JELLY_BEAN) {
|
||||
if (!hasReadCallLogPermission && hasReadContactsPermission) {
|
||||
printUsesPermission(String8("android.permission.READ_CALL_LOG"));
|
||||
printUsesImpliedPermission(String8("android.permission.READ_CALL_LOG"),
|
||||
@@ -2291,21 +2310,23 @@ int doDump(Bundle* bundle)
|
||||
// the screen size support was introduced, so all default to
|
||||
// enabled.
|
||||
if (smallScreen > 0) {
|
||||
smallScreen = targetSdk >= 4 ? -1 : 0;
|
||||
smallScreen = targetSdk >= SDK_DONUT ? -1 : 0;
|
||||
}
|
||||
if (normalScreen > 0) {
|
||||
normalScreen = -1;
|
||||
}
|
||||
if (largeScreen > 0) {
|
||||
largeScreen = targetSdk >= 4 ? -1 : 0;
|
||||
largeScreen = targetSdk >= SDK_DONUT ? -1 : 0;
|
||||
}
|
||||
if (xlargeScreen > 0) {
|
||||
// Introduced in Gingerbread.
|
||||
xlargeScreen = targetSdk >= 9 ? -1 : 0;
|
||||
xlargeScreen = targetSdk >= SDK_GINGERBREAD ? -1 : 0;
|
||||
}
|
||||
if (anyDensity > 0) {
|
||||
anyDensity = (targetSdk >= 4 || requiresSmallestWidthDp > 0
|
||||
|| compatibleWidthLimitDp > 0) ? -1 : 0;
|
||||
anyDensity = (targetSdk >= SDK_DONUT || requiresSmallestWidthDp > 0 ||
|
||||
compatibleWidthLimitDp > 0)
|
||||
? -1
|
||||
: 0;
|
||||
}
|
||||
printf("supports-screens:");
|
||||
if (smallScreen != 0) {
|
||||
|
||||
@@ -47,6 +47,7 @@ enum {
|
||||
SDK_Q = 29,
|
||||
SDK_R = 30,
|
||||
SDK_S = 31,
|
||||
SDK_CUR_DEVELOPMENT = 10000,
|
||||
};
|
||||
|
||||
#endif // H_AAPT_SDK_CONSTANTS
|
||||
|
||||
@@ -57,6 +57,7 @@ enum : ApiVersion {
|
||||
SDK_Q = 29,
|
||||
SDK_R = 30,
|
||||
SDK_S = 31,
|
||||
SDK_CUR_DEVELOPMENT = 10000,
|
||||
};
|
||||
|
||||
ApiVersion FindAttributeSdkLevel(const ResourceId& id);
|
||||
|
||||
@@ -92,7 +92,6 @@ enum {
|
||||
};
|
||||
|
||||
const std::string& kAndroidNamespace = "http://schemas.android.com/apk/res/android";
|
||||
constexpr int kCurrentDevelopmentVersion = 10000;
|
||||
constexpr int kNeverForLocation = 0x00010000;
|
||||
|
||||
/** Retrieves the attribute of the element with the specified attribute resource id. */
|
||||
@@ -331,7 +330,7 @@ class ManifestExtractor {
|
||||
ConfigDescription config;
|
||||
config.orientation = android::ResTable_config::ORIENTATION_PORT;
|
||||
config.density = android::ResTable_config::DENSITY_MEDIUM;
|
||||
config.sdkVersion = kCurrentDevelopmentVersion; // Very high.
|
||||
config.sdkVersion = SDK_CUR_DEVELOPMENT; // Very high.
|
||||
config.screenWidthDp = 320;
|
||||
config.screenHeightDp = 480;
|
||||
config.smallestScreenWidthDp = 320;
|
||||
@@ -621,7 +620,7 @@ class UsesSdkBadging : public ManifestExtractor::Element {
|
||||
// Detect the target sdk of the element
|
||||
if ((min_sdk_name && *min_sdk_name == "Donut")
|
||||
|| (target_sdk_name && *target_sdk_name == "Donut")) {
|
||||
extractor()->RaiseTargetSdk(4);
|
||||
extractor()->RaiseTargetSdk(SDK_DONUT);
|
||||
}
|
||||
if (min_sdk) {
|
||||
extractor()->RaiseTargetSdk(*min_sdk);
|
||||
@@ -629,7 +628,7 @@ class UsesSdkBadging : public ManifestExtractor::Element {
|
||||
if (target_sdk) {
|
||||
extractor()->RaiseTargetSdk(*target_sdk);
|
||||
} else if (target_sdk_name) {
|
||||
extractor()->RaiseTargetSdk(kCurrentDevelopmentVersion);
|
||||
extractor()->RaiseTargetSdk(SDK_CUR_DEVELOPMENT);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -746,21 +745,23 @@ class SupportsScreen : public ManifestExtractor::Element {
|
||||
// the screen size support was introduced, so all default to
|
||||
// enabled.
|
||||
if (small_screen_temp > 0) {
|
||||
small_screen_temp = target_sdk >= 4 ? -1 : 0;
|
||||
small_screen_temp = target_sdk >= SDK_DONUT ? -1 : 0;
|
||||
}
|
||||
if (normal_screen_temp > 0) {
|
||||
normal_screen_temp = -1;
|
||||
}
|
||||
if (large_screen_temp > 0) {
|
||||
large_screen_temp = target_sdk >= 4 ? -1 : 0;
|
||||
large_screen_temp = target_sdk >= SDK_DONUT ? -1 : 0;
|
||||
}
|
||||
if (xlarge_screen_temp > 0) {
|
||||
// Introduced in Gingerbread.
|
||||
xlarge_screen_temp = target_sdk >= 9 ? -1 : 0;
|
||||
xlarge_screen_temp = target_sdk >= SDK_GINGERBREAD ? -1 : 0;
|
||||
}
|
||||
if (any_density_temp > 0) {
|
||||
any_density_temp = (target_sdk >= 4 || requires_smallest_width_dp > 0
|
||||
|| compatible_width_limit_dp > 0) ? -1 : 0;
|
||||
any_density_temp = (target_sdk >= SDK_DONUT || requires_smallest_width_dp > 0 ||
|
||||
compatible_width_limit_dp > 0)
|
||||
? -1
|
||||
: 0;
|
||||
}
|
||||
|
||||
// Print the formatted screen info
|
||||
@@ -2030,7 +2031,7 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) {
|
||||
auto write_external_permission = ElementCast<UsesPermission>(
|
||||
FindPermission(root.get(), "android.permission.WRITE_EXTERNAL_STORAGE"));
|
||||
|
||||
if (target_sdk() < 4) {
|
||||
if (target_sdk() < SDK_DONUT) {
|
||||
if (!write_external_permission) {
|
||||
PrintPermission("android.permission.WRITE_EXTERNAL_STORAGE", "targetSdkVersion < 4", -1);
|
||||
insert_write_external = true;
|
||||
@@ -2053,7 +2054,7 @@ bool ManifestExtractor::Dump(text::Printer* printer, IDiagnostics* diag) {
|
||||
}
|
||||
|
||||
// Pre-JellyBean call log permission compatibility.
|
||||
if (target_sdk() < 16) {
|
||||
if (target_sdk() < SDK_JELLY_BEAN) {
|
||||
if (!FindPermission(root.get(), "android.permission.READ_CALL_LOG")
|
||||
&& FindPermission(root.get(), "android.permission.READ_CONTACTS")) {
|
||||
PrintPermission("android.permission.READ_CALL_LOG",
|
||||
|
||||
Reference in New Issue
Block a user