Support devices with more than two ABIs on >=21

Also, start using String[] like Android's SUPPORTED_ABIS instead of
Set<String>. Said list of ABIs will always be very short, at most containing a
handful of elements.
This commit is contained in:
Daniel Martí 2015-01-03 17:53:36 +01:00
parent a03053e80a
commit 55c1bd0572
3 changed files with 33 additions and 19 deletions

View File

@ -18,7 +18,7 @@ public class CompatibilityChecker extends Compatibility {
private Context context; private Context context;
private Set<String> features; private Set<String> features;
private Set<String> cpuAbis; private String[] cpuAbis;
private String cpuAbisDesc; private String cpuAbisDesc;
private boolean ignoreTouchscreen; private boolean ignoreTouchscreen;
@ -59,8 +59,8 @@ public class CompatibilityChecker extends Compatibility {
private boolean compatibleApi(Utils.CommaSeparatedList nativecode) { private boolean compatibleApi(Utils.CommaSeparatedList nativecode) {
if (nativecode == null) return true; if (nativecode == null) return true;
for (String abi : nativecode) { for (final String abi : nativecode) {
if (cpuAbis.contains(abi)) { if (Utils.arrayContains(cpuAbis, abi)) {
return true; return true;
} }
} }
@ -79,7 +79,7 @@ public class CompatibilityChecker extends Compatibility {
} }
if (apk.features != null) { if (apk.features != null) {
for (String feat : apk.features) { for (final String feat : apk.features) {
if (ignoreTouchscreen if (ignoreTouchscreen
&& feat.equals("android.hardware.touchscreen")) { && feat.equals("android.hardware.touchscreen")) {
// Don't check it! // Don't check it!

View File

@ -507,4 +507,13 @@ public final class Utils {
} }
} }
public static <T> boolean arrayContains(final T[] array, final T v) {
for (final T e : array) {
if (e == v || v != null && v.equals(e)) {
return true;
}
}
return false;
}
} }

View File

@ -1,30 +1,35 @@
package org.fdroid.fdroid.compat; package org.fdroid.fdroid.compat;
import java.util.Set;
import java.util.HashSet;
import android.annotation.TargetApi; import android.annotation.TargetApi;
import android.os.Build; import android.os.Build;
public class SupportedArchitectures extends Compatibility { public class SupportedArchitectures extends Compatibility {
private static Set<String> getOneAbi() { private static String[] getAbisDonut() {
Set<String> abis = new HashSet<String>(1); return new String[]{Build.CPU_ABI};
abis.add(Build.CPU_ABI);
return abis;
} }
@TargetApi(8) @TargetApi(8)
private static Set<String> getTwoAbis() { private static String[] getAbisFroyo() {
Set<String> abis = new HashSet<String>(2); return new String[]{Build.CPU_ABI, Build.CPU_ABI2};
abis.add(Build.CPU_ABI);
abis.add(Build.CPU_ABI2);
return abis;
} }
public static Set<String> getAbis() { @TargetApi(21)
if (hasApi(8)) return getTwoAbis(); private static String[] getAbisLollipop() {
return getOneAbi(); return Build.SUPPORTED_ABIS;
}
/**
* The most preferred ABI is the first element in the list.
*/
public static String[] getAbis() {
if (hasApi(21)) {
return getAbisLollipop();
}
if (hasApi(8)) {
return getAbisFroyo();
}
return getAbisDonut();
} }
} }