Merge branch 'targetSdkVersion' into 'master'
include targetSdkVersion in Apk In order to work well with the Android 6.0+ permissions, the client needs to know whether an APK has been built against android-23 or higher. @pserwylo @dschuermann how does this look? See merge request !323
This commit is contained in:
commit
d40c94ab11
@ -128,6 +128,9 @@ public class RepoXMLHandler extends DefaultHandler {
|
|||||||
case "sdkver":
|
case "sdkver":
|
||||||
curapk.minSdkVersion = Utils.parseInt(str, Apk.SDK_VERSION_MIN_VALUE);
|
curapk.minSdkVersion = Utils.parseInt(str, Apk.SDK_VERSION_MIN_VALUE);
|
||||||
break;
|
break;
|
||||||
|
case "targetSdkVersion":
|
||||||
|
curapk.targetSdkVersion = Utils.parseInt(str, Apk.SDK_VERSION_MIN_VALUE);
|
||||||
|
break;
|
||||||
case "maxsdkver":
|
case "maxsdkver":
|
||||||
curapk.maxSdkVersion = Utils.parseInt(str, Apk.SDK_VERSION_MAX_VALUE);
|
curapk.maxSdkVersion = Utils.parseInt(str, Apk.SDK_VERSION_MAX_VALUE);
|
||||||
if (curapk.maxSdkVersion == 0) {
|
if (curapk.maxSdkVersion == 0) {
|
||||||
|
@ -26,6 +26,7 @@ public class Apk extends ValueObject implements Comparable<Apk> {
|
|||||||
public String hash;
|
public String hash;
|
||||||
public String hashType;
|
public String hashType;
|
||||||
public int minSdkVersion = SDK_VERSION_MIN_VALUE; // 0 if unknown
|
public int minSdkVersion = SDK_VERSION_MIN_VALUE; // 0 if unknown
|
||||||
|
public int targetSdkVersion = SDK_VERSION_MIN_VALUE; // 0 if unknown
|
||||||
public int maxSdkVersion = SDK_VERSION_MAX_VALUE; // "infinity" if not set
|
public int maxSdkVersion = SDK_VERSION_MAX_VALUE; // "infinity" if not set
|
||||||
public Date added;
|
public Date added;
|
||||||
public Utils.CommaSeparatedList permissions; // null if empty or
|
public Utils.CommaSeparatedList permissions; // null if empty or
|
||||||
@ -93,6 +94,9 @@ public class Apk extends ValueObject implements Comparable<Apk> {
|
|||||||
case ApkProvider.DataColumns.MIN_SDK_VERSION:
|
case ApkProvider.DataColumns.MIN_SDK_VERSION:
|
||||||
minSdkVersion = cursor.getInt(i);
|
minSdkVersion = cursor.getInt(i);
|
||||||
break;
|
break;
|
||||||
|
case ApkProvider.DataColumns.TARGET_SDK_VERSION:
|
||||||
|
targetSdkVersion = cursor.getInt(i);
|
||||||
|
break;
|
||||||
case ApkProvider.DataColumns.MAX_SDK_VERSION:
|
case ApkProvider.DataColumns.MAX_SDK_VERSION:
|
||||||
maxSdkVersion = cursor.getInt(i);
|
maxSdkVersion = cursor.getInt(i);
|
||||||
break;
|
break;
|
||||||
@ -198,6 +202,7 @@ public class Apk extends ValueObject implements Comparable<Apk> {
|
|||||||
values.put(ApkProvider.DataColumns.SIZE, size);
|
values.put(ApkProvider.DataColumns.SIZE, size);
|
||||||
values.put(ApkProvider.DataColumns.NAME, apkName);
|
values.put(ApkProvider.DataColumns.NAME, apkName);
|
||||||
values.put(ApkProvider.DataColumns.MIN_SDK_VERSION, minSdkVersion);
|
values.put(ApkProvider.DataColumns.MIN_SDK_VERSION, minSdkVersion);
|
||||||
|
values.put(ApkProvider.DataColumns.TARGET_SDK_VERSION, targetSdkVersion);
|
||||||
values.put(ApkProvider.DataColumns.MAX_SDK_VERSION, maxSdkVersion);
|
values.put(ApkProvider.DataColumns.MAX_SDK_VERSION, maxSdkVersion);
|
||||||
values.put(ApkProvider.DataColumns.ADDED_DATE, Utils.formatDate(added, ""));
|
values.put(ApkProvider.DataColumns.ADDED_DATE, Utils.formatDate(added, ""));
|
||||||
values.put(ApkProvider.DataColumns.PERMISSIONS, Utils.CommaSeparatedList.str(permissions));
|
values.put(ApkProvider.DataColumns.PERMISSIONS, Utils.CommaSeparatedList.str(permissions));
|
||||||
|
@ -208,6 +208,7 @@ public class ApkProvider extends FDroidProvider {
|
|||||||
String SIGNATURE = "sig";
|
String SIGNATURE = "sig";
|
||||||
String SOURCE_NAME = "srcname";
|
String SOURCE_NAME = "srcname";
|
||||||
String MIN_SDK_VERSION = "minSdkVersion";
|
String MIN_SDK_VERSION = "minSdkVersion";
|
||||||
|
String TARGET_SDK_VERSION = "targetSdkVersion";
|
||||||
String MAX_SDK_VERSION = "maxSdkVersion";
|
String MAX_SDK_VERSION = "maxSdkVersion";
|
||||||
String PERMISSIONS = "permissions";
|
String PERMISSIONS = "permissions";
|
||||||
String FEATURES = "features";
|
String FEATURES = "features";
|
||||||
@ -221,7 +222,7 @@ public class ApkProvider extends FDroidProvider {
|
|||||||
|
|
||||||
String[] ALL = {
|
String[] ALL = {
|
||||||
_ID, PACKAGE_NAME, VERSION_NAME, REPO_ID, HASH, VERSION_CODE, NAME,
|
_ID, PACKAGE_NAME, VERSION_NAME, REPO_ID, HASH, VERSION_CODE, NAME,
|
||||||
SIZE, SIGNATURE, SOURCE_NAME, MIN_SDK_VERSION, MAX_SDK_VERSION,
|
SIZE, SIGNATURE, SOURCE_NAME, MIN_SDK_VERSION, TARGET_SDK_VERSION, MAX_SDK_VERSION,
|
||||||
PERMISSIONS, FEATURES, NATIVE_CODE, HASH_TYPE, ADDED_DATE,
|
PERMISSIONS, FEATURES, NATIVE_CODE, HASH_TYPE, ADDED_DATE,
|
||||||
IS_COMPATIBLE, REPO_VERSION, REPO_ADDRESS, INCOMPATIBLE_REASONS,
|
IS_COMPATIBLE, REPO_VERSION, REPO_ADDRESS, INCOMPATIBLE_REASONS,
|
||||||
};
|
};
|
||||||
|
@ -329,9 +329,10 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
apk.versionName = packageInfo.versionName;
|
apk.versionName = packageInfo.versionName;
|
||||||
apk.versionCode = packageInfo.versionCode;
|
apk.versionCode = packageInfo.versionCode;
|
||||||
apk.added = this.added;
|
apk.added = this.added;
|
||||||
int[] minMaxSdkVersions = getMinMaxSdkVersions(context, packageName);
|
int[] minTargetMax = getMinTargetMaxSdkVersions(context, packageName);
|
||||||
apk.minSdkVersion = minMaxSdkVersions[0];
|
apk.minSdkVersion = minTargetMax[0];
|
||||||
apk.maxSdkVersion = minMaxSdkVersions[1];
|
apk.targetSdkVersion = minTargetMax[1];
|
||||||
|
apk.maxSdkVersion = minTargetMax[2];
|
||||||
apk.packageName = this.packageName;
|
apk.packageName = this.packageName;
|
||||||
apk.permissions = Utils.CommaSeparatedList.make(packageInfo.requestedPermissions);
|
apk.permissions = Utils.CommaSeparatedList.make(packageInfo.requestedPermissions);
|
||||||
apk.apkName = apk.packageName + "_" + apk.versionCode + ".apk";
|
apk.apkName = apk.packageName + "_" + apk.versionCode + ".apk";
|
||||||
@ -509,11 +510,16 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link PackageManager} doesn't give us {@code minSdkVersion} and {@code maxSdkVersion},
|
* {@link PackageManager} doesn't give us {@code minSdkVersion}, {@code targetSdkVersion},
|
||||||
* so we have to parse it straight from {@code <uses-sdk>} in {@code AndroidManifest.xml}.
|
* and {@code maxSdkVersion}, so we have to parse it straight from {@code <uses-sdk>} in
|
||||||
|
* {@code AndroidManifest.xml}. If {@code targetSdkVersion} is not set, then it is
|
||||||
|
* equal to {@code minSdkVersion}
|
||||||
|
*
|
||||||
|
* @see <a href="https://developer.android.com/guide/topics/manifest/uses-sdk-element.html"><uses-sdk> element</a>
|
||||||
*/
|
*/
|
||||||
private static int[] getMinMaxSdkVersions(Context context, String packageName) {
|
private static int[] getMinTargetMaxSdkVersions(Context context, String packageName) {
|
||||||
int minSdkVersion = Apk.SDK_VERSION_MIN_VALUE;
|
int minSdkVersion = Apk.SDK_VERSION_MIN_VALUE;
|
||||||
|
int targetSdkVersion = Apk.SDK_VERSION_MIN_VALUE;
|
||||||
int maxSdkVersion = Apk.SDK_VERSION_MAX_VALUE;
|
int maxSdkVersion = Apk.SDK_VERSION_MAX_VALUE;
|
||||||
try {
|
try {
|
||||||
AssetManager am = context.createPackageContext(packageName, 0).getAssets();
|
AssetManager am = context.createPackageContext(packageName, 0).getAssets();
|
||||||
@ -524,6 +530,8 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
for (int j = 0; j < xml.getAttributeCount(); j++) {
|
for (int j = 0; j < xml.getAttributeCount(); j++) {
|
||||||
if (xml.getAttributeName(j).equals("minSdkVersion")) {
|
if (xml.getAttributeName(j).equals("minSdkVersion")) {
|
||||||
minSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
|
minSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
|
||||||
|
} else if (xml.getAttributeName(j).equals("targetSdkVersion")) {
|
||||||
|
targetSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
|
||||||
} else if (xml.getAttributeName(j).equals("maxSdkVersion")) {
|
} else if (xml.getAttributeName(j).equals("maxSdkVersion")) {
|
||||||
maxSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
|
maxSdkVersion = Integer.parseInt(xml.getAttributeValue(j));
|
||||||
}
|
}
|
||||||
@ -535,6 +543,9 @@ public class App extends ValueObject implements Comparable<App> {
|
|||||||
} catch (PackageManager.NameNotFoundException | IOException | XmlPullParserException e) {
|
} catch (PackageManager.NameNotFoundException | IOException | XmlPullParserException e) {
|
||||||
Log.e(TAG, "Could not get min/max sdk version", e);
|
Log.e(TAG, "Could not get min/max sdk version", e);
|
||||||
}
|
}
|
||||||
return new int[]{minSdkVersion, maxSdkVersion};
|
if (targetSdkVersion < minSdkVersion) {
|
||||||
|
targetSdkVersion = minSdkVersion;
|
||||||
|
}
|
||||||
|
return new int[]{minSdkVersion, targetSdkVersion, maxSdkVersion};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|||||||
+ "sig string, "
|
+ "sig string, "
|
||||||
+ "srcname string, "
|
+ "srcname string, "
|
||||||
+ "minSdkVersion integer, "
|
+ "minSdkVersion integer, "
|
||||||
|
+ "targetSdkVersion integer, "
|
||||||
+ "maxSdkVersion integer, "
|
+ "maxSdkVersion integer, "
|
||||||
+ "permissions string, "
|
+ "permissions string, "
|
||||||
+ "features string, "
|
+ "features string, "
|
||||||
@ -110,7 +111,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|||||||
+ " );";
|
+ " );";
|
||||||
private static final String DROP_TABLE_INSTALLED_APP = "DROP TABLE " + TABLE_INSTALLED_APP + ";";
|
private static final String DROP_TABLE_INSTALLED_APP = "DROP TABLE " + TABLE_INSTALLED_APP + ";";
|
||||||
|
|
||||||
private static final int DB_VERSION = 56;
|
private static final int DB_VERSION = 57;
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
@ -299,6 +300,7 @@ class DBHelper extends SQLiteOpenHelper {
|
|||||||
useMaxValueInMaxSdkVersion(db, oldVersion);
|
useMaxValueInMaxSdkVersion(db, oldVersion);
|
||||||
requireTimestampInRepos(db, oldVersion);
|
requireTimestampInRepos(db, oldVersion);
|
||||||
recreateInstalledAppTable(db, oldVersion);
|
recreateInstalledAppTable(db, oldVersion);
|
||||||
|
addTargetSdkVersionToApk(db, oldVersion);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -572,6 +574,16 @@ class DBHelper extends SQLiteOpenHelper {
|
|||||||
db.execSQL(CREATE_TABLE_INSTALLED_APP);
|
db.execSQL(CREATE_TABLE_INSTALLED_APP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void addTargetSdkVersionToApk(SQLiteDatabase db, int oldVersion) {
|
||||||
|
if (oldVersion >= 57) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Utils.debugLog(TAG, "Adding " + ApkProvider.DataColumns.TARGET_SDK_VERSION
|
||||||
|
+ " columns to " + TABLE_APK);
|
||||||
|
db.execSQL("alter table " + TABLE_APK + " add column "
|
||||||
|
+ ApkProvider.DataColumns.TARGET_SDK_VERSION + " integer");
|
||||||
|
}
|
||||||
|
|
||||||
private static boolean columnExists(SQLiteDatabase db,
|
private static boolean columnExists(SQLiteDatabase db,
|
||||||
String table, String column) {
|
String table, String column) {
|
||||||
return db.rawQuery("select * from " + table + " limit 0,1", null)
|
return db.rawQuery("select * from " + table + " limit 0,1", null)
|
||||||
|
@ -421,6 +421,9 @@ public final class LocalRepoManager {
|
|||||||
if (app.installedApk.minSdkVersion > Apk.SDK_VERSION_MIN_VALUE) {
|
if (app.installedApk.minSdkVersion > Apk.SDK_VERSION_MIN_VALUE) {
|
||||||
tag("sdkver", app.installedApk.minSdkVersion);
|
tag("sdkver", app.installedApk.minSdkVersion);
|
||||||
}
|
}
|
||||||
|
if (app.installedApk.targetSdkVersion > app.installedApk.minSdkVersion) {
|
||||||
|
tag("targetSdkVersion", app.installedApk.targetSdkVersion);
|
||||||
|
}
|
||||||
if (app.installedApk.maxSdkVersion < Apk.SDK_VERSION_MAX_VALUE) {
|
if (app.installedApk.maxSdkVersion < Apk.SDK_VERSION_MAX_VALUE) {
|
||||||
tag("maxsdkver", app.installedApk.maxSdkVersion);
|
tag("maxsdkver", app.installedApk.maxSdkVersion);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user