X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c1df34b5e38a671c7cd57aa223a5251812e84824..12bbc51dcbb7eccf4189dcc8f7d9c20aa634aad9:/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 99e114d5..fd0849e4 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -43,6 +43,7 @@ import android.support.v4.app.FragmentTransaction; 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; @@ -113,12 +114,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private static final String KEY_PASSWORD_EXPOSED = "PASSWORD_VISIBLE"; private static final String KEY_AUTH_STATUS_TEXT = "AUTH_STATUS_TEXT"; private static final String KEY_AUTH_STATUS_ICON = "AUTH_STATUS_ICON"; - private static final String KEY_REFRESH_BUTTON_ENABLED = "REFRESH_BUTTON_ENABLED"; private static final String KEY_SERVER_AUTH_METHOD = "SERVER_AUTH_METHOD"; - private static final String KEY_GET_SERVER_INFO_OP_ID = "DETECT_AUTH_OP_ID"; - private static final String KEY_EXISTENCE_CHECK_OP_ID = "EXISTENCE_CHECK_OP_ID"; - private static final String KEY_OAUTH2_GET_ACCESS_TOKEN_OP_ID = "OAUTH2_GET_ACCESS_TOKEN"; - private static final String KEY_GET_USER_NAME_OP_ID = "GET_USER_NAME"; + private static final String KEY_WAITING_FOR_OP_ID = "DETECT_AUTH_OP_ID"; private static final String KEY_AUTH_TOKEN = "AUTH_TOKEN"; private static final String AUTH_ON = "on"; @@ -176,11 +173,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private String mAuthToken = ""; - /// Operation-in-progress identifiers - TODO improve pull-interface with OperationsService - private int mGetServerInfoOpId = -1; - private int mOauth2GetAccessTokenOpId = -1; - private int mExistenceCheckOpId = -1; - private int mGetUserNameOpId = -1; + /// Identifier of operation in progress which result shouldn't be lost + private long mWaitingForOpId = Long.MAX_VALUE; /** @@ -217,6 +211,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { initAuthTokenType(); } else { mAuthTokenType = savedInstanceState.getString(KEY_AUTH_TOKEN_TYPE); + mWaitingForOpId = savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID); } /// load user interface @@ -344,9 +339,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mServerInfo.mAuthMethod = AuthenticationMethod.valueOf( savedInstanceState.getString(KEY_SERVER_AUTH_METHOD)); - // TODO save and recover any operation in progress, in a reasonable way - mGetServerInfoOpId = savedInstanceState.getInt(KEY_GET_SERVER_INFO_OP_ID); - } /// step 2 - set properties of UI elements (text, visibility, enabled...) @@ -363,7 +355,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { findViewById(R.id.hostUrlFrame).setVisibility(View.GONE); mRefreshButton = findViewById(R.id.centeredRefreshButton); } - showRefreshButton(mServerIsChecked && !mServerIsValid && mGetServerInfoOpId == -1); + showRefreshButton(mServerIsChecked && !mServerIsValid && + mWaitingForOpId > Integer.MAX_VALUE); mServerStatusView = (TextView) findViewById(R.id.server_status_text); showServerStatus(); @@ -451,9 +444,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mAuthStatusText = savedInstanceState.getInt(KEY_AUTH_STATUS_TEXT); mAuthStatusIcon = savedInstanceState.getInt(KEY_AUTH_STATUS_ICON); mAuthToken = savedInstanceState.getString(KEY_AUTH_TOKEN); - mExistenceCheckOpId = savedInstanceState.getInt(KEY_EXISTENCE_CHECK_OP_ID); - mOauth2GetAccessTokenOpId = savedInstanceState.getInt(KEY_OAUTH2_GET_ACCESS_TOKEN_OP_ID); - mGetUserNameOpId = savedInstanceState.getInt(KEY_GET_USER_NAME_OP_ID); } /// step 2 - set properties of UI elements (text, visibility, enabled...) @@ -547,19 +537,17 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { */ @Override protected void onSaveInstanceState(Bundle outState) { - //Log.wtf(TAG, "onSaveInstanceState init" ); + Log.wtf(TAG, "onSaveInstanceState init" ); super.onSaveInstanceState(outState); /// global state outState.putString(KEY_AUTH_TOKEN_TYPE, mAuthTokenType); + outState.putLong(KEY_WAITING_FOR_OP_ID, mWaitingForOpId); /// Server PRE-fragment state - //outState.putBoolean(KEY_REFRESH_BUTTON_ENABLED, (mRefreshButton.getVisibility() == View.VISIBLE)); outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText); outState.putInt(KEY_SERVER_STATUS_ICON, mServerStatusIcon); outState.putBoolean(KEY_SERVER_CHECKED, mServerIsChecked); - //outState.putBoolean(KEY_SERVER_CHECK_IN_PROGRESS, (!mServerIsValid && mServerInfoOperation != null)); - outState.putInt(KEY_GET_SERVER_INFO_OP_ID, mGetServerInfoOpId); outState.putBoolean(KEY_SERVER_VALID, mServerIsValid); outState.putBoolean(KEY_IS_SSL_CONN, mServerInfo.mIsSslConn); outState.putString(KEY_HOST_URL_TEXT, mServerInfo.mBaseUrl); @@ -573,11 +561,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { outState.putInt(KEY_AUTH_STATUS_ICON, mAuthStatusIcon); outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText); outState.putString(KEY_AUTH_TOKEN, mAuthToken); - outState.putInt(KEY_EXISTENCE_CHECK_OP_ID, mExistenceCheckOpId); - outState.putInt(KEY_OAUTH2_GET_ACCESS_TOKEN_OP_ID, mOauth2GetAccessTokenOpId); - outState.putInt(KEY_GET_USER_NAME_OP_ID, mGetUserNameOpId); - //Log.wtf(TAG, "onSaveInstanceState end" ); + Log.wtf(TAG, "onSaveInstanceState end" ); } @@ -625,9 +610,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { @Override protected void onPause() { - //Log.wtf(TAG, "onPause init" ); + Log.wtf(TAG, "onPause init" ); if (mOperationsServiceBinder != null) { - //Log.wtf(TAG, "unregistering to listen for operation callbacks" ); + Log.wtf(TAG, "unregistering to listen for operation callbacks" ); mOperationsServiceBinder.removeOperationListener(this); } @@ -635,7 +620,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mHostUrlInput.setOnFocusChangeListener(null); super.onPause(); - //Log.wtf(TAG, "onPause end" ); + Log.wtf(TAG, "onPause end" ); } @Override @@ -678,8 +663,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { queryParameters); if (mOperationsServiceBinder != null) { - //Log.wtf(TAG, "getting access token..." ); - mOauth2GetAccessTokenOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent); + //Log_OC.wtf(TAG, "getting access token..." ); + mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent); } } @@ -744,8 +729,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri); getServerInfoIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN_TYPE, mAuthTokenType); if (mOperationsServiceBinder != null) { - //Log.wtf(TAG, "checking server..." ); - mGetServerInfoOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent); + //Log_OC.wtf(TAG, "checking server..." ); + mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent); } } else { @@ -882,7 +867,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { if (mOperationsServiceBinder != null) { Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." ); - mExistenceCheckOpId = mOperationsServiceBinder.newOperation(existenceCheckIntent); + mWaitingForOpId = mOperationsServiceBinder.newOperation(existenceCheckIntent); } } @@ -945,7 +930,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { public void onRemoteOperationFinish(RemoteOperation operation, RemoteOperationResult result) { if (operation instanceof GetServerInfoOperation) { - if (operation.hashCode() == mGetServerInfoOpId) { + if (operation.hashCode() == mWaitingForOpId) { onGetServerInfoFinish(result); } // else nothing ; only the last check operation is considered; // multiple can be started if the user amends a URL quickly @@ -968,7 +953,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } private void onGetUserNameFinish(RemoteOperationResult result) { - mGetUserNameOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; if (result.isSuccess()) { boolean success = false; String username = (String) result.getData().get(0); @@ -1001,7 +986,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperationResult result) { - mExistenceCheckOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; dismissDialog(WAIT_DIALOG_TAG); //if (result.isTemporalRedirection() && result.isIdPRedirection()) { @@ -1036,7 +1021,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private void onGetServerInfoFinish(RemoteOperationResult result) { /// update activity state mServerIsChecked = true; - mGetServerInfoOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; // update server status, but don't show it yet updateServerStatusIconAndText(result); @@ -1303,7 +1288,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { * @param result Result of the operation. */ private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) { - mOauth2GetAccessTokenOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; dismissDialog(WAIT_DIALOG_TAG); String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType); @@ -1342,9 +1327,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { * @param result Result of the operation. */ private void onAuthorizationCheckFinish(RemoteOperationResult result) { - mExistenceCheckOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; dismissDialog(WAIT_DIALOG_TAG); + result = new RemoteOperationResult(new RuntimeException("FAKE")); if (result.isSuccess()) { Log_OC.d(TAG, "Successful access - time to save the account"); @@ -1674,7 +1660,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { if (mOperationsServiceBinder != null) { //Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." ); - mGetUserNameOpId = mOperationsServiceBinder.newOperation(getUserNameIntent); + mWaitingForOpId = mOperationsServiceBinder.newOperation(getUserNameIntent); } } @@ -1768,51 +1754,11 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private void doOnResumeAndBound() { - //Log.wtf(TAG, "registering to listen for operation callbacks" ); + Log.wtf(TAG, "registering to listen for operation callbacks" ); mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler); - - - - if (mGetServerInfoOpId != -1) { - RemoteOperationResult result = - mOperationsServiceBinder.getOperationResultIfFinished(mGetServerInfoOpId); - if (result != null) { - //Log_OC.wtf(TAG, "found result of operation finished while rotating"); - onGetServerInfoFinish(result); - } - - } else if (mOauth2GetAccessTokenOpId != -1) { - RemoteOperationResult result = - mOperationsServiceBinder.getOperationResultIfFinished( - mOauth2GetAccessTokenOpId); - if (result != null) { - //Log_OC.wtf(TAG, "found result of operation finished while rotating"); - onGetOAuthAccessTokenFinish(result); - } - - } else if (mExistenceCheckOpId != -1) { - RemoteOperationResult result = - mOperationsServiceBinder.getOperationResultIfFinished(mExistenceCheckOpId); - if (result != null) { - //Log_OC.wtf(TAG, "found result of operation finished while rotating"); - if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie( - MainApp.getAccountType()).equals(mAuthTokenType)) { - onSamlBasedFederatedSingleSignOnAuthorizationStart(result); - - } else { - onAuthorizationCheckFinish(result); - } - } - }if (mGetUserNameOpId != -1) { - RemoteOperationResult result = - mOperationsServiceBinder.getOperationResultIfFinished(mGetUserNameOpId); - if (result != null) { - //Log_OC.wtf(TAG, "found result of operation finished while rotating"); - onGetUserNameFinish(result); - } - - } - + if (mWaitingForOpId <= Integer.MAX_VALUE) { + mOperationsServiceBinder.dispatchResultIfFinished((int)mWaitingForOpId, this); + } } @@ -1833,7 +1779,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { @Override public void onServiceConnected(ComponentName component, IBinder service) { if (component.equals(new ComponentName(AuthenticatorActivity.this, OperationsService.class))) { - //Log_OC.wtf(TAG, "Operations service connected"); + Log_OC.wtf(TAG, "Operations service connected"); mOperationsServiceBinder = (OperationsServiceBinder) service; doOnResumeAndBound();