format ApkProvider using Android Studio Ctrl-Alt-L

This commit is contained in:
Hans-Christoph Steiner 2018-04-25 11:23:39 +02:00
parent 80734891a6
commit 94b70608d0

View File

@ -26,7 +26,6 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@SuppressWarnings("LineLength")
public class ApkProvider extends FDroidProvider { public class ApkProvider extends FDroidProvider {
private static final String TAG = "ApkProvider"; private static final String TAG = "ApkProvider";
@ -41,7 +40,8 @@ public class ApkProvider extends FDroidProvider {
public static final class Helper { public static final class Helper {
private Helper() { } private Helper() {
}
public static void update(Context context, Apk apk) { public static void update(Context context, Apk apk) {
ContentResolver resolver = context.getContentResolver(); ContentResolver resolver = context.getContentResolver();
@ -83,19 +83,21 @@ public class ApkProvider extends FDroidProvider {
/** /**
* Find an app which is closest to the version code suggested by the server, with some caveates: * Find an app which is closest to the version code suggested by the server, with some caveates:
* <ul> * <ul>
* <li>If installed, limit to apks signed by the same signer as the installed apk.</li> * <li>If installed, limit to apks signed by the same signer as the installed apk.</li>
* <li>Otherwise, limit to apks signed by the "preferred" signer (see {@link App#preferredSigner}).</li> * <li>Otherwise, limit to apks signed by the "preferred" signer (see {@link App#preferredSigner}).</li>
* </ul> * </ul>
*/ */
public static Apk findSuggestedApk(Context context, App app) { public static Apk findSuggestedApk(Context context, App app) {
return findApkFromAnyRepo(context, app.packageName, app.suggestedVersionCode, app.getMostAppropriateSignature()); return findApkFromAnyRepo(context, app.packageName, app.suggestedVersionCode,
app.getMostAppropriateSignature());
} }
public static Apk findApkFromAnyRepo(Context context, String packageName, int versionCode) { public static Apk findApkFromAnyRepo(Context context, String packageName, int versionCode) {
return findApkFromAnyRepo(context, packageName, versionCode, null, Cols.ALL); return findApkFromAnyRepo(context, packageName, versionCode, null, Cols.ALL);
} }
public static Apk findApkFromAnyRepo(Context context, String packageName, int versionCode, String signature) { public static Apk findApkFromAnyRepo(Context context, String packageName, int versionCode,
String signature) {
return findApkFromAnyRepo(context, packageName, versionCode, signature, Cols.ALL); return findApkFromAnyRepo(context, packageName, versionCode, signature, Cols.ALL);
} }
@ -185,7 +187,7 @@ public class ApkProvider extends FDroidProvider {
protected static final String PATH_REPO_APP = "repo-app"; protected static final String PATH_REPO_APP = "repo-app";
private static final String PATH_APKS = "apks"; private static final String PATH_APKS = "apks";
private static final String PATH_APP = "app"; private static final String PATH_APP = "app";
private static final String PATH_REPO = "repo"; private static final String PATH_REPO = "repo";
private static final String PATH_APK_ROW_ID = "apk-rowId"; private static final String PATH_APK_ROW_ID = "apk-rowId";
private static final UriMatcher MATCHER = new UriMatcher(-1); private static final UriMatcher MATCHER = new UriMatcher(-1);
@ -226,27 +228,27 @@ public class ApkProvider extends FDroidProvider {
public static Uri getAppUri(String packageName) { public static Uri getAppUri(String packageName) {
return getContentUri() return getContentUri()
.buildUpon() .buildUpon()
.appendPath(PATH_APP) .appendPath(PATH_APP)
.appendPath(packageName) .appendPath(packageName)
.build(); .build();
} }
public static Uri getRepoUri(long repoId) { public static Uri getRepoUri(long repoId) {
return getContentUri() return getContentUri()
.buildUpon() .buildUpon()
.appendPath(PATH_REPO) .appendPath(PATH_REPO)
.appendPath(Long.toString(repoId)) .appendPath(Long.toString(repoId))
.build(); .build();
} }
public static Uri getRepoUri(long repoId, String packageName) { public static Uri getRepoUri(long repoId, String packageName) {
return getContentUri() return getContentUri()
.buildUpon() .buildUpon()
.appendPath(PATH_REPO_APP) .appendPath(PATH_REPO_APP)
.appendPath(Long.toString(repoId)) .appendPath(Long.toString(repoId))
.appendPath(packageName) .appendPath(packageName)
.build(); .build();
} }
public static Uri getApkFromAnyRepoUri(Apk apk) { public static Uri getApkFromAnyRepoUri(Apk apk) {
@ -296,10 +298,13 @@ public class ApkProvider extends FDroidProvider {
private boolean antiFeaturesRequested; private boolean antiFeaturesRequested;
/** /**
* If the query includes anti features, then we group by apk id. This is because joining onto the anti-features * If the query includes anti features, then we group by apk id. This
* table will result in multiple result rows for each apk (potentially), so we will GROUP_CONCAT each of the * is because joining onto the anti-features table will result in
* anti features into a single comma separated list for each apk. If we are _not_ including anti features, then * multiple result rows for each apk (potentially), so we will
* don't group by apk, because when doing a COUNT(*) this will result in the wrong result. * {@code GROUP_CONCAT} each of the anti-features into a single comma-
* separated list for each apk. If we are _not_ including anti-
* features, then don't group by apk, because when doing a COUNT(*)
* this will result in the wrong result.
*/ */
@Override @Override
protected String groupBy() { protected String groupBy() {
@ -313,8 +318,8 @@ public class ApkProvider extends FDroidProvider {
final String pkg = PackageTable.NAME; final String pkg = PackageTable.NAME;
return apk + " AS apk " + return apk + " AS apk " +
" LEFT JOIN " + app + " AS app ON (app." + AppMetadataTable.Cols.ROW_ID + " = apk." + Cols.APP_ID + ")" + " LEFT JOIN " + app + " AS app ON (app." + AppMetadataTable.Cols.ROW_ID + " = apk." + Cols.APP_ID + ")" + // NOPMD NOCHECKSTYLE LineLength
" LEFT JOIN " + pkg + " AS pkg ON (pkg." + PackageTable.Cols.ROW_ID + " = app." + AppMetadataTable.Cols.PACKAGE_ID + ")"; " LEFT JOIN " + pkg + " AS pkg ON (pkg." + PackageTable.Cols.ROW_ID + " = app." + AppMetadataTable.Cols.PACKAGE_ID + ")"; // NOPMD NOCHECKSTYLE LineLength
} }
@Override @Override
@ -357,9 +362,11 @@ public class ApkProvider extends FDroidProvider {
"apk." + Cols.ROW_ID + " = " + apkAntiFeature + "." + ApkAntiFeatureJoinTable.Cols.APK_ID); "apk." + Cols.ROW_ID + " = " + apkAntiFeature + "." + ApkAntiFeatureJoinTable.Cols.APK_ID);
leftJoin(AntiFeatureTable.NAME, antiFeature, leftJoin(AntiFeatureTable.NAME, antiFeature,
apkAntiFeature + "." + ApkAntiFeatureJoinTable.Cols.ANTI_FEATURE_ID + " = " + antiFeature + "." + AntiFeatureTable.Cols.ROW_ID); apkAntiFeature + "." + ApkAntiFeatureJoinTable.Cols.ANTI_FEATURE_ID + " = "
+ antiFeature + "." + AntiFeatureTable.Cols.ROW_ID);
appendField("group_concat(" + antiFeature + "." + AntiFeatureTable.Cols.NAME + ") as " + Cols.AntiFeatures.ANTI_FEATURES); appendField("group_concat(" + antiFeature + "." + AntiFeatureTable.Cols.NAME + ") as "
+ Cols.AntiFeatures.ANTI_FEATURES);
} }
} }
@ -378,11 +385,11 @@ public class ApkProvider extends FDroidProvider {
String selection = String selection =
alias + Cols.VERSION_CODE + " = ? AND " + alias + Cols.VERSION_CODE + " = ? AND " +
alias + Cols.APP_ID + " IN (" + getMetadataIdFromPackageNameQuery() + ")"; alias + Cols.APP_ID + " IN (" + getMetadataIdFromPackageNameQuery() + ")";
List<String> pathSegments = uri.getPathSegments(); List<String> pathSegments = uri.getPathSegments();
List<String> args = new ArrayList<>(3); List<String> args = new ArrayList<>(3);
args.add(pathSegments.get(1)); // First (0th) path segment is the word "apk" and we are not interested in it. args.add(pathSegments.get(1)); // 0th path segment is the word "apk" and we are not interested in it.
args.add(pathSegments.get(2)); args.add(pathSegments.get(2));
if (pathSegments.size() >= 4) { if (pathSegments.size() >= 4) {
@ -438,8 +445,8 @@ public class ApkProvider extends FDroidProvider {
final String[] apkDetails = apkKeys.split(","); final String[] apkDetails = apkKeys.split(",");
if (apkDetails.length > MAX_APKS_TO_QUERY) { if (apkDetails.length > MAX_APKS_TO_QUERY) {
throw new IllegalArgumentException( throw new IllegalArgumentException(
"Cannot query more than " + MAX_APKS_TO_QUERY + ". " + "Cannot query more than " + MAX_APKS_TO_QUERY + ". " +
"You tried to query " + apkDetails.length); "You tried to query " + apkDetails.length);
} }
String alias = includeAlias ? "apk." : ""; String alias = includeAlias ? "apk." : "";
final String[] args = new String[apkDetails.length * 2]; final String[] args = new String[apkDetails.length * 2];
@ -569,7 +576,9 @@ public class ApkProvider extends FDroidProvider {
} }
protected void ensureAntiFeatures(String[] antiFeatures, long apkId) { protected void ensureAntiFeatures(String[] antiFeatures, long apkId) {
db().delete(getApkAntiFeatureJoinTableName(), ApkAntiFeatureJoinTable.Cols.APK_ID + " = ?", new String[] {Long.toString(apkId)}); db().delete(getApkAntiFeatureJoinTableName(),
ApkAntiFeatureJoinTable.Cols.APK_ID + " = ?",
new String[]{Long.toString(apkId)});
if (antiFeatures != null) { if (antiFeatures != null) {
Set<String> antiFeatureSet = new HashSet<>(); Set<String> antiFeatureSet = new HashSet<>();
for (String antiFeatureName : antiFeatures) { for (String antiFeatureName : antiFeatures) {
@ -594,7 +603,8 @@ public class ApkProvider extends FDroidProvider {
protected long ensureAntiFeature(String antiFeatureName) { protected long ensureAntiFeature(String antiFeatureName) {
long antiFeatureId = 0; long antiFeatureId = 0;
Cursor cursor = db().query(AntiFeatureTable.NAME, new String[] {AntiFeatureTable.Cols.ROW_ID}, AntiFeatureTable.Cols.NAME + " = ?", new String[]{antiFeatureName}, null, null, null); Cursor cursor = db().query(AntiFeatureTable.NAME, new String[]{AntiFeatureTable.Cols.ROW_ID},
AntiFeatureTable.Cols.NAME + " = ?", new String[]{antiFeatureName}, null, null, null);
if (cursor != null) { if (cursor != null) {
if (cursor.getCount() > 0) { if (cursor.getCount() > 0) {
cursor.moveToFirst(); cursor.moveToFirst();