浏览代码

Merge remote-tracking branch 'origin/operations_service' into operations_service

David A. Velasco 11 年之前
父节点
当前提交
7c4fc0486f

+ 38 - 8
src/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -187,8 +187,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private boolean mResumed; // Control if activity is resumed
 
     public static String DIALOG_UNTRUSTED_CERT = "DIALOG_UNTRUSTED_CERT";
-
-    private DetectAuthenticationMethodOperation mDetectAuthenticationOperation;
+    
+    private ServiceConnection mOperationsServiceConnection = null;
+    
+    private OperationsServiceBinder mOperationsServiceBinder = null;
 
 
     /**
@@ -430,6 +432,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                 return false;
             }
         });
+        
+        mOperationsServiceConnection = new OperationsServiceConnection();
+        bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection, Context.BIND_AUTO_CREATE);
     }
 
 
@@ -1010,13 +1015,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 
         Log_OC.d(TAG, "Trying empty authorization to detect authentication method");
 
-        /// get the path to the root folder through WebDAV from the version server
-        String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);
-
         /// test credentials 
-        mDetectAuthenticationOperation = new DetectAuthenticationMethodOperation(this);
-        OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);
-        mOperationThread = mDetectAuthenticationOperation.execute(client, this, mHandler);
+        Intent service = new Intent(this, OperationsService.class);
+        service.setAction(OperationsService.ACTION_DETECT_AUTHENTICATION_METHOD);
+        service.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl);
+        startService(service);
     }
 
 
@@ -1842,4 +1845,31 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 
     }
 
+    /** 
+     * Implements callback methods for service binding. Passed as a parameter to { 
+     */
+    private class OperationsServiceConnection implements ServiceConnection {
+
+        @Override
+        public void onServiceConnected(ComponentName component, IBinder service) {
+            if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) {
+                Log_OC.d(TAG, "Operations service connected");
+                mOperationsServiceBinder = (OperationsServiceBinder) service;
+                mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler);
+            } else {
+                return;
+            }
+            
+        }
+
+        @Override
+        public void onServiceDisconnected(ComponentName component) {
+            if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) {
+                Log_OC.d(TAG, "Operations service disconnected");
+                mOperationsServiceBinder = null;
+                // TODO whatever could be waiting for the service is unbound
+            }
+        }
+    
+    }
 }

+ 5 - 1
src/com/owncloud/android/services/OperationsService.java

@@ -32,6 +32,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 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.UnshareLinkOperation;
 import com.owncloud.android.utils.Log_OC;
 
@@ -47,7 +48,6 @@ import android.os.IBinder;
 import android.os.Looper;
 import android.os.Message;
 import android.os.Process;
-//import android.support.v4.content.LocalBroadcastManager;
 import android.util.Pair;
 
 public class OperationsService extends Service {
@@ -62,6 +62,7 @@ public class OperationsService extends Service {
     
     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_OPERATION_ADDED = OperationsService.class.getName() + ".OPERATION_ADDED";
     public static final String ACTION_OPERATION_FINISHED = OperationsService.class.getName() + ".OPERATION_FINISHED";
@@ -134,6 +135,9 @@ public class OperationsService extends Service {
                 if (remotePath.length() > 0) {
                     operation = new UnshareLinkOperation(remotePath, this.getApplicationContext());
                 }
+            } else if (action.equals(ACTION_DETECT_AUTHENTICATION_METHOD)) { // Detect Authentication Method
+                operation = new DetectAuthenticationMethodOperation(this.getApplicationContext());
+            
             } else {
                 // nothing we are going to handle
                 return START_NOT_STICKY;

+ 0 - 1
src/com/owncloud/android/ui/activity/FileDisplayActivity.java

@@ -19,7 +19,6 @@
 package com.owncloud.android.ui.activity;
 
 import java.io.File;
-import java.io.InvalidClassException;
 
 import android.accounts.Account;
 import android.app.AlertDialog;