Improve handling of snet extention

This commit is contained in:
topjohnwu 2018-04-05 20:52:34 +08:00
parent e79d764148
commit fb5e8ef40c

View File

@ -43,31 +43,26 @@ public class CheckSafetyNet extends ParallelTask<Void, Void, Exception> {
conn.disconnect(); conn.disconnect();
} }
private void loadClasses() throws ClassNotFoundException { private void dyload() throws ReflectiveOperationException {
loader = new DexClassLoader(dexPath.toString(), dexPath.getParent(), loader = new DexClassLoader(dexPath.getPath(), dexPath.getParent(),
null, ClassLoader.getSystemClassLoader()); null, ClassLoader.getSystemClassLoader());
helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper"); helperClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetHelper");
callbackClazz = loader.loadClass(Const.SNET_PKG + ".SafetyNetCallback"); 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 @Override
protected Exception doInBackground(Void... voids) { protected Exception doInBackground(Void... voids) {
int snet_ver = -1;
try { try {
if (!dexPath.exists())
dlSnet();
loadClasses();
try { try {
snet_ver = (int) helperClazz.getMethod("getVersion").invoke(null); dyload();
} catch (NoSuchMethodException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); // If dynamic load failed, try re-downloading and reload
}
if (snet_ver != Const.SNET_VER) {
dlSnet(); dlSnet();
loadClasses(); dyload();
} }
} catch (Exception e) { } catch (Exception e) {
return e; return e;