Add support for shorthand SDK for bounding check

- fixes #1630
This commit is contained in:
Connor Tumbleson 2017-09-28 08:23:02 -04:00
parent 212330e0c9
commit 3ec4f360ab
No known key found for this signature in database
GPG Key ID: C3CC0A201EC7DA75
3 changed files with 40 additions and 17 deletions

View File

@ -287,7 +287,7 @@ public class Androlib {
if (meta.sdkInfo != null && meta.sdkInfo.get("minSdkVersion") != null) {
String minSdkVersion = meta.sdkInfo.get("minSdkVersion");
mMinSdkVersion = getMinSdkVersionFromAndroidCodename(meta, minSdkVersion);
mMinSdkVersion = mAndRes.getMinSdkVersionFromAndroidCodename(meta, minSdkVersion);
}
if (outFile == null) {
@ -728,19 +728,6 @@ public class Androlib {
return files;
}
private int getMinSdkVersionFromAndroidCodename(MetaInfo meta, String sdkVersion) {
switch (sdkVersion) {
case "M":
return ResConfigFlags.SDK_MNC;
case "N":
return ResConfigFlags.SDK_NOUGAT;
case "O":
return ResConfigFlags.SDK_OREO;
default:
return Integer.parseInt(meta.sdkInfo.get("minSdkVersion"));
}
}
private boolean isModified(File working, File stored) {
return ! stored.exists() || BrutIO.recursiveModifiedTime(working) > BrutIO .recursiveModifiedTime(stored);
}

View File

@ -19,6 +19,7 @@ package brut.androlib.res;
import brut.androlib.AndrolibException;
import brut.androlib.ApkOptions;
import brut.androlib.err.CantFindFrameworkResException;
import brut.androlib.meta.MetaInfo;
import brut.androlib.meta.PackageInfo;
import brut.androlib.meta.VersionInfo;
import brut.androlib.res.data.*;
@ -308,9 +309,10 @@ final public class AndrolibResources {
}
public String checkTargetSdkVersionBounds() {
int target = Integer.parseInt(mTargetSdkVersion);
int min = (mMinSdkVersion != null) ? Integer.parseInt(mMinSdkVersion) : 0;
int max = (mMaxSdkVersion != null) ? Integer.parseInt(mMaxSdkVersion) : target;
int target = mapSdkShorthandToVersion(mTargetSdkVersion);
int min = (mMinSdkVersion != null) ? mapSdkShorthandToVersion(mMinSdkVersion) : 0;
int max = (mMaxSdkVersion != null) ? mapSdkShorthandToVersion(mMaxSdkVersion) : target;
target = Math.min(max, target);
target = Math.max(min, target);
@ -455,6 +457,28 @@ final public class AndrolibResources {
}
}
public int getMinSdkVersionFromAndroidCodename(MetaInfo meta, String sdkVersion) {
int sdkNumber = mapSdkShorthandToVersion(sdkVersion);
if (sdkNumber == ResConfigFlags.SDK_BASE) {
return Integer.parseInt(meta.sdkInfo.get("minSdkVersion"));
}
return sdkNumber;
}
private int mapSdkShorthandToVersion(String sdkVersion) {
switch (sdkVersion) {
case "M":
return ResConfigFlags.SDK_MNC;
case "N":
return ResConfigFlags.SDK_NOUGAT;
case "O":
return ResConfigFlags.SDK_OREO;
default:
return Integer.parseInt(sdkVersion);
}
}
public boolean detectWhetherAppIsFramework(File appDir)
throws AndrolibException {
File publicXml = new File(appDir, "res/values/public.xml");

View File

@ -75,4 +75,16 @@ public class InvalidSdkBoundingTest {
androlibResources.setSdkInfo(sdkInfo);
assertEquals("25", androlibResources.checkTargetSdkVersionBounds());
}
@Test
public void checkForShortHandSdkTag() throws BrutException, IOException {
AndrolibResources androlibResources = new AndrolibResources();
Map<String, String> sdkInfo = new LinkedHashMap<>();
sdkInfo.put("targetSdkVersion", "O");
androlibResources.setSdkInfo(sdkInfo);
assertEquals("26", androlibResources.checkTargetSdkVersionBounds());
}
}