1

I'm trying to get the runtime in my device, I've tested the following methods in 2 devices, Xperia Z1, Note 4.

The following codes I've tried :

private String getIsArtInUse() {
return System.getProperty("java.vm.version");
}

This code returns 2.1, As some stackoverflow answers say, version greater than 2.0 means it's ART, but my runtime is Dalvik.

private CharSequence getCurrentRuntimeValue() {
private static final String SELECT_RUNTIME_PROPERTY = "persist.sys.dalvik.vm.lib";
private static final String LIB_DALVIK = "libdvm.so";
private static final String LIB_ART = "libart.so";
private static final String LIB_ART_D = "libartd.so";
    try {
        Class<?> systemProperties = Class.forName("android.os.SystemProperties");
        try {
            Method get = systemProperties.getMethod("get",
               String.class, String.class);
            if (get == null) {
                return "WTF?!";
            }
        try {
            final String value = (String)get.invoke(
                systemProperties, SELECT_RUNTIME_PROPERTY,
                    /* Assuming default is */"Dalvik");
            if (LIB_DALVIK.equals(value)) {
                    return "Dalvik";
                } else if (LIB_ART.equals(value)) {
                    return "ART";
                } else if (LIB_ART_D.equals(value)) {
                    return "ART debug build";
            }

          return value;
        } catch (IllegalAccessException e) {
                return "IllegalAccessException";
        } catch (IllegalArgumentException e) {
                return "IllegalArgumentException";
        } catch (InvocationTargetException e) {
                return "InvocationTargetException";
        }
        } catch (NoSuchMethodException e) {
          return "SystemProperties.get(String key, String def) method is not found";
        }
        } catch (ClassNotFoundException e) {
          return "SystemProperties class is not found";
    }
}

This code returns Dalvik, always.

public String getRuntime()
{ 
return System.getProperty("java.vm.name");
}

The following also returns Dalvik, but i don't think it returns the exact applied runtime .

Any suggestions ?

Stanojkovic
  • 1,612
  • 1
  • 17
  • 24
Jaeger
  • 1,646
  • 8
  • 27
  • 59

0 Answers0