Updated .gitmodules for easier access to ownCloud library from different environments
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index ad40a06..61e31b4 100644 (file)
@@ -53,23 +53,25 @@ import com.actionbarsherlock.app.SherlockDialogFragment;
 import com.owncloud.android.MainApp;\r
 import com.owncloud.android.R;\r
 import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
 import com.owncloud.android.MainApp;\r
 import com.owncloud.android.R;\r
 import com.owncloud.android.authentication.SsoWebViewClient.SsoWebViewClientListener;\r
-import com.owncloud.android.oc_framework.accounts.AccountTypeUtils;\r
-import com.owncloud.android.oc_framework.accounts.OwnCloudAccount;\r
-import com.owncloud.android.oc_framework.network.webdav.OwnCloudClientFactory;\r
-import com.owncloud.android.oc_framework.network.webdav.WebdavClient;\r
+import com.owncloud.android.lib.accounts.AccountTypeUtils;\r
+import com.owncloud.android.lib.accounts.OwnCloudAccount;\r
+import com.owncloud.android.lib.network.OwnCloudClientFactory;\r
+import com.owncloud.android.lib.network.OwnCloudClient;\r
 import com.owncloud.android.operations.OAuth2GetAccessToken;\r
 import com.owncloud.android.operations.OAuth2GetAccessToken;\r
-import com.owncloud.android.oc_framework.operations.OnRemoteOperationListener;\r
-import com.owncloud.android.operations.OwnCloudServerCheckOperation;\r
-import com.owncloud.android.oc_framework.operations.RemoteOperation;\r
-import com.owncloud.android.oc_framework.operations.RemoteOperationResult;\r
-import com.owncloud.android.oc_framework.operations.RemoteOperationResult.ResultCode;\r
-import com.owncloud.android.oc_framework.operations.remote.ExistenceCheckRemoteOperation;\r
-import com.owncloud.android.oc_framework.operations.remote.GetUserNameRemoteOperation;\r
+
+import com.owncloud.android.lib.operations.common.OnRemoteOperationListener;\r
+import com.owncloud.android.lib.operations.remote.OwnCloudServerCheckOperation;\r
+import com.owncloud.android.lib.operations.common.RemoteOperation;\r
+import com.owncloud.android.lib.operations.common.RemoteOperationResult;\r
+import com.owncloud.android.lib.operations.common.RemoteOperationResult.ResultCode;\r
+import com.owncloud.android.lib.operations.remote.ExistenceCheckRemoteOperation;\r
+import com.owncloud.android.lib.operations.remote.GetUserNameRemoteOperation;\r
+
 import com.owncloud.android.ui.dialog.SamlWebViewDialog;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
 import com.owncloud.android.utils.Log_OC;\r
 import com.owncloud.android.ui.dialog.SamlWebViewDialog;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog;\r
 import com.owncloud.android.ui.dialog.SslValidatorDialog.OnSslValidatorListener;\r
 import com.owncloud.android.utils.Log_OC;\r
-import com.owncloud.android.oc_framework.utils.OwnCloudVersion;\r
+import com.owncloud.android.lib.utils.OwnCloudVersion;\r
 \r
 /**\r
  * This Activity is used to add an ownCloud account to the App\r
 \r
 /**\r
  * This Activity is used to add an ownCloud account to the App\r
@@ -92,6 +94,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     private static final String KEY_AUTH_MESSAGE_TEXT = "AUTH_MESSAGE_TEXT";\r
     private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";\r
     private static final String KEY_OC_VERSION = "OC_VERSION";\r
     private static final String KEY_AUTH_MESSAGE_TEXT = "AUTH_MESSAGE_TEXT";\r
     private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT";\r
     private static final String KEY_OC_VERSION = "OC_VERSION";\r
+    private static final String KEY_OC_VERSION_STRING = "OC_VERSION_STRING";\r
     private static final String KEY_ACCOUNT = "ACCOUNT";\r
     private static final String KEY_SERVER_VALID = "SERVER_VALID";\r
     private static final String KEY_SERVER_CHECKED = "SERVER_CHECKED";\r
     private static final String KEY_ACCOUNT = "ACCOUNT";\r
     private static final String KEY_SERVER_VALID = "SERVER_VALID";\r
     private static final String KEY_SERVER_CHECKED = "SERVER_CHECKED";\r
@@ -103,6 +106,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
     private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
     private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED";\r
     private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT";\r
     private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON";\r
     private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED";\r
+    private static final String KEY_IS_SHARED_SUPPORTED = "KEY_IS_SHARE_SUPPORTED";\r
 \r
     private static final String AUTH_ON = "on";\r
     private static final String AUTH_OFF = "off";\r
 \r
     private static final String AUTH_ON = "on";\r
     private static final String AUTH_OFF = "off";\r
@@ -235,13 +239,15 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);\r
             if (mAccount != null) {\r
                 String ocVersion = mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION);\r
             mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);\r
             if (mAccount != null) {\r
                 String ocVersion = mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION);\r
+                String ocVersionString = mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING);\r
                 if (ocVersion != null) {\r
                 if (ocVersion != null) {\r
-                    mDiscoveredVersion = new OwnCloudVersion(ocVersion);\r
+                    mDiscoveredVersion = new OwnCloudVersion(ocVersion, ocVersionString);\r
                 }\r
                 mHostBaseUrl = normalizeUrl(mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL));\r
                 mHostUrlInput.setText(mHostBaseUrl);\r
                 String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
                 mUsernameInput.setText(userName);\r
                 }\r
                 mHostBaseUrl = normalizeUrl(mAccountMgr.getUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL));\r
                 mHostUrlInput.setText(mHostBaseUrl);\r
                 String userName = mAccount.name.substring(0, mAccount.name.lastIndexOf('@'));\r
                 mUsernameInput.setText(userName);\r
+                \r
             }\r
             initAuthorizationMethod();  // checks intent and setup.xml to determine mCurrentAuthorizationMethod\r
             mJustCreated = true;\r
             }\r
             initAuthorizationMethod();  // checks intent and setup.xml to determine mCurrentAuthorizationMethod\r
             mJustCreated = true;\r
@@ -268,8 +274,9 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             \r
             /// server data\r
             String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);\r
             \r
             /// server data\r
             String ocVersion = savedInstanceState.getString(KEY_OC_VERSION);\r
+            String ocVersionString = savedInstanceState.getString(KEY_OC_VERSION_STRING);\r
             if (ocVersion != null) {\r
             if (ocVersion != null) {\r
-                mDiscoveredVersion = new OwnCloudVersion(ocVersion);\r
+                mDiscoveredVersion = new OwnCloudVersion(ocVersion, ocVersionString);\r
             }\r
             mHostBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);\r
 \r
             }\r
             mHostBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT);\r
 \r
@@ -444,7 +451,8 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
         /// server data\r
         if (mDiscoveredVersion != null) {\r
 \r
         /// server data\r
         if (mDiscoveredVersion != null) {\r
-            outState.putString(KEY_OC_VERSION, mDiscoveredVersion.toString());\r
+            outState.putString(KEY_OC_VERSION, mDiscoveredVersion.getVersion());\r
+            outState.putString(KEY_OC_VERSION_STRING, mDiscoveredVersion.getVersionString());\r
         }\r
         outState.putString(KEY_HOST_URL_TEXT, mHostBaseUrl);\r
 \r
         }\r
         outState.putString(KEY_HOST_URL_TEXT, mHostBaseUrl);\r
 \r
@@ -524,8 +532,8 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 getString(R.string.oauth2_redirect_uri),       \r
                 getString(R.string.oauth2_grant_type),\r
                 queryParameters);\r
                 getString(R.string.oauth2_redirect_uri),       \r
                 getString(R.string.oauth2_grant_type),\r
                 queryParameters);\r
-        //WebdavClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());\r
-        WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mOAuthTokenEndpointText.getText().toString().trim()), getApplicationContext(), true);\r
+        //OwnCloudClient client = OwnCloudClientUtils.createOwnCloudClient(Uri.parse(getString(R.string.oauth2_url_endpoint_access)), getApplicationContext());\r
+        OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mOAuthTokenEndpointText.getText().toString().trim()), getApplicationContext(), true);\r
         operation.execute(client, this, mHandler);\r
     }\r
 \r
         operation.execute(client, this, mHandler);\r
     }\r
 \r
@@ -589,7 +597,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             mServerStatusIcon = R.drawable.progress_small;\r
             showServerStatus();\r
             mOcServerChkOperation = new  OwnCloudServerCheckOperation(uri, this);\r
             mServerStatusIcon = R.drawable.progress_small;\r
             showServerStatus();\r
             mOcServerChkOperation = new  OwnCloudServerCheckOperation(uri, this);\r
-            WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(uri), this, true);\r
+            OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(uri), this, true);\r
             mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
         } else {\r
             mServerStatusText = 0;\r
             mOperationThread = mOcServerChkOperation.execute(client, this, mHandler);\r
         } else {\r
             mServerStatusText = 0;\r
@@ -716,7 +724,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
         /// test credentials accessing the root folder\r
         mAuthCheckOperation = new  ExistenceCheckRemoteOperation("", this, false);\r
 \r
         /// test credentials accessing the root folder\r
         mAuthCheckOperation = new  ExistenceCheckRemoteOperation("", this, false);\r
-        WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
+        OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
         client.setBasicCredentials(username, password);\r
         mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
     }\r
         client.setBasicCredentials(username, password);\r
         mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
     }\r
@@ -765,7 +773,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
         /// test credentials accessing the root folder\r
         mAuthCheckOperation = new  ExistenceCheckRemoteOperation("", this, false);\r
 \r
         /// test credentials accessing the root folder\r
         mAuthCheckOperation = new  ExistenceCheckRemoteOperation("", this, false);\r
-        WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, false);\r
+        OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, false);\r
         mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
       \r
     }\r
         mOperationThread = mAuthCheckOperation.execute(client, this, mHandler);\r
       \r
     }\r
@@ -822,6 +830,10 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             \r
             if (success)\r
                 finish();\r
             \r
             if (success)\r
                 finish();\r
+        } else {\r
+            updateAuthStatusIconAndText(result);\r
+            showAuthStatus();\r
+            Log_OC.e(TAG, "Access to user name failed: " + result.getLogMessage());\r
         }\r
         \r
     }\r
         }\r
         \r
     }\r
@@ -890,7 +902,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
 \r
             /// allow or not the user try to access the server\r
             mOkButton.setEnabled(mServerIsValid);\r
 \r
             /// allow or not the user try to access the server\r
             mOkButton.setEnabled(mServerIsValid);\r
-\r
+            \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 can be triggered\r
     }\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 can be triggered\r
     }\r
@@ -1115,7 +1127,7 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
             mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
             Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
             mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false);\r
             mAuthToken = ((OAuth2GetAccessToken)operation).getResultTokenMap().get(OAuth2Constants.KEY_ACCESS_TOKEN);\r
             Log_OC.d(TAG, "Got ACCESS TOKEN: " + mAuthToken);\r
             mAuthCheckOperation = new ExistenceCheckRemoteOperation("", this, false);\r
-            WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
+            OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl + webdav_path), this, true);\r
             client.setBearerCredentials(mAuthToken);\r
             mAuthCheckOperation.execute(client, this, mHandler);\r
 \r
             client.setBearerCredentials(mAuthToken);\r
             mAuthCheckOperation.execute(client, this, mHandler);\r
 \r
@@ -1281,7 +1293,8 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
                 mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);\r
             }\r
             /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA\r
                 mAccountMgr.setAuthToken(mAccount, mAuthTokenType, mAuthToken);\r
             }\r
             /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA\r
-            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION,    mDiscoveredVersion.toString());\r
+            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION,         mDiscoveredVersion.getVersion());\r
+            mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_VERSION_STRING,  mDiscoveredVersion.getVersionString());\r
             mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL,   mHostBaseUrl);\r
             if (isSaml) {\r
                 mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); \r
             mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_OC_BASE_URL,   mHostBaseUrl);\r
             if (isSaml) {\r
                 mAccountMgr.setUserData(mAccount, OwnCloudAccount.Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE"); \r
@@ -1591,14 +1604,14 @@ implements  OnRemoteOperationListener, OnSslValidatorListener, OnFocusChangeList
     }\r
 \r
 \r
     }\r
 \r
 \r
-    public void onSamlDialogSuccess(String sessionCookie){\r
+    public void onSamlDialogSuccess(String sessionCookie) {\r
         mAuthToken = sessionCookie;\r
         \r
         if (sessionCookie != null && sessionCookie.length() > 0) {\r
             mAuthToken = sessionCookie;\r
 \r
             GetUserNameRemoteOperation getUserOperation = new GetUserNameRemoteOperation();            \r
         mAuthToken = sessionCookie;\r
         \r
         if (sessionCookie != null && sessionCookie.length() > 0) {\r
             mAuthToken = sessionCookie;\r
 \r
             GetUserNameRemoteOperation getUserOperation = new GetUserNameRemoteOperation();            \r
-            WebdavClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl), getApplicationContext(), true);\r
+            OwnCloudClient client = OwnCloudClientFactory.createOwnCloudClient(Uri.parse(mHostBaseUrl), getApplicationContext(), true);\r
             client.setSsoSessionCookie(mAuthToken);\r
             getUserOperation.execute(client, this, mHandler);\r
         }\r
             client.setSsoSessionCookie(mAuthToken);\r
             getUserOperation.execute(client, this, mHandler);\r
         }\r