Skip to content

Commit 113ebf6

Browse files
Merge pull request #330 from iskradelta/master
FindBugs and PMD appeased
2 parents 10c1f0f + 48c4eb8 commit 113ebf6

File tree

103 files changed

+1213
-1224
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+1213
-1224
lines changed

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ dependencies {
4747
compile 'com.jakewharton:disklrucache:2.0.2'
4848
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
4949
compile 'com.getbase:floatingactionbutton:1.10.1'
50+
compile 'com.google.code.findbugs:annotations:2.0.1'
5051

5152

5253
/// dependencies for local unit tests

pmd-ruleset.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
</description>
1010
<exclude-pattern>.*/R.java</exclude-pattern>
1111
<exclude-pattern>.*/gen/.*</exclude-pattern>
12+
<exclude-pattern>.*/third_parties/.*</exclude-pattern>
1213

1314
<rule ref="rulesets/java/logging-java.xml" />
1415
<rule ref="rulesets/java/braces.xml" />

src/com/owncloud/android/MainApp.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@
3737
import com.owncloud.android.lib.common.utils.Log_OC;
3838
import com.owncloud.android.ui.activity.Preferences;
3939

40+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
41+
42+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
43+
4044

4145
/**
4246
* Main Application of the project
@@ -61,14 +65,14 @@ public class MainApp extends Application {
6165

6266
private static boolean mOnlyOnDevice = false;
6367

64-
68+
@SuppressFBWarnings("ST")
6569
public void onCreate(){
6670
super.onCreate();
6771
MainApp.mContext = getApplicationContext();
6872

6973
SharedPreferences appPrefs =
7074
PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
71-
MainApp.storagePath = appPrefs.getString(Preferences.Keys.STORAGE_PATH, Environment.
75+
MainApp.storagePath = appPrefs.getString(Preferences.PreferenceKeys.STORAGE_PATH, Environment.
7276
getExternalStorageDirectory().getAbsolutePath());
7377

7478
boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
@@ -196,7 +200,7 @@ public static void showOnlyFilesOnDevice(boolean state){
196200
mOnlyOnDevice = state;
197201
}
198202

199-
public static boolean getOnlyOnDevice(){
203+
public static boolean isOnlyOnDevice(){
200204
return mOnlyOnDevice;
201205
}
202206

src/com/owncloud/android/authentication/AccountAuthenticator.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ public Bundle addAccount(AccountAuthenticatorResponse response,
8787
validateAccountType(accountType);
8888
} catch (AuthenticatorException e) {
8989
Log_OC.e(TAG, "Failed to validate account type " + accountType + ": "
90-
+ e.getMessage());
91-
e.printStackTrace();
90+
+ e.getMessage(), e);
9291
return e.getFailureBundle();
9392
}
9493

@@ -133,8 +132,7 @@ public Bundle confirmCredentials(AccountAuthenticatorResponse response,
133132
validateAccountType(account.type);
134133
} catch (AuthenticatorException e) {
135134
Log_OC.e(TAG, "Failed to validate account type " + account.type + ": "
136-
+ e.getMessage());
137-
e.printStackTrace();
135+
+ e.getMessage(), e);
138136
return e.getFailureBundle();
139137
}
140138
Intent intent = new Intent(mContext, AuthenticatorActivity.class);
@@ -169,8 +167,7 @@ public Bundle getAuthToken(AccountAuthenticatorResponse response,
169167
validateAuthTokenType(authTokenType);
170168
} catch (AuthenticatorException e) {
171169
Log_OC.e(TAG, "Failed to validate account type " + account.type + ": "
172-
+ e.getMessage());
173-
e.printStackTrace();
170+
+ e.getMessage(), e);
174171
return e.getFailureBundle();
175172
}
176173

src/com/owncloud/android/authentication/AccountUtils.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static boolean exists(Account account, Context context) {
119119
*/
120120
public static String getAccountUsername(String accountName) {
121121
if (accountName != null) {
122-
return accountName.substring(0, accountName.lastIndexOf("@"));
122+
return accountName.substring(0, accountName.lastIndexOf('@'));
123123
} else {
124124
return null;
125125
}
@@ -135,8 +135,9 @@ public static Account getOwnCloudAccountByName(Context context, String accountNa
135135
Account[] ocAccounts = AccountManager.get(context).getAccountsByType(
136136
MainApp.getAccountType());
137137
for (Account account : ocAccounts) {
138-
if(account.name.equals(accountName))
138+
if(account.name.equals(accountName)) {
139139
return account;
140+
}
140141
}
141142
return null;
142143
}
@@ -241,15 +242,13 @@ public static void updateAccountVersion(Context context) {
241242
);
242243

243244
// copy type of authentication
244-
String isSamlStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO);
245-
boolean isSaml = "TRUE".equals(isSamlStr);
246-
if (isSaml) {
245+
final String isSamlStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_SAML_WEB_SSO);
246+
if (Boolean.parseBoolean(isSamlStr)) {
247247
accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_SAML_WEB_SSO, "TRUE");
248248
}
249249

250-
String isOauthStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2);
251-
boolean isOAuth = "TRUE".equals(isOauthStr);
252-
if (isOAuth) {
250+
final String isOauthStr = accountMgr.getUserData(account, Constants.KEY_SUPPORTS_OAUTH2);
251+
if (Boolean.parseBoolean(isOauthStr)) {
253252
accountMgr.setUserData(newAccount, Constants.KEY_SUPPORTS_OAUTH2, "TRUE");
254253
}
255254
/* TODO - study if it's possible to run this method in a background thread to copy the authToken

src/com/owncloud/android/authentication/AuthenticatorActivity.java

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog;
9292
import com.owncloud.android.ui.dialog.SslUntrustedCertDialog.OnSslUntrustedCertListener;
9393
import com.owncloud.android.utils.DisplayUtils;
94-
94+
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
9595
import java.security.cert.X509Certificate;
9696
import java.util.Map;
9797

@@ -142,6 +142,8 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
142142
private static final String KEY_ASYNC_TASK_IN_PROGRESS = "AUTH_IN_PROGRESS";
143143
public static final String PROTOCOL_SUFFIX = "://";
144144
public static final String LOGIN_URL_DATA_KEY_VALUE_SEPARATOR = ":";
145+
private static final String HTTPS_PROTOCOL = "https://";
146+
private static final String HTTP_PROTOCOL = "http://";
145147

146148
/// parameters from EXTRAs in starter Intent
147149
private byte mAction;
@@ -167,7 +169,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
167169

168170
private boolean mServerIsChecked = false;
169171
private boolean mServerIsValid = false;
170-
private boolean mPendingAutoCheck = false;
171172

172173
private GetServerInfoOperation.ServerInfo mServerInfo = new GetServerInfoOperation.ServerInfo();
173174

@@ -408,11 +409,11 @@ private void initServerPreFragment(Bundle savedInstanceState) {
408409
if (mAccount != null) {
409410
mServerInfo.mBaseUrl = mAccountMgr.getUserData(mAccount, Constants.KEY_OC_BASE_URL);
410411
// TODO do next in a setter for mBaseUrl
411-
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
412+
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith(HTTPS_PROTOCOL);
412413
mServerInfo.mVersion = AccountUtils.getServerVersion(mAccount);
413414
} else {
414415
mServerInfo.mBaseUrl = getString(R.string.server_url).trim();
415-
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith("https://");
416+
mServerInfo.mIsSslConn = mServerInfo.mBaseUrl.startsWith(HTTPS_PROTOCOL);
416417
}
417418
} else {
418419
mServerStatusText = savedInstanceState.getInt(KEY_SERVER_STATUS_TEXT);
@@ -492,24 +493,16 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
492493
findViewById(R.id.scroll).setOnTouchListener(new OnTouchListener() {
493494
@Override
494495
public boolean onTouch(View view, MotionEvent event) {
495-
if (event.getAction() == MotionEvent.ACTION_DOWN) {
496-
if (
497-
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(
498-
MainApp.getAccountType()
499-
).equals(mAuthTokenType) &&
500-
mHostUrlInput.hasFocus()
501-
) {
502-
checkOcServer();
503-
}
496+
if (event.getAction() == MotionEvent.ACTION_DOWN &&
497+
AccountTypeUtils
498+
.getAuthTokenTypeSamlSessionCookie(MainApp
499+
.getAccountType()).equals(mAuthTokenType) &&
500+
mHostUrlInput.hasFocus()) {
501+
checkOcServer();
504502
}
505503
return false;
506504
}
507505
});
508-
509-
510-
/// step 4 - mark automatic check to be started when OperationsService is ready
511-
mPendingAutoCheck = (savedInstanceState == null &&
512-
(mAction != ACTION_CREATE || checkHostUrl));
513506
}
514507

515508

@@ -1127,8 +1120,9 @@ private void onGetUserNameFinish(RemoteOperationResult result) {
11271120
}
11281121
}
11291122

1130-
if (success)
1123+
if (success) {
11311124
finish();
1125+
}
11321126
} else {
11331127
updateStatusIconFailUserName();
11341128
showAuthStatus();
@@ -1197,14 +1191,15 @@ private boolean authSupported(AuthenticationMethod authMethod) {
11971191

11981192
// TODO remove, if possible
11991193
private String normalizeUrl(String url, boolean sslWhenUnprefixed) {
1194+
12001195
if (url != null && url.length() > 0) {
12011196
url = url.trim();
1202-
if (!url.toLowerCase().startsWith("http://") &&
1203-
!url.toLowerCase().startsWith("https://")) {
1197+
if (!url.toLowerCase().startsWith(HTTP_PROTOCOL) &&
1198+
!url.toLowerCase().startsWith(HTTP_PROTOCOL)) {
12041199
if (sslWhenUnprefixed) {
1205-
url = "https://" + url;
1200+
url = HTTPS_PROTOCOL + url;
12061201
} else {
1207-
url = "http://" + url;
1202+
url = HTTP_PROTOCOL + url;
12081203
}
12091204
}
12101205

@@ -1259,7 +1254,7 @@ private void updateServerStatusIconAndText(RemoteOperationResult result) {
12591254

12601255
case OK_NO_SSL:
12611256
case OK:
1262-
if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith("http://")) {
1257+
if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith(HTTP_PROTOCOL)) {
12631258
mServerStatusText = R.string.auth_connection_established;
12641259
mServerStatusIcon = R.drawable.ic_ok;
12651260
} else {
@@ -1340,7 +1335,7 @@ private void updateAuthStatusIconAndText(RemoteOperationResult result) {
13401335

13411336
case OK_NO_SSL:
13421337
case OK:
1343-
if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith("http://")) {
1338+
if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith(HTTP_PROTOCOL)) {
13441339
mAuthStatusText = R.string.auth_connection_established;
13451340
mAuthStatusIcon = R.drawable.ic_ok;
13461341
} else {
@@ -1576,6 +1571,7 @@ private void updateAccountAuthentication() throws AccountNotFoundException {
15761571
*
15771572
* TODO Decide how to name the OAuth accounts
15781573
*/
1574+
@SuppressFBWarnings("DMI")
15791575
private boolean createAccount(RemoteOperationResult authResult) {
15801576
/// create and save new ownCloud account
15811577
boolean isOAuth = AccountTypeUtils.
@@ -1782,11 +1778,10 @@ public boolean onEditorAction(TextView inputField, int actionId, KeyEvent event)
17821778
}
17831779

17841780
} else if (actionId == EditorInfo.IME_ACTION_NEXT && inputField != null &&
1785-
inputField.equals(mHostUrlInput)) {
1786-
if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
1787-
equals(mAuthTokenType)) {
1781+
inputField.equals(mHostUrlInput) &&
1782+
AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()).
1783+
equals(mAuthTokenType)) {
17881784
checkOcServer();
1789-
}
17901785
}
17911786
return false; // always return false to grant that the software keyboard is hidden anyway
17921787
}
@@ -1847,7 +1842,7 @@ public void onSsoFinished(String sessionCookie) {
18471842
mAuthToken = sessionCookie;
18481843
getRemoteUserNameOperation(sessionCookie);
18491844
Fragment fd = getSupportFragmentManager().findFragmentByTag(SAML_DIALOG_TAG);
1850-
if (fd != null && fd instanceof DialogFragment) {
1845+
if (fd instanceof DialogFragment) {
18511846
Dialog d = ((DialogFragment) fd).getDialog();
18521847
if (d != null && d.isShowing()) {
18531848
d.dismiss();
@@ -1950,7 +1945,7 @@ private void doOnResumeAndBound() {
19501945

19511946
private void dismissDialog(String dialogTag) {
19521947
Fragment frag = getSupportFragmentManager().findFragmentByTag(dialogTag);
1953-
if (frag != null && frag instanceof DialogFragment) {
1948+
if (frag instanceof DialogFragment) {
19541949
DialogFragment dialog = (DialogFragment) frag;
19551950
dialog.dismiss();
19561951
}

src/com/owncloud/android/authentication/AuthenticatorAsyncTask.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
*/
4141
public class AuthenticatorAsyncTask extends AsyncTask<Object, Void, RemoteOperationResult> {
4242

43-
private static String REMOTE_PATH = "/";
44-
private static boolean SUCCESS_IF_ABSENT = false;
43+
private static final String REMOTE_PATH = "/";
44+
private static final boolean SUCCESS_IF_ABSENT = false;
4545

4646
private Context mContext;
4747
private final WeakReference<OnAuthenticatorTaskListener> mListener;

src/com/owncloud/android/authentication/PassCodeManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public class PassCodeManager {
4343
// other activities may be exempted, if needed
4444
}
4545

46-
private static int PASS_CODE_TIMEOUT = 1000;
46+
private static final int PASS_CODE_TIMEOUT = 1000;
4747
// keeping a "low" positive value is the easiest way to prevent the pass code is requested on rotations
4848

4949
public static PassCodeManager mPassCodeManagerInstance = null;

0 commit comments

Comments
 (0)