forked from I2P_Developers/i2p.i2p
* SystemVersion: New util, to consolidate duplicate code,
and determine Java version on Android
This commit is contained in:
@ -37,6 +37,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
import net.i2p.util.SecureFile;
|
import net.i2p.util.SecureFile;
|
||||||
import net.i2p.util.SecureFileOutputStream;
|
import net.i2p.util.SecureFileOutputStream;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class providing methods to parse and write files in config file
|
* Utility class providing methods to parse and write files in config file
|
||||||
@ -49,7 +50,7 @@ import net.i2p.util.SecureFileOutputStream;
|
|||||||
*/
|
*/
|
||||||
class ConfigParser {
|
class ConfigParser {
|
||||||
|
|
||||||
private static final boolean isWindows = System.getProperty("os.name").startsWith("Win");
|
private static final boolean isWindows = SystemVersion.isWindows();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Strip the comments from a String. Lines that begin with '#' and ';' are
|
* Strip the comments from a String. Lines that begin with '#' and ';' are
|
||||||
|
@ -36,6 +36,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
import net.i2p.crypto.SHA1;
|
import net.i2p.crypto.SHA1;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SecureFile;
|
import net.i2p.util.SecureFile;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maintains pieces on disk. Can be used to store and retrieve pieces.
|
* Maintains pieces on disk. Can be used to store and retrieve pieces.
|
||||||
@ -77,7 +78,7 @@ public class Storage
|
|||||||
|
|
||||||
private static final Map<String, String> _filterNameCache = new ConcurrentHashMap();
|
private static final Map<String, String> _filterNameCache = new ConcurrentHashMap();
|
||||||
|
|
||||||
private static final boolean _isWindows = System.getProperty("os.name").startsWith("Win");
|
private static final boolean _isWindows = SystemVersion.isWindows();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new storage based on the supplied MetaInfo. This will
|
* Creates a new storage based on the supplied MetaInfo. This will
|
||||||
|
@ -8,6 +8,7 @@ import net.i2p.apps.systray.UrlLauncher;
|
|||||||
import net.i2p.router.Router;
|
import net.i2p.router.Router;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.router.startup.ClientAppConfig;
|
import net.i2p.router.startup.ClientAppConfig;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
import net.i2p.util.VersionComparator;
|
import net.i2p.util.VersionComparator;
|
||||||
|
|
||||||
import org.tanukisoftware.wrapper.WrapperManager;
|
import org.tanukisoftware.wrapper.WrapperManager;
|
||||||
@ -140,7 +141,7 @@ public class ConfigServiceHandler extends FormHandler {
|
|||||||
*/
|
*/
|
||||||
synchronized static void registerSignalHandler(RouterContext ctx) {
|
synchronized static void registerSignalHandler(RouterContext ctx) {
|
||||||
if (ctx.hasWrapper() && _wrapperListener == null &&
|
if (ctx.hasWrapper() && _wrapperListener == null &&
|
||||||
!System.getProperty("os.name").startsWith("Win")) {
|
!SystemVersion.isWindows()) {
|
||||||
String wv = System.getProperty("wrapper.version");
|
String wv = System.getProperty("wrapper.version");
|
||||||
if (wv != null && (new VersionComparator()).compare(wv, LISTENER_AVAILABLE) >= 0) {
|
if (wv != null && (new VersionComparator()).compare(wv, LISTENER_AVAILABLE) >= 0) {
|
||||||
try {
|
try {
|
||||||
|
@ -23,6 +23,7 @@ import net.i2p.stat.Rate;
|
|||||||
import net.i2p.stat.RateStat;
|
import net.i2p.stat.RateStat;
|
||||||
import net.i2p.util.FileUtil;
|
import net.i2p.util.FileUtil;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
import org.jrobin.core.RrdException;
|
import org.jrobin.core.RrdException;
|
||||||
import org.jrobin.graph.RrdGraph;
|
import org.jrobin.graph.RrdGraph;
|
||||||
@ -418,7 +419,7 @@ public class StatSummarizer implements Runnable {
|
|||||||
FileUtil.rmdir(rrdDir, false);
|
FileUtil.rmdir(rrdDir, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean IS_WIN = System.getProperty("os.name").startsWith("Win");
|
private static final boolean IS_WIN = SystemVersion.isWindows();
|
||||||
|
|
||||||
/** translate a string */
|
/** translate a string */
|
||||||
private String _(String s) {
|
private String _(String s) {
|
||||||
|
@ -18,6 +18,7 @@ import net.i2p.data.DataHelper;
|
|||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
import net.i2p.router.util.EventLog;
|
import net.i2p.router.util.EventLog;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
import org.jrobin.core.RrdException;
|
import org.jrobin.core.RrdException;
|
||||||
import org.jrobin.graph.RrdGraph;
|
import org.jrobin.graph.RrdGraph;
|
||||||
@ -221,7 +222,7 @@ class SummaryRenderer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final boolean IS_WIN = System.getProperty("os.name").startsWith("Win");
|
private static final boolean IS_WIN = SystemVersion.isWindows();
|
||||||
|
|
||||||
/** translate a string */
|
/** translate a string */
|
||||||
private String _(String s) {
|
private String _(String s) {
|
||||||
|
@ -15,6 +15,7 @@ import java.io.File;
|
|||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.SimpleScheduler;
|
import net.i2p.util.SimpleScheduler;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
import snoozesoft.systray4j.SysTrayMenu;
|
import snoozesoft.systray4j.SysTrayMenu;
|
||||||
import snoozesoft.systray4j.SysTrayMenuEvent;
|
import snoozesoft.systray4j.SysTrayMenuEvent;
|
||||||
@ -37,8 +38,7 @@ public class SysTray implements SysTrayMenuListener {
|
|||||||
private static String _portString;
|
private static String _portString;
|
||||||
private static boolean _showIcon;
|
private static boolean _showIcon;
|
||||||
private static UrlLauncher _urlLauncher = new UrlLauncher();
|
private static UrlLauncher _urlLauncher = new UrlLauncher();
|
||||||
private static final boolean _is64 = "64".equals(System.getProperty("sun.arch.data.model")) ||
|
private static final boolean _is64 = SystemVersion.is64Bit();
|
||||||
System.getProperty("os.arch").contains("64");
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
File config = new File(I2PAppContext.getGlobalContext().getConfigDir(), "systray.config");
|
File config = new File(I2PAppContext.getGlobalContext().getConfigDir(), "systray.config");
|
||||||
@ -54,7 +54,7 @@ public class SysTray implements SysTrayMenuListener {
|
|||||||
//if (!(new File("router.config")).exists())
|
//if (!(new File("router.config")).exists())
|
||||||
// openRouterConsole("http://localhost:" + _portString + "/index.jsp");
|
// openRouterConsole("http://localhost:" + _portString + "/index.jsp");
|
||||||
|
|
||||||
if ( (System.getProperty("os.name").startsWith("Windows")) && (!Boolean.getBoolean("systray.disable")) && (!_is64))
|
if ( (SystemVersion.isWindows()) && (!Boolean.getBoolean("systray.disable")) && (!_is64))
|
||||||
_instance = new SysTray();
|
_instance = new SysTray();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.ShellCommand;
|
import net.i2p.util.ShellCommand;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A quick and simple multi-platform URL launcher. It attempts to launch the
|
* A quick and simple multi-platform URL launcher. It attempts to launch the
|
||||||
@ -124,7 +125,7 @@ public class UrlLauncher {
|
|||||||
if (_shellCommand.executeSilentAndWaitTimed("iexplore " + url, 5))
|
if (_shellCommand.executeSilentAndWaitTimed("iexplore " + url, 5))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (osName.startsWith("Windows")) {
|
} else if (SystemVersion.isWindows()) {
|
||||||
|
|
||||||
String browserString = "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" -nohome";
|
String browserString = "\"C:\\Program Files\\Internet Explorer\\iexplore.exe\" -nohome";
|
||||||
BufferedReader bufferedReader = null;
|
BufferedReader bufferedReader = null;
|
||||||
|
@ -19,6 +19,7 @@ import java.util.Locale;
|
|||||||
|
|
||||||
import net.i2p.I2PAppContext;
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.FileUtil;
|
import net.i2p.util.FileUtil;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,15 +51,15 @@ public class CPUID {
|
|||||||
|
|
||||||
private static final boolean isX86 = System.getProperty("os.arch").contains("86") ||
|
private static final boolean isX86 = System.getProperty("os.arch").contains("86") ||
|
||||||
System.getProperty("os.arch").equals("amd64");
|
System.getProperty("os.arch").equals("amd64");
|
||||||
private static final String libPrefix = (System.getProperty("os.name").startsWith("Win") ? "" : "lib");
|
private static final boolean isWindows = SystemVersion.isWindows();
|
||||||
private static final String libSuffix = (System.getProperty("os.name").startsWith("Win") ? ".dll" : ".so");
|
private static final String libPrefix = isWindows ? "" : "lib";
|
||||||
private static final boolean isWindows = System.getProperty("os.name").toLowerCase(Locale.US).contains("windows");
|
private static final String libSuffix = isWindows ? ".dll" : ".so";
|
||||||
private static final boolean isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
|
private static final boolean isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
|
||||||
private static final boolean isFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd");
|
private static final boolean isFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd");
|
||||||
private static final boolean isNetbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("netbsd");
|
private static final boolean isNetbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("netbsd");
|
||||||
private static final boolean isOpenbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("openbsd");
|
private static final boolean isOpenbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("openbsd");
|
||||||
private static final boolean isSunos = System.getProperty("os.name").toLowerCase(Locale.US).contains("sunos");
|
private static final boolean isSunos = System.getProperty("os.name").toLowerCase(Locale.US).contains("sunos");
|
||||||
private static final boolean isMac = System.getProperty("os.name").startsWith("Mac");
|
private static final boolean isMac = SystemVersion.isMac();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -71,8 +72,7 @@ public class CPUID {
|
|||||||
* sun.arch.data.model == 32 => A 32 bit JVM but could be either 32 or 64 bit processor or libs
|
* sun.arch.data.model == 32 => A 32 bit JVM but could be either 32 or 64 bit processor or libs
|
||||||
* os.arch contains "64" could be 32 or 64 bit libs
|
* os.arch contains "64" could be 32 or 64 bit libs
|
||||||
*/
|
*/
|
||||||
private static final boolean is64 = "64".equals(System.getProperty("sun.arch.data.model")) ||
|
private static final boolean is64 = SystemVersion.is64Bit();
|
||||||
System.getProperty("os.arch").contains("64");
|
|
||||||
|
|
||||||
static
|
static
|
||||||
{
|
{
|
||||||
|
@ -15,8 +15,7 @@ import java.io.PipedInputStream;
|
|||||||
*/
|
*/
|
||||||
public class BigPipedInputStream extends PipedInputStream {
|
public class BigPipedInputStream extends PipedInputStream {
|
||||||
|
|
||||||
private static final boolean oneDotSix =
|
private static final boolean oneDotSix = SystemVersion.isJava6();
|
||||||
(new VersionComparator()).compare(System.getProperty("java.version"), "1.6") >= 0;
|
|
||||||
|
|
||||||
private static final int PIPE_SIZE = 64*1024;
|
private static final int PIPE_SIZE = 64*1024;
|
||||||
|
|
||||||
|
@ -452,7 +452,7 @@ public class FileUtil {
|
|||||||
if (!from.exists())
|
if (!from.exists())
|
||||||
return false;
|
return false;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
boolean isWindows = System.getProperty("os.name").startsWith("Win");
|
boolean isWindows = SystemVersion.isWindows();
|
||||||
// overwrite fails on windows
|
// overwrite fails on windows
|
||||||
if (!isWindows)
|
if (!isWindows)
|
||||||
success = from.renameTo(to);
|
success = from.renameTo(to);
|
||||||
|
@ -158,15 +158,15 @@ public class NativeBigInteger extends BigInteger {
|
|||||||
/**
|
/**
|
||||||
* Operating systems
|
* Operating systems
|
||||||
*/
|
*/
|
||||||
private static final boolean _isWin = System.getProperty("os.name").startsWith("Win");
|
private static final boolean _isWin = SystemVersion.isWindows();
|
||||||
private static final boolean _isOS2 = System.getProperty("os.name").startsWith("OS/2");
|
private static final boolean _isOS2 = System.getProperty("os.name").startsWith("OS/2");
|
||||||
private static final boolean _isMac = System.getProperty("os.name").startsWith("Mac");
|
private static final boolean _isMac = SystemVersion.isMac();
|
||||||
private static final boolean _isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
|
private static final boolean _isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux");
|
||||||
private static final boolean _isFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd");
|
private static final boolean _isFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd");
|
||||||
private static final boolean _isNetbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("netbsd");
|
private static final boolean _isNetbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("netbsd");
|
||||||
private static final boolean _isOpenbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("openbsd");
|
private static final boolean _isOpenbsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("openbsd");
|
||||||
private static final boolean _isSunos = System.getProperty("os.name").toLowerCase(Locale.US).contains("sunos");
|
private static final boolean _isSunos = System.getProperty("os.name").toLowerCase(Locale.US).contains("sunos");
|
||||||
private static final boolean _isAndroid = System.getProperty("java.vendor").contains("Android");
|
private static final boolean _isAndroid = SystemVersion.isAndroid();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This isn't always correct.
|
* This isn't always correct.
|
||||||
@ -178,8 +178,7 @@ public class NativeBigInteger extends BigInteger {
|
|||||||
* sun.arch.data.model == 32 => A 32 bit JVM but could be either 32 or 64 bit processor or libs
|
* sun.arch.data.model == 32 => A 32 bit JVM but could be either 32 or 64 bit processor or libs
|
||||||
* os.arch contains "64" could be 32 or 64 bit libs
|
* os.arch contains "64" could be 32 or 64 bit libs
|
||||||
*/
|
*/
|
||||||
private static final boolean _is64 = "64".equals(System.getProperty("sun.arch.data.model")) ||
|
private static final boolean _is64 = SystemVersion.is64Bit();
|
||||||
System.getProperty("os.arch").contains("64");
|
|
||||||
|
|
||||||
private static final boolean _isX86 = System.getProperty("os.arch").contains("86") ||
|
private static final boolean _isX86 = System.getProperty("os.arch").contains("86") ||
|
||||||
System.getProperty("os.arch").equals("amd64");
|
System.getProperty("os.arch").equals("amd64");
|
||||||
|
@ -10,7 +10,7 @@ public class ReusableGZIPInputStream extends ResettableGZIPInputStream {
|
|||||||
// Apache Harmony 5.0M13 Deflater doesn't work after reset()
|
// Apache Harmony 5.0M13 Deflater doesn't work after reset()
|
||||||
// Neither does Android
|
// Neither does Android
|
||||||
private static final boolean ENABLE_CACHING = !(System.getProperty("java.vendor").startsWith("Apache") ||
|
private static final boolean ENABLE_CACHING = !(System.getProperty("java.vendor").startsWith("Apache") ||
|
||||||
System.getProperty("java.vendor").contains("Android"));
|
SystemVersion.isAndroid());
|
||||||
private static final LinkedBlockingQueue<ReusableGZIPInputStream> _available;
|
private static final LinkedBlockingQueue<ReusableGZIPInputStream> _available;
|
||||||
static {
|
static {
|
||||||
if (ENABLE_CACHING)
|
if (ENABLE_CACHING)
|
||||||
|
@ -21,7 +21,7 @@ public class ReusableGZIPOutputStream extends ResettableGZIPOutputStream {
|
|||||||
// Apache Harmony 5.0M13 Deflater doesn't work after reset()
|
// Apache Harmony 5.0M13 Deflater doesn't work after reset()
|
||||||
// Neither does Android
|
// Neither does Android
|
||||||
private static final boolean ENABLE_CACHING = !(System.getProperty("java.vendor").startsWith("Apache") ||
|
private static final boolean ENABLE_CACHING = !(System.getProperty("java.vendor").startsWith("Apache") ||
|
||||||
System.getProperty("java.vendor").contains("Android"));
|
SystemVersion.isAndroid());
|
||||||
private static final LinkedBlockingQueue<ReusableGZIPOutputStream> _available;
|
private static final LinkedBlockingQueue<ReusableGZIPOutputStream> _available;
|
||||||
static {
|
static {
|
||||||
if (ENABLE_CACHING)
|
if (ENABLE_CACHING)
|
||||||
|
@ -91,7 +91,7 @@ public class SSLEepGet extends EepGet {
|
|||||||
/** may be null if init failed */
|
/** may be null if init failed */
|
||||||
private SavingTrustManager _stm;
|
private SavingTrustManager _stm;
|
||||||
|
|
||||||
private static final boolean _isAndroid = System.getProperty("java.vendor").contains("Android");
|
private static final boolean _isAndroid = SystemVersion.isAndroid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A new SSLEepGet with a new SSLState
|
* A new SSLEepGet with a new SSLState
|
||||||
|
@ -12,7 +12,7 @@ import java.io.File;
|
|||||||
*/
|
*/
|
||||||
public class SecureDirectory extends File {
|
public class SecureDirectory extends File {
|
||||||
|
|
||||||
protected static final boolean isNotWindows = !System.getProperty("os.name").startsWith("Win");
|
protected static final boolean isNotWindows = !SystemVersion.isWindows();
|
||||||
|
|
||||||
public SecureDirectory(String pathname) {
|
public SecureDirectory(String pathname) {
|
||||||
super(pathname);
|
super(pathname);
|
||||||
|
@ -15,8 +15,7 @@ import net.i2p.I2PAppContext;
|
|||||||
*/
|
*/
|
||||||
public class SecureFileOutputStream extends FileOutputStream {
|
public class SecureFileOutputStream extends FileOutputStream {
|
||||||
|
|
||||||
private static final boolean oneDotSix =
|
private static final boolean oneDotSix = SystemVersion.isJava6();
|
||||||
(new VersionComparator()).compare(System.getProperty("java.version"), "1.6") >= 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets output file to mode 600
|
* Sets output file to mode 600
|
||||||
|
87
core/java/src/net/i2p/util/SystemVersion.java
Normal file
87
core/java/src/net/i2p/util/SystemVersion.java
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
package net.i2p.util;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* public domain
|
||||||
|
*/
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Methods to find out what system we are running on
|
||||||
|
*
|
||||||
|
* @since 0.9.3 consolidated from various places
|
||||||
|
*/
|
||||||
|
public abstract class SystemVersion {
|
||||||
|
|
||||||
|
private static final boolean _isWin = System.getProperty("os.name").startsWith("Win");
|
||||||
|
private static final boolean _isMac = System.getProperty("os.name").startsWith("Mac");
|
||||||
|
private static final boolean _isAndroid = System.getProperty("java.vendor").contains("Android");
|
||||||
|
private static final boolean _is64 = "64".equals(System.getProperty("sun.arch.data.model")) ||
|
||||||
|
System.getProperty("os.arch").contains("64");
|
||||||
|
|
||||||
|
private static final boolean _oneDotSix;
|
||||||
|
private static final int _androidSDK;
|
||||||
|
|
||||||
|
static {
|
||||||
|
int sdk = 0;
|
||||||
|
if (_isAndroid) {
|
||||||
|
try {
|
||||||
|
Class ver = Class.forName("android.os.Build.VERSION", true, ClassLoader.getSystemClassLoader());
|
||||||
|
Field field = ver.getField("SDK_INT");
|
||||||
|
sdk = field.getInt(null);
|
||||||
|
} catch (Exception e) {}
|
||||||
|
}
|
||||||
|
_androidSDK = sdk;
|
||||||
|
|
||||||
|
if (_isAndroid) {
|
||||||
|
_oneDotSix = _androidSDK >= 9;
|
||||||
|
} else {
|
||||||
|
_oneDotSix = (new VersionComparator()).compare(System.getProperty("java.version"), "1.6") >= 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isWindows() {
|
||||||
|
return _isWin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isMac() {
|
||||||
|
return _isMac;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isAndroid() {
|
||||||
|
return _isAndroid;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Better than (new VersionComparator()).compare(System.getProperty("java.version"), "1.6") >= 0
|
||||||
|
* as it handles Android also, where java.version = "0".
|
||||||
|
*
|
||||||
|
* @return true if Java 1.6 or higher, or Android API 9 or higher
|
||||||
|
*/
|
||||||
|
public static boolean isJava6() {
|
||||||
|
return _oneDotSix;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This isn't always correct.
|
||||||
|
* http://stackoverflow.com/questions/807263/how-do-i-detect-which-kind-of-jre-is-installed-32bit-vs-64bit
|
||||||
|
* http://mark.koli.ch/2009/10/javas-osarch-system-property-is-the-bitness-of-the-jre-not-the-operating-system.html
|
||||||
|
* http://mark.koli.ch/2009/10/reliably-checking-os-bitness-32-or-64-bit-on-windows-with-a-tiny-c-app.html
|
||||||
|
* sun.arch.data.model not on all JVMs
|
||||||
|
* sun.arch.data.model == 64 => 64 bit processor
|
||||||
|
* sun.arch.data.model == 32 => A 32 bit JVM but could be either 32 or 64 bit processor or libs
|
||||||
|
* os.arch contains "64" could be 32 or 64 bit libs
|
||||||
|
*/
|
||||||
|
public static boolean is64Bit() {
|
||||||
|
return _is64;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Identical to android.os.Build.VERSION.SDK_INT.
|
||||||
|
* For use outside of Android code.
|
||||||
|
* @return The SDK (API) version, e.g. 8 for Froyo, 0 if unknown
|
||||||
|
*/
|
||||||
|
public static int getAndroidVersion() {
|
||||||
|
return _androidSDK;
|
||||||
|
}
|
||||||
|
}
|
@ -52,6 +52,7 @@ import net.i2p.util.Log;
|
|||||||
import net.i2p.util.SecureFileOutputStream;
|
import net.i2p.util.SecureFileOutputStream;
|
||||||
import net.i2p.util.SimpleByteCache;
|
import net.i2p.util.SimpleByteCache;
|
||||||
import net.i2p.util.SimpleScheduler;
|
import net.i2p.util.SimpleScheduler;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main driver for the router.
|
* Main driver for the router.
|
||||||
@ -207,7 +208,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
|||||||
List<RouterContext> contexts = RouterContext.getContexts();
|
List<RouterContext> contexts = RouterContext.getContexts();
|
||||||
if (contexts.isEmpty()) {
|
if (contexts.isEmpty()) {
|
||||||
RouterContext.killGlobalContext();
|
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");
|
System.err.println("Warning: Killing " + contexts.size() + " other routers in this JVM");
|
||||||
contexts.clear();
|
contexts.clear();
|
||||||
RouterContext.killGlobalContext();
|
RouterContext.killGlobalContext();
|
||||||
@ -260,7 +261,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
|||||||
// ********* Start no threads before here ********* //
|
// ********* Start no threads before here ********* //
|
||||||
//
|
//
|
||||||
// NOW we can start the ping file thread.
|
// NOW we can start the ping file thread.
|
||||||
if (!System.getProperty("java.vendor").contains("Android"))
|
if (!SystemVersion.isAndroid())
|
||||||
beginMarkingLiveliness();
|
beginMarkingLiveliness();
|
||||||
|
|
||||||
// Apps may use this as an easy way to determine if they are in the router JVM
|
// 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);
|
//Runtime.getRuntime().halt(exitCode);
|
||||||
// allow the Runtime shutdown hooks to execute
|
// allow the Runtime shutdown hooks to execute
|
||||||
Runtime.getRuntime().exit(exitCode);
|
Runtime.getRuntime().exit(exitCode);
|
||||||
} else if (System.getProperty("java.vendor").contains("Android")) {
|
} else if (SystemVersion.isAndroid()) {
|
||||||
Runtime.getRuntime().gc();
|
Runtime.getRuntime().gc();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1217,8 +1218,8 @@ public class Router implements RouterClock.ClockShiftListener {
|
|||||||
String osArch = System.getProperty("os.arch");
|
String osArch = System.getProperty("os.arch");
|
||||||
boolean isX86 = osArch.contains("86") || osArch.equals("amd64");
|
boolean isX86 = osArch.contains("86") || osArch.equals("amd64");
|
||||||
String osName = System.getProperty("os.name").toLowerCase(Locale.US);
|
String osName = System.getProperty("os.name").toLowerCase(Locale.US);
|
||||||
boolean isWin = osName.startsWith("win");
|
boolean isWin = SystemVersion.isWindows();
|
||||||
boolean isMac = osName.startsWith("mac");
|
boolean isMac = SystemVersion.isMac();
|
||||||
// only do this on these OSes
|
// only do this on these OSes
|
||||||
boolean goodOS = isWin || isMac ||
|
boolean goodOS = isWin || isMac ||
|
||||||
osName.contains("linux") || osName.contains("freebsd");
|
osName.contains("linux") || osName.contains("freebsd");
|
||||||
|
@ -11,6 +11,7 @@ package net.i2p.router.startup;
|
|||||||
|
|
||||||
import net.i2p.router.JobImpl;
|
import net.i2p.router.JobImpl;
|
||||||
import net.i2p.router.RouterContext;
|
import net.i2p.router.RouterContext;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The StartupJob should be run once on router startup to initialize the system
|
* 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 String getName() { return "Startup Router"; }
|
||||||
public void runJob() {
|
public void runJob() {
|
||||||
if (!System.getProperty("java.vendor").contains("Android"))
|
if (!SystemVersion.isAndroid())
|
||||||
getContext().jobQueue().addJob(new LoadClientAppsJob(getContext()));
|
getContext().jobQueue().addJob(new LoadClientAppsJob(getContext()));
|
||||||
getContext().statPublisher().startup();
|
getContext().statPublisher().startup();
|
||||||
getContext().jobQueue().addJob(new LoadRouterInfoJob(getContext()));
|
getContext().jobQueue().addJob(new LoadRouterInfoJob(getContext()));
|
||||||
|
@ -13,6 +13,7 @@ import java.util.Properties;
|
|||||||
import net.i2p.data.DataHelper;
|
import net.i2p.data.DataHelper;
|
||||||
import net.i2p.util.SecureDirectory;
|
import net.i2p.util.SecureDirectory;
|
||||||
import net.i2p.util.SecureFileOutputStream;
|
import net.i2p.util.SecureFileOutputStream;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a working directory for i2p.
|
* Get a working directory for i2p.
|
||||||
@ -69,7 +70,7 @@ public class WorkingDir {
|
|||||||
dir = envProps.getProperty(PROP_WORKING_DIR);
|
dir = envProps.getProperty(PROP_WORKING_DIR);
|
||||||
if (dir == null)
|
if (dir == null)
|
||||||
dir = System.getProperty(PROP_WORKING_DIR);
|
dir = System.getProperty(PROP_WORKING_DIR);
|
||||||
boolean isWindows = System.getProperty("os.name").startsWith("Win");
|
boolean isWindows = SystemVersion.isWindows();
|
||||||
File dirf = null;
|
File dirf = null;
|
||||||
if (dir != null) {
|
if (dir != null) {
|
||||||
dirf = new SecureDirectory(dir);
|
dirf = new SecureDirectory(dir);
|
||||||
|
@ -11,6 +11,7 @@ import net.i2p.stat.Rate;
|
|||||||
import net.i2p.stat.RateStat;
|
import net.i2p.stat.RateStat;
|
||||||
import net.i2p.util.ShellCommand;
|
import net.i2p.util.ShellCommand;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Periodically check to make sure things haven't gone totally haywire (and if
|
* 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...
|
// This works on linux...
|
||||||
// It won't on windows, and we can't call i2prouter.bat either, it does something
|
// It won't on windows, and we can't call i2prouter.bat either, it does something
|
||||||
// completely different...
|
// completely different...
|
||||||
if (_context.hasWrapper() && !System.getProperty("os.name").startsWith("Win")) {
|
if (_context.hasWrapper() && !SystemVersion.isWindows()) {
|
||||||
ShellCommand sc = new ShellCommand();
|
ShellCommand sc = new ShellCommand();
|
||||||
File i2pr = new File(_context.getBaseDir(), "i2prouter");
|
File i2pr = new File(_context.getBaseDir(), "i2prouter");
|
||||||
String[] args = new String[2];
|
String[] args = new String[2];
|
||||||
|
@ -5,7 +5,7 @@ import java.net.NetworkInterface;
|
|||||||
import java.net.SocketException;
|
import java.net.SocketException;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
|
|
||||||
import net.i2p.util.VersionComparator;
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the MTU for the network interface of an address.
|
* Get the MTU for the network interface of an address.
|
||||||
@ -14,8 +14,7 @@ import net.i2p.util.VersionComparator;
|
|||||||
*/
|
*/
|
||||||
abstract class MTU {
|
abstract class MTU {
|
||||||
|
|
||||||
private static final boolean hasMTU =
|
private static final boolean hasMTU = SystemVersion.isJava6();
|
||||||
(new VersionComparator()).compare(System.getProperty("java.version"), "1.6") >= 0;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The MTU for the socket interface, if available.
|
* 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.I2PThread;
|
||||||
import net.i2p.util.Log;
|
import net.i2p.util.Log;
|
||||||
import net.i2p.util.SimpleTimer;
|
import net.i2p.util.SimpleTimer;
|
||||||
|
import net.i2p.util.SystemVersion;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lowest level component to pull raw UDP datagrams off the wire as fast
|
* Lowest level component to pull raw UDP datagrams off the wire as fast
|
||||||
@ -32,7 +33,7 @@ class UDPReceiver {
|
|||||||
private static int __id;
|
private static int __id;
|
||||||
private final 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 TYPE_POISON = -99999;
|
||||||
private static final int MIN_QUEUE_SIZE = 16;
|
private static final int MIN_QUEUE_SIZE = 16;
|
||||||
|
@ -14,6 +14,7 @@ import java.util.NoSuchElementException;
|
|||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import net.i2p.util.RandomSource;
|
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 */
|
/** Used to narrow the range to take random indexes from */
|
||||||
private int lower, upper;
|
private int lower, upper;
|
||||||
|
|
||||||
private static final boolean isAndroid = System.getProperty("java.vendor").contains("Android");
|
private static final boolean hasAndroidBug;
|
||||||
|
|
||||||
static {
|
static {
|
||||||
if (isAndroid)
|
if (SystemVersion.isAndroid()) {
|
||||||
testAndroid();
|
// 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){
|
public RandomIterator(List<E> list){
|
||||||
@ -137,7 +144,7 @@ public class RandomIterator<E> implements Iterator<E> {
|
|||||||
if (hasNext()) {
|
if (hasNext()) {
|
||||||
if (index == lower)
|
if (index == lower)
|
||||||
// workaround for Android ICS bug - see below
|
// 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)
|
else if (index == upper)
|
||||||
upper = previousClearBit(index - 1);
|
upper = previousClearBit(index - 1);
|
||||||
}
|
}
|
||||||
@ -199,7 +206,7 @@ public class RandomIterator<E> implements Iterator<E> {
|
|||||||
* @since 0.9.2
|
* @since 0.9.2
|
||||||
*/
|
*/
|
||||||
private static void testAndroid() {
|
private static void testAndroid() {
|
||||||
System.out.println("checking for Android bug");
|
System.out.println("Checking for Android BitSet bug");
|
||||||
BitSet theBitSet = new BitSet(864);
|
BitSet theBitSet = new BitSet(864);
|
||||||
for (int exp =0; exp < 864; exp++) {
|
for (int exp =0; exp < 864; exp++) {
|
||||||
int act = theBitSet.nextClearBit(0);
|
int act = theBitSet.nextClearBit(0);
|
||||||
|
Reference in New Issue
Block a user