Moved execution of GetServerInfoOperation into OperationsService
authorDavid A. Velasco <dvelasco@solidgear.es>
Tue, 1 Apr 2014 09:59:38 +0000 (11:59 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Tue, 1 Apr 2014 09:59:38 +0000 (11:59 +0200)
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/services/OperationsService.java

index dd20d48..d9e1bea 100644 (file)
@@ -45,7 +45,6 @@ import android.support.v4.app.FragmentTransaction;
 import android.text.Editable;\r
 import android.text.InputType;\r
 import android.text.TextWatcher;\r
 import android.text.Editable;\r
 import android.text.InputType;\r
 import android.text.TextWatcher;\r
-import android.util.Log;\r
 import android.view.KeyEvent;\r
 import android.view.MotionEvent;\r
 import android.view.View;\r
 import android.view.KeyEvent;\r
 import android.view.MotionEvent;\r
 import android.view.View;\r
@@ -69,7 +68,6 @@ import com.owncloud.android.lib.common.accounts.AccountTypeUtils;
 import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
 import com.owncloud.android.lib.common.OwnCloudClientFactory;\r
 import com.owncloud.android.lib.common.OwnCloudClient;\r
 import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
 import com.owncloud.android.lib.common.OwnCloudClientFactory;\r
 import com.owncloud.android.lib.common.OwnCloudClient;\r
-import com.owncloud.android.operations.DetectAuthenticationMethodOperation;\r
 import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;\r
 import com.owncloud.android.operations.GetServerInfoOperation;\r
 import com.owncloud.android.operations.OAuth2GetAccessToken;\r
 import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod;\r
 import com.owncloud.android.operations.GetServerInfoOperation;\r
 import com.owncloud.android.operations.OAuth2GetAccessToken;\r
@@ -149,7 +147,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;\r
     private boolean mServerIsChecked, mServerIsValid, mIsSslConn;\r
     private AuthenticationMethod mServerAuthMethod = AuthenticationMethod.UNKNOWN;\r
     private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon;\r
     private boolean mServerIsChecked, mServerIsValid, mIsSslConn;\r
     private AuthenticationMethod mServerAuthMethod = AuthenticationMethod.UNKNOWN;\r
-    private int mDetectAuthOpId = -1;\r
+    private int mGetServerInfoOpId = -1;\r
 \r
     private int mAuthStatusText, mAuthStatusIcon;    \r
     private TextView mAuthStatusLayout;\r
 \r
     private int mAuthStatusText, mAuthStatusIcon;    \r
     private TextView mAuthStatusLayout;\r
@@ -341,7 +339,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 \r
             mServerAuthMethod = AuthenticationMethod.valueOf(\r
                     savedInstanceState.getString(KEY_SERVER_AUTH_METHOD));\r
 \r
             mServerAuthMethod = AuthenticationMethod.valueOf(\r
                     savedInstanceState.getString(KEY_SERVER_AUTH_METHOD));\r
-            mDetectAuthOpId = savedInstanceState.getInt(KEY_DETECT_AUTH_OP_ID);\r
+            mGetServerInfoOpId = savedInstanceState.getInt(KEY_DETECT_AUTH_OP_ID);\r
 \r
         }\r
 \r
 \r
         }\r
 \r
@@ -364,7 +362,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
             mOAuth2Check.setVisibility(View.GONE);\r
         }\r
 \r
             mOAuth2Check.setVisibility(View.GONE);\r
         }\r
 \r
-        //showRefreshButton(mServerIsChecked && !mServerIsValid && mRefreshButtonEnabled);\r
         showRefreshButton(mServerIsChecked && !mServerIsValid && refreshButtonEnabled);\r
         mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
 \r
         showRefreshButton(mServerIsChecked && !mServerIsValid && refreshButtonEnabled);\r
         mOkButton.setEnabled(mServerIsValid); // state not automatically recovered in configuration changes\r
 \r
@@ -514,7 +511,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
         \r
         outState.putString(KEY_SERVER_AUTH_METHOD, mServerAuthMethod.name());\r
         outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
         \r
         outState.putString(KEY_SERVER_AUTH_METHOD, mServerAuthMethod.name());\r
-        outState.putInt(KEY_DETECT_AUTH_OP_ID, mDetectAuthOpId);\r
+        outState.putInt(KEY_DETECT_AUTH_OP_ID, mGetServerInfoOpId);\r
         //Log.wtf(TAG, "onSaveInstanceState end" );\r
     }\r
 \r
         //Log.wtf(TAG, "onSaveInstanceState end" );\r
     }\r
 \r
@@ -674,21 +671,21 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
             mServerStatusText = R.string.auth_testing_connection;\r
             mServerStatusIcon = R.drawable.progress_small;\r
             showServerStatus();\r
             mServerStatusText = R.string.auth_testing_connection;\r
             mServerStatusIcon = R.drawable.progress_small;\r
             showServerStatus();\r
+            \r
+            /*\r
             mServerInfoOperation = new GetServerInfoOperation(uri, mAuthTokenType, this);\r
             OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(uri), this, true);\r
             mServerInfoOperation.execute(client, this, mHandler);\r
             mServerInfoOperation = new GetServerInfoOperation(uri, mAuthTokenType, this);\r
             OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(uri), this, true);\r
             mServerInfoOperation.execute(client, this, mHandler);\r
+            */\r
             \r
             \r
-            /*\r
-             * TODO start joint operation in OperationsService\r
-            Intent detectAuthIntent = new Intent();\r
-            detectAuthIntent.setAction(OperationsService.ACTION_DETECT_AUTHENTICATION_METHOD);\r
-            detectAuthIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mBaseUrl);\r
-            detectAuthIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
+            Intent getServerInfoIntent = new Intent();\r
+            getServerInfoIntent.setAction(OperationsService.ACTION_GET_SERVER_INFO);\r
+            getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri);\r
+            getServerInfoIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN_TYPE, mAuthTokenType);\r
             if (mOperationsServiceBinder != null) {\r
             if (mOperationsServiceBinder != null) {\r
-                //Log.wtf(TAG, "starting detection..." );\r
-                mDetectAuthOpId = mOperationsServiceBinder.newOperation(detectAuthIntent);\r
+                //Log.wtf(TAG, "checking server..." );\r
+                mGetServerInfoOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
             }\r
             }\r
-            */\r
             \r
         } else {\r
             mServerStatusText = 0;\r
             \r
         } else {\r
             mServerStatusText = 0;\r
@@ -878,11 +875,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {\r
 \r
         if (operation instanceof GetServerInfoOperation) {\r
     public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) {\r
 \r
         if (operation instanceof GetServerInfoOperation) {\r
-            if (operation.equals(mServerInfoOperation)) {\r
+            if (operation.hashCode() == mGetServerInfoOpId) {\r
                 onGetServerInfoFinish(result);\r
             }   // else nothing ; only the last check operation is considered; \r
                 onGetServerInfoFinish(result);\r
             }   // else nothing ; only the last check operation is considered; \r
-                // multiple can be triggered if the user amends a URL before a previous check \r
-                // can be triggered\r
+                // multiple can be started if the user amends a URL quickly\r
 \r
         } else if (operation instanceof OAuth2GetAccessToken) {\r
             onGetOAuthAccessTokenFinish((OAuth2GetAccessToken)operation, result);\r
 \r
         } else if (operation instanceof OAuth2GetAccessToken) {\r
             onGetOAuthAccessTokenFinish((OAuth2GetAccessToken)operation, result);\r
@@ -897,44 +893,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         } else if (operation instanceof GetRemoteUserNameOperation) {\r
             onGetUserNameFinish((GetRemoteUserNameOperation) operation, result);\r
 \r
         } else if (operation instanceof GetRemoteUserNameOperation) {\r
             onGetUserNameFinish((GetRemoteUserNameOperation) operation, result);\r
 \r
-        } else if (operation instanceof DetectAuthenticationMethodOperation) {\r
-            Log.wtf(TAG, "received detection response through callback" );\r
-            onDetectAuthenticationFinish(result);\r
         }\r
 \r
     }\r
 \r
         }\r
 \r
     }\r
 \r
-    private void onDetectAuthenticationFinish(RemoteOperationResult result) {\r
-        // Read authentication method\r
-        mDetectAuthOpId = -1;\r
-        if (result.getData().size() > 0) {\r
-            AuthenticationMethod authMethod = (AuthenticationMethod) result.getData().get(0);\r
-            String basic = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType());\r
-            String oAuth = AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType());\r
-            String saml =  AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType());\r
-\r
-            if ( ( mAuthTokenType.equals(basic) && !authMethod.equals(AuthenticationMethod.BASIC_HTTP_AUTH) ) ||\r
-                    ( mAuthTokenType.equals(oAuth) && !authMethod.equals(AuthenticationMethod.BEARER_TOKEN) ) || \r
-                    ( mAuthTokenType.equals(saml)  && !authMethod.equals(AuthenticationMethod.SAML_WEB_SSO) ) ) {\r
-\r
-                mOkButton.setEnabled(false);\r
-                mServerIsValid = false;\r
-                //show an alert message ( Server Status )\r
-                updateServerStatusIconNoRegularAuth();\r
-                showServerStatus();\r
-\r
-            } else {\r
-                mOkButton.setEnabled(true);\r
-\r
-                // Show server status\r
-                showServerStatus();\r
-            }\r
-\r
-        }\r
-    }\r
-\r
-\r
-\r
     private void onGetUserNameFinish(GetRemoteUserNameOperation operation, RemoteOperationResult result) {\r
 \r
         if (result.isSuccess()) {\r
     private void onGetUserNameFinish(GetRemoteUserNameOperation operation, RemoteOperationResult result) {\r
 \r
         if (result.isSuccess()) {\r
@@ -1008,7 +970,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         mServerIsChecked = true;\r
         mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
         mServerInfoOperation = null;\r
         mServerIsChecked = true;\r
         mIsSslConn = (result.getCode() == ResultCode.OK_SSL);\r
         mServerInfoOperation = null;\r
-        mDetectAuthOpId = -1;\r
+        mGetServerInfoOpId = -1;\r
         \r
         // update server status, but don't show it yet\r
         updateServerStatusIconAndText(result);\r
         \r
         // update server status, but don't show it yet\r
         updateServerStatusIconAndText(result);\r
@@ -1022,8 +984,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
             mServerInfo = (GetServerInfoOperation.ServerInfo) (result.getData().get(0));\r
             mDiscoveredVersion = mServerInfo.mVersion;\r
             mHostBaseUrl = mServerInfo.mBaseUrl;\r
             mServerInfo = (GetServerInfoOperation.ServerInfo) (result.getData().get(0));\r
             mDiscoveredVersion = mServerInfo.mVersion;\r
             mHostBaseUrl = mServerInfo.mBaseUrl;\r
+            mServerAuthMethod = mServerInfo.mAuthMethod;\r
             \r
             \r
-            if (!authSupported(mServerInfo.mAuthMethod)) {\r
+            if (!authSupported(mServerAuthMethod)) {\r
                 \r
                 updateServerStatusIconNoRegularAuth();  // overrides updateServerStatusIconAndText()  \r
                 mServerIsValid = false;\r
                 \r
                 updateServerStatusIconNoRegularAuth();  // overrides updateServerStatusIconAndText()  \r
                 mServerIsValid = false;\r
@@ -1063,32 +1026,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     }\r
 \r
 \r
     }\r
 \r
 \r
-    /**\r
-     *  Try to access with  user/pass ""/"", to know if it is a regular server\r
-     */\r
-    private void detectAuthorizationMethod() {\r
-\r
-        Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
-        \r
-        String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);\r
-        \r
-        /// test credentials \r
-        //Intent detectAuthIntent = new Intent(this, OperationsService.class);\r
-        Intent detectAuthIntent = new Intent();\r
-        detectAuthIntent.setAction(OperationsService.ACTION_DETECT_AUTHENTICATION_METHOD);\r
-        detectAuthIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl);\r
-        detectAuthIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
-        \r
-        //if (mOperationsBinder != null) {  // let's let it crash to detect if is really possible\r
-        mServerAuthMethod = AuthenticationMethod.UNKNOWN;\r
-        if (mOperationsServiceBinder != null) {\r
-            //Log.wtf(TAG, "starting detection..." );\r
-            mDetectAuthOpId = mOperationsServiceBinder.newOperation(detectAuthIntent);\r
-        }\r
-        //}\r
-    }\r
-\r
-\r
     // TODO remove, if possible\r
     private String normalizeUrl(String url) {\r
         if (url != null && url.length() > 0) {\r
     // TODO remove, if possible\r
     private String normalizeUrl(String url) {\r
         if (url != null && url.length() > 0) {\r
@@ -1918,12 +1855,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         //Log.wtf(TAG, "registering to listen for operation callbacks" );\r
         mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler);\r
         \r
         //Log.wtf(TAG, "registering to listen for operation callbacks" );\r
         mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler);\r
         \r
-        if (mDetectAuthOpId != -1) {\r
+        if (mGetServerInfoOpId != -1) {\r
             RemoteOperationResult result = \r
             RemoteOperationResult result = \r
-                    mOperationsServiceBinder.getOperationResultIfFinished(mDetectAuthOpId);\r
+                    mOperationsServiceBinder.getOperationResultIfFinished(mGetServerInfoOpId);\r
             if (result != null) {\r
                 //Log.wtf(TAG, "found result of operation finished while rotating");\r
             if (result != null) {\r
                 //Log.wtf(TAG, "found result of operation finished while rotating");\r
-                onDetectAuthenticationFinish(result);\r
+                onGetServerInfoFinish(result);\r
             }\r
         }\r
     }\r
             }\r
         }\r
     }\r
index 0ccd909..518f2af 100644 (file)
@@ -33,6 +33,7 @@ import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.operations.CreateShareOperation;
 import com.owncloud.android.operations.DetectAuthenticationMethodOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.operations.CreateShareOperation;
 import com.owncloud.android.operations.DetectAuthenticationMethodOperation;
+import com.owncloud.android.operations.GetServerInfoOperation;
 import com.owncloud.android.operations.UnshareLinkOperation;
 import com.owncloud.android.utils.Log_OC;
 
 import com.owncloud.android.operations.UnshareLinkOperation;
 import com.owncloud.android.utils.Log_OC;
 
@@ -56,14 +57,15 @@ public class OperationsService extends Service {
     
     public static final String EXTRA_ACCOUNT = "ACCOUNT";
     public static final String EXTRA_SERVER_URL = "SERVER_URL";
     
     public static final String EXTRA_ACCOUNT = "ACCOUNT";
     public static final String EXTRA_SERVER_URL = "SERVER_URL";
+    public static final String EXTRA_AUTH_TOKEN_TYPE = "AUTH_TOKEN_TYPE";
     public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
     public static final String EXTRA_SEND_INTENT = "SEND_INTENT";
     public static final String EXTRA_RESULT = "RESULT";
     public static final String EXTRA_REMOTE_PATH = "REMOTE_PATH";
     public static final String EXTRA_SEND_INTENT = "SEND_INTENT";
     public static final String EXTRA_RESULT = "RESULT";
-    public static final String EXTRA_WEBDAV_PATH = "WEBDAV_PATH";
     
     public static final String ACTION_CREATE_SHARE = "CREATE_SHARE";
     public static final String ACTION_UNSHARE = "UNSHARE";
     
     public static final String ACTION_CREATE_SHARE = "CREATE_SHARE";
     public static final String ACTION_UNSHARE = "UNSHARE";
-    public static final String ACTION_DETECT_AUTHENTICATION_METHOD = "DETECT_AUTHENTICATION_METHOD";
+    //public static final String ACTION_DETECT_AUTHENTICATION_METHOD = "DETECT_AUTHENTICATION_METHOD";
+    public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO";
     
     public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
     public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
     
     public static final String ACTION_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
     public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
@@ -248,13 +250,12 @@ public class OperationsService extends Service {
                                     remotePath, 
                                     OperationsService.this);
                         }
                                     remotePath, 
                                     OperationsService.this);
                         }
-                    } else if (action.equals(ACTION_DETECT_AUTHENTICATION_METHOD)) { 
-                        // Detect Authentication Method
-                        String webdav_url = 
-                                serverUrl + operationIntent.getStringExtra(EXTRA_WEBDAV_PATH);
-                        operation = new DetectAuthenticationMethodOperation(
-                                OperationsService.this, 
-                                webdav_url);
+                    } else if (action.equals(ACTION_GET_SERVER_INFO)) { 
+                        // check OC server and get basic information from it
+                        String authTokenType = 
+                                operationIntent.getStringExtra(EXTRA_AUTH_TOKEN_TYPE);
+                        operation = new GetServerInfoOperation(
+                                serverUrl, authTokenType, OperationsService.this);
                     }
                 }
                     
                     }
                 }