Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 24344bc

Browse files
authored
Run cleartoken task in background (#889)
1 parent 4478ab9 commit 24344bc

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

packages/google_sign_in/android/src/main/java/io/flutter/plugins/googlesignin/GoogleSignInPlugin.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import android.accounts.Account;
88
import android.app.Activity;
99
import android.content.Intent;
10-
import com.google.android.gms.auth.GoogleAuthException;
1110
import com.google.android.gms.auth.GoogleAuthUtil;
1211
import com.google.android.gms.auth.UserRecoverableAuthException;
1312
import com.google.android.gms.auth.api.signin.GoogleSignIn;
@@ -28,7 +27,6 @@
2827
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
2928
import io.flutter.plugin.common.MethodChannel.Result;
3029
import io.flutter.plugin.common.PluginRegistry;
31-
import java.io.IOException;
3230
import java.util.HashMap;
3331
import java.util.List;
3432
import java.util.Map;
@@ -403,13 +401,31 @@ private static class PendingOperation {
403401

404402
/** Clears the token kept in the client side cache. */
405403
@Override
406-
public void clearAuthCache(Result result, String token) {
407-
try {
408-
GoogleAuthUtil.clearToken(registrar.context(), token);
409-
result.success(null);
410-
} catch (GoogleAuthException | IOException e) {
411-
result.error(ERROR_REASON_EXCEPTION, e.getMessage(), e);
412-
}
404+
public void clearAuthCache(final Result result, final String token) {
405+
Callable<Void> clearTokenTask =
406+
new Callable<Void>() {
407+
@Override
408+
public Void call() throws Exception {
409+
GoogleAuthUtil.clearToken(registrar.context(), token);
410+
return null;
411+
}
412+
};
413+
414+
backgroundTaskRunner.runInBackground(
415+
clearTokenTask,
416+
new BackgroundTaskRunner.Callback<Void>() {
417+
@Override
418+
public void run(Future<Void> clearTokenFuture) {
419+
try {
420+
result.success(clearTokenFuture.get());
421+
} catch (ExecutionException e) {
422+
result.error(ERROR_REASON_EXCEPTION, e.getCause().getMessage(), null);
423+
} catch (InterruptedException e) {
424+
result.error(ERROR_REASON_EXCEPTION, e.getMessage(), null);
425+
Thread.currentThread().interrupt();
426+
}
427+
}
428+
});
413429
}
414430

415431
/**

0 commit comments

Comments
 (0)