standardize SDK version test methods
I just took the most common method, using the SDK int value, and applied that throughout the code to have it consistent.
This commit is contained in:
parent
610ead83d0
commit
e021eb5ca7
@ -172,7 +172,7 @@ public abstract class ProviderTestCase2MockContext<T extends ContentProvider> ex
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
||||
private void shutdownProvider() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
mProvider.shutdown();
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.FeatureInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import org.fdroid.fdroid.compat.Compatibility;
|
||||
import org.fdroid.fdroid.compat.SupportedArchitectures;
|
||||
import org.fdroid.fdroid.data.Apk;
|
||||
|
||||
@ -18,7 +18,7 @@ import java.util.Set;
|
||||
|
||||
// Call getIncompatibleReasons(apk) on an instance of this class to
|
||||
// find reasons why an apk may be incompatible with the user's device.
|
||||
public class CompatibilityChecker extends Compatibility {
|
||||
public class CompatibilityChecker {
|
||||
|
||||
private static final String TAG = "Compatibility";
|
||||
|
||||
@ -85,11 +85,11 @@ public class CompatibilityChecker extends Compatibility {
|
||||
|
||||
List<String> incompatibleReasons = new ArrayList<>();
|
||||
|
||||
if (!hasApi(apk.minSdkVersion)) {
|
||||
if (Build.VERSION.SDK_INT < apk.minSdkVersion) {
|
||||
incompatibleReasons.add(context.getString(
|
||||
R.string.minsdk_or_later,
|
||||
Utils.getAndroidVersionName(apk.minSdkVersion)));
|
||||
} else if (!upToApi(apk.maxSdkVersion)) {
|
||||
} else if (Build.VERSION.SDK_INT > apk.maxSdkVersion) {
|
||||
incompatibleReasons.add(context.getString(
|
||||
R.string.up_to_maxsdk,
|
||||
Utils.getAndroidVersionName(apk.maxSdkVersion)));
|
||||
|
@ -146,7 +146,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
//
|
||||
// http://stackoverflow.com/a/20032920
|
||||
//
|
||||
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) {
|
||||
if (Build.VERSION.SDK_INT <= 10) {
|
||||
Intent pendingIntent = new Intent(this, FDroid.class);
|
||||
pendingIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
notificationBuilder.setContentIntent(PendingIntent.getActivity(this, 0, pendingIntent, PendingIntent.FLAG_UPDATE_CURRENT));
|
||||
|
@ -1,15 +1,16 @@
|
||||
package org.fdroid.fdroid.compat;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
import android.widget.ArrayAdapter;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ArrayAdapterCompat extends Compatibility {
|
||||
public class ArrayAdapterCompat {
|
||||
|
||||
@TargetApi(11)
|
||||
public static <T> void addAll(ArrayAdapter<T> adapter, List<T> list) {
|
||||
if (hasApi(11)) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
adapter.addAll(list);
|
||||
} else {
|
||||
for (T category : list) {
|
||||
|
@ -4,13 +4,14 @@ import android.annotation.TargetApi;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
|
||||
public abstract class ClipboardCompat extends Compatibility {
|
||||
public abstract class ClipboardCompat {
|
||||
|
||||
public abstract String getText();
|
||||
|
||||
public static ClipboardCompat create(Context context) {
|
||||
if (hasApi(11)) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
return new HoneycombClipboard(context);
|
||||
}
|
||||
return new OldClipboard();
|
||||
|
@ -1,21 +0,0 @@
|
||||
package org.fdroid.fdroid.compat;
|
||||
|
||||
import android.os.Build;
|
||||
|
||||
public abstract class Compatibility {
|
||||
|
||||
// like minSdkVersion
|
||||
protected static boolean hasApi(int apiLevel) {
|
||||
return getApi() >= apiLevel;
|
||||
}
|
||||
|
||||
// like maxSdkVersion
|
||||
protected static boolean upToApi(int apiLevel) {
|
||||
return apiLevel < 1 || getApi() <= apiLevel;
|
||||
}
|
||||
|
||||
static int getApi() {
|
||||
return Build.VERSION.SDK_INT;
|
||||
}
|
||||
|
||||
}
|
@ -17,15 +17,15 @@ import java.lang.reflect.Method;
|
||||
* This helps prevent things like SQL injection, shell command injection
|
||||
* and other attacks based on putting various characters into filenames.
|
||||
*/
|
||||
public class FileCompat extends Compatibility {
|
||||
public class FileCompat {
|
||||
|
||||
private static final String TAG = "FileCompat";
|
||||
|
||||
public static boolean symlink(SanitizedFile source, SanitizedFile dest) {
|
||||
|
||||
if (hasApi(21)) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
symlinkOs(source, dest);
|
||||
} else if (hasApi(15)) {
|
||||
} else if (Build.VERSION.SDK_INT >= 15) {
|
||||
symlinkLibcore(source, dest);
|
||||
} else {
|
||||
symlinkRuntime(source, dest);
|
||||
@ -88,7 +88,7 @@ public class FileCompat extends Compatibility {
|
||||
@TargetApi(9)
|
||||
public static boolean setReadable(SanitizedFile file, boolean readable, boolean ownerOnly) {
|
||||
|
||||
if (hasApi(9)) {
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
return file.setReadable(readable, ownerOnly);
|
||||
}
|
||||
String mode;
|
||||
@ -126,7 +126,7 @@ public class FileCompat extends Compatibility {
|
||||
@TargetApi(9)
|
||||
public static boolean setExecutable(SanitizedFile file, boolean executable, boolean ownerOnly) {
|
||||
|
||||
if (hasApi(9)) {
|
||||
if (Build.VERSION.SDK_INT >= 9) {
|
||||
return file.setExecutable(executable, ownerOnly);
|
||||
}
|
||||
String mode;
|
||||
|
@ -36,10 +36,8 @@ import java.security.Security;
|
||||
* Cryptography Architecture primitives. A good place to invoke them is in the
|
||||
* application's {@code onCreate}.
|
||||
*/
|
||||
public final class PRNGFixes extends Compatibility {
|
||||
public final class PRNGFixes {
|
||||
|
||||
private static final int VERSION_CODE_JELLY_BEAN = 16;
|
||||
private static final int VERSION_CODE_JELLY_BEAN_MR2 = 18;
|
||||
private static final byte[] BUILD_FINGERPRINT_AND_DEVICE_SERIAL =
|
||||
getBuildFingerprintAndDeviceSerial();
|
||||
|
||||
@ -63,7 +61,7 @@ public final class PRNGFixes extends Compatibility {
|
||||
* @throws SecurityException if the fix is needed but could not be applied.
|
||||
*/
|
||||
private static void applyOpenSSLFix() throws SecurityException {
|
||||
if (getApi() < VERSION_CODE_JELLY_BEAN || getApi() > VERSION_CODE_JELLY_BEAN_MR2) {
|
||||
if (Build.VERSION.SDK_INT < 16 || Build.VERSION.SDK_INT > 18) {
|
||||
// No need to apply the fix
|
||||
return;
|
||||
}
|
||||
@ -98,7 +96,7 @@ public final class PRNGFixes extends Compatibility {
|
||||
*/
|
||||
private static void installLinuxPRNGSecureRandom()
|
||||
throws SecurityException {
|
||||
if (getApi() > VERSION_CODE_JELLY_BEAN_MR2) {
|
||||
if (Build.VERSION.SDK_INT > 18) {
|
||||
// No need to apply the fix
|
||||
return;
|
||||
}
|
||||
|
@ -2,17 +2,18 @@ package org.fdroid.fdroid.compat;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
import org.fdroid.fdroid.Utils;
|
||||
|
||||
public class PackageManagerCompat extends Compatibility {
|
||||
public class PackageManagerCompat {
|
||||
|
||||
private static final String TAG = "PackageManagerCompat";
|
||||
|
||||
@TargetApi(11)
|
||||
public static void setInstaller(PackageManager mPm, String packageName) {
|
||||
if (!hasApi(11)) return;
|
||||
if (Build.VERSION.SDK_INT < 11) return;
|
||||
try {
|
||||
mPm.setInstallerPackageName(packageName, "org.fdroid.fdroid");
|
||||
Utils.debugLog(TAG, "Installer package name for " + packageName + " set successfully");
|
||||
|
@ -3,7 +3,7 @@ package org.fdroid.fdroid.compat;
|
||||
import android.annotation.TargetApi;
|
||||
import android.os.Build;
|
||||
|
||||
public class SupportedArchitectures extends Compatibility {
|
||||
public class SupportedArchitectures {
|
||||
|
||||
/**
|
||||
* The most preferred ABI is the first element in the list.
|
||||
@ -11,7 +11,7 @@ public class SupportedArchitectures extends Compatibility {
|
||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||
@SuppressWarnings("deprecation")
|
||||
public static String[] getAbis() {
|
||||
if (hasApi(21)) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
return Build.SUPPORTED_ABIS;
|
||||
}
|
||||
return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
|
||||
|
@ -12,7 +12,7 @@ public class UriCompat {
|
||||
*/
|
||||
public static String getQueryParameter(Uri uri, String key) {
|
||||
String value = uri.getQueryParameter(key);
|
||||
if (value != null && Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
if (value != null && Build.VERSION.SDK_INT < 14) {
|
||||
value = value.replaceAll("\\+", " ");
|
||||
}
|
||||
return value;
|
||||
|
@ -127,7 +127,7 @@ public abstract class FDroidProvider extends ContentProvider {
|
||||
@TargetApi(11)
|
||||
private Set<String> getKeySet(ContentValues values) {
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||
if (Build.VERSION.SDK_INT >= 11) {
|
||||
return values.keySet();
|
||||
}
|
||||
|
||||
|
@ -62,7 +62,7 @@ public class DefaultSdk14Installer extends Installer {
|
||||
// following extras only work when being installed as system-app
|
||||
// https://code.google.com/p/android/issues/detail?id=42253
|
||||
intent.putExtra(Intent.EXTRA_NOT_UNKNOWN_SOURCE, true);
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
|
||||
if (android.os.Build.VERSION.SDK_INT < 16) {
|
||||
// deprecated in Android 4.1
|
||||
intent.putExtra(Intent.EXTRA_ALLOW_REPLACE, true);
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public abstract class Installer {
|
||||
}
|
||||
|
||||
// else -> DefaultInstaller
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
|
||||
if (android.os.Build.VERSION.SDK_INT >= 14) {
|
||||
// Default installer on Android >= 4.0
|
||||
try {
|
||||
Utils.debugLog(TAG, "try default installer for Android >= 4");
|
||||
|
@ -47,10 +47,10 @@ abstract class InstallExtension {
|
||||
}
|
||||
|
||||
public static InstallExtension create(final Context context) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (Build.VERSION.SDK_INT >= 21) {
|
||||
return new LollipopImpl(context);
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
if (Build.VERSION.SDK_INT >= 19) {
|
||||
return new KitKatToLollipopImpl(context);
|
||||
}
|
||||
return new PreKitKatImpl(context);
|
||||
|
Loading…
x
Reference in New Issue
Block a user