Merge remote-tracking branch 'origin/operations_service' into operations_service
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index 6ff9f6a..638b5dd 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
     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
 \r
 \r
     /**\r
@@ -430,6 +432,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                 return false;\r
             }\r
         });\r
                 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
     }\r
 \r
 \r
@@ -1010,13 +1015,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 \r
         Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
 \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
-        String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);\r
-\r
         /// test credentials \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
+        startService(service);\r
     }\r
 \r
 \r
     }\r
 \r
 \r
@@ -1842,4 +1845,31 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 \r
     }\r
 \r
 \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
 }\r