java/syncbase: Modify Android Login to be safer

This change is needed because we now persist blessings and load them
from disk whenever appropriate.

MultiPart: 2/2
Change-Id: I0cc8d11005e8a732d70e44895dd623a66ac5c962
diff --git a/syncbase/build.gradle b/syncbase/build.gradle
index f971ff0..7721ab3 100644
--- a/syncbase/build.gradle
+++ b/syncbase/build.gradle
@@ -19,7 +19,7 @@
 
 // You should update this after releasing a new version of the Syncbase API. See the
 // list of published versions at: https://repo1.maven.org/maven2/io/v/syncbase
-version = '0.1.6'
+version = '0.1.7'
 group = 'io.v'
 
 def siteUrl = 'https://github.com/vanadium/java/syncbase'
diff --git a/syncbase/src/main/java/io/v/syncbase/Syncbase.java b/syncbase/src/main/java/io/v/syncbase/Syncbase.java
index 56083da..a4c3308 100644
--- a/syncbase/src/main/java/io/v/syncbase/Syncbase.java
+++ b/syncbase/src/main/java/io/v/syncbase/Syncbase.java
@@ -135,7 +135,6 @@
      */
     public static void init(Options opts) throws SyncbaseException {
         try {
-
             System.loadLibrary("syncbase");
             sOpts = opts;
             io.v.syncbase.internal.Service.Init(sOpts.rootDir, sOpts.testLogin);
@@ -202,13 +201,18 @@
 
     /**
      * Logs in the user on Android.
-     * The user selects an account through an account picker flow and is logged into Syncbase.
+     * If the user is already logged in, it runs the callback immediately. Otherwise, the user
+     * selects an account through an account picker flow and is logged into Syncbase.
      * Note: This default account flow is currently restricted to Google accounts.
      *
      * @param activity The Android activity where login will occur.
      * @param cb       The callback to call when the login was done.
      */
     public static void loginAndroid(Activity activity, final LoginCallback cb) {
+        if (isLoggedIn()) {
+            cb.onSuccess();
+            return;
+        }
         FragmentTransaction transaction = activity.getFragmentManager().beginTransaction();
         LoginFragment fragment = new LoginFragment();
         fragment.setTokenReceiver(new LoginFragment.TokenReceiver() {