X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/1bda7e1e872273e48cc5bf1ae8f289e6d03f00ab..281212045672b8439f09e50896d90a1f5c7524f1:/src/com/owncloud/android/authentication/AuthenticatorActivity.java diff --git a/src/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/com/owncloud/android/authentication/AuthenticatorActivity.java index e5e80144..cf768833 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -25,8 +25,11 @@ import android.accounts.AccountManager; import android.app.AlertDialog; import android.app.Dialog; import android.app.ProgressDialog; +import android.content.ComponentName; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; +import android.content.ServiceConnection; import android.content.SharedPreferences; import android.graphics.Rect; import android.graphics.drawable.Drawable; @@ -34,6 +37,7 @@ import android.net.Uri; import android.net.http.SslError; import android.os.Bundle; import android.os.Handler; +import android.os.IBinder; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentManager; @@ -54,6 +58,7 @@ import android.widget.CheckBox; import android.widget.EditText; import android.widget.TextView; import android.widget.TextView.OnEditorActionListener; +import android.widget.Toast; import com.actionbarsherlock.app.SherlockDialogFragment; import com.owncloud.android.MainApp; @@ -76,6 +81,8 @@ import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCo import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import com.owncloud.android.lib.resources.users.GetRemoteUserNameOperation; +import com.owncloud.android.services.OperationsService; +import com.owncloud.android.services.OperationsService.OperationsServiceBinder; import com.owncloud.android.ui.dialog.SamlWebViewDialog; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog; import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener; @@ -140,6 +147,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private int mAuthStatusText, mAuthStatusIcon; private TextView mAuthStatusLayout; + private ServiceConnection mOperationsConnection = null; + private OperationsServiceBinder mOperationsBinder = null; + private final Handler mHandler = new Handler(); private Thread mOperationThread; private GetRemoteStatusOperation mOcServerChkOperation; @@ -177,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; /** @@ -191,6 +203,32 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); + // bind to Operations Service + mOperationsConnection = new ServiceConnection() { + + @Override + public void onServiceConnected(ComponentName name, IBinder service) { + Log_OC.d(TAG, "Operations service connected"); + mOperationsBinder = (OperationsServiceBinder) service; + } + + @Override + public void onServiceDisconnected(ComponentName name) { + Log_OC.d(TAG, "Operations service crashed"); + mOperationsBinder = null; + } + + }; + if (!bindService(new Intent(this, OperationsService.class), + mOperationsConnection, + Context.BIND_AUTO_CREATE)) { + Toast.makeText(this, + R.string.error_cant_bind_to_operations_service, + Toast.LENGTH_LONG) + .show(); + finish(); + } + /// set view and get references to view elements setContentView(R.layout.account_setup); mAuthMessage = (TextView) findViewById(R.id.auth_message); @@ -394,6 +432,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { return false; } }); + + mOperationsServiceConnection = new OperationsServiceConnection(); + bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection, Context.BIND_AUTO_CREATE); } @@ -477,7 +518,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { // refresh button enabled outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE)); - } @@ -497,7 +537,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } } - /** * The redirection triggered by the OAuth authentication server as response to the GET AUTHORIZATION, and * deferred in {@link #onNewIntent(Intent)}, is processed here. @@ -525,6 +564,16 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mJustCreated = false; } + + + @Override + protected void onDestroy() { + if (mOperationsConnection != null) { + unbindService(mOperationsConnection); + mOperationsBinder = null; + } + super.onDestroy(); + } /** @@ -963,14 +1012,15 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private void detectAuthorizationMethod() { 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); + service.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path); + startService(service); } @@ -1796,4 +1846,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 + } + } + + } }