diff --git a/src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java b/src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java index 8899755b5..603c7aefb 100644 --- a/src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java +++ b/src/main/java/com/topjohnwu/magisk/asyncs/CheckSafetyNet.java @@ -43,31 +43,26 @@ public class CheckSafetyNet extends ParallelTask { conn.disconnect(); } - private void loadClasses() throws ClassNotFoundException { - loader = new DexClassLoader(dexPath.toString(), dexPath.getParent(), + private void dyload() throws ReflectiveOperationException { + loader = new DexClassLoader(dexPath.getPath(), dexPath.getParent(), null, ClassLoader.getSystemClassLoader()); helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper"); callbackClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetCallback"); + int snet_ver = (int) helperClazz.getMethod("getVersion").invoke(null); + if (snet_ver != Const.SNET_VER) { + throw new ReflectiveOperationException(); + } } @Override protected Exception doInBackground(Void... voids) { - int snet_ver = -1; - try { - if (!dexPath.exists()) - dlSnet(); - loadClasses(); - try { - snet_ver = (int) helperClazz.getMethod("getVersion").invoke(null); - } catch (NoSuchMethodException e) { - e.printStackTrace(); - } - - if (snet_ver != Const.SNET_VER) { + dyload(); + } catch (ReflectiveOperationException e) { + // If dynamic load failed, try re-downloading and reload dlSnet(); - loadClasses(); + dyload(); } } catch (Exception e) { return e;