SubtleUtil.java (tink-1.6.0) | : | SubtleUtil.java (tink-1.6.1) | ||
---|---|---|---|---|
skipping to change at line 85 | skipping to change at line 85 | |||
} | } | |||
throw new GeneralSecurityException("Unsupported hash " + hash); | throw new GeneralSecurityException("Unsupported hash " + hash); | |||
} | } | |||
/** | /** | |||
* Best-effort checks that this is Android. | * Best-effort checks that this is Android. | |||
* | * | |||
* @return true if running on Android. | * @return true if running on Android. | |||
*/ | */ | |||
public static boolean isAndroid() { | public static boolean isAndroid() { | |||
try { | // https://developer.android.com/reference/java/lang/System#getProperties%28 | |||
Class.forName("android.app.Application", /*initialize=*/ false, null); | %29 | |||
return true; | return "The Android Project".equals(System.getProperty("java.vendor")); | |||
} catch (Exception e) { | ||||
// If Application isn't loaded, it might as well not be Android. | ||||
return false; | ||||
} | ||||
} | } | |||
/** Returns the Android API level or -1 if Tink isn't running on Android */ | /** Returns the Android API level or -1 if Tink isn't running on Android */ | |||
public static int androidApiLevel() { | public static int androidApiLevel() { | |||
try { | try { | |||
Class<?> buildVersion = Class.forName("android.os.Build$VERSION"); | Class<?> buildVersion = Class.forName("android.os.Build$VERSION"); | |||
return buildVersion.getDeclaredField("SDK_INT").getInt(null); | return buildVersion.getDeclaredField("SDK_INT").getInt(null); | |||
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessExcept ion e) { | } catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessExcept ion e) { | |||
return -1; | return -1; | |||
} | } | |||
End of changes. 1 change blocks. | ||||
7 lines changed or deleted | 3 lines changed or added |