Add webdav url to DetectAuthenticationMethodOperation
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index 6ff9f6a..cf76883 100644 (file)
@@ -187,8 +187,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private boolean mResumed; // Control if activity is resumed\r
 \r
     public static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT";\r
-\r
-    private DetectAuthenticationMethodOperation mDetectAuthenticationOperation;\r
+    \r
+    private ServiceConnection mOperationsServiceConnection = null;\r
+    \r
+    private OperationsServiceBinder mOperationsServiceBinder = null;\r
 \r
 \r
     /**\r
@@ -430,6 +432,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                 return false;\r
             }\r
         });\r
+        \r
+        mOperationsServiceConnection = new OperationsServiceConnection();\r
+        bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection, Context.BIND_AUTO_CREATE);\r
     }\r
 \r
 \r
@@ -513,7 +518,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         // refresh button enabled\r
         outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
 \r
-\r
     }\r
 \r
 \r
@@ -533,7 +537,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         }\r
     }\r
 \r
-\r
     /**\r
      * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION, and \r
      * deferred in {@link #onNewIntent(Intent)}, is processed here.\r
@@ -1009,14 +1012,15 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private void detectAuthorizationMethod() {\r
 \r
         Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
-\r
-        /// get the path to the root folder through WebDAV from the version server\r
+        \r
         String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);\r
-\r
+        \r
         /// test credentials \r
-        mDetectAuthenticationOperation = new DetectAuthenticationMethodOperation(this);\r
-        OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
-        mOperationThread = mDetectAuthenticationOperation.execute(client, this, mHandler);\r
+        Intent service = new Intent(this, OperationsService.class);        \r
+        service.setAction(OperationsService.ACTION_DETECT_AUTHENTICATION_METHOD);\r
+        service.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl);\r
+        service.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path);\r
+        startService(service);\r
     }\r
 \r
 \r
@@ -1842,4 +1846,31 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 \r
     }\r
 \r
+    /** \r
+     * Implements callback methods for service binding. Passed as a parameter to { \r
+     */\r
+    private class OperationsServiceConnection implements ServiceConnection {\r
+\r
+        @Override\r
+        public void onServiceConnected(ComponentName component, IBinder service) {\r
+            if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) {\r
+                Log_OC.d(TAG, "Operations service connected");\r
+                mOperationsServiceBinder = (OperationsServiceBinder) service;\r
+                mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler);\r
+            } else {\r
+                return;\r
+            }\r
+            \r
+        }\r
+\r
+        @Override\r
+        public void onServiceDisconnected(ComponentName component) {\r
+            if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) {\r
+                Log_OC.d(TAG, "Operations service disconnected");\r
+                mOperationsServiceBinder = null;\r
+                // TODO whatever could be waiting for the service is unbound\r
+            }\r
+        }\r
+    \r
+    }\r
 }\r