Add webdav url to DetectAuthenticationMethodOperation
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index 255ed80..cf76883 100644 (file)
@@ -58,6 +58,7 @@ import android.widget.CheckBox;
 import android.widget.EditText;\r
 import android.widget.TextView;\r
 import android.widget.TextView.OnEditorActionListener;\r
 import android.widget.EditText;\r
 import android.widget.TextView;\r
 import android.widget.TextView.OnEditorActionListener;\r
+import android.widget.Toast;\r
 \r
 import com.actionbarsherlock.app.SherlockDialogFragment;\r
 import com.owncloud.android.MainApp;\r
 \r
 import com.actionbarsherlock.app.SherlockDialogFragment;\r
 import com.owncloud.android.MainApp;\r
@@ -146,6 +147,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private int mAuthStatusText, mAuthStatusIcon;    \r
     private TextView mAuthStatusLayout;\r
 \r
     private int mAuthStatusText, mAuthStatusIcon;    \r
     private TextView mAuthStatusLayout;\r
 \r
+    private ServiceConnection mOperationsConnection = null;\r
+    private OperationsServiceBinder mOperationsBinder = null;\r
+    \r
     private final Handler mHandler = new Handler();\r
     private Thread mOperationThread;\r
     private GetRemoteStatusOperation mOcServerChkOperation;\r
     private final Handler mHandler = new Handler();\r
     private Thread mOperationThread;\r
     private GetRemoteStatusOperation mOcServerChkOperation;\r
@@ -199,6 +203,32 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         super.onCreate(savedInstanceState);\r
         getWindow().requestFeature(Window.FEATURE_NO_TITLE);\r
 \r
         super.onCreate(savedInstanceState);\r
         getWindow().requestFeature(Window.FEATURE_NO_TITLE);\r
 \r
+        // bind to Operations Service\r
+        mOperationsConnection = new ServiceConnection() {\r
+\r
+            @Override\r
+            public void onServiceConnected(ComponentName name, IBinder service) {\r
+                Log_OC.d(TAG, "Operations service connected");\r
+                mOperationsBinder = (OperationsServiceBinder) service;\r
+            }\r
+\r
+            @Override\r
+            public void onServiceDisconnected(ComponentName name) {\r
+                Log_OC.d(TAG, "Operations service crashed");\r
+                mOperationsBinder = null;\r
+            }\r
+            \r
+        };\r
+        if (!bindService(new Intent(this, OperationsService.class), \r
+                        mOperationsConnection, \r
+                        Context.BIND_AUTO_CREATE)) {\r
+            Toast.makeText(this, \r
+                    R.string.error_cant_bind_to_operations_service, \r
+                    Toast.LENGTH_LONG)\r
+                        .show();\r
+            finish();\r
+        }\r
+\r
         /// set view and get references to view elements\r
         setContentView(R.layout.account_setup);\r
         mAuthMessage = (TextView) findViewById(R.id.auth_message);\r
         /// set view and get references to view elements\r
         setContentView(R.layout.account_setup);\r
         mAuthMessage = (TextView) findViewById(R.id.auth_message);\r
@@ -488,7 +518,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         // refresh button enabled\r
         outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
 \r
         // refresh button enabled\r
         outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE));\r
 \r
-\r
     }\r
 \r
 \r
     }\r
 \r
 \r
@@ -508,7 +537,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         }\r
     }\r
 \r
         }\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
     /**\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
@@ -536,6 +564,16 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         mJustCreated = false;\r
 \r
     }\r
         mJustCreated = false;\r
 \r
     }\r
+    \r
+    \r
+    @Override\r
+    protected void onDestroy() {\r
+        if (mOperationsConnection != null) {\r
+            unbindService(mOperationsConnection);\r
+            mOperationsBinder = null;\r
+        }\r
+        super.onDestroy();\r
+    }\r
 \r
 \r
     /**\r
 \r
 \r
     /**\r
@@ -974,11 +1012,14 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private void detectAuthorizationMethod() {\r
 \r
         Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
     private void detectAuthorizationMethod() {\r
 \r
         Log_OC.d(TAG, "Trying empty authorization to detect authentication method");\r
-\r
+        \r
+        String webdav_path = AccountUtils.getWebdavPath(mDiscoveredVersion, mAuthTokenType);\r
+        \r
         /// test credentials \r
         /// test credentials \r
-        Intent service = new Intent(this, OperationsService.class);\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.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
         startService(service);\r
     }\r
 \r