forked from I2P_Developers/i2p.i2p
* SystemVersion: New util, to consolidate duplicate code,
and determine Java version on Android
This commit is contained in:
@ -52,6 +52,7 @@ import net.i2p.util.Log;
|
||||
import net.i2p.util.SecureFileOutputStream;
|
||||
import net.i2p.util.SimpleByteCache;
|
||||
import net.i2p.util.SimpleScheduler;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
* Main driver for the router.
|
||||
@ -207,7 +208,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
List<RouterContext> contexts = RouterContext.getContexts();
|
||||
if (contexts.isEmpty()) {
|
||||
RouterContext.killGlobalContext();
|
||||
} else if (System.getProperty("java.vendor").contains("Android")) {
|
||||
} else if (SystemVersion.isAndroid()) {
|
||||
System.err.println("Warning: Killing " + contexts.size() + " other routers in this JVM");
|
||||
contexts.clear();
|
||||
RouterContext.killGlobalContext();
|
||||
@ -260,7 +261,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
// ********* Start no threads before here ********* //
|
||||
//
|
||||
// NOW we can start the ping file thread.
|
||||
if (!System.getProperty("java.vendor").contains("Android"))
|
||||
if (!SystemVersion.isAndroid())
|
||||
beginMarkingLiveliness();
|
||||
|
||||
// Apps may use this as an easy way to determine if they are in the router JVM
|
||||
@ -888,7 +889,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
//Runtime.getRuntime().halt(exitCode);
|
||||
// allow the Runtime shutdown hooks to execute
|
||||
Runtime.getRuntime().exit(exitCode);
|
||||
} else if (System.getProperty("java.vendor").contains("Android")) {
|
||||
} else if (SystemVersion.isAndroid()) {
|
||||
Runtime.getRuntime().gc();
|
||||
}
|
||||
}
|
||||
@ -1217,8 +1218,8 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
String osArch = System.getProperty("os.arch");
|
||||
boolean isX86 = osArch.contains("86") || osArch.equals("amd64");
|
||||
String osName = System.getProperty("os.name").toLowerCase(Locale.US);
|
||||
boolean isWin = osName.startsWith("win");
|
||||
boolean isMac = osName.startsWith("mac");
|
||||
boolean isWin = SystemVersion.isWindows();
|
||||
boolean isMac = SystemVersion.isMac();
|
||||
// only do this on these OSes
|
||||
boolean goodOS = isWin || isMac ||
|
||||
osName.contains("linux") || osName.contains("freebsd");
|
||||
|
@ -11,6 +11,7 @@ package net.i2p.router.startup;
|
||||
|
||||
import net.i2p.router.JobImpl;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
* The StartupJob should be run once on router startup to initialize the system
|
||||
@ -33,7 +34,7 @@ public class StartupJob extends JobImpl {
|
||||
|
||||
public String getName() { return "Startup Router"; }
|
||||
public void runJob() {
|
||||
if (!System.getProperty("java.vendor").contains("Android"))
|
||||
if (!SystemVersion.isAndroid())
|
||||
getContext().jobQueue().addJob(new LoadClientAppsJob(getContext()));
|
||||
getContext().statPublisher().startup();
|
||||
getContext().jobQueue().addJob(new LoadRouterInfoJob(getContext()));
|
||||
|
@ -13,6 +13,7 @@ import java.util.Properties;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.util.SecureDirectory;
|
||||
import net.i2p.util.SecureFileOutputStream;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
* Get a working directory for i2p.
|
||||
@ -69,7 +70,7 @@ public class WorkingDir {
|
||||
dir = envProps.getProperty(PROP_WORKING_DIR);
|
||||
if (dir == null)
|
||||
dir = System.getProperty(PROP_WORKING_DIR);
|
||||
boolean isWindows = System.getProperty("os.name").startsWith("Win");
|
||||
boolean isWindows = SystemVersion.isWindows();
|
||||
File dirf = null;
|
||||
if (dir != null) {
|
||||
dirf = new SecureDirectory(dir);
|
||||
|
@ -11,6 +11,7 @@ import net.i2p.stat.Rate;
|
||||
import net.i2p.stat.RateStat;
|
||||
import net.i2p.util.ShellCommand;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
* Periodically check to make sure things haven't gone totally haywire (and if
|
||||
@ -112,7 +113,7 @@ public class RouterWatchdog implements Runnable {
|
||||
// This works on linux...
|
||||
// It won't on windows, and we can't call i2prouter.bat either, it does something
|
||||
// completely different...
|
||||
if (_context.hasWrapper() && !System.getProperty("os.name").startsWith("Win")) {
|
||||
if (_context.hasWrapper() && !SystemVersion.isWindows()) {
|
||||
ShellCommand sc = new ShellCommand();
|
||||
File i2pr = new File(_context.getBaseDir(), "i2prouter");
|
||||
String[] args = new String[2];
|
||||
|
@ -5,7 +5,7 @@ import java.net.NetworkInterface;
|
||||
import java.net.SocketException;
|
||||
import java.util.Enumeration;
|
||||
|
||||
import net.i2p.util.VersionComparator;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
* Get the MTU for the network interface of an address.
|
||||
@ -14,8 +14,7 @@ import net.i2p.util.VersionComparator;
|
||||
*/
|
||||
abstract class MTU {
|
||||
|
||||
private static final boolean hasMTU =
|
||||
(new VersionComparator()).compare(System.getProperty("java.version"), "1.6") >= 0;
|
||||
private static final boolean hasMTU = SystemVersion.isJava6();
|
||||
|
||||
/**
|
||||
* The MTU for the socket interface, if available.
|
||||
|
@ -11,6 +11,7 @@ import net.i2p.router.util.CoDelBlockingQueue;
|
||||
import net.i2p.util.I2PThread;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.SimpleTimer;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
* Lowest level component to pull raw UDP datagrams off the wire as fast
|
||||
@ -32,7 +33,7 @@ class UDPReceiver {
|
||||
private static int __id;
|
||||
private final int _id;
|
||||
|
||||
private static final boolean _isAndroid = System.getProperty("java.vendor").contains("Android");
|
||||
private static final boolean _isAndroid = SystemVersion.isAndroid();
|
||||
|
||||
private static final int TYPE_POISON = -99999;
|
||||
private static final int MIN_QUEUE_SIZE = 16;
|
||||
|
@ -14,6 +14,7 @@ import java.util.NoSuchElementException;
|
||||
import java.util.Random;
|
||||
|
||||
import net.i2p.util.RandomSource;
|
||||
import net.i2p.util.SystemVersion;
|
||||
|
||||
/**
|
||||
*
|
||||
@ -89,11 +90,17 @@ public class RandomIterator<E> implements Iterator<E> {
|
||||
/** Used to narrow the range to take random indexes from */
|
||||
private int lower, upper;
|
||||
|
||||
private static final boolean isAndroid = System.getProperty("java.vendor").contains("Android");
|
||||
|
||||
private static final boolean hasAndroidBug;
|
||||
static {
|
||||
if (isAndroid)
|
||||
testAndroid();
|
||||
if (SystemVersion.isAndroid()) {
|
||||
// only present on Gingerbread (API 11), but set if version check failed also
|
||||
int ver = SystemVersion.getAndroidVersion();
|
||||
hasAndroidBug = ver == 11 || ver == 0;
|
||||
if (hasAndroidBug)
|
||||
testAndroid();
|
||||
} else {
|
||||
hasAndroidBug = false;
|
||||
}
|
||||
}
|
||||
|
||||
public RandomIterator(List<E> list){
|
||||
@ -137,7 +144,7 @@ public class RandomIterator<E> implements Iterator<E> {
|
||||
if (hasNext()) {
|
||||
if (index == lower)
|
||||
// workaround for Android ICS bug - see below
|
||||
lower = isAndroid ? nextClearBit(index) : served.nextClearBit(index);
|
||||
lower = hasAndroidBug ? nextClearBit(index) : served.nextClearBit(index);
|
||||
else if (index == upper)
|
||||
upper = previousClearBit(index - 1);
|
||||
}
|
||||
@ -199,7 +206,7 @@ public class RandomIterator<E> implements Iterator<E> {
|
||||
* @since 0.9.2
|
||||
*/
|
||||
private static void testAndroid() {
|
||||
System.out.println("checking for Android bug");
|
||||
System.out.println("Checking for Android BitSet bug");
|
||||
BitSet theBitSet = new BitSet(864);
|
||||
for (int exp =0; exp < 864; exp++) {
|
||||
int act = theBitSet.nextClearBit(0);
|
||||
|
Reference in New Issue
Block a user