cmd/tailsca,java/comt/tailscale/ipn: don't require an Activity for Google sign-out

The GoogleSignIn.getClient has a version that only needs a Context, not an Activity.

Updates tailscale/tailscale#670

Signed-off-by: Elias Naur <mail@eliasnaur.com>
pull/3/head
Elias Naur 4 years ago
parent a0a33e92c4
commit 3089ad8347

@ -27,6 +27,11 @@ import java.security.GeneralSecurityException;
import androidx.security.crypto.EncryptedSharedPreferences; import androidx.security.crypto.EncryptedSharedPreferences;
import androidx.security.crypto.MasterKey; import androidx.security.crypto.MasterKey;
import com.google.android.gms.auth.api.signin.GoogleSignIn;
import com.google.android.gms.auth.api.signin.GoogleSignInAccount;
import com.google.android.gms.auth.api.signin.GoogleSignInClient;
import com.google.android.gms.auth.api.signin.GoogleSignInOptions;
import org.gioui.Gio; import org.gioui.Gio;
public class App extends Application { public class App extends Application {
@ -85,6 +90,13 @@ public class App extends Application {
); );
} }
void googleSignOut() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.build();
GoogleSignInClient client = GoogleSignIn.getClient(this, gso);
client.signOut();
}
void setTileStatus(boolean wantRunning) { void setTileStatus(boolean wantRunning) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
return; return;

@ -58,13 +58,6 @@ public class Peer extends Fragment {
super.onDestroy(); super.onDestroy();
} }
public void googleSignOut() {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.build();
GoogleSignInClient client = GoogleSignIn.getClient(getActivity(), gso);
client.signOut();
}
public void googleSignIn(String serverOAuthID) { public void googleSignIn(String serverOAuthID) {
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(serverOAuthID) .requestIdToken(serverOAuthID)

@ -670,7 +670,7 @@ func (a *App) processUIEvents(w *app.Window, events []UIEvent, peer jni.Object,
a.store.WriteString(loginMethodPrefKey, loginMethodWeb) a.store.WriteString(loginMethodPrefKey, loginMethodWeb)
requestBackend(e) requestBackend(e)
case LogoutEvent: case LogoutEvent:
a.signOut(peer) a.signOut()
requestBackend(e) requestBackend(e)
case ConnectEvent: case ConnectEvent:
requestBackend(e) requestBackend(e)
@ -686,12 +686,9 @@ func (a *App) processUIEvents(w *app.Window, events []UIEvent, peer jni.Object,
} }
} }
func (a *App) signOut(peer jni.Object) { func (a *App) signOut() {
if peer == 0 {
return
}
err := jni.Do(a.jvm, func(env jni.Env) error { err := jni.Do(a.jvm, func(env jni.Env) error {
return a.callVoidMethod(peer, "googleSignOut", "()V") return a.callVoidMethod(a.appCtx, "googleSignOut", "()V")
}) })
if err != nil { if err != nil {
fatalErr(err) fatalErr(err)

Loading…
Cancel
Save