From: David A. Velasco Date: Fri, 28 Mar 2014 11:57:44 +0000 (+0100) Subject: Merge remote-tracking branch 'origin/operations_service' into operations_service X-Git-Tag: oc-android-1.7.0_signed~345^2~21 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/7c4fc0486ffedcbbc35050d285570a4563befb2d?hp=-c Merge remote-tracking branch 'origin/operations_service' into operations_service --- 7c4fc0486ffedcbbc35050d285570a4563befb2d diff --combined src/com/owncloud/android/authentication/AuthenticatorActivity.java index 6ff9f6a7,255ed801..638b5dd8 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@@ -58,7 -58,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; @@@ -147,9 -146,6 +147,9 @@@ SsoWebViewClientListener, OnSslUntruste 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; @@@ -187,8 -183,10 +187,10 @@@ 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; /** @@@ -201,32 -199,6 +203,32 @@@ 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); @@@ -430,6 -402,9 +432,9 @@@ return false; } }); + + mOperationsServiceConnection = new OperationsServiceConnection(); + bindService(new Intent(this, OperationsService.class), mOperationsServiceConnection, Context.BIND_AUTO_CREATE); } @@@ -561,16 -536,6 +566,16 @@@ mJustCreated = false; } + + + @Override + protected void onDestroy() { + if (mOperationsConnection != null) { + unbindService(mOperationsConnection); + mOperationsBinder = null; + } + super.onDestroy(); + } /** @@@ -1010,13 -975,11 +1015,11 @@@ 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 -1805,31 +1845,31 @@@ } + /** + * 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 + } + } + + } } diff --combined src/com/owncloud/android/services/OperationsService.java index 9dc89709,bef03ada..4d1789e7 --- a/src/com/owncloud/android/services/OperationsService.java +++ b/src/com/owncloud/android/services/OperationsService.java @@@ -1,5 -1,5 +1,5 @@@ /* ownCloud Android client application - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2012-2014 ownCloud Inc. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, @@@ -32,6 -32,7 +32,7 @@@ import com.owncloud.android.lib.common. 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 +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 +62,7 @@@ 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 +135,9 @@@ 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;