From e505421db948cd44d0d3b6658c19654db39449b8 Mon Sep 17 00:00:00 2001 From: tobiasKaminsky Date: Fri, 8 Dec 2017 14:31:59 +0100 Subject: [PATCH 1/2] Implicitly using the default locale is a common source of bugs internal: Locale.ROOT otherwise Locale.getDefault() --- .../com/owncloud/android/utils/PushUtils.java | 3 +- .../authentication/AuthenticatorActivity.java | 59 ++++++++++--------- .../authentication/AuthenticatorUrlUtils.java | 8 ++- .../owncloud/android/datamodel/OCFile.java | 3 +- .../DetectAuthenticationMethodOperation.java | 3 +- .../operations/GetServerInfoOperation.java | 7 ++- .../UsersAndGroupsSearchProvider.java | 3 +- .../com/owncloud/android/ui/TextDrawable.java | 4 +- .../ui/activity/SyncedFoldersActivity.java | 10 +++- .../ui/adapter/FileListListAdapter.java | 4 +- .../ui/adapter/LocalFileListAdapter.java | 20 ++++--- .../android/ui/dialog/ShareLinkToDialog.java | 7 ++- .../owncloud/android/utils/BitmapUtils.java | 3 +- .../owncloud/android/utils/DisplayUtils.java | 3 +- .../android/utils/FileStorageUtils.java | 2 +- .../owncloud/android/utils/MimeTypeUtil.java | 17 +++--- .../daveKoeller/AlphanumComparator.java | 9 +-- .../ezvcard_android/DataMappings.java | 9 +-- .../com/owncloud/android/utils/PushUtils.java | 3 +- 19 files changed, 101 insertions(+), 76 deletions(-) diff --git a/src/gplay/java/com/owncloud/android/utils/PushUtils.java b/src/gplay/java/com/owncloud/android/utils/PushUtils.java index 9bc50f5781..bd6ded2311 100644 --- a/src/gplay/java/com/owncloud/android/utils/PushUtils.java +++ b/src/gplay/java/com/owncloud/android/utils/PushUtils.java @@ -63,6 +63,7 @@ import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; +import java.util.Locale; public class PushUtils { @@ -191,7 +192,7 @@ public class PushUtils { if (!TextUtils.isEmpty(MainApp.getAppContext().getResources().getString(R.string.push_server_url)) && !TextUtils.isEmpty(token)) { PushUtils.generateRsa2048KeyPair(); - String pushTokenHash = PushUtils.generateSHA512Hash(token).toLowerCase(); + String pushTokenHash = PushUtils.generateSHA512Hash(token).toLowerCase(Locale.ROOT); PublicKey devicePublicKey = (PublicKey) PushUtils.readKeyFromFile(true); if (devicePublicKey != null) { byte[] publicKeyBytes = Base64.encode(devicePublicKey.getEncoded(), Base64.NO_WRAP); diff --git a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java index b04f73b04b..02d41957bd 100644 --- a/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java +++ b/src/main/java/com/owncloud/android/authentication/AuthenticatorActivity.java @@ -130,6 +130,7 @@ import java.io.InputStream; import java.net.URLDecoder; import java.security.cert.X509Certificate; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @@ -330,7 +331,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } else { setContentView(R.layout.account_setup_webview); - mLoginWebView = (WebView) findViewById(R.id.login_webview); + mLoginWebView = findViewById(R.id.login_webview); initWebViewLogin(null); } @@ -353,14 +354,14 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } private static String getWebLoginUserAgent() { - return Build.MANUFACTURER.substring(0, 1).toUpperCase() + - Build.MANUFACTURER.substring(1).toLowerCase() + " " + Build.MODEL; + return Build.MANUFACTURER.substring(0, 1).toUpperCase(Locale.getDefault()) + + Build.MANUFACTURER.substring(1).toLowerCase(Locale.getDefault()) + " " + Build.MODEL; } private void initWebViewLogin(String baseURL) { mLoginWebView.setVisibility(View.GONE); - final ProgressBar progressBar = (ProgressBar) findViewById(R.id.login_webview_progress_bar); + final ProgressBar progressBar = findViewById(R.id.login_webview_progress_bar); mLoginWebView.getSettings().setAllowFileAccess(false); mLoginWebView.getSettings().setJavaScriptEnabled(true); @@ -572,15 +573,15 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity * Configures elements in the user interface under direct control of the Activity. */ private void initOverallUi() { - mHostUrlInput = (CustomEditText) findViewById(R.id.hostUrlInput); - mUsernameInputLayout = (TextInputLayout) findViewById(R.id.input_layout_account_username); - mPasswordInputLayout = (TextInputLayout) findViewById(R.id.input_layout_account_password); - mPasswordInput = (EditText) findViewById(R.id.account_password); - mUsernameInput = (EditText) findViewById(R.id.account_username); - mAuthStatusView = (TextView) findViewById(R.id.auth_status_text); - mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check); - mServerStatusView = (TextView) findViewById(R.id.server_status_text); - mTestServerButton = (ImageButton) findViewById(R.id.testServerButton); + mHostUrlInput = findViewById(R.id.hostUrlInput); + mUsernameInputLayout = findViewById(R.id.input_layout_account_username); + mPasswordInputLayout = findViewById(R.id.input_layout_account_password); + mPasswordInput = findViewById(R.id.account_password); + mUsernameInput = findViewById(R.id.account_username); + mAuthStatusView = findViewById(R.id.auth_status_text); + mOAuth2Check = findViewById(R.id.oauth_onOff_check); + mServerStatusView = findViewById(R.id.server_status_text); + mTestServerButton = findViewById(R.id.testServerButton); mOkButton = findViewById(R.id.buttonOK); mOkButton.setOnClickListener(v -> onOkClick()); @@ -603,13 +604,13 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } /// step 2 - set properties of UI elements (text, visibility, enabled...) - Button welcomeLink = (Button) findViewById(R.id.welcome_link); + Button welcomeLink = findViewById(R.id.welcome_link); welcomeLink.setVisibility(mAction == ACTION_CREATE && isWelcomeLinkVisible ? View.VISIBLE : View.GONE); welcomeLink.setText(getString(R.string.auth_register)); mTestServerButton.setVisibility(mAction == ACTION_CREATE ? View.VISIBLE : View.GONE); - TextView instructionsView = (TextView) findViewById(R.id.instructions_message); + TextView instructionsView = findViewById(R.id.instructions_message); if (instructionsMessageText != null) { instructionsView.setVisibility(View.VISIBLE); instructionsView.setText(instructionsMessageText); @@ -665,7 +666,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity if (!webViewLoginMethod) { /// step 2 - set properties of UI elements (text, visibility, enabled...) - mHostUrlInput = (CustomEditText) findViewById(R.id.hostUrlInput); + mHostUrlInput = findViewById(R.id.hostUrlInput); // Convert IDN to Unicode mHostUrlInput.setText(DisplayUtils.convertIdn(mServerInfo.mBaseUrl, false)); if (mAction != ACTION_CREATE) { @@ -681,7 +682,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } showRefreshButton(mServerIsChecked && !mServerIsValid && mWaitingForOpId > Integer.MAX_VALUE); - mServerStatusView = (TextView) findViewById(R.id.server_status_text); + mServerStatusView = findViewById(R.id.server_status_text); showServerStatus(); /// step 3 - bind some listeners and options @@ -741,12 +742,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity private void initAuthorizationPreFragment(Bundle savedInstanceState) { /// step 0 - get UI elements in layout - mOAuth2Check = (CheckBox) findViewById(R.id.oauth_onOff_check); - mOAuthAuthEndpointText = (TextView) findViewById(R.id.oAuthEntryPoint_1); - mOAuthTokenEndpointText = (TextView) findViewById(R.id.oAuthEntryPoint_2); - mUsernameInput = (EditText) findViewById(R.id.account_username); - mPasswordInput = (EditText) findViewById(R.id.account_password); - mAuthStatusView = (TextView) findViewById(R.id.auth_status_text); + mOAuth2Check = findViewById(R.id.oauth_onOff_check); + mOAuthAuthEndpointText = findViewById(R.id.oAuthEntryPoint_1); + mOAuthTokenEndpointText = findViewById(R.id.oAuthEntryPoint_2); + mUsernameInput = findViewById(R.id.account_username); + mPasswordInput = findViewById(R.id.account_password); + mAuthStatusView = findViewById(R.id.auth_status_text); /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState) String presetUserName = null; @@ -1434,7 +1435,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mPasswordInputLayout.setVisibility(View.GONE); setContentView(R.layout.account_setup_webview); - mLoginWebView = (WebView) findViewById(R.id.login_webview); + mLoginWebView = findViewById(R.id.login_webview); initWebViewLogin(mServerInfo.mBaseUrl); } else { // show old login @@ -1507,7 +1508,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity case OK_NO_SSL: case OK: - if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith(HTTP_PROTOCOL)) { + if (mHostUrlInput.getText().toString().trim().toLowerCase(Locale.ROOT).startsWith(HTTP_PROTOCOL)) { mServerStatusText = getResources().getString(R.string.auth_connection_established); mServerStatusIcon = R.drawable.ic_ok; } else { @@ -1592,7 +1593,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity case OK_NO_SSL: case OK: - if (mHostUrlInput.getText().toString().trim().toLowerCase().startsWith(HTTP_PROTOCOL)) { + if (mHostUrlInput.getText().toString().trim().toLowerCase(Locale.ROOT).startsWith(HTTP_PROTOCOL)) { mAuthStatusText = getResources().getString(R.string.auth_connection_established); mAuthStatusIcon = R.drawable.ic_ok; } else { @@ -1712,12 +1713,12 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity mLoginWebView.setVisibility(View.GONE); setContentView(R.layout.account_setup); - CustomEditText serverAddressField = (CustomEditText) findViewById(R.id.hostUrlInput); + CustomEditText serverAddressField = findViewById(R.id.hostUrlInput); serverAddressField.setText(mServerInfo.mBaseUrl); findViewById(R.id.oauth_onOff_check).setVisibility(View.GONE); findViewById(R.id.server_status_text).setVisibility(View.GONE); - mAuthStatusView = (TextView) findViewById(R.id.auth_status_text); + mAuthStatusView = findViewById(R.id.auth_status_text); showAuthStatus(); } @@ -1749,7 +1750,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity } else { // authorization fail due to client side - probably wrong credentials if (webViewLoginMethod) { - mLoginWebView = (WebView) findViewById(R.id.login_webview); + mLoginWebView = findViewById(R.id.login_webview); initWebViewLogin(mServerInfo.mBaseUrl); Snackbar.make(mLoginWebView, getString(R.string.auth_access_failed) + ": " + result.getLogMessage(), diff --git a/src/main/java/com/owncloud/android/authentication/AuthenticatorUrlUtils.java b/src/main/java/com/owncloud/android/authentication/AuthenticatorUrlUtils.java index 1982b6bb4f..56cf4f1064 100644 --- a/src/main/java/com/owncloud/android/authentication/AuthenticatorUrlUtils.java +++ b/src/main/java/com/owncloud/android/authentication/AuthenticatorUrlUtils.java @@ -25,6 +25,8 @@ import com.owncloud.android.MainApp; import com.owncloud.android.lib.common.accounts.AccountTypeUtils; import com.owncloud.android.lib.resources.status.OwnCloudVersion; +import java.util.Locale; + /** * Helper class for authenticator-URL related logic. */ @@ -75,8 +77,8 @@ public abstract class AuthenticatorUrlUtils { if (normalizedUrl != null && normalizedUrl.length() > 0) { normalizedUrl = normalizedUrl.trim(); - if (!normalizedUrl.toLowerCase().startsWith(HTTP_PROTOCOL) && - !normalizedUrl.toLowerCase().startsWith(HTTP_PROTOCOL)) { + if (!normalizedUrl.toLowerCase(Locale.ROOT).startsWith(HTTP_PROTOCOL) && + !normalizedUrl.toLowerCase(Locale.ROOT).startsWith(HTTP_PROTOCOL)) { if (sslWhenUnprefixed) { normalizedUrl = HTTPS_PROTOCOL + normalizedUrl; } else { @@ -110,7 +112,7 @@ public abstract class AuthenticatorUrlUtils { } private static String trimUrlWebdav(String url) { - if (url.toLowerCase().endsWith(WEBDAV_PATH_4_0_AND_LATER)) { + if (url.toLowerCase(Locale.ROOT).endsWith(WEBDAV_PATH_4_0_AND_LATER)) { return url.substring(0, url.length() - WEBDAV_PATH_4_0_AND_LATER.length()); } diff --git a/src/main/java/com/owncloud/android/datamodel/OCFile.java b/src/main/java/com/owncloud/android/datamodel/OCFile.java index 7ac975a2c1..464582f95b 100644 --- a/src/main/java/com/owncloud/android/datamodel/OCFile.java +++ b/src/main/java/com/owncloud/android/datamodel/OCFile.java @@ -34,6 +34,7 @@ import com.owncloud.android.lib.common.utils.Log_OC; import com.owncloud.android.utils.MimeType; import java.io.File; +import java.util.Locale; import third_parties.daveKoeller.AlphanumComparator; @@ -563,7 +564,7 @@ public class OCFile implements Parcelable, Comparable { @Override public int compareTo(OCFile another) { if (isFolder() && another.isFolder()) { - return getRemotePath().toLowerCase().compareTo(another.getRemotePath().toLowerCase()); + return getRemotePath().toLowerCase(Locale.ROOT).compareTo(another.getRemotePath().toLowerCase(Locale.ROOT)); } else if (isFolder()) { return -1; } else if (another.isFolder()) { diff --git a/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java b/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java index 95cff3902b..165f4189ee 100644 --- a/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java +++ b/src/main/java/com/owncloud/android/operations/DetectAuthenticationMethodOperation.java @@ -32,6 +32,7 @@ import com.owncloud.android.lib.resources.files.ExistenceCheckRemoteOperation; import org.apache.commons.httpclient.HttpStatus; import java.util.ArrayList; +import java.util.Locale; /** * Operation to find out what authentication method requires the server to access files. @@ -101,7 +102,7 @@ public class DetectAuthenticationMethodOperation extends RemoteOperation { for (String header : authHeaders) { // currently we only support basic auth - if (header.toLowerCase().startsWith("basic")) { + if (header.toLowerCase(Locale.ROOT).startsWith("basic")) { authMethod = AuthenticationMethod.BASIC_HTTP_AUTH; break; } diff --git a/src/main/java/com/owncloud/android/operations/GetServerInfoOperation.java b/src/main/java/com/owncloud/android/operations/GetServerInfoOperation.java index 5f75c4ec52..5cd7b95c38 100644 --- a/src/main/java/com/owncloud/android/operations/GetServerInfoOperation.java +++ b/src/main/java/com/owncloud/android/operations/GetServerInfoOperation.java @@ -34,6 +34,7 @@ import com.owncloud.android.lib.resources.status.OwnCloudVersion; import com.owncloud.android.operations.DetectAuthenticationMethodOperation.AuthenticationMethod; import java.util.ArrayList; +import java.util.Locale; /** * Get basic information from an ownCloud server given its URL. @@ -119,7 +120,7 @@ public class GetServerInfoOperation extends RemoteOperation { if (trimmedUrl.endsWith("/")) { trimmedUrl = trimmedUrl.substring(0, trimmedUrl.length() - 1); } - if (trimmedUrl.toLowerCase().endsWith(AuthenticatorUrlUtils.WEBDAV_PATH_4_0_AND_LATER)) { + if (trimmedUrl.toLowerCase(Locale.ROOT).endsWith(AuthenticatorUrlUtils.WEBDAV_PATH_4_0_AND_LATER)) { trimmedUrl = trimmedUrl.substring(0, trimmedUrl.length() - AuthenticatorUrlUtils.WEBDAV_PATH_4_0_AND_LATER.length()); } @@ -129,8 +130,8 @@ public class GetServerInfoOperation extends RemoteOperation { private String normalizeProtocolPrefix(String url, boolean isSslConn) { - if (!url.toLowerCase().startsWith("http://") && - !url.toLowerCase().startsWith("https://")) { + if (!url.toLowerCase(Locale.ROOT).startsWith("http://") && + !url.toLowerCase(Locale.ROOT).startsWith("https://")) { if (isSslConn) { return "https://" + url; } else { diff --git a/src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java b/src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java index 393cf008f1..8021630681 100644 --- a/src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java +++ b/src/main/java/com/owncloud/android/providers/UsersAndGroupsSearchProvider.java @@ -51,6 +51,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Locale; /** @@ -148,7 +149,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider { MatrixCursor response = null; - String userQuery = uri.getLastPathSegment().toLowerCase(); + String userQuery = uri.getLastPathSegment().toLowerCase(Locale.ROOT); /// need to trust on the AccountUtils to get the current account since the query in the client side is not diff --git a/src/main/java/com/owncloud/android/ui/TextDrawable.java b/src/main/java/com/owncloud/android/ui/TextDrawable.java index 035df79435..7dfe71f696 100644 --- a/src/main/java/com/owncloud/android/ui/TextDrawable.java +++ b/src/main/java/com/owncloud/android/ui/TextDrawable.java @@ -33,6 +33,7 @@ import com.owncloud.android.utils.BitmapUtils; import java.io.UnsupportedEncodingException; import java.security.NoSuchAlgorithmException; +import java.util.Locale; /** * A Drawable object that draws text (1 character) on top of a circular/filled background. @@ -116,7 +117,8 @@ public class TextDrawable extends Drawable { int[] hsl = BitmapUtils.calculateHSL(name); int[] rgb = BitmapUtils.HSLtoRGB(hsl[0], hsl[1], hsl[2], 1); - return new TextDrawable(name.substring(0, 1).toUpperCase(), rgb[0], rgb[1], rgb[2], radiusInDp); + return new TextDrawable(name.substring(0, 1).toUpperCase(Locale.getDefault()), rgb[0], rgb[1], rgb[2], + radiusInDp); } /** diff --git a/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java b/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java index 77616c1c37..e72958e43a 100644 --- a/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java +++ b/src/main/java/com/owncloud/android/ui/activity/SyncedFoldersActivity.java @@ -74,6 +74,7 @@ import java.util.Collections; import java.util.Comparator; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import static android.support.design.widget.AppBarLayout.LayoutParams.SCROLL_FLAG_ENTER_ALWAYS; @@ -280,7 +281,8 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA } else if (f2 == null) { return 1; } else if (f1.isEnabled() && f2.isEnabled()) { - return f1.getFolderName().toLowerCase().compareTo(f2.getFolderName().toLowerCase()); + return f1.getFolderName().toLowerCase(Locale.getDefault()).compareTo( + f2.getFolderName().toLowerCase(Locale.getDefault())); } else if (f1.isEnabled()) { return -1; } else if (f2.isEnabled()) { @@ -291,14 +293,16 @@ public class SyncedFoldersActivity extends FileActivity implements SyncedFolderA return -1; } else if (f2.getFolderName() == null) { return 1; - } else if (PRIORITIZED_FOLDER.equals(f1.getFolderName()) && PRIORITIZED_FOLDER.equals(f2.getFolderName())) { + } else if (PRIORITIZED_FOLDER.equals(f1.getFolderName()) && + PRIORITIZED_FOLDER.equals(f2.getFolderName())) { return 0; } else if (PRIORITIZED_FOLDER.equals(f1.getFolderName())) { return -1; } else if (PRIORITIZED_FOLDER.equals(f2.getFolderName())) { return 1; } else { - return f1.getFolderName().toLowerCase().compareTo(f2.getFolderName().toLowerCase()); + return f1.getFolderName().toLowerCase(Locale.getDefault()).compareTo( + f2.getFolderName().toLowerCase(Locale.getDefault())); } } }); diff --git a/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java index 4b957a0b48..821ce0106e 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/FileListListAdapter.java @@ -71,6 +71,7 @@ import com.owncloud.android.utils.ThemeUtils; import java.io.File; import java.util.ArrayList; +import java.util.Locale; import java.util.Vector; @@ -686,7 +687,8 @@ public class FileListListAdapter extends BaseAdapter { for (int i = 0; i < mFilesAll.size(); i++) { OCFile currentFile = mFilesAll.get(i); if (currentFile.getParentRemotePath().equals(currentDirectory.getRemotePath()) && - currentFile.getFileName().toLowerCase().contains(constraint.toString().toLowerCase()) && + currentFile.getFileName().toLowerCase(Locale.getDefault()).contains( + constraint.toString().toLowerCase(Locale.getDefault())) && !filteredFiles.contains(currentFile)) { filteredFiles.add(currentFile); } diff --git a/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java b/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java index 3808cc2507..898c1f789b 100644 --- a/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java +++ b/src/main/java/com/owncloud/android/ui/adapter/LocalFileListAdapter.java @@ -47,6 +47,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.Locale; import java.util.Vector; /** @@ -147,12 +148,12 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA } if(!ViewType.GRID_IMAGE.equals(viewType)) { - TextView fileName = (TextView) view.findViewById(R.id.Filename); + TextView fileName = view.findViewById(R.id.Filename); String name = file.getName(); fileName.setText(name); } - ImageView fileIcon = (ImageView) view.findViewById(R.id.thumbnail); + ImageView fileIcon = view.findViewById(R.id.thumbnail); /** Cancellation needs do be checked and done before changing the drawable in fileIcon, or * {@link ThumbnailsCacheManager#cancelPotentialThumbnailWork} will NEVER cancel any task. @@ -166,11 +167,11 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA } fileIcon.setTag(file.hashCode()); - ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox); - TextView fileSizeV = (TextView) view.findViewById(R.id.file_size); - TextView fileSizeSeparatorV = (TextView) view.findViewById(R.id.file_separator); + ImageView checkBoxV = view.findViewById(R.id.custom_checkbox); + TextView fileSizeV = view.findViewById(R.id.file_size); + TextView fileSizeSeparatorV = view.findViewById(R.id.file_separator); if (!isGridView) { - TextView lastModV = (TextView) view.findViewById(R.id.last_mod); + TextView lastModV = view.findViewById(R.id.last_mod); lastModV.setVisibility(View.VISIBLE); lastModV.setText(DisplayUtils.getRelativeTimestamp(mContext, file.lastModified())); view.findViewById(R.id.overflow_menu).setVisibility(View.GONE); @@ -289,7 +290,8 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA } private int compareNames(File lhs, File rhs) { - return lhs.getName().toLowerCase().compareTo(rhs.getName().toLowerCase()); + return lhs.getName().toLowerCase(Locale.getDefault()).compareTo( + rhs.getName().toLowerCase(Locale.getDefault())); } }); @@ -329,9 +331,9 @@ public class LocalFileListAdapter extends BaseAdapter implements FilterableListA mFiles = mFilesAll.toArray(new File[1]); } else { ArrayList result = new ArrayList<>(); - text = text.toLowerCase(); + text = text.toLowerCase(Locale.getDefault()); for (File file: mFilesAll) { - if (file.getName().toLowerCase().contains(text)) { + if (file.getName().toLowerCase(Locale.getDefault()).contains(text)) { result.add(file); } } diff --git a/src/main/java/com/owncloud/android/ui/dialog/ShareLinkToDialog.java b/src/main/java/com/owncloud/android/ui/dialog/ShareLinkToDialog.java index a5f65aad67..899e5ff7d4 100644 --- a/src/main/java/com/owncloud/android/ui/dialog/ShareLinkToDialog.java +++ b/src/main/java/com/owncloud/android/ui/dialog/ShareLinkToDialog.java @@ -48,6 +48,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.Iterator; import java.util.List; +import java.util.Locale; /** * Dialog showing a list activities able to resolve a given Intent, @@ -92,7 +93,7 @@ public class ShareLinkToDialog extends DialogFragment { ResolveInfo resolveInfo; while (it.hasNext()) { resolveInfo = it.next(); - if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase())){ + if (packagesToExcludeList.contains(resolveInfo.activityInfo.packageName.toLowerCase(Locale.ROOT))) { it.remove(); } } @@ -169,9 +170,9 @@ public class ShareLinkToDialog extends DialogFragment { } private void bindView(int position, View row) { - TextView label = (TextView) row.findViewById(R.id.title); + TextView label = row.findViewById(R.id.title); label.setText(getItem(position).loadLabel(mPackageManager)); - ImageView icon = (ImageView) row.findViewById(R.id.icon); + ImageView icon = row.findViewById(R.id.icon); icon.setImageDrawable(getItem(position).loadIcon(mPackageManager)); } } diff --git a/src/main/java/com/owncloud/android/utils/BitmapUtils.java b/src/main/java/com/owncloud/android/utils/BitmapUtils.java index cba52789fb..89e44a1096 100644 --- a/src/main/java/com/owncloud/android/utils/BitmapUtils.java +++ b/src/main/java/com/owncloud/android/utils/BitmapUtils.java @@ -34,6 +34,7 @@ import org.apache.commons.codec.binary.Hex; import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; +import java.util.Locale; /** * Utility class with methods for decoding Bitmaps. @@ -277,7 +278,7 @@ public class BitmapUtils { int lum = 68; int modulo = 16; - String hash = name.toLowerCase().replaceAll("[^0-9a-f]", ""); + String hash = name.toLowerCase(Locale.ROOT).replaceAll("[^0-9a-f]", ""); if (!hash.matches("^[0-9a-f]{32}")) { hash = md5(hash); diff --git a/src/main/java/com/owncloud/android/utils/DisplayUtils.java b/src/main/java/com/owncloud/android/utils/DisplayUtils.java index 768b6b3d1d..d36cb408e5 100644 --- a/src/main/java/com/owncloud/android/utils/DisplayUtils.java +++ b/src/main/java/com/owncloud/android/utils/DisplayUtils.java @@ -88,6 +88,7 @@ import java.util.Collection; import java.util.Date; import java.util.HashMap; import java.util.HashSet; +import java.util.Locale; import java.util.Map; import java.util.Set; @@ -163,7 +164,7 @@ public class DisplayUtils { return mimeType2HumanReadable.get(mimetype); } if (mimetype.split("/").length >= 2) { - return mimetype.split("/")[1].toUpperCase() + " file"; + return mimetype.split("/")[1].toUpperCase(Locale.getDefault()) + " file"; } return MIME_TYPE_UNKNOWN; } diff --git a/src/main/java/com/owncloud/android/utils/FileStorageUtils.java b/src/main/java/com/owncloud/android/utils/FileStorageUtils.java index b8f2db5ceb..4fad3e37f6 100644 --- a/src/main/java/com/owncloud/android/utils/FileStorageUtils.java +++ b/src/main/java/com/owncloud/android/utils/FileStorageUtils.java @@ -286,7 +286,7 @@ public class FileStorageUtils { if (pos >= 0) { extension = path.substring(pos + 1); } - String result = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase()); + String result = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase(Locale.ROOT)); return (result != null) ? result : ""; } diff --git a/src/main/java/com/owncloud/android/utils/MimeTypeUtil.java b/src/main/java/com/owncloud/android/utils/MimeTypeUtil.java index c2d10e383f..f91a520088 100644 --- a/src/main/java/com/owncloud/android/utils/MimeTypeUtil.java +++ b/src/main/java/com/owncloud/android/utils/MimeTypeUtil.java @@ -33,6 +33,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; /** @@ -177,29 +178,29 @@ public class MimeTypeUtil { * @return 'True' if the mime type defines image */ public static boolean isImage(String mimeType) { - return (mimeType != null && mimeType.toLowerCase().startsWith("image/") && !mimeType.toLowerCase().contains - ("djvu")); + return (mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("image/") && + !mimeType.toLowerCase(Locale.ROOT).contains("djvu")); } /** * @return 'True' the mime type defines video */ public static boolean isVideo(String mimeType) { - return (mimeType != null && mimeType.toLowerCase().startsWith("video/")); + return (mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("video/")); } /** * @return 'True' the mime type defines audio */ public static boolean isAudio(String mimeType) { - return (mimeType != null && mimeType.toLowerCase().startsWith("audio/")); + return (mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("audio/")); } /** * @return 'True' if mime type defines text */ public static boolean isText(String mimeType) { - return (mimeType != null && mimeType.toLowerCase().startsWith("text/")); + return (mimeType != null && mimeType.toLowerCase(Locale.ROOT).startsWith("text/")); } /** @@ -284,7 +285,7 @@ public class MimeTypeUtil { */ private static String extractMimeType(File file) { Uri selectedUri = Uri.fromFile(file); - String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString().toLowerCase()); + String fileExtension = MimeTypeMap.getFileExtensionFromUrl(selectedUri.toString().toLowerCase(Locale.ROOT)); return MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtension); } @@ -354,7 +355,7 @@ public class MimeTypeUtil { if (pos >= 0) { extension = path.substring(pos + 1); } - String result = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase()); + String result = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension.toLowerCase(Locale.ROOT)); return (result != null) ? result : ""; } @@ -365,7 +366,7 @@ public class MimeTypeUtil { * @return the file extension */ private static String getExtension(String filename) { - return filename.substring(filename.lastIndexOf('.') + 1).toLowerCase(); + return filename.substring(filename.lastIndexOf('.') + 1).toLowerCase(Locale.ROOT); } /** diff --git a/src/main/java/third_parties/daveKoeller/AlphanumComparator.java b/src/main/java/third_parties/daveKoeller/AlphanumComparator.java index da849c27da..7630411a8a 100644 --- a/src/main/java/third_parties/daveKoeller/AlphanumComparator.java +++ b/src/main/java/third_parties/daveKoeller/AlphanumComparator.java @@ -29,6 +29,7 @@ import com.owncloud.android.datamodel.OCFile; import java.io.File; import java.text.Collator; import java.util.Comparator; +import java.util.Locale; /* * This is an updated version with enhancements made by Daniel Migowski, Andre Bogus, and David Koelle @@ -86,15 +87,15 @@ public class AlphanumComparator implements Comparator { } public int compare(OCFile o1, OCFile o2) { - String s1 = o1.getRemotePath().toLowerCase(); - String s2 = o2.getRemotePath().toLowerCase(); + String s1 = o1.getRemotePath().toLowerCase(Locale.ROOT); + String s2 = o2.getRemotePath().toLowerCase(Locale.ROOT); return compare(s1, s2); } public int compare(File f1, File f2) { - String s1 = f1.getPath().toLowerCase(); - String s2 = f2.getPath().toLowerCase(); + String s1 = f1.getPath().toLowerCase(Locale.ROOT); + String s2 = f2.getPath().toLowerCase(Locale.ROOT); return compare(s1, s2); } diff --git a/src/main/java/third_parties/ezvcard_android/DataMappings.java b/src/main/java/third_parties/ezvcard_android/DataMappings.java index bb0948a548..9bc0042533 100644 --- a/src/main/java/third_parties/ezvcard_android/DataMappings.java +++ b/src/main/java/third_parties/ezvcard_android/DataMappings.java @@ -4,6 +4,7 @@ import android.provider.ContactsContract; import java.util.Collections; import java.util.HashMap; +import java.util.Locale; import java.util.Map; import ezvcard.parameter.AddressType; @@ -164,7 +165,7 @@ public class DataMappings { return ContactsContract.CommonDataKinds.Website.TYPE_CUSTOM; } - type = type.toLowerCase(); + type = type.toLowerCase(Locale.ROOT); Integer value = websiteTypeMappings.get(type); return (value == null) ? ContactsContract.CommonDataKinds.Website.TYPE_CUSTOM : value; } @@ -180,7 +181,7 @@ public class DataMappings { return ContactsContract.CommonDataKinds.Event.TYPE_OTHER; } - type = type.toLowerCase(); + type = type.toLowerCase(Locale.ROOT); for (Map.Entry entry : abDateMappings.entrySet()){ if (type.contains(entry.getKey())){ return entry.getValue(); @@ -200,7 +201,7 @@ public class DataMappings { return ContactsContract.CommonDataKinds.Relation.TYPE_CUSTOM; } - type = type.toLowerCase(); + type = type.toLowerCase(Locale.ROOT); for (Map.Entry entry : abRelatedNamesMappings.entrySet()){ if (type.contains(entry.getKey())){ return entry.getValue(); @@ -230,7 +231,7 @@ public class DataMappings { return ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM; } - protocol = protocol.toLowerCase(); + protocol = protocol.toLowerCase(Locale.ROOT); Integer value = imProtocolMappings.get(protocol); return (value == null) ? ContactsContract.CommonDataKinds.Im.PROTOCOL_CUSTOM : value; } diff --git a/src/modified/java/com/owncloud/android/utils/PushUtils.java b/src/modified/java/com/owncloud/android/utils/PushUtils.java index dbb58f5a59..1a86197718 100644 --- a/src/modified/java/com/owncloud/android/utils/PushUtils.java +++ b/src/modified/java/com/owncloud/android/utils/PushUtils.java @@ -63,6 +63,7 @@ import java.security.PublicKey; import java.security.spec.InvalidKeySpecException; import java.security.spec.PKCS8EncodedKeySpec; import java.security.spec.X509EncodedKeySpec; +import java.util.Locale; public class PushUtils { @@ -191,7 +192,7 @@ public class PushUtils { if (!TextUtils.isEmpty(MainApp.getAppContext().getResources().getString(R.string.push_server_url)) && !TextUtils.isEmpty(token)) { PushUtils.generateRsa2048KeyPair(); - String pushTokenHash = PushUtils.generateSHA512Hash(token).toLowerCase(); + String pushTokenHash = PushUtils.generateSHA512Hash(token).toLowerCase(Locale.ROOT); PublicKey devicePublicKey = (PublicKey) PushUtils.readKeyFromFile(true); if (devicePublicKey != null) { byte[] publicKeyBytes = Base64.encode(devicePublicKey.getEncoded(), Base64.NO_WRAP); From d724df86f874f94bd4b7af03116909f417c726d2 Mon Sep 17 00:00:00 2001 From: nextcloud-android-bot <> Date: Fri, 29 Dec 2017 08:43:56 +0000 Subject: [PATCH 2/2] Drone: update Lint results to reflect reduced error/warning count [skip ci] --- scripts/lint/lint-results.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/lint/lint-results.txt b/scripts/lint/lint-results.txt index 6b93ab5519..f346a7aa70 100644 --- a/scripts/lint/lint-results.txt +++ b/scripts/lint/lint-results.txt @@ -1,2 +1,2 @@ DO NOT TOUCH; GENERATED BY DRONE - Lint Report: 172 warnings + Lint Report: 131 warnings