Prevent crashing when requesting SN check while checking

Fixed #208, fixed #212
This commit is contained in:
topjohnwu 2017-07-13 15:12:43 +08:00
parent b0ab55b0bf
commit aaa12853ad

View File

@ -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);
});
}