From aaa12853ad02f8f3177abed87a928c485046fbda Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 13 Jul 2017 15:12:43 +0800 Subject: [PATCH] Prevent crashing when requesting SN check while checking Fixed #208, fixed #212 --- .../topjohnwu/magisk/utils/SafetyNetHelper.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/SafetyNetHelper.java b/app/src/main/java/com/topjohnwu/magisk/utils/SafetyNetHelper.java index b985cac42..726fcdcc0 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/SafetyNetHelper.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/SafetyNetHelper.java @@ -20,6 +20,8 @@ import java.security.SecureRandom; public abstract class SafetyNetHelper implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks { + private static boolean isRunning = false; + private GoogleApiClient mGoogleApiClient; private Result ret; protected FragmentActivity mActivity; @@ -27,17 +29,20 @@ public abstract class SafetyNetHelper public SafetyNetHelper(FragmentActivity activity) { ret = new Result(); mActivity = activity; - mGoogleApiClient = new GoogleApiClient.Builder(activity) - .enableAutoManage(activity, this) - .addApi(SafetyNet.API) - .addConnectionCallbacks(this) - .build(); } // Entry point to start test public void requestTest() { + if (isRunning) + return; // Connect Google Service + mGoogleApiClient = new GoogleApiClient.Builder(mActivity) + .enableAutoManage(mActivity, this) + .addApi(SafetyNet.API) + .addConnectionCallbacks(this) + .build(); mGoogleApiClient.connect(); + isRunning = true; } @Override @@ -92,6 +97,7 @@ public abstract class SafetyNetHelper // Disconnect mGoogleApiClient.stopAutoManage(mActivity); mGoogleApiClient.disconnect(); + isRunning = false; handleResults(ret); }); }