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

Run cleartoken task in background #889

Merged
merged 2 commits into from
Nov 7, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import android.accounts.Account;
import android.app.Activity;
import android.content.Intent;
import com.google.android.gms.auth.GoogleAuthException;
import com.google.android.gms.auth.GoogleAuthUtil;
import com.google.android.gms.auth.UserRecoverableAuthException;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
Expand All @@ -28,7 +27,6 @@
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -403,13 +401,31 @@ private static class PendingOperation {

/** Clears the token kept in the client side cache. */
@Override
public void clearAuthCache(Result result, String token) {
try {
GoogleAuthUtil.clearToken(registrar.context(), token);
result.success(null);
} catch (GoogleAuthException | IOException e) {
result.error(ERROR_REASON_EXCEPTION, e.getMessage(), e);
}
public void clearAuthCache(final Result result, final String token) {
Callable<Void> clearTokenTask =
new Callable<Void>() {
@Override
public Void call() throws Exception {
GoogleAuthUtil.clearToken(registrar.context(), token);
return null;
}
};

backgroundTaskRunner.runInBackground(
clearTokenTask,
new BackgroundTaskRunner.Callback<Void>() {
@Override
public void run(Future<Void> clearTokenFuture) {
try {
result.success(clearTokenFuture.get());
} catch (ExecutionException e) {
result.error(ERROR_REASON_EXCEPTION, e.getCause().getMessage(), null);
} catch (InterruptedException e) {
result.error(ERROR_REASON_EXCEPTION, e.getMessage(), null);
Thread.currentThread().interrupt();
}
}
});
}

/**
Expand Down