From: masensio Date: Tue, 1 Apr 2014 12:18:32 +0000 (+0200) Subject: Merge branch 'develop' into operations_service X-Git-Tag: oc-android-1.7.0_signed~345^2~14^2~1 X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/commitdiff_plain/5ac1a1ebbb78aaa7b85318bd7542b1c047291d19?hp=-c Merge branch 'develop' into operations_service --- 5ac1a1ebbb78aaa7b85318bd7542b1c047291d19 diff --combined src/com/owncloud/android/authentication/AuthenticatorActivity.java index 129da6c9,8cbe7ad8..69eea77b --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@@ -25,11 -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; @@@ -37,7 -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; @@@ -45,7 -41,6 +45,7 @@@ import android.support.v4.app.FragmentT import android.text.Editable; import android.text.InputType; import android.text.TextWatcher; +import android.util.Log; import android.view.KeyEvent; import android.view.MotionEvent; import android.view.View; @@@ -59,7 -54,6 +59,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; @@@ -82,8 -76,6 +82,8 @@@ import com.owncloud.android.lib.common. 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; @@@ -112,7 -104,6 +112,6 @@@ SsoWebViewClientListener, OnSslUntruste private static final String KEY_AUTH_MESSAGE_TEXT = "AUTH_MESSAGE_TEXT"; private static final String KEY_HOST_URL_TEXT = "HOST_URL_TEXT"; private static final String KEY_OC_VERSION = "OC_VERSION"; - private static final String KEY_OC_VERSION_STRING = "OC_VERSION_STRING"; private static final String KEY_ACCOUNT = "ACCOUNT"; private static final String KEY_SERVER_VALID = "SERVER_VALID"; private static final String KEY_SERVER_CHECKED = "SERVER_CHECKED"; @@@ -125,9 -116,6 +124,9 @@@ private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON"; private static final String KEY_REFRESH_BUTTON_ENABLED = "KEY_REFRESH_BUTTON_ENABLED"; //private static final String KEY_IS_SHARED_SUPPORTED = "KEY_IS_SHARE_SUPPORTED"; + private static final String KEY_SERVER_AUTH_METHOD = "KEY_SERVER_AUTH_METHOD"; + private static final String KEY_DETECT_AUTH_OP_ID = "KEY_DETECT_AUTH_OP_ID"; + private static final String AUTH_ON = "on"; private static final String AUTH_OFF = "off"; @@@ -148,9 -136,6 +147,9 @@@ private String mAuthMessageText; private int mAuthMessageVisibility, mServerStatusText, mServerStatusIcon; private boolean mServerIsChecked, mServerIsValid, mIsSslConn; + private AuthenticationMethod mServerAuthMethod = AuthenticationMethod.UNKNOWN; + private int mDetectAuthOpId = -1; + private int mAuthStatusText, mAuthStatusIcon; private TextView mAuthStatusLayout; @@@ -191,10 -176,9 +190,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; /** * {@inheritDoc} @@@ -206,18 -190,6 +205,18 @@@ super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); + // bind to Operations Service + mOperationsServiceConnection = new OperationsServiceConnection(); + if (!bindService(new Intent(this, OperationsService.class), + mOperationsServiceConnection, + 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); @@@ -277,10 -249,9 +276,9 @@@ /// retrieve extras from intent mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT); if (mAccount != null) { - String ocVersion = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION); - String ocVersionString = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION_STRING); + String ocVersion = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_VERSION); if (ocVersion != null) { - mDiscoveredVersion = new OwnCloudVersion(ocVersion, ocVersionString); + mDiscoveredVersion = new OwnCloudVersion(ocVersion); } mHostBaseUrl = normalizeUrl(mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL)); mHostUrlInput.setText(mHostBaseUrl); @@@ -313,9 -284,8 +311,8 @@@ /// server data String ocVersion = savedInstanceState.getString(KEY_OC_VERSION); - String ocVersionString = savedInstanceState.getString(KEY_OC_VERSION_STRING); if (ocVersion != null) { - mDiscoveredVersion = new OwnCloudVersion(ocVersion, ocVersionString); + mDiscoveredVersion = new OwnCloudVersion(ocVersion); } mHostBaseUrl = savedInstanceState.getString(KEY_HOST_URL_TEXT); @@@ -336,10 -306,6 +333,10 @@@ refreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED); + mServerAuthMethod = AuthenticationMethod.valueOf( + savedInstanceState.getString(KEY_SERVER_AUTH_METHOD)); + mDetectAuthOpId = savedInstanceState.getInt(KEY_DETECT_AUTH_OP_ID); + } if (mAuthMessageVisibility== View.VISIBLE) { @@@ -425,7 -391,6 +422,7 @@@ return false; } }); + } @@@ -478,7 -443,6 +475,7 @@@ */ @Override protected void onSaveInstanceState(Bundle outState) { + //Log.wtf(TAG, "onSaveInstanceState init" ); super.onSaveInstanceState(outState); /// connection state and info @@@ -497,7 -461,6 +494,6 @@@ /// server data if (mDiscoveredVersion != null) { outState.putString(KEY_OC_VERSION, mDiscoveredVersion.getVersion()); - outState.putString(KEY_OC_VERSION_STRING, mDiscoveredVersion.getVersionString()); } outState.putString(KEY_HOST_URL_TEXT, mHostBaseUrl); @@@ -509,10 -472,8 +505,10 @@@ // refresh button enabled outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE)); - - + + outState.putString(KEY_SERVER_AUTH_METHOD, mServerAuthMethod.name()); + outState.putInt(KEY_DETECT_AUTH_OP_ID, mDetectAuthOpId); + //Log.wtf(TAG, "onSaveInstanceState end" ); } @@@ -539,9 -500,7 +535,9 @@@ */ @Override protected void onResume() { + //Log.wtf(TAG, "onResume init" ); super.onResume(); + if (mAction == ACTION_UPDATE_TOKEN && mJustCreated && getIntent().getBooleanExtra(EXTRA_ENFORCED_UPDATE, false)) { if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType)) { //Toast.makeText(this, R.string.auth_expired_oauth_token_toast, Toast.LENGTH_LONG).show(); @@@ -558,35 -517,9 +554,35 @@@ if (mNewCapturedUriFromOAuth2Redirection != null) { getOAuth2AccessTokenFromCapturedRedirection(); } - + mJustCreated = false; + if (mOperationsServiceBinder != null) { + doOnResumeAndBound(); + } + + //Log.wtf(TAG, "onResume end" ); + } + + + @Override + protected void onPause() { + //Log.wtf(TAG, "onPause init" ); + if (mOperationsServiceBinder != null) { + //Log.wtf(TAG, "unregistering to listen for operation callbacks" ); + mOperationsServiceBinder.removeOperationListener(this); + } + super.onPause(); + //Log.wtf(TAG, "onPause end" ); + } + + @Override + protected void onDestroy() { + if (mOperationsServiceConnection != null) { + unbindService(mOperationsServiceConnection); + mOperationsServiceBinder = null; + } + super.onDestroy(); } @@@ -878,15 -811,13 +874,15 @@@ onGetUserNameFinish((GetRemoteUserNameOperation) operation, result); } else if (operation instanceof DetectAuthenticationMethodOperation) { - onDetectAutheticationFinish((DetectAuthenticationMethodOperation) operation, result); + Log.wtf(TAG, "received detection response through callback" ); + onDetectAuthenticationFinish(result); } } - private void onDetectAutheticationFinish(DetectAuthenticationMethodOperation operation, RemoteOperationResult result) { + private void onDetectAuthenticationFinish(RemoteOperationResult result) { // Read authentication method + mDetectAuthOpId = -1; if (result.getData().size() > 0) { AuthenticationMethod authMethod = (AuthenticationMethod) result.getData().get(0); String basic = AccountTypeUtils.getAuthTokenTypePass(MainApp.getAccountType()); @@@ -1028,23 -959,14 +1024,23 @@@ 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 detectAuthIntent = new Intent(this, OperationsService.class); + Intent detectAuthIntent = new Intent(); + detectAuthIntent.setAction(OperationsService.ACTION_DETECT_AUTHENTICATION_METHOD); + detectAuthIntent.putExtra(OperationsService.EXTRA_SERVER_URL, mHostBaseUrl); + detectAuthIntent.putExtra(OperationsService.EXTRA_WEBDAV_PATH, webdav_path); + + //if (mOperationsBinder != null) { // let's let it crash to detect if is really possible + mServerAuthMethod = AuthenticationMethod.UNKNOWN; + if (mOperationsServiceBinder != null) { + //Log.wtf(TAG, "starting detection..." ); + mDetectAuthOpId = mOperationsServiceBinder.newOperation(detectAuthIntent); + } + //} } @@@ -1444,7 -1366,6 +1440,6 @@@ } /// add user data to the new account; TODO probably can be done in the last parameter addAccountExplicitly, or in KEY_USERDATA mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION, mDiscoveredVersion.getVersion()); - mAccountMgr.setUserData(mAccount, Constants.KEY_OC_VERSION_STRING, mDiscoveredVersion.getVersionString()); mAccountMgr.setUserData(mAccount, Constants.KEY_OC_BASE_URL, mHostBaseUrl); if (isSaml) { @@@ -1869,49 -1790,5 +1864,49 @@@ } } + + + private void doOnResumeAndBound() { + //Log.wtf(TAG, "registering to listen for operation callbacks" ); + mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler); + + if (mDetectAuthOpId != -1) { + RemoteOperationResult result = + mOperationsServiceBinder.getOperationResultIfFinished(mDetectAuthOpId); + if (result != null) { + //Log.wtf(TAG, "found result of operation finished while rotating"); + onDetectAuthenticationFinish(result); + } + } + } + + /** + * Implements callback methods for service binding. + */ + private class OperationsServiceConnection implements ServiceConnection { + + @Override + public void onServiceConnected(ComponentName component, IBinder service) { + if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) { + //Log_OC.wtf(TAG, "Operations service connected"); + mOperationsServiceBinder = (OperationsServiceBinder) service; + + doOnResumeAndBound(); + + } else { + return; + } + + } + @Override + public void onServiceDisconnected(ComponentName component) { + if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) { + Log_OC.e(TAG, "Operations service crashed"); + mOperationsServiceBinder = null; + } + } + + } + }