X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/af45cabf35fd1f8fa48038930a0a59d0ad121037..cfe589231a558f3f7e5ce483ae46f1422182e8e1:/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 a9fac0c4..32bbcdcc 100644 --- a/src/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -43,7 +43,6 @@ 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; @@ -114,12 +113,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 = "WAITING_FOR_OP_ID"; private static final String KEY_AUTH_TOKEN = "AUTH_TOKEN"; private static final String AUTH_ON = "on"; @@ -158,6 +153,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private boolean mServerIsChecked = false; private boolean mServerIsValid = false; + private boolean mPendingAutoCheck = false; private GetServerInfoOperation.ServerInfo mServerInfo = new GetServerInfoOperation.ServerInfo(); @@ -177,12 +173,9 @@ 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; + /** * {@inheritDoc} @@ -191,7 +184,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { */ @Override protected void onCreate(Bundle savedInstanceState) { - Log_OC.wtf(TAG, "onCreate init"); + //Log_OC.wtf(TAG, "onCreate init"); super.onCreate(savedInstanceState); getWindow().requestFeature(Window.FEATURE_NO_TITLE); @@ -218,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 @@ -226,13 +220,15 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /// initialize general UI elements initOverallUi(savedInstanceState); + mOkButton = findViewById(R.id.buttonOK); + /// initialize block to be moved to single Fragment to check server and get info about it initServerPreFragment(savedInstanceState); /// initialize block to be moved to single Fragment to retrieve and validate credentials initAuthorizationPreFragment(savedInstanceState); - Log_OC.wtf(TAG, "onCreate end"); + //Log_OC.wtf(TAG, "onCreate end"); } private void initAuthTokenType() { @@ -314,7 +310,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState) boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input); - //boolean refreshButtonEnabled = false; if (savedInstanceState == null) { if (mAccount != null) { mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL); @@ -328,7 +323,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://"); } } else { - //refreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED); mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT); mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON); @@ -345,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...) @@ -364,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(); @@ -415,12 +407,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { }); - /// step 4 - automatic actions to start - if (savedInstanceState == null) { - if (mAction != ACTION_CREATE || !isUrlInputAllowed) { - checkOcServer(); - } - } + /// step 4 - mark automatic check to be started when OperationsService is ready + mPendingAutoCheck = (savedInstanceState == null && + (mAction != ACTION_CREATE || !isUrlInputAllowed)); } @@ -437,7 +426,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mUsernameInput = (EditText) findViewById(R.id.account_username); mPasswordInput = (EditText) findViewById(R.id.account_password); mAuthStatusView = (TextView) findViewById(R.id.auth_status_text); - mOkButton = findViewById(R.id.buttonOK); /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState) String presetUserName = null; @@ -452,9 +440,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...) @@ -548,19 +533,17 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { */ @Override protected void onSaveInstanceState(Bundle outState) { - Log.wtf(TAG, "onSaveInstanceState init" ); + //Log_OC.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); @@ -574,11 +557,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_OC.wtf(TAG, "onSaveInstanceState end" ); } @@ -605,7 +585,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { */ @Override protected void onResume() { - Log_OC.wtf(TAG, "onResume init" ); + //Log_OC.wtf(TAG, "onResume init" ); super.onResume(); // bound here to avoid spurious changes triggered by Android on device rotations @@ -620,15 +600,15 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { doOnResumeAndBound(); } - Log_OC.wtf(TAG, "onResume end" ); + //Log_OC.wtf(TAG, "onResume end" ); } @Override protected void onPause() { - Log.wtf(TAG, "onPause init" ); + //Log_OC.wtf(TAG, "onPause init" ); if (mOperationsServiceBinder != null) { - Log.wtf(TAG, "unregistering to listen for operation callbacks" ); + //Log_OC.wtf(TAG, "unregistering to listen for operation callbacks" ); mOperationsServiceBinder.removeOperationListener(this); } @@ -636,7 +616,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mHostUrlInput.setOnFocusChangeListener(null); super.onPause(); - Log.wtf(TAG, "onPause end" ); + //Log_OC.wtf(TAG, "onPause end" ); } @Override @@ -679,8 +659,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); } } @@ -745,8 +725,10 @@ 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 { + Log_OC.wtf(TAG, "Server check tried with OperationService unbound!" ); } } else { @@ -778,10 +760,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private void showViewPasswordButton() { - //int drawable = android.R.drawable.ic_menu_view; int drawable = R.drawable.ic_view; if (isPasswordVisible()) { - //drawable = android.R.drawable.ic_secure; drawable = R.drawable.ic_hide; } mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0); @@ -829,7 +809,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { mServerStatusText = R.string.auth_wtf_reenter_URL; showServerStatus(); mOkButton.setEnabled(false); - Log_OC.wtf(TAG, "The user was allowed to click 'connect' to an unchecked server!!"); + //Log_OC.wtf(TAG, "The user was allowed to click 'connect' to an unchecked server!!"); return; } @@ -882,8 +862,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { existenceCheckIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects); if (mOperationsServiceBinder != null) { - Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." ); - mExistenceCheckOpId = mOperationsServiceBinder.newOperation(existenceCheckIntent); + //Log_OC.wtf(TAG, "starting existenceCheckRemoteOperation..." ); + mWaitingForOpId = mOperationsServiceBinder.newOperation(existenceCheckIntent); } } @@ -898,14 +878,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { showAuthStatus(); // GET AUTHORIZATION request - //Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth)); Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim()); Uri.Builder uriBuilder = uri.buildUpon(); uriBuilder.appendQueryParameter(OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type)); uriBuilder.appendQueryParameter(OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri)); uriBuilder.appendQueryParameter(OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id)); uriBuilder.appendQueryParameter(OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope)); - //uriBuilder.appendQueryParameter(OAuth2Constants.KEY_STATE, whateverwewant); uri = uriBuilder.build(); Log_OC.d(TAG, "Starting browser to view " + uri.toString()); Intent i = new Intent(Intent.ACTION_VIEW, uri); @@ -946,7 +924,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 @@ -955,7 +933,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { onGetOAuthAccessTokenFinish(result); } else if (operation instanceof ExistenceCheckRemoteOperation) { - Log_OC.wtf(TAG, "received detection response through callback" ); + //Log_OC.wtf(TAG, "received detection response through callback" ); if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).equals(mAuthTokenType)) { onSamlBasedFederatedSingleSignOnAuthorizationStart(result); @@ -969,7 +947,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); @@ -1002,10 +980,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { } private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperationResult result) { - mExistenceCheckOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; dismissDialog(WAIT_DIALOG_TAG); - //if (result.isTemporalRedirection() && result.isIdPRedirection()) { if (result.isIdPRedirection()) { String url = result.getRedirectedLocation(); String targetUrl = mServerInfo.mBaseUrl @@ -1037,7 +1014,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); @@ -1304,7 +1281,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); @@ -1343,7 +1320,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { * @param result Result of the operation. */ private void onAuthorizationCheckFinish(RemoteOperationResult result) { - mExistenceCheckOpId = -1; + mWaitingForOpId = Long.MAX_VALUE; dismissDialog(WAIT_DIALOG_TAG); if (result.isSuccess()) { @@ -1367,12 +1344,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { /// the server mServerIsChecked = true; mServerIsValid = false; - /* - mServerInfo.mIsSslConn = false; - mServerInfo.mVersion = null; - mServerInfo.mBaseUrl = - normalizeUrl(mHostUrlInput.getText().toString(), mServerInfo.mIsSslConn); // TODO remove? - */ mServerInfo = new GetServerInfoOperation.ServerInfo(); // update status icon and text @@ -1674,8 +1645,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { getUserNameIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects); if (mOperationsServiceBinder != null) { - Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." ); - mGetUserNameOpId = mOperationsServiceBinder.newOperation(getUserNameIntent); + //Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." ); + mWaitingForOpId = mOperationsServiceBinder.newOperation(getUserNameIntent); } } @@ -1769,51 +1740,15 @@ SsoWebViewClientListener, OnSslUntrustedCertListener { private void doOnResumeAndBound() { - Log.wtf(TAG, "registering to listen for operation callbacks" ); + //Log_OC.wtf(TAG, "registering to listen for operation callbacks" ); mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler); + if (mWaitingForOpId <= Integer.MAX_VALUE) { + mOperationsServiceBinder.dispatchResultIfFinished((int)mWaitingForOpId, this); + } - - - 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 (mPendingAutoCheck) { + checkOcServer(); + } } @@ -1834,7 +1769,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();