Removed commented code and remaining forced exception
[pub/Android/ownCloud.git] / src / com / owncloud / android / authentication / AuthenticatorActivity.java
index ee9d9bc..6011193 100644 (file)
@@ -43,7 +43,6 @@ import android.support.v4.app.FragmentTransaction;
 import android.text.Editable;\r
 import android.text.InputType;\r
 import android.text.TextWatcher;\r
 import android.text.Editable;\r
 import android.text.InputType;\r
 import android.text.TextWatcher;\r
-import android.util.Log;\r
 import android.view.KeyEvent;\r
 import android.view.MotionEvent;\r
 import android.view.View;\r
 import android.view.KeyEvent;\r
 import android.view.MotionEvent;\r
 import android.view.View;\r
@@ -174,7 +173,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 \r
     \r
     /// Identifier of operation in progress which result shouldn't be lost \r
 \r
     \r
     /// Identifier of operation in progress which result shouldn't be lost \r
-    private int mWaitingForOpId = -1;\r
+    private long mWaitingForOpId = Long.MAX_VALUE;\r
     \r
     \r
     /**\r
     \r
     \r
     /**\r
@@ -211,7 +210,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
             initAuthTokenType();\r
         } else {\r
             mAuthTokenType = savedInstanceState.getString(KEY_AUTH_TOKEN_TYPE);\r
             initAuthTokenType();\r
         } else {\r
             mAuthTokenType = savedInstanceState.getString(KEY_AUTH_TOKEN_TYPE);\r
-            mWaitingForOpId = savedInstanceState.getInt(KEY_WAITING_FOR_OP_ID);\r
+            mWaitingForOpId = savedInstanceState.getLong(KEY_WAITING_FOR_OP_ID);\r
         }\r
         \r
         /// load user interface\r
         }\r
         \r
         /// load user interface\r
@@ -308,7 +307,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 \r
         /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)\r
         boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input); \r
 \r
         /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState)\r
         boolean isUrlInputAllowed = getResources().getBoolean(R.bool.show_server_url_input); \r
-        //boolean refreshButtonEnabled = false;\r
         if (savedInstanceState == null) {\r
             if (mAccount != null) {\r
                 mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);\r
         if (savedInstanceState == null) {\r
             if (mAccount != null) {\r
                 mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);\r
@@ -322,7 +320,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                 mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");\r
             }\r
         } else {\r
                 mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");\r
             }\r
         } else {\r
-            //refreshButtonEnabled = savedInstanceState.getBoolean(KEY_REFRESH_BUTTON_ENABLED);\r
             mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);\r
             mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);\r
             \r
             mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);\r
             mServerStatusIcon = savedInstanceState.getInt(KEY_SERVER_STATUS_ICON);\r
             \r
@@ -355,7 +352,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
             findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);\r
             mRefreshButton = findViewById(R.id.centeredRefreshButton);\r
         }\r
             findViewById(R.id.hostUrlFrame).setVisibility(View.GONE);\r
             mRefreshButton = findViewById(R.id.centeredRefreshButton);\r
         }\r
-        showRefreshButton(mServerIsChecked && !mServerIsValid && mWaitingForOpId == -1);\r
+        showRefreshButton(mServerIsChecked && !mServerIsValid && \r
+                mWaitingForOpId > Integer.MAX_VALUE);\r
         mServerStatusView = (TextView) findViewById(R.id.server_status_text);\r
         showServerStatus();\r
         \r
         mServerStatusView = (TextView) findViewById(R.id.server_status_text);\r
         showServerStatus();\r
         \r
@@ -536,12 +534,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
      */\r
     @Override\r
     protected void onSaveInstanceState(Bundle outState) {\r
      */\r
     @Override\r
     protected void onSaveInstanceState(Bundle outState) {\r
-        Log.wtf(TAG, "onSaveInstanceState init" );\r
+        Log_OC.wtf(TAG, "onSaveInstanceState init" );\r
         super.onSaveInstanceState(outState);\r
 \r
         /// global state\r
         outState.putString(KEY_AUTH_TOKEN_TYPE, mAuthTokenType);\r
         super.onSaveInstanceState(outState);\r
 \r
         /// global state\r
         outState.putString(KEY_AUTH_TOKEN_TYPE, mAuthTokenType);\r
-        outState.putInt(KEY_WAITING_FOR_OP_ID, mWaitingForOpId);\r
+        outState.putLong(KEY_WAITING_FOR_OP_ID, mWaitingForOpId);\r
 \r
         /// Server PRE-fragment state\r
         outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText);\r
 \r
         /// Server PRE-fragment state\r
         outState.putInt(KEY_SERVER_STATUS_TEXT, mServerStatusText);\r
@@ -561,7 +559,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
         outState.putString(KEY_AUTH_TOKEN, mAuthToken);\r
 \r
         outState.putInt(KEY_AUTH_STATUS_TEXT, mAuthStatusText);\r
         outState.putString(KEY_AUTH_TOKEN, mAuthToken);\r
 \r
-        Log.wtf(TAG, "onSaveInstanceState end" );\r
+        Log_OC.wtf(TAG, "onSaveInstanceState end" );\r
     }\r
 \r
 \r
     }\r
 \r
 \r
@@ -609,9 +607,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     \r
     @Override\r
     protected void onPause() {\r
     \r
     @Override\r
     protected void onPause() {\r
-        Log.wtf(TAG, "onPause init" );\r
+        Log_OC.wtf(TAG, "onPause init" );\r
         if (mOperationsServiceBinder != null) {\r
         if (mOperationsServiceBinder != null) {\r
-            Log.wtf(TAG, "unregistering to listen for operation callbacks" );\r
+            Log_OC.wtf(TAG, "unregistering to listen for operation callbacks" );\r
             mOperationsServiceBinder.removeOperationListener(this);\r
         }\r
         \r
             mOperationsServiceBinder.removeOperationListener(this);\r
         }\r
         \r
@@ -619,7 +617,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         mHostUrlInput.setOnFocusChangeListener(null);\r
         \r
         super.onPause();\r
         mHostUrlInput.setOnFocusChangeListener(null);\r
         \r
         super.onPause();\r
-        Log.wtf(TAG, "onPause end" );\r
+        Log_OC.wtf(TAG, "onPause end" );\r
     }\r
     \r
     @Override\r
     }\r
     \r
     @Override\r
@@ -662,7 +660,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
                 queryParameters);\r
         \r
         if (mOperationsServiceBinder != null) {\r
                 queryParameters);\r
         \r
         if (mOperationsServiceBinder != null) {\r
-            //Log_OC.wtf(TAG, "getting access token..." );\r
+            Log_OC.wtf(TAG, "getting access token..." );\r
             mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
         }\r
     }\r
             mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
         }\r
     }\r
@@ -728,7 +726,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
             getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri);\r
             getServerInfoIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN_TYPE, mAuthTokenType);\r
             if (mOperationsServiceBinder != null) {\r
             getServerInfoIntent.putExtra(OperationsService.EXTRA_SERVER_URL, uri);\r
             getServerInfoIntent.putExtra(OperationsService.EXTRA_AUTH_TOKEN_TYPE, mAuthTokenType);\r
             if (mOperationsServiceBinder != null) {\r
-                //Log_OC.wtf(TAG, "checking server..." );\r
+                Log_OC.wtf(TAG, "checking server..." );\r
                 mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
             }\r
             \r
                 mWaitingForOpId = mOperationsServiceBinder.newOperation(getServerInfoIntent);\r
             }\r
             \r
@@ -761,10 +759,8 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 \r
 \r
     private void showViewPasswordButton() {\r
 \r
 \r
     private void showViewPasswordButton() {\r
-        //int drawable = android.R.drawable.ic_menu_view;\r
         int drawable = R.drawable.ic_view;\r
         if (isPasswordVisible()) {\r
         int drawable = R.drawable.ic_view;\r
         if (isPasswordVisible()) {\r
-            //drawable = android.R.drawable.ic_secure;\r
             drawable = R.drawable.ic_hide;\r
         }\r
         mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0);\r
             drawable = R.drawable.ic_hide;\r
         }\r
         mPasswordInput.setCompoundDrawablesWithIntrinsicBounds(0, 0, drawable, 0);\r
@@ -881,14 +877,12 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         showAuthStatus();\r
 \r
         // GET AUTHORIZATION request\r
         showAuthStatus();\r
 \r
         // GET AUTHORIZATION request\r
-        //Uri uri = Uri.parse(getString(R.string.oauth2_url_endpoint_auth));\r
         Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim());\r
         Uri.Builder uriBuilder = uri.buildUpon();\r
         uriBuilder.appendQueryParameter(OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type));\r
         uriBuilder.appendQueryParameter(OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri));   \r
         uriBuilder.appendQueryParameter(OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id));\r
         uriBuilder.appendQueryParameter(OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope));\r
         Uri uri = Uri.parse(mOAuthAuthEndpointText.getText().toString().trim());\r
         Uri.Builder uriBuilder = uri.buildUpon();\r
         uriBuilder.appendQueryParameter(OAuth2Constants.KEY_RESPONSE_TYPE, getString(R.string.oauth2_response_type));\r
         uriBuilder.appendQueryParameter(OAuth2Constants.KEY_REDIRECT_URI, getString(R.string.oauth2_redirect_uri));   \r
         uriBuilder.appendQueryParameter(OAuth2Constants.KEY_CLIENT_ID, getString(R.string.oauth2_client_id));\r
         uriBuilder.appendQueryParameter(OAuth2Constants.KEY_SCOPE, getString(R.string.oauth2_scope));\r
-        //uriBuilder.appendQueryParameter(OAuth2Constants.KEY_STATE, whateverwewant);\r
         uri = uriBuilder.build();\r
         Log_OC.d(TAG, "Starting browser to view " + uri.toString());\r
         Intent i = new Intent(Intent.ACTION_VIEW, uri);\r
         uri = uriBuilder.build();\r
         Log_OC.d(TAG, "Starting browser to view " + uri.toString());\r
         Intent i = new Intent(Intent.ACTION_VIEW, uri);\r
@@ -952,7 +946,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     }\r
 \r
     private void onGetUserNameFinish(RemoteOperationResult result) {\r
     }\r
 \r
     private void onGetUserNameFinish(RemoteOperationResult result) {\r
-        mWaitingForOpId = -1;\r
+        mWaitingForOpId = Long.MAX_VALUE;\r
         if (result.isSuccess()) {\r
             boolean success = false;\r
             String username = (String) result.getData().get(0);\r
         if (result.isSuccess()) {\r
             boolean success = false;\r
             String username = (String) result.getData().get(0);\r
@@ -985,10 +979,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     }\r
 \r
     private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperationResult result) {\r
     }\r
 \r
     private void onSamlBasedFederatedSingleSignOnAuthorizationStart(RemoteOperationResult result) {\r
-        mWaitingForOpId = -1;\r
+        mWaitingForOpId = Long.MAX_VALUE;\r
         dismissDialog(WAIT_DIALOG_TAG);\r
 
         dismissDialog(WAIT_DIALOG_TAG);\r
 
-        //if (result.isTemporalRedirection() && result.isIdPRedirection()) {\r
         if (result.isIdPRedirection()) {
             String url = result.getRedirectedLocation();\r
             String targetUrl = mServerInfo.mBaseUrl \r
         if (result.isIdPRedirection()) {
             String url = result.getRedirectedLocation();\r
             String targetUrl = mServerInfo.mBaseUrl \r
@@ -1020,7 +1013,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
     private void onGetServerInfoFinish(RemoteOperationResult result) {\r
         /// update activity state\r
         mServerIsChecked = true;\r
     private void onGetServerInfoFinish(RemoteOperationResult result) {\r
         /// update activity state\r
         mServerIsChecked = true;\r
-        mWaitingForOpId = -1;\r
+        mWaitingForOpId = Long.MAX_VALUE;\r
         \r
         // update server status, but don't show it yet\r
         updateServerStatusIconAndText(result);\r
         \r
         // update server status, but don't show it yet\r
         updateServerStatusIconAndText(result);\r
@@ -1287,7 +1280,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
      * @param result        Result of the operation.\r
      */\r
     private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) {\r
      * @param result        Result of the operation.\r
      */\r
     private void onGetOAuthAccessTokenFinish(RemoteOperationResult result) {\r
-        mWaitingForOpId = -1;\r
+        mWaitingForOpId = Long.MAX_VALUE;\r
         dismissDialog(WAIT_DIALOG_TAG);\r
 \r
         String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
         dismissDialog(WAIT_DIALOG_TAG);\r
 \r
         String webdav_path = AccountUtils.getWebdavPath(mServerInfo.mVersion, mAuthTokenType);\r
@@ -1326,10 +1319,9 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
      * @param result        Result of the operation.\r
      */\r
     private void onAuthorizationCheckFinish(RemoteOperationResult result) {\r
      * @param result        Result of the operation.\r
      */\r
     private void onAuthorizationCheckFinish(RemoteOperationResult result) {\r
-        mWaitingForOpId = -1;\r
+        mWaitingForOpId = Long.MAX_VALUE;\r
         dismissDialog(WAIT_DIALOG_TAG);\r
 \r
         dismissDialog(WAIT_DIALOG_TAG);\r
 \r
-        result = new RemoteOperationResult(new RuntimeException("FAKE"));\r
         if (result.isSuccess()) {\r
             Log_OC.d(TAG, "Successful access - time to save the account");\r
 \r
         if (result.isSuccess()) {\r
             Log_OC.d(TAG, "Successful access - time to save the account");\r
 \r
@@ -1351,12 +1343,6 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
             /// the server\r
             mServerIsChecked = true;\r
             mServerIsValid = false;\r
             /// the server\r
             mServerIsChecked = true;\r
             mServerIsValid = false;\r
-            /*\r
-            mServerInfo.mIsSslConn = false;\r
-            mServerInfo.mVersion = null;\r
-            mServerInfo.mBaseUrl = \r
-                    normalizeUrl(mHostUrlInput.getText().toString(), mServerInfo.mIsSslConn);    // TODO remove?\r
-                    */\r
             mServerInfo = new GetServerInfoOperation.ServerInfo();  \r
 \r
             // update status icon and text\r
             mServerInfo = new GetServerInfoOperation.ServerInfo();  \r
 \r
             // update status icon and text\r
@@ -1658,7 +1644,7 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
         getUserNameIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
         \r
         if (mOperationsServiceBinder != null) {\r
         getUserNameIntent.putExtra(OperationsService.EXTRA_FOLLOW_REDIRECTS, followRedirects);\r
         \r
         if (mOperationsServiceBinder != null) {\r
-            //Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." );\r
+            Log_OC.wtf(TAG, "starting getRemoteUserNameOperation..." );\r
             mWaitingForOpId = mOperationsServiceBinder.newOperation(getUserNameIntent);\r
         }\r
     }\r
             mWaitingForOpId = mOperationsServiceBinder.newOperation(getUserNameIntent);\r
         }\r
     }\r
@@ -1753,10 +1739,10 @@ SsoWebViewClientListener, OnSslUntrustedCertListener {
 \r
 \r
     private void doOnResumeAndBound() {\r
 \r
 \r
     private void doOnResumeAndBound() {\r
-        Log.wtf(TAG, "registering to listen for operation callbacks" );\r
+        Log_OC.wtf(TAG, "registering to listen for operation callbacks" );\r
         mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler);\r
         mOperationsServiceBinder.addOperationListener(AuthenticatorActivity.this, mHandler);\r
-        if (mWaitingForOpId != -1) {\r
-            mOperationsServiceBinder.dispatchResultIfFinished(mWaitingForOpId, this);\r
+        if (mWaitingForOpId <= Integer.MAX_VALUE) {\r
+            mOperationsServiceBinder.dispatchResultIfFinished((int)mWaitingForOpId, this);\r
         }\r
     }\r
 \r
         }\r
     }\r
 \r