Run GetRemoteUserNameOperation in OperationsService
authormasensio <masensio@solidgear.es>
Wed, 2 Apr 2014 07:46:40 +0000 (09:46 +0200)
committermasensio <masensio@solidgear.es>
Wed, 2 Apr 2014 07:46:40 +0000 (09:46 +0200)
owncloud-android-library
src/com/owncloud/android/authentication/AuthenticatorActivity.java
src/com/owncloud/android/services/OperationsService.java

index 6b69b5a..d066e9d 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 6b69b5af1a79275a23339ad6382210d75b061f9f
+Subproject commit d066e9da51a04837504f9be3e266bdc82caabc64
index fc1e398..fb55c14 100644 (file)
@@ -67,8 +67,6 @@ import com.owncloud.android.R;
 import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
 import com.owncloud.android.lib.common.accounts.AccountTypeUtils;\r
 import com.owncloud.android.lib.common.accounts.AccountUtils.Constants;\r
 import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
 import com.owncloud.android.lib.common.accounts.AccountTypeUtils;\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.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
@@ -158,8 +156,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private Thread mOperationThread;\r
     private GetServerInfoOperation mServerInfoOperation;\r
 \r
     private Thread mOperationThread;\r
     private GetServerInfoOperation mServerInfoOperation;\r
 \r
-    //private ExistenceCheckRemoteOperation mAuthCheckOperation;\r
     private int mExistenceCheckOpId = -1;\r
     private int mExistenceCheckOpId = -1;\r
+    private int mGetUserNameOpId = -1;\r
     \r
     private Uri mNewCapturedUriFromOAuth2Redirection;\r
 \r
     \r
     private Uri mNewCapturedUriFromOAuth2Redirection;\r
 \r
@@ -925,17 +923,16 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                 onAuthorizationCheckFinish(result);\r
             }\r
         } else if (operation instanceof GetRemoteUserNameOperation) {\r
                 onAuthorizationCheckFinish(result);\r
             }\r
         } else if (operation instanceof GetRemoteUserNameOperation) {\r
-            onGetUserNameFinish((GetRemoteUserNameOperation) operation, result);\r
-\r
+            onGetUserNameFinish(result);\r
         }\r
 \r
     }\r
 \r
         }\r
 \r
     }\r
 \r
-    private void onGetUserNameFinish(GetRemoteUserNameOperation operation, RemoteOperationResult result) {\r
-\r
+    private void onGetUserNameFinish(RemoteOperationResult result) {\r
+        mGetUserNameOpId = -1;\r
         if (result.isSuccess()) {\r
             boolean success = false;\r
         if (result.isSuccess()) {\r
             boolean success = false;\r
-            String username = operation.getUserName();\r
+            String username = (String) result.getData().get(0);\r
 \r
             if ( mAction == ACTION_CREATE) {\r
                 mUsernameInput.setText(username);\r
 \r
             if ( mAction == ACTION_CREATE) {\r
                 mUsernameInput.setText(username);\r
@@ -1753,13 +1750,27 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         if (sessionCookie != null && sessionCookie.length() > 0) {\r
             mAuthToken = sessionCookie;\r
 \r
         if (sessionCookie != null && sessionCookie.length() > 0) {\r
             mAuthToken = sessionCookie;\r
 \r
-            GetRemoteUserNameOperation getUserOperation = new GetRemoteUserNameOperation();            \r
-            OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl), getApplicationContext(), true);\r
-            client.setSsoSessionCookie(mAuthToken);\r
-            getUserOperation.execute(client, this, mHandler);\r
+//            GetRemoteUserNameOperation getUserOperation = new GetRemoteUserNameOperation();\r
+//            OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl), getApplicationContext(), true);\r
+//            client.setSsoSessionCookie(mAuthToken);\r
+//            getUserOperation.execute(client, this, mHandler);\r
+            boolean followRedirects = true;\r
+            getRemoteUserNameOperation(sessionCookie, followRedirects);\r
+        }\r
+    }\r
+    \r
+    private void getRemoteUserNameOperation(String sessionCookie, boolean followRedirects) {\r
+        \r
+        Intent getUserNameIntent = new Intent();\r
+        getUserNameIntent.setAction(OperationsService.ACTION_GET_USER_NAME);\r
+        getUserNameIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl);\r
+        getUserNameIntent.putExtra(OperationsService.EXTRA_COOKIE, sessionCookie);\r
+        getUserNameIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
+        \r
+        if (mOperationsServiceBinder != null) {\r
+            Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." );\r
+            mGetUserNameOpId = mOperationsServiceBinder.newOperation(getUserNameIntent);\r
         }\r
         }\r
-\r
-\r
     }\r
 \r
 \r
     }\r
 \r
 \r
@@ -1923,7 +1934,16 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                     onAuthorizationCheckFinish(result);\r
                 }\r
             }\r
                     onAuthorizationCheckFinish(result);\r
                 }\r
             }\r
-        }\r
+        }if (mGetUserNameOpId != -1) {\r
+            RemoteOperationResult result = \r
+                    mOperationsServiceBinder.getOperationResultIfFinished(mGetUserNameOpId);\r
+            if (result != null) {\r
+                //Log_OC.wtf(TAG, "found result of operation finished while rotating");\r
+                onGetUserNameFinish(result);\r
+            }\r
+            \r
+        } \r
+        \r
     }\r
     \r
     /** \r
     }\r
     \r
     /** \r
index f0f37f5..81a4ade 100644 (file)
@@ -32,6 +32,7 @@ import com.owncloud.android.lib.common.operations.RemoteOperation;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
 import com.owncloud.android.lib.resources.shares.ShareType;
 import com.owncloud.android.lib.common.operations.RemoteOperationResult;
 import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation;
 import com.owncloud.android.lib.resources.shares.ShareType;
+import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.operations.CreateShareOperation;
 import com.owncloud.android.operations.GetServerInfoOperation;
 import com.owncloud.android.operations.common.SyncOperation;
 import com.owncloud.android.operations.CreateShareOperation;
 import com.owncloud.android.operations.GetServerInfoOperation;
@@ -72,12 +73,14 @@ public class OperationsService extends Service {
     public static final String EXTRA_PASSWORD = "PASSWORD";
     public static final String EXTRA_AUTH_TOKEN = "AUTH_TOKEN";
     public static final String EXTRA_FOLLOW_REDIRECTS = "FOLLOW_REDIRECTS";
     public static final String EXTRA_PASSWORD = "PASSWORD";
     public static final String EXTRA_AUTH_TOKEN = "AUTH_TOKEN";
     public static final String EXTRA_FOLLOW_REDIRECTS = "FOLLOW_REDIRECTS";
+    public static final String EXTRA_COOKIE = "COOKIE";
     
     public static final String ACTION_CREATE_SHARE = "CREATE_SHARE";
     public static final String ACTION_UNSHARE = "UNSHARE";
     public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO";
     public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN = "OAUTH2_GET_ACCESS_TOKEN";
     public static final String ACTION_EXISTENCE_CHECK = "EXISTENCE_CHECK";
     
     public static final String ACTION_CREATE_SHARE = "CREATE_SHARE";
     public static final String ACTION_UNSHARE = "UNSHARE";
     public static final String ACTION_GET_SERVER_INFO = "GET_SERVER_INFO";
     public static final String ACTION_OAUTH2_GET_ACCESS_TOKEN = "OAUTH2_GET_ACCESS_TOKEN";
     public static final String ACTION_EXISTENCE_CHECK = "EXISTENCE_CHECK";
+    public static final String ACTION_GET_USER_NAME = "GET_USER_NAME";
     
     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";
@@ -96,9 +99,10 @@ public class OperationsService extends Service {
         public String mPassword = "";
         public String mAuthToken = "";
         public boolean mFollowRedirects = true;
         public String mPassword = "";
         public String mAuthToken = "";
         public boolean mFollowRedirects = true;
+        public String mCookie = "";
         
         public Target(Account account, Uri serverUrl, String webdavUrl, String username, String password, String authToken,
         
         public Target(Account account, Uri serverUrl, String webdavUrl, String username, String password, String authToken,
-                boolean followRedirects) {
+                boolean followRedirects, String cookie) {
             mAccount = account;
             mServerUrl = serverUrl;
             mWebDavUrl = webdavUrl;
             mAccount = account;
             mServerUrl = serverUrl;
             mWebDavUrl = webdavUrl;
@@ -106,6 +110,7 @@ public class OperationsService extends Service {
             mPassword = password;
             mAuthToken = authToken;
             mFollowRedirects = followRedirects;
             mPassword = password;
             mAuthToken = authToken;
             mFollowRedirects = followRedirects;
+            mCookie = cookie;
         }
     }
 
         }
     }
 
@@ -260,6 +265,7 @@ public class OperationsService extends Service {
                     String password = operationIntent.getStringExtra(EXTRA_PASSWORD);
                     String authToken = operationIntent.getStringExtra(EXTRA_AUTH_TOKEN);
                     boolean followRedirects = operationIntent.getBooleanExtra(EXTRA_FOLLOW_REDIRECTS, true);
                     String password = operationIntent.getStringExtra(EXTRA_PASSWORD);
                     String authToken = operationIntent.getStringExtra(EXTRA_AUTH_TOKEN);
                     boolean followRedirects = operationIntent.getBooleanExtra(EXTRA_FOLLOW_REDIRECTS, true);
+                    String cookie = operationIntent.getStringExtra(EXTRA_COOKIE);
                     target = new Target(
                             account, 
                             (serverUrl == null) ? null : Uri.parse(serverUrl),
                     target = new Target(
                             account, 
                             (serverUrl == null) ? null : Uri.parse(serverUrl),
@@ -267,7 +273,8 @@ public class OperationsService extends Service {
                             (username == null) ? "" : username,
                             (password == null) ? "" : password,
                             (authToken == null) ? "" : authToken,
                             (username == null) ? "" : username,
                             (password == null) ? "" : password,
                             (authToken == null) ? "" : authToken,
-                            followRedirects
+                            followRedirects,
+                            (cookie == null) ? "" : cookie
                     );
                     
                     String action = operationIntent.getAction();
                     );
                     
                     String action = operationIntent.getAction();
@@ -310,6 +317,9 @@ public class OperationsService extends Service {
                         boolean successIfAbsent = operationIntent.getBooleanExtra(EXTRA_SUCCESS_IF_ABSENT, true);
                         operation = new ExistenceCheckRemoteOperation(remotePath, OperationsService.this, successIfAbsent);
                         
                         boolean successIfAbsent = operationIntent.getBooleanExtra(EXTRA_SUCCESS_IF_ABSENT, true);
                         operation = new ExistenceCheckRemoteOperation(remotePath, OperationsService.this, successIfAbsent);
                         
+                    } else if (action.equals(ACTION_GET_USER_NAME)) {
+                        // Get User Name
+                        operation = new GetRemoteUserNameOperation();
                     }
                 }
                     
                     }
                 }
                     
@@ -393,6 +403,8 @@ public class OperationsService extends Service {
                             mOwnCloudClient.setBasicCredentials(mLastTarget.mUsername, mLastTarget.mPassword);
                         } else if (mLastTarget.mAuthToken != "") {
                             mOwnCloudClient.setBearerCredentials(mLastTarget.mAuthToken);
                             mOwnCloudClient.setBasicCredentials(mLastTarget.mUsername, mLastTarget.mPassword);
                         } else if (mLastTarget.mAuthToken != "") {
                             mOwnCloudClient.setBearerCredentials(mLastTarget.mAuthToken);
+                        } else if (mLastTarget.mCookie != "") {
+                            mOwnCloudClient.setSsoSessionCookie(mLastTarget.mCookie);
                         }
                         mStorageManager = null;
                     }
                         }
                         mStorageManager = null;
                     }