Using default singleton OwnCloudClientManager instead of holding a reference in appli...
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index f6decb8..fccd615 100644 (file)
@@ -114,7 +114,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
     private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
     private static final String KEY_SERVER_AUTH_METHOD = "SERVER_AUTH_METHOD";\r
-    private static final String KEY_WAITING_FOR_OP_ID = "DETECT_AUTH_OP_ID";\r
+    private static final String KEY_WAITING_FOR_OP_ID = "WAITING_FOR_OP_ID";\r
     private static final String KEY_AUTH_TOKEN = "AUTH_TOKEN";\r
 \r
     private static final String AUTH_ON = "on";\r
@@ -153,6 +153,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     \r
     private boolean mServerIsChecked = false;\r
     private boolean mServerIsValid = false;\r
+    private boolean mPendingAutoCheck = false;\r
 \r
     private GetServerInfoOperation.ServerInfo mServerInfo = \r
             new GetServerInfoOperation.ServerInfo();\r
@@ -174,7 +175,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     \r
     /// Identifier of operation in progress which result shouldn't be lost \r
     private long mWaitingForOpId = Long.MAX_VALUE;\r
-    \r
+\r
     \r
     /**\r
      * {@inheritDoc}\r
@@ -406,12 +407,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         });\r
      \r
         \r
-        /// step 4 - automatic actions to start\r
-        if (savedInstanceState == null) {\r
-            if (mAction != ACTION_CREATE || !isUrlInputAllowed) {\r
-                checkOcServer(); \r
-            }\r
-        }\r
+        /// step 4 - mark automatic check to be started when OperationsService is ready\r
+        mPendingAutoCheck = (savedInstanceState == null && \r
+                (mAction != ACTION_CREATE || !isUrlInputAllowed));\r
     }\r
     \r
     \r
@@ -729,6 +727,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
             if (mOperationsServiceBinder != null) {\r
                 //Log_OC.wtf(TAG, "checking server..." );\r
                 mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
+            } else {\r
+              Log_OC.wtf(TAG, "Server check tried with OperationService unbound!" );\r
             }\r
             \r
         } else {\r
@@ -828,9 +828,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
      * the root folder of the ownCloud server.\r
      */\r
     private void checkBasicAuthorization() {\r
-        /// get the path to the root folder through WebDAV from the version server\r
-        String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
-\r
         /// get basic credentials entered by user\r
         String username = mUsernameInput.getText().toString();\r
         String password = mPasswordInput.getText().toString();\r
@@ -844,18 +841,19 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         String remotePath ="";\r
         boolean successIfAbsent = false;\r
         boolean followRedirects = true;\r
-        startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, username, password, followRedirects);\r
+        startExistenceCheckRemoteOperation(\r
+                remotePath, this, successIfAbsent, username, password, followRedirects);\r
         \r
     }\r
 \r
-    private void startExistenceCheckRemoteOperation(String remotePath, Context context, boolean successIfAbsent, String webdav_path,\r
+    private void startExistenceCheckRemoteOperation(\r
+            String remotePath, Context context, boolean successIfAbsent,\r
             String username, String password, boolean followRedirects) {\r
         Intent existenceCheckIntent = new Intent();\r
         existenceCheckIntent.setAction(OperationsService.ACTION_EXISTENCE_CHECK);\r
         existenceCheckIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mServerInfo.mBaseUrl);\r
         existenceCheckIntent.putExtra(OperationsService.EXTRA_REMOTE_PATH, remotePath);\r
         existenceCheckIntent.putExtra(OperationsService.EXTRA_SUCCESS_IF_ABSENT, successIfAbsent);\r
-        existenceCheckIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
         existenceCheckIntent.putExtra(OperationsService.EXTRA_USERNAME, username);\r
         existenceCheckIntent.putExtra(OperationsService.EXTRA_PASSWORD, password);\r
         existenceCheckIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN, mAuthToken);\r
@@ -904,14 +902,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                 IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
         dialog.show(getSupportFragmentManager(), WAIT_DIALOG_TAG);\r
 \r
-        /// get the path to the root folder through WebDAV from the version server\r
-        String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
-\r
         /// test credentials accessing the root folder\r
         String remotePath ="";\r
         boolean successIfAbsent = false;\r
         boolean followRedirections = false;\r
-        startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirections);\r
+        startExistenceCheckRemoteOperation(\r
+                remotePath, this, successIfAbsent, "", "", followRedirections);\r
 \r
     }\r
 \r
@@ -1284,8 +1280,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         mWaitingForOpId = Long.MAX_VALUE;\r
         dismissDialog(WAIT_DIALOG_TAG);\r
 \r
-        String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
-        if (result.isSuccess() && webdav_path != null) {\r
+        if (result.isSuccess()) {\r
             /// be gentle with the user\r
             IndeterminateProgressDialog dialog = \r
                     IndeterminateProgressDialog.newInstance(R.string.auth_trying_to_login, true);\r
@@ -1301,7 +1296,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
             String remotePath ="";\r
             boolean successIfAbsent = false;\r
             boolean followRedirects = true;\r
-            startExistenceCheckRemoteOperation(remotePath, this, successIfAbsent, webdav_path, "", "", followRedirects);\r
+            startExistenceCheckRemoteOperation(\r
+                    remotePath, this, successIfAbsent, "", "", followRedirects);\r
 \r
         } else {\r
             updateAuthStatusIconAndText(result);\r
@@ -1417,11 +1413,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         String username = mUsernameInput.getText().toString().trim();\r
         if (isOAuth) {\r
             username = "OAuth_user" + (new java.util.Random(System.currentTimeMillis())).nextLong();\r
-        }            \r
-        String accountName = username + "@" + uri.getHost();\r
-        if (uri.getPort() >= 0) {\r
-            accountName += ":" + uri.getPort();\r
         }\r
+        String accountName = com.owncloud.android.lib.common.accounts.AccountUtils.\r
+                buildAccountName(uri, username);\r
         Account newAccount = new Account(accountName, MainApp.getAccountType());\r
         if (AccountUtils.exists(newAccount, getApplicationContext())) {\r
             // fail - not a new account, but an existing one; disallow\r
@@ -1745,6 +1739,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         if (mWaitingForOpId <= Integer.MAX_VALUE) {\r
             mOperationsServiceBinder.dispatchResultIfFinished((int)mWaitingForOpId, this);\r
         }\r
+        \r
+        if (mPendingAutoCheck) {\r
+            checkOcServer();\r
+        }\r
     }\r
 \r
     \r