From a6b804e93ac323797fbf84ada4d5018152215150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 17 Feb 2016 11:58:35 +0000 Subject: [PATCH] checkstyle: obey NeedBraces on multi-line stmts We still allow them in single-line statements, like: if (foo) bar; for (int i : ints) bar; Everything else should use braces to help readability and avoid silly human mistakes that might result in bugs. These changes were completely automated via a python script. --- F-Droid/src/org/fdroid/fdroid/AppDetails.java | 87 +++++++++++-------- .../fdroid/fdroid/CompatibilityChecker.java | 5 +- F-Droid/src/org/fdroid/fdroid/FDroid.java | 6 +- F-Droid/src/org/fdroid/fdroid/FDroidApp.java | 3 +- F-Droid/src/org/fdroid/fdroid/Hasher.java | 9 +- F-Droid/src/org/fdroid/fdroid/NfcHelper.java | 12 ++- .../fdroid/fdroid/NfcNotEnabledActivity.java | 5 +- .../src/org/fdroid/fdroid/QrGenAsyncTask.java | 5 +- .../src/org/fdroid/fdroid/RepoUpdater.java | 9 +- .../src/org/fdroid/fdroid/UpdateService.java | 18 ++-- F-Droid/src/org/fdroid/fdroid/Utils.java | 49 +++++++---- .../org/fdroid/fdroid/compat/TabManager.java | 6 +- F-Droid/src/org/fdroid/fdroid/data/App.java | 20 +++-- .../src/org/fdroid/fdroid/data/DBHelper.java | 9 +- .../fdroid/localrepo/LocalRepoKeyStore.java | 6 +- .../fdroid/localrepo/LocalRepoManager.java | 36 +++++--- .../fdroid/fdroid/localrepo/SwapService.java | 3 +- .../fdroid/localrepo/peers/BonjourFinder.java | 3 +- .../fdroid/localrepo/type/BluetoothSwap.java | 12 ++- .../localrepo/type/BonjourBroadcast.java | 3 +- .../fdroid/net/BluetoothDownloader.java | 3 +- .../org/fdroid/fdroid/net/HttpDownloader.java | 3 +- .../src/org/fdroid/fdroid/net/LocalHTTPD.java | 3 +- .../fdroid/net/WifiStateChangeService.java | 29 ++++--- .../fdroid/net/bluetooth/BluetoothClient.java | 3 +- .../fdroid/net/bluetooth/BluetoothServer.java | 6 +- .../fdroid/net/bluetooth/httpish/Request.java | 14 +-- .../fdroid/views/ManageReposActivity.java | 6 +- .../fdroid/views/RepoDetailsActivity.java | 6 +- .../fragments/AvailableAppsFragment.java | 12 ++- .../views/fragments/PreferencesFragment.java | 10 ++- .../fdroid/views/swap/SwapAppsView.java | 6 +- .../views/swap/SwapWorkflowActivity.java | 3 +- .../fdroid/fdroid/views/swap/WifiQrView.java | 3 +- .../fdroid/fdroid/ApkProviderHelperTest.java | 27 ++++-- .../fdroid/fdroid/MultiRepoUpdaterTest.java | 3 +- .../org/fdroid/fdroid/RepoUpdaterTest.java | 21 +++-- config/checkstyle/checkstyle.xml | 4 +- 38 files changed, 303 insertions(+), 165 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/AppDetails.java b/F-Droid/src/org/fdroid/fdroid/AppDetails.java index c1a3df1bc..8a9cb29e0 100644 --- a/F-Droid/src/org/fdroid/fdroid/AppDetails.java +++ b/F-Droid/src/org/fdroid/fdroid/AppDetails.java @@ -468,10 +468,11 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A new IntentFilter(Downloader.LOCAL_ACTION_PROGRESS)); downloadHandler.setProgressListener(this); - if (downloadHandler.getTotalBytes() == 0) + if (downloadHandler.getTotalBytes() == 0) { mHeaderFragment.startProgress(); - else + } else { mHeaderFragment.updateProgress(downloadHandler.getBytesRead(), downloadHandler.getTotalBytes()); + } } } } @@ -523,9 +524,10 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A private final BroadcastReceiver downloaderProgressReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - if (mHeaderFragment != null) + if (mHeaderFragment != null) { mHeaderFragment.updateProgress(intent.getIntExtra(Downloader.EXTRA_BYTES_READ, -1), - intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, -1)); + intent.getIntExtra(Downloader.EXTRA_TOTAL_BYTES, -1)); + } } }; @@ -618,8 +620,9 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A public boolean onPrepareOptionsMenu(Menu menu) { super.onPrepareOptionsMenu(menu); menu.clear(); - if (app == null) + if (app == null) { return true; + } if (mPm.getLaunchIntentForPackage(app.packageName) != null && app.canAndWantToUpdate()) { MenuItemCompat.setShowAsAction(menu.add( @@ -773,10 +776,11 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A return true; case IGNORETHIS: - if (app.ignoreThisUpdate >= app.suggestedVercode) + if (app.ignoreThisUpdate >= app.suggestedVercode) { app.ignoreThisUpdate = 0; - else + } else { app.ignoreThisUpdate = app.suggestedVercode; + } item.setChecked(app.ignoreThisUpdate > 0); return true; @@ -803,8 +807,9 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A } // Ignore call if another download is running. - if (downloadHandler != null && !downloadHandler.isComplete()) + if (downloadHandler != null && !downloadHandler.isComplete()) { return; + } final String repoaddress = getRepoAddress(apk); if (repoaddress == null) return; @@ -988,10 +993,11 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A switch (event.type) { case ApkDownloader.EVENT_ERROR: final int res; - if (event.getData().getInt(ApkDownloader.EVENT_DATA_ERROR_TYPE) == ApkDownloader.ERROR_HASH_MISMATCH) + if (event.getData().getInt(ApkDownloader.EVENT_DATA_ERROR_TYPE) == ApkDownloader.ERROR_HASH_MISMATCH) { res = R.string.corrupt_download; - else + } else { res = R.string.details_notinstalled; + } // this must be on the main UI thread Toast.makeText(this, res, Toast.LENGTH_LONG).show(); cleanUpFinishedDownload(); @@ -1004,8 +1010,9 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A } if (finished) { - if (mHeaderFragment != null) + if (mHeaderFragment != null) { mHeaderFragment.removeProgress(); + } downloadHandler = null; } } @@ -1215,10 +1222,11 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A // App ID final TextView packageNameView = (TextView) view.findViewById(R.id.package_name); - if (prefs.expertMode()) + if (prefs.expertMode()) { packageNameView.setText(app.packageName); - else + } else { packageNameView.setVisibility(View.GONE); + } // Summary final TextView summaryView = (TextView) view.findViewById(R.id.summary); @@ -1232,73 +1240,83 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A // Website button View tv = view.findViewById(R.id.website); - if (!TextUtils.isEmpty(app.webURL)) + if (!TextUtils.isEmpty(app.webURL)) { tv.setOnClickListener(mOnClickListener); - else + } else { tv.setVisibility(View.GONE); + } // Email button tv = view.findViewById(R.id.email); - if (!TextUtils.isEmpty(app.email)) + if (!TextUtils.isEmpty(app.email)) { tv.setOnClickListener(mOnClickListener); - else + } else { tv.setVisibility(View.GONE); + } // Source button tv = view.findViewById(R.id.source); - if (!TextUtils.isEmpty(app.sourceURL)) + if (!TextUtils.isEmpty(app.sourceURL)) { tv.setOnClickListener(mOnClickListener); - else + } else { tv.setVisibility(View.GONE); + } // Issues button tv = view.findViewById(R.id.issues); - if (!TextUtils.isEmpty(app.trackerURL)) + if (!TextUtils.isEmpty(app.trackerURL)) { tv.setOnClickListener(mOnClickListener); - else + } else { tv.setVisibility(View.GONE); + } // Changelog button tv = view.findViewById(R.id.changelog); - if (!TextUtils.isEmpty(app.changelogURL)) + if (!TextUtils.isEmpty(app.changelogURL)) { tv.setOnClickListener(mOnClickListener); - else + } else { tv.setVisibility(View.GONE); + } // Donate button tv = view.findViewById(R.id.donate); - if (!TextUtils.isEmpty(app.donateURL)) + if (!TextUtils.isEmpty(app.donateURL)) { tv.setOnClickListener(mOnClickListener); - else + } else { tv.setVisibility(View.GONE); + } // Bitcoin tv = view.findViewById(R.id.bitcoin); - if (!TextUtils.isEmpty(app.bitcoinAddr)) + if (!TextUtils.isEmpty(app.bitcoinAddr)) { tv.setOnClickListener(mOnClickListener); - else + } else { tv.setVisibility(View.GONE); + } // Litecoin tv = view.findViewById(R.id.litecoin); - if (!TextUtils.isEmpty(app.litecoinAddr)) + if (!TextUtils.isEmpty(app.litecoinAddr)) { tv.setOnClickListener(mOnClickListener); - else + } else { tv.setVisibility(View.GONE); + } // Flattr tv = view.findViewById(R.id.flattr); - if (!TextUtils.isEmpty(app.flattrID)) + if (!TextUtils.isEmpty(app.flattrID)) { tv.setOnClickListener(mOnClickListener); - else + } else { tv.setVisibility(View.GONE); + } // Categories TextView final TextView categories = (TextView) view.findViewById(R.id.categories); - if (prefs.expertMode() && app.categories != null) + if (prefs.expertMode() && app.categories != null) { categories.setText(app.categories.toString().replaceAll(",", ", ")); - else + } else { categories.setVisibility(View.GONE); + } Apk curApk = null; for (int i = 0; i < getApks().getCount(); i++) { @@ -1544,8 +1562,9 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A @Override public void onClick(View view) { AppDetails activity = (AppDetails) getActivity(); - if (activity == null || activity.downloadHandler == null) + if (activity == null || activity.downloadHandler == null) { return; + } activity.downloadHandler.cancel(true); activity.cleanUpFinishedDownload(); diff --git a/F-Droid/src/org/fdroid/fdroid/CompatibilityChecker.java b/F-Droid/src/org/fdroid/fdroid/CompatibilityChecker.java index 6046f677e..656b98c0c 100644 --- a/F-Droid/src/org/fdroid/fdroid/CompatibilityChecker.java +++ b/F-Droid/src/org/fdroid/fdroid/CompatibilityChecker.java @@ -59,10 +59,11 @@ public class CompatibilityChecker extends Compatibility { StringBuilder builder = new StringBuilder(); boolean first = true; for (final String abi : cpuAbis) { - if (first) + if (first) { first = false; - else + } else { builder.append(", "); + } builder.append(abi); } cpuAbisDesc = builder.toString(); diff --git a/F-Droid/src/org/fdroid/fdroid/FDroid.java b/F-Droid/src/org/fdroid/fdroid/FDroid.java index 3c8761d7b..11f2cc73d 100644 --- a/F-Droid/src/org/fdroid/fdroid/FDroid.java +++ b/F-Droid/src/org/fdroid/fdroid/FDroid.java @@ -232,12 +232,14 @@ public class FDroid extends AppCompatActivity implements SearchView.OnQueryTextL if (!TextUtils.isEmpty(query)) { // an old format for querying via packageName - if (query.startsWith("pname:")) + if (query.startsWith("pname:")) { packageName = query.split(":")[1]; + } // sometimes, search URLs include pub: or other things before the query string - if (query.contains(":")) + if (query.contains(":")) { query = query.split(":")[1]; + } } if (!TextUtils.isEmpty(packageName)) { diff --git a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java index 0e58fb95d..b02d34cc2 100644 --- a/F-Droid/src/org/fdroid/fdroid/FDroidApp.java +++ b/F-Droid/src/org/fdroid/fdroid/FDroidApp.java @@ -309,8 +309,9 @@ public class FDroidApp extends Application { } public void sendViaBluetooth(Activity activity, int resultCode, String packageName) { - if (resultCode == Activity.RESULT_CANCELED) + if (resultCode == Activity.RESULT_CANCELED) { return; + } String bluetoothPackageName = null; String className = null; boolean found = false; diff --git a/F-Droid/src/org/fdroid/fdroid/Hasher.java b/F-Droid/src/org/fdroid/fdroid/Hasher.java index 2ce6f18fd..a6bf80635 100644 --- a/F-Droid/src/org/fdroid/fdroid/Hasher.java +++ b/F-Droid/src/org/fdroid/fdroid/Hasher.java @@ -124,14 +124,15 @@ public class Hasher { for (int i = 0; i < data.length(); i++) { char halfbyte = data.charAt(i); int value; - if ('0' <= halfbyte && halfbyte <= '9') + if ('0' <= halfbyte && halfbyte <= '9') { value = halfbyte - '0'; - else if ('a' <= halfbyte && halfbyte <= 'f') + } else if ('a' <= halfbyte && halfbyte <= 'f') { value = halfbyte - 'a' + 10; - else if ('A' <= halfbyte && halfbyte <= 'F') + } else if ('A' <= halfbyte && halfbyte <= 'F') { value = halfbyte - 'A' + 10; - else + } else { throw new IllegalArgumentException("Bad hex digit"); + } rawdata[i / 2] += (byte) (i % 2 == 0 ? value << 4 : value); } return rawdata; diff --git a/F-Droid/src/org/fdroid/fdroid/NfcHelper.java b/F-Droid/src/org/fdroid/fdroid/NfcHelper.java index 17eba082e..7490c1598 100644 --- a/F-Droid/src/org/fdroid/fdroid/NfcHelper.java +++ b/F-Droid/src/org/fdroid/fdroid/NfcHelper.java @@ -18,8 +18,9 @@ public class NfcHelper { @TargetApi(14) private static NfcAdapter getAdapter(Context context) { - if (Build.VERSION.SDK_INT < 14) + if (Build.VERSION.SDK_INT < 14) { return null; + } return NfcAdapter.getDefaultAdapter(context.getApplicationContext()); } @@ -38,8 +39,9 @@ public class NfcHelper { @TargetApi(16) static void setAndroidBeam(Activity activity, String packageName) { - if (Build.VERSION.SDK_INT < 16) + if (Build.VERSION.SDK_INT < 16) { return; + } PackageManager pm = activity.getPackageManager(); NfcAdapter nfcAdapter = getAdapter(activity); if (nfcAdapter != null) { @@ -58,11 +60,13 @@ public class NfcHelper { @TargetApi(16) static void disableAndroidBeam(Activity activity) { - if (Build.VERSION.SDK_INT < 16) + if (Build.VERSION.SDK_INT < 16) { return; + } NfcAdapter nfcAdapter = getAdapter(activity); - if (nfcAdapter != null) + if (nfcAdapter != null) { nfcAdapter.setBeamPushUris(null, activity); + } } } diff --git a/F-Droid/src/org/fdroid/fdroid/NfcNotEnabledActivity.java b/F-Droid/src/org/fdroid/fdroid/NfcNotEnabledActivity.java index a0f1c8e94..e6f49ad48 100644 --- a/F-Droid/src/org/fdroid/fdroid/NfcNotEnabledActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/NfcNotEnabledActivity.java @@ -24,10 +24,11 @@ public class NfcNotEnabledActivity extends ActionBarActivity { if (nfcAdapter == null) { return; } - if (nfcAdapter.isEnabled()) + if (nfcAdapter.isEnabled()) { intent.setAction(Settings.ACTION_NFCSHARING_SETTINGS); - else + } else { intent.setAction(Settings.ACTION_NFC_SETTINGS); + } } // this API was added in 4.0 aka Ice Cream Sandwich diff --git a/F-Droid/src/org/fdroid/fdroid/QrGenAsyncTask.java b/F-Droid/src/org/fdroid/fdroid/QrGenAsyncTask.java index 4ba8800fc..c257859ed 100644 --- a/F-Droid/src/org/fdroid/fdroid/QrGenAsyncTask.java +++ b/F-Droid/src/org/fdroid/fdroid/QrGenAsyncTask.java @@ -48,10 +48,11 @@ public class QrGenAsyncTask extends AsyncTask { x = display.getWidth(); y = display.getHeight(); } - if (x < y) + if (x < y) { qrCodeDimension = x; - else + } else { qrCodeDimension = y; + } Utils.debugLog(TAG, "generating QRCode Bitmap of " + qrCodeDimension + "x" + qrCodeDimension); QRCodeEncoder qrCodeEncoder = new QRCodeEncoder(qrData, null, Contents.Type.TEXT, BarcodeFormat.QR_CODE.toString(), qrCodeDimension); diff --git a/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java b/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java index 26819e2e9..cdb55020f 100644 --- a/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java +++ b/F-Droid/src/org/fdroid/fdroid/RepoUpdater.java @@ -164,8 +164,9 @@ public class RepoUpdater { public void processDownloadedFile(File downloadedFile) throws UpdateException { InputStream indexInputStream = null; try { - if (downloadedFile == null || !downloadedFile.exists()) + if (downloadedFile == null || !downloadedFile.exists()) { throw new UpdateException(repo, downloadedFile + " does not exist!"); + } // Due to a bug in Android 5.0 Lollipop, the inclusion of spongycastle causes // breakage when verifying the signature of the downloaded .jar. For more @@ -306,8 +307,9 @@ public class RepoUpdater { */ private void verifyAndStoreTOFUCerts(String certFromIndexXml, X509Certificate rawCertFromJar) throws SigningException { - if (repo.pubkey != null) + if (repo.pubkey != null) { return; // there is a repo.pubkey already, nothing to TOFU + } /* The first time a repo is added, it can be added with the signing certificate's * fingerprint. In that case, check that fingerprint against what is @@ -348,8 +350,9 @@ public class RepoUpdater { // repo and repo.pubkey must be pre-loaded from the database if (TextUtils.isEmpty(repo.pubkey) || TextUtils.isEmpty(certFromJar) - || TextUtils.isEmpty(certFromIndexXml)) + || TextUtils.isEmpty(certFromIndexXml)) { throw new SigningException(repo, "A empty repo or signing certificate is invalid!"); + } // though its called repo.pubkey, its actually a X509 certificate if (repo.pubkey.equals(certFromJar) diff --git a/F-Droid/src/org/fdroid/fdroid/UpdateService.java b/F-Droid/src/org/fdroid/fdroid/UpdateService.java index dfe23e177..927d4783d 100644 --- a/F-Droid/src/org/fdroid/fdroid/UpdateService.java +++ b/F-Droid/src/org/fdroid/fdroid/UpdateService.java @@ -173,8 +173,9 @@ public class UpdateService extends IntentService implements ProgressListener { protected static void sendStatus(Context context, int statusCode, String message, int progress) { Intent intent = new Intent(LOCAL_ACTION_STATUS); intent.putExtra(EXTRA_STATUS_CODE, statusCode); - if (!TextUtils.isEmpty(message)) + if (!TextUtils.isEmpty(message)) { intent.putExtra(EXTRA_MESSAGE, message); + } intent.putExtra(EXTRA_PROGRESS, progress); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); } @@ -190,11 +191,13 @@ public class UpdateService extends IntentService implements ProgressListener { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (TextUtils.isEmpty(action)) + if (TextUtils.isEmpty(action)) { return; + } - if (!action.equals(Downloader.LOCAL_ACTION_PROGRESS)) + if (!action.equals(Downloader.LOCAL_ACTION_PROGRESS)) { return; + } String repoAddress = intent.getStringExtra(Downloader.EXTRA_ADDRESS); int downloadedSize = intent.getIntExtra(Downloader.EXTRA_BYTES_READ, -1); @@ -220,11 +223,13 @@ public class UpdateService extends IntentService implements ProgressListener { @Override public void onReceive(Context context, Intent intent) { String action = intent.getAction(); - if (TextUtils.isEmpty(action)) + if (TextUtils.isEmpty(action)) { return; + } - if (!action.equals(LOCAL_ACTION_STATUS)) + if (!action.equals(LOCAL_ACTION_STATUS)) { return; + } final String message = intent.getStringExtra(EXTRA_MESSAGE); int resultCode = intent.getIntExtra(EXTRA_STATUS_CODE, -1); @@ -317,8 +322,9 @@ public class UpdateService extends IntentService implements ProgressListener { // this could be cellular or wifi NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); - if (activeNetwork == null) + if (activeNetwork == null) { return false; + } SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI diff --git a/F-Droid/src/org/fdroid/fdroid/Utils.java b/F-Droid/src/org/fdroid/fdroid/Utils.java index 8aa75072c..ee5c7f8a2 100644 --- a/F-Droid/src/org/fdroid/fdroid/Utils.java +++ b/F-Droid/src/org/fdroid/fdroid/Utils.java @@ -275,38 +275,44 @@ public final class Utils { public static String formatFingerprint(Context context, String fingerprint) { if (TextUtils.isEmpty(fingerprint) || fingerprint.length() != 64 // SHA-256 is 64 hex chars - || fingerprint.matches(".*[^0-9a-fA-F].*")) // its a hex string + || fingerprint.matches(".*[^0-9a-fA-F].*")) { // its a hex string return context.getString(R.string.bad_fingerprint); + } String displayFP = fingerprint.substring(0, 2); - for (int i = 2; i < fingerprint.length(); i = i + 2) + for (int i = 2; i < fingerprint.length(); i = i + 2) { displayFP += " " + fingerprint.substring(i, i + 2); + } return displayFP; } @NonNull public static Uri getLocalRepoUri(Repo repo) { - if (TextUtils.isEmpty(repo.address)) + if (TextUtils.isEmpty(repo.address)) { return Uri.parse("http://wifi-not-enabled"); + } Uri uri = Uri.parse(repo.address); Uri.Builder b = uri.buildUpon(); - if (!TextUtils.isEmpty(repo.fingerprint)) + if (!TextUtils.isEmpty(repo.fingerprint)) { b.appendQueryParameter("fingerprint", repo.fingerprint); + } String scheme = Preferences.get().isLocalRepoHttpsEnabled() ? "https" : "http"; b.scheme(scheme); return b.build(); } public static Uri getSharingUri(Repo repo) { - if (TextUtils.isEmpty(repo.address)) + if (TextUtils.isEmpty(repo.address)) { return Uri.parse("http://wifi-not-enabled"); + } Uri localRepoUri = getLocalRepoUri(repo); Uri.Builder b = localRepoUri.buildUpon(); b.scheme(localRepoUri.getScheme().replaceFirst("http", "fdroidrepo")); b.appendQueryParameter("swap", "1"); if (!TextUtils.isEmpty(FDroidApp.bssid)) { b.appendQueryParameter("bssid", FDroidApp.bssid); - if (!TextUtils.isEmpty(FDroidApp.ssid)) + if (!TextUtils.isEmpty(FDroidApp.ssid)) { b.appendQueryParameter("ssid", FDroidApp.ssid); + } } return b.build(); } @@ -350,8 +356,9 @@ public final class Utils { } public static String calcFingerprint(Certificate cert) { - if (cert == null) + if (cert == null) { return null; + } try { return calcFingerprint(cert.getEncoded()); } catch (CertificateEncodingException e) { @@ -360,8 +367,9 @@ public final class Utils { } private static String calcFingerprint(byte[] key) { - if (key == null) + if (key == null) { return null; + } if (key.length < 256) { Log.e(TAG, "key was shorter than 256 bytes (" + key.length + "), cannot be valid!"); return null; @@ -426,8 +434,9 @@ public final class Utils { } public static CommaSeparatedList make(List list) { - if (list == null || list.isEmpty()) + if (list == null || list.isEmpty()) { return null; + } StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.size(); i++) { if (i > 0) { @@ -439,8 +448,9 @@ public final class Utils { } public static CommaSeparatedList make(String[] list) { - if (list == null || list.length == 0) + if (list == null || list.length == 0) { return null; + } StringBuilder sb = new StringBuilder(); for (int i = 0; i < list.length; i++) { if (i > 0) { @@ -453,8 +463,9 @@ public final class Utils { @Nullable public static CommaSeparatedList make(@Nullable String list) { - if (TextUtils.isEmpty(list)) + if (TextUtils.isEmpty(list)) { return null; + } return new CommaSeparatedList(list); } @@ -480,8 +491,9 @@ public final class Utils { public boolean contains(String v) { for (final String s : this) { - if (s.equals(v)) + if (s.equals(v)) { return true; + } } return false; } @@ -522,8 +534,9 @@ public final class Utils { byte[] dataBytes = new byte[524288]; int nread; - while ((nread = bis.read(dataBytes)) != -1) + while ((nread = bis.read(dataBytes)) != -1) { md.update(dataBytes, 0, nread); + } byte[] mdbytes = md.digest(); return toHexString(mdbytes); @@ -609,16 +622,18 @@ public final class Utils { XMLReader reader) { switch (tag) { case "ul": - if (opening) + if (opening) { listNum = -1; - else + } else { output.append('\n'); + } break; case "ol": - if (opening) + if (opening) { listNum = 1; - else + } else { output.append('\n'); + } break; case "li": if (opening) { diff --git a/F-Droid/src/org/fdroid/fdroid/compat/TabManager.java b/F-Droid/src/org/fdroid/fdroid/compat/TabManager.java index b0be97bf0..cda6801c8 100644 --- a/F-Droid/src/org/fdroid/fdroid/compat/TabManager.java +++ b/F-Droid/src/org/fdroid/fdroid/compat/TabManager.java @@ -56,8 +56,9 @@ public class TabManager { FragmentTransaction ft) { int pos = tab.getPosition(); pager.setCurrentItem(pos); - if (pos == INDEX_CAN_UPDATE) + if (pos == INDEX_CAN_UPDATE) { removeNotification(1); + } } @Override @@ -78,8 +79,9 @@ public class TabManager { if (actionBarSpinner != null) { actionBarSpinner.setSelection(index); } - if (index == INDEX_CAN_UPDATE) + if (index == INDEX_CAN_UPDATE) { removeNotification(1); + } } public void refreshTabLabel(int index) { diff --git a/F-Droid/src/org/fdroid/fdroid/data/App.java b/F-Droid/src/org/fdroid/fdroid/data/App.java index db8c0d002..27d650a88 100644 --- a/F-Droid/src/org/fdroid/fdroid/data/App.java +++ b/F-Droid/src/org/fdroid/fdroid/data/App.java @@ -250,20 +250,23 @@ public class App extends ValueObject implements Comparable { Log.w(TAG, "Could not get app info: " + installerPackageName, e); } } - if (TextUtils.isEmpty(installerPackageLabel)) + if (TextUtils.isEmpty(installerPackageLabel)) { installerPackageLabel = installerPackageName; + } final CharSequence appDescription = appInfo.loadDescription(pm); - if (TextUtils.isEmpty(appDescription)) + if (TextUtils.isEmpty(appDescription)) { this.summary = "(installed by " + installerPackageLabel + ")"; - else + } else { this.summary = (String) appDescription.subSequence(0, 40); + } this.packageName = appInfo.packageName; this.added = new Date(packageInfo.firstInstallTime); this.lastUpdated = new Date(packageInfo.lastUpdateTime); this.description = "

"; - if (!TextUtils.isEmpty(appDescription)) + if (!TextUtils.isEmpty(appDescription)) { this.description += appDescription + "\n"; + } this.description += "(installed by " + installerPackageLabel + ", first installed on " + this.added + ", last updated on " + this.lastUpdated + ")

"; @@ -358,14 +361,17 @@ public class App extends ValueObject implements Comparable { public boolean isValid() { if (TextUtils.isEmpty(this.name) - || TextUtils.isEmpty(this.packageName)) + || TextUtils.isEmpty(this.packageName)) { return false; + } - if (this.installedApk == null) + if (this.installedApk == null) { return false; + } - if (TextUtils.isEmpty(this.installedApk.sig)) + if (TextUtils.isEmpty(this.installedApk.sig)) { return false; + } final File apkFile = this.installedApk.installedFile; return !(apkFile == null || !apkFile.canRead()); diff --git a/F-Droid/src/org/fdroid/fdroid/data/DBHelper.java b/F-Droid/src/org/fdroid/fdroid/data/DBHelper.java index da0e1dd87..083abe138 100644 --- a/F-Droid/src/org/fdroid/fdroid/data/DBHelper.java +++ b/F-Droid/src/org/fdroid/fdroid/data/DBHelper.java @@ -350,10 +350,12 @@ public class DBHelper extends SQLiteOpenHelper { boolean nameExists = columnExists(db, TABLE_REPO, "name"); boolean descriptionExists = columnExists(db, TABLE_REPO, "description"); if (oldVersion < 21 && !(nameExists && descriptionExists)) { - if (!nameExists) + if (!nameExists) { db.execSQL("alter table " + TABLE_REPO + " add column name text"); - if (!descriptionExists) + } + if (!descriptionExists) { db.execSQL("alter table " + TABLE_REPO + " add column description text"); + } insertNameAndDescription(db, R.string.fdroid_repo_address, R.string.fdroid_repo_name, R.string.fdroid_repo_description); insertNameAndDescription(db, R.string.fdroid_archive_address, @@ -372,8 +374,9 @@ public class DBHelper extends SQLiteOpenHelper { */ private void addFingerprintToRepo(SQLiteDatabase db, int oldVersion) { if (oldVersion < 44) { - if (!columnExists(db, TABLE_REPO, "fingerprint")) + if (!columnExists(db, TABLE_REPO, "fingerprint")) { db.execSQL("alter table " + TABLE_REPO + " add column fingerprint text"); + } List oldrepos = new ArrayList<>(); Cursor cursor = db.query(TABLE_REPO, new String[] {"address", "pubkey"}, diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoKeyStore.java b/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoKeyStore.java index e54a2fa8f..7e1b3cf0b 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoKeyStore.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoKeyStore.java @@ -73,8 +73,9 @@ public final class LocalRepoKeyStore { private File keyStoreFile; public static LocalRepoKeyStore get(Context context) throws InitException { - if (localRepoKeyStore == null) + if (localRepoKeyStore == null) { localRepoKeyStore = new LocalRepoKeyStore(context); + } return localRepoKeyStore; } @@ -240,8 +241,9 @@ public final class LocalRepoKeyStore { public Certificate getCertificate() { try { Key key = keyStore.getKey(INDEX_CERT_ALIAS, "".toCharArray()); - if (key instanceof PrivateKey) + if (key instanceof PrivateKey) { return keyStore.getCertificate(INDEX_CERT_ALIAS); + } } catch (GeneralSecurityException e) { Log.e(TAG, "Unable to get certificate for local repo", e); } diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java b/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java index b055ac9d6..5ae72b52b 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java @@ -96,8 +96,9 @@ public final class LocalRepoManager { @NonNull public static LocalRepoManager get(Context context) { - if (localRepoManager == null) + if (localRepoManager == null) { localRepoManager = new LocalRepoManager(context); + } return localRepoManager; } @@ -118,17 +119,23 @@ public final class LocalRepoManager { xmlIndexJar = new SanitizedFile(repoDir, "index.jar"); xmlIndexJarUnsigned = new SanitizedFile(repoDir, "index.unsigned.jar"); - if (!fdroidDir.exists()) - if (!fdroidDir.mkdir()) + if (!fdroidDir.exists()) { + if (!fdroidDir.mkdir()) { Log.e(TAG, "Unable to create empty base: " + fdroidDir); + } + } - if (!repoDir.exists()) - if (!repoDir.mkdir()) + if (!repoDir.exists()) { + if (!repoDir.mkdir()) { Log.e(TAG, "Unable to create empty repo: " + repoDir); + } + } - if (!iconsDir.exists()) - if (!iconsDir.mkdir()) + if (!iconsDir.exists()) { + if (!iconsDir.mkdir()) { Log.e(TAG, "Unable to create icons folder: " + iconsDir); + } + } } private String writeFdroidApkToWebroot() { @@ -140,8 +147,9 @@ public final class LocalRepoManager { SanitizedFile apkFile = SanitizedFile.knownSanitized(appInfo.publicSourceDir); SanitizedFile fdroidApkLink = new SanitizedFile(webRoot, "fdroid.client.apk"); attemptToDelete(fdroidApkLink); - if (Utils.symlinkOrCopyFileQuietly(apkFile, fdroidApkLink)) + if (Utils.symlinkOrCopyFileQuietly(apkFile, fdroidApkLink)) { fdroidClientURL = "/" + fdroidApkLink.getName(); + } } catch (PackageManager.NameNotFoundException e) { Log.e(TAG, "Could not set up F-Droid apk in the webroot", e); } @@ -249,8 +257,9 @@ public final class LocalRepoManager { if (app.installedApk != null) { SanitizedFile outFile = new SanitizedFile(repoDir, app.installedApk.apkName); - if (Utils.symlinkOrCopyFileQuietly(app.installedApk.installedFile, outFile)) + if (Utils.symlinkOrCopyFileQuietly(app.installedApk.installedFile, outFile)) { continue; + } } // if we got here, something went wrong throw new IllegalStateException("Unable to copy APK"); @@ -261,8 +270,9 @@ public final class LocalRepoManager { App app; try { app = new App(context.getApplicationContext(), pm, packageName); - if (!app.isValid()) + if (!app.isValid()) { return; + } PackageInfo packageInfo = pm.getPackageInfo(packageName, PackageManager.GET_META_DATA); app.icon = getIconFile(packageName, packageInfo.versionCode).getName(); } catch (PackageManager.NameNotFoundException | CertificateEncodingException | IOException e) { @@ -464,16 +474,18 @@ public final class LocalRepoManager { buff.append(','); } String out = buff.toString(); - if (!TextUtils.isEmpty(out)) + if (!TextUtils.isEmpty(out)) { serializer.text(out.substring(0, out.length() - 1)); + } } serializer.endTag("", "permissions"); } private void tagFeatures(App app) throws IOException { serializer.startTag("", "features"); - if (app.installedApk.features != null) + if (app.installedApk.features != null) { serializer.text(Utils.CommaSeparatedList.str(app.installedApk.features)); + } serializer.endTag("", "features"); } diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java index 48296f5c7..f5596c33c 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/SwapService.java @@ -279,8 +279,9 @@ public class SwapService extends Service { values.put(RepoProvider.DataColumns.ADDRESS, peer.getRepoAddress()); values.put(RepoProvider.DataColumns.DESCRIPTION, ""); String fingerprint = peer.getFingerprint(); - if (!TextUtils.isEmpty(fingerprint)) + if (!TextUtils.isEmpty(fingerprint)) { values.put(RepoProvider.DataColumns.FINGERPRINT, peer.getFingerprint()); + } values.put(RepoProvider.DataColumns.IN_USE, true); values.put(RepoProvider.DataColumns.IS_SWAP, true); Uri uri = RepoProvider.Helper.insert(this, values); diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/peers/BonjourFinder.java b/F-Droid/src/org/fdroid/fdroid/localrepo/peers/BonjourFinder.java index 6d0c411bb..7d763dd19 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/peers/BonjourFinder.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/peers/BonjourFinder.java @@ -152,8 +152,9 @@ class BonjourFinder extends PeerFinder implements ServiceListener { isScanning = false; - if (jmdns == null) + if (jmdns == null) { return; + } jmdns.removeServiceListener(HTTP_SERVICE_TYPE, this); jmdns.removeServiceListener(HTTPS_SERVICE_TYPE, this); jmdns = null; diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/type/BluetoothSwap.java b/F-Droid/src/org/fdroid/fdroid/localrepo/type/BluetoothSwap.java index 9a7d4b8aa..31c191a52 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/type/BluetoothSwap.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/type/BluetoothSwap.java @@ -35,8 +35,9 @@ public final class BluetoothSwap extends SwapType { if (adapter == null) { return new NoBluetoothType(context); } - if (mInstance == null) + if (mInstance == null) { mInstance = new BluetoothSwap(context, adapter); + } return mInstance; } @@ -59,8 +60,9 @@ public final class BluetoothSwap extends SwapType { @Override public synchronized void start() { - if (isConnected()) + if (isConnected()) { return; + } receiver = new BroadcastReceiver() { @Override @@ -90,8 +92,9 @@ public final class BluetoothSwap extends SwapType { server = null; }*/ - if (server == null) + if (server == null) { server = new BluetoothServer(this, context.getFilesDir()); + } sendBroadcast(SwapService.EXTRA_STARTING); @@ -100,8 +103,9 @@ public final class BluetoothSwap extends SwapType { /* Utils.debugLog(TAG, "Prefixing Bluetooth adapter name with " + BLUETOOTH_NAME_TAG + " to make it identifiable as a swap device."); - if (!deviceBluetoothName.startsWith(BLUETOOTH_NAME_TAG)) + if (!deviceBluetoothName.startsWith(BLUETOOTH_NAME_TAG)) { adapter.setName(BLUETOOTH_NAME_TAG + deviceBluetoothName); + } if (!adapter.getName().startsWith(BLUETOOTH_NAME_TAG)) { Log.e(TAG, "Couldn't change the name of the Bluetooth adapter, it will not get recognized by other swap clients."); diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/type/BonjourBroadcast.java b/F-Droid/src/org/fdroid/fdroid/localrepo/type/BonjourBroadcast.java index 63181ce26..821731a54 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/type/BonjourBroadcast.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/type/BonjourBroadcast.java @@ -40,8 +40,9 @@ public class BonjourBroadcast extends SwapType { * of JmDNS, and there is only ever a single LocalHTTPD port to * advertise anyway. */ - if (pairService != null || jmdns != null) + if (pairService != null || jmdns != null) { clearCurrentMDNSService(); + } String repoName = Preferences.get().getLocalRepoName(); HashMap values = new HashMap<>(); values.put("path", "/fdroid/repo"); diff --git a/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java index 6ce82cdfb..cf38c1d2a 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/BluetoothDownloader.java @@ -95,8 +95,9 @@ public class BluetoothDownloader extends Downloader { @Override protected void close() { - if (connection != null) + if (connection != null) { connection.closeQuietly(); + } } } diff --git a/F-Droid/src/org/fdroid/fdroid/net/HttpDownloader.java b/F-Droid/src/org/fdroid/fdroid/net/HttpDownloader.java index 1b428aab3..9cfa0310c 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/HttpDownloader.java +++ b/F-Droid/src/org/fdroid/fdroid/net/HttpDownloader.java @@ -89,8 +89,9 @@ public class HttpDownloader extends Downloader { } protected void setupConnection() throws IOException { - if (connection != null) + if (connection != null) { return; + } Preferences prefs = Preferences.get(); if (prefs.isProxyEnabled() && !isSwapUrl()) { SocketAddress sa = new InetSocketAddress(prefs.getProxyHost(), prefs.getProxyPort()); diff --git a/F-Droid/src/org/fdroid/fdroid/net/LocalHTTPD.java b/F-Droid/src/org/fdroid/fdroid/net/LocalHTTPD.java index 243464f9d..dcb318d1f 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/LocalHTTPD.java +++ b/F-Droid/src/org/fdroid/fdroid/net/LocalHTTPD.java @@ -40,8 +40,9 @@ public class LocalHTTPD extends NanoHTTPD { super(hostname, port); this.webRoot = webRoot; this.context = context.getApplicationContext(); - if (useHttps) + if (useHttps) { enableHTTPS(); + } } /** diff --git a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java index a45484fee..dd6a1dcd5 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java +++ b/F-Droid/src/org/fdroid/fdroid/net/WifiStateChangeService.java @@ -80,8 +80,9 @@ public class WifiStateChangeService extends Service { wifiState = wifiManager.getWifiState(); while (FDroidApp.ipAddressString == null) { - if (isCancelled()) // can be canceled by a change via WifiStateChangeReceiver + if (isCancelled()) { // can be canceled by a change via WifiStateChangeReceiver return null; + } if (wifiState == WifiManager.WIFI_STATE_ENABLED) { wifiInfo = wifiManager.getConnectionInfo(); FDroidApp.ipAddressString = formatIpAddress(wifiInfo.getIpAddress()); @@ -90,14 +91,16 @@ public class WifiStateChangeService extends Service { return null; } String netmask = formatIpAddress(dhcpInfo.netmask); - if (!TextUtils.isEmpty(FDroidApp.ipAddressString) && netmask != null) + if (!TextUtils.isEmpty(FDroidApp.ipAddressString) && netmask != null) { FDroidApp.subnetInfo = new SubnetUtils(FDroidApp.ipAddressString, netmask).getInfo(); + } } else if (wifiState == WifiManager.WIFI_STATE_DISABLED || wifiState == WifiManager.WIFI_STATE_DISABLING) { // try once to see if its a hotspot setIpInfoFromNetworkInterface(); - if (FDroidApp.ipAddressString == null) + if (FDroidApp.ipAddressString == null) { return null; + } } else { // a hotspot can be active during WIFI_STATE_UNKNOWN setIpInfoFromNetworkInterface(); } @@ -107,8 +110,9 @@ public class WifiStateChangeService extends Service { Utils.debugLog(TAG, "waiting for an IP address..."); } } - if (isCancelled()) // can be canceled by a change via WifiStateChangeReceiver + if (isCancelled()) { // can be canceled by a change via WifiStateChangeReceiver return null; + } if (wifiInfo != null) { String ssid = wifiInfo.getSSID(); @@ -124,23 +128,26 @@ public class WifiStateChangeService extends Service { // TODO: Can this be moved to the swap service instead? String scheme; - if (Preferences.get().isLocalRepoHttpsEnabled()) + if (Preferences.get().isLocalRepoHttpsEnabled()) { scheme = "https"; - else + } else { scheme = "http"; + } FDroidApp.repo.name = Preferences.get().getLocalRepoName(); FDroidApp.repo.address = String.format(Locale.ENGLISH, "%s://%s:%d/fdroid/repo", scheme, FDroidApp.ipAddressString, FDroidApp.port); - if (isCancelled()) // can be canceled by a change via WifiStateChangeReceiver + if (isCancelled()) { // can be canceled by a change via WifiStateChangeReceiver return null; + } Context context = WifiStateChangeService.this.getApplicationContext(); LocalRepoManager lrm = LocalRepoManager.get(context); lrm.writeIndexPage(Utils.getSharingUri(FDroidApp.repo).toString()); - if (isCancelled()) // can be canceled by a change via WifiStateChangeReceiver + if (isCancelled()) { // can be canceled by a change via WifiStateChangeReceiver return null; + } // the fingerprint for the local repo's signing key LocalRepoKeyStore localRepoKeyStore = LocalRepoKeyStore.get(context); @@ -154,8 +161,9 @@ public class WifiStateChangeService extends Service { * because if this is the first time the singleton is run, it * can take a while to instantiate. */ - if (Preferences.get().isLocalRepoHttpsEnabled()) + if (Preferences.get().isLocalRepoHttpsEnabled()) { localRepoKeyStore.setupHTTPSCertificate(); + } } catch (LocalRepoKeyStore.InitException | InterruptedException e) { Log.e(TAG, "Unable to configure a fingerprint or HTTPS for the local repo", e); @@ -204,8 +212,9 @@ public class WifiStateChangeService extends Service { || netIf.getDisplayName().contains("eth0") || netIf.getDisplayName().contains("ap0")) { FDroidApp.ipAddressString = inetAddress.getHostAddress(); - if (Build.VERSION.SDK_INT < 9) + if (Build.VERSION.SDK_INT < 9) { return; + } // the following methods were not added until android-9/Gingerbread for (InterfaceAddress address : netIf.getInterfaceAddresses()) { if (inetAddress.equals(address.getAddress()) && !TextUtils.isEmpty(FDroidApp.ipAddressString)) { diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothClient.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothClient.java index 1b85e5190..44ec1a0d3 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothClient.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothClient.java @@ -32,8 +32,9 @@ public class BluetoothClient { return connection; } catch (IOException e1) { - if (connection != null) + if (connection != null) { connection.closeQuietly(); + } throw e1; diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java index 61de28a37..3c39917f9 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/BluetoothServer.java @@ -135,8 +135,9 @@ public class BluetoothServer extends Thread { break; } - if (isInterrupted()) + if (isInterrupted()) { break; + } } connection.closeQuietly(); @@ -183,8 +184,9 @@ public class BluetoothServer extends Thread { Log.e(TAG, "error processing request; sending 500 response", e); - if (builder == null) + if (builder == null) { builder = new Response.Builder(); + } return builder .setStatusCode(500) diff --git a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Request.java b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Request.java index 8ed354478..509a9f74d 100644 --- a/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Request.java +++ b/F-Droid/src/org/fdroid/fdroid/net/bluetooth/httpish/Request.java @@ -91,14 +91,16 @@ public final class Request { String requestLine = readLine(); - if (requestLine == null || requestLine.trim().length() == 0) + if (requestLine == null || requestLine.trim().length() == 0) { return false; + } String[] parts = requestLine.split("\\s+"); // First part is the method (GET/HEAD), second is the path (/fdroid/repo/index.jar) - if (parts.length < 2) + if (parts.length < 2) { return false; + } method = parts[0].toUpperCase(Locale.ENGLISH); path = parts[1]; @@ -143,8 +145,9 @@ public final class Request { int b = input.read(); if (((char) b) == '\n') { - if (baos.size() > 0) + if (baos.size() > 0) { line = new String(baos.toByteArray()); + } return line; } @@ -180,10 +183,11 @@ public final class Request { headers.put(header, value); } - if (input.available() > 0) + if (input.available() > 0) { responseLine = readLine(); - else + } else { break; + } } return headers; diff --git a/F-Droid/src/org/fdroid/fdroid/views/ManageReposActivity.java b/F-Droid/src/org/fdroid/fdroid/views/ManageReposActivity.java index f5c7dfd0d..b28449847 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/ManageReposActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/ManageReposActivity.java @@ -182,8 +182,9 @@ public class ManageReposActivity extends ActionBarActivity { Uri uri = Uri.parse(text); fingerprint = uri.getQueryParameter("fingerprint"); // uri might contain a QR-style, all uppercase URL: - if (TextUtils.isEmpty(fingerprint)) + if (TextUtils.isEmpty(fingerprint)) { fingerprint = uri.getQueryParameter("FINGERPRINT"); + } text = NewRepoConfig.sanitizeRepoUri(uri); } catch (MalformedURLException e) { text = null; @@ -683,8 +684,9 @@ public class ManageReposActivity extends ActionBarActivity { WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); WifiInfo wifiInfo = wifiManager.getConnectionInfo(); String bssid = wifiInfo.getBSSID(); - if (TextUtils.isEmpty(bssid)) /* not all devices have wifi */ + if (TextUtils.isEmpty(bssid)) { /* not all devices have wifi */ return; + } bssid = bssid.toLowerCase(Locale.ENGLISH); String newRepoBssid = Uri.decode(newRepo.getBssid()).toLowerCase(Locale.ENGLISH); if (!bssid.equals(newRepoBssid)) { diff --git a/F-Droid/src/org/fdroid/fdroid/views/RepoDetailsActivity.java b/F-Droid/src/org/fdroid/fdroid/views/RepoDetailsActivity.java index d0e12bf7a..bd8be7ac5 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/RepoDetailsActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/RepoDetailsActivity.java @@ -156,8 +156,9 @@ public class RepoDetailsActivity extends ActionBarActivity { @TargetApi(9) void processIntent(Intent i) { - if (Build.VERSION.SDK_INT < 9) + if (Build.VERSION.SDK_INT < 9) { return; + } if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(i.getAction())) { Parcelable[] rawMsgs = i.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES); @@ -176,8 +177,9 @@ public class RepoDetailsActivity extends ActionBarActivity { @Override public void onReceive(Context context, Intent intent) { int statusCode = intent.getIntExtra(UpdateService.EXTRA_STATUS_CODE, -1); - if (statusCode == UpdateService.STATUS_COMPLETE_WITH_CHANGES) + if (statusCode == UpdateService.STATUS_COMPLETE_WITH_CHANGES) { updateRepoView(); + } } }; diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java index c45c72cdc..f0b595f08 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/AvailableAppsFragment.java @@ -83,8 +83,9 @@ public class AvailableAppsFragment extends AppListFragment implements // hierarchy can touch its views." final Activity activity = getActivity(); // this nullguard is temporary, this Fragment really needs to merged into the Activity - if (activity == null) + if (activity == null) { return; + } activity.runOnUiThread(new Runnable() { @Override public void run() { @@ -162,12 +163,15 @@ public class AvailableAppsFragment extends AppListFragment implements @Override protected Uri getDataUri() { - if (currentCategory == null || currentCategory.equals(AppProvider.Helper.getCategoryAll(getActivity()))) + if (currentCategory == null || currentCategory.equals(AppProvider.Helper.getCategoryAll(getActivity()))) { return AppProvider.getContentUri(); - if (currentCategory.equals(AppProvider.Helper.getCategoryRecentlyUpdated(getActivity()))) + } + if (currentCategory.equals(AppProvider.Helper.getCategoryRecentlyUpdated(getActivity()))) { return AppProvider.getRecentlyUpdatedUri(); - if (currentCategory.equals(AppProvider.Helper.getCategoryWhatsNew(getActivity()))) + } + if (currentCategory.equals(AppProvider.Helper.getCategoryWhatsNew(getActivity()))) { return AppProvider.getNewlyAddedUri(); + } return AppProvider.getCategoryUri(currentCategory); } diff --git a/F-Droid/src/org/fdroid/fdroid/views/fragments/PreferencesFragment.java b/F-Droid/src/org/fdroid/fdroid/views/fragments/PreferencesFragment.java index 92a252c15..f8d107156 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/fragments/PreferencesFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/fragments/PreferencesFragment.java @@ -153,19 +153,21 @@ public class PreferencesFragment extends PreferenceFragment case Preferences.PREF_PROXY_HOST: EditTextPreference textPref = (EditTextPreference) findPreference(key); String text = Preferences.get().getProxyHost(); - if (TextUtils.isEmpty(text) || text.equals(Preferences.DEFAULT_PROXY_HOST)) + if (TextUtils.isEmpty(text) || text.equals(Preferences.DEFAULT_PROXY_HOST)) { textPref.setSummary(R.string.proxy_host_summary); - else + } else { textPref.setSummary(text); + } break; case Preferences.PREF_PROXY_PORT: EditTextPreference textPref2 = (EditTextPreference) findPreference(key); int port = Preferences.get().getProxyPort(); - if (port == Preferences.DEFAULT_PROXY_PORT) + if (port == Preferences.DEFAULT_PROXY_PORT) { textPref2.setSummary(R.string.proxy_port_summary); - else + } else { textPref2.setSummary(String.valueOf(port)); + } break; } diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppsView.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppsView.java index ec408373a..6d955039f 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppsView.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppsView.java @@ -379,14 +379,16 @@ public class SwapAppsView extends ListView implements private void resetView() { - if (app == null) + if (app == null) { return; + } progressView.setVisibility(View.GONE); progressView.setIndeterminate(true); - if (app.name != null) + if (app.name != null) { nameView.setText(app.name); + } ImageLoader.getInstance().displayImage(app.iconUrl, iconView, displayImageOptions); diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java index 720387286..75f8335f7 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapWorkflowActivity.java @@ -603,7 +603,7 @@ public class SwapWorkflowActivity extends AppCompatActivity { Utils.debugLog(TAG, "Initiating Bluetooth swap, will ensure the Bluetooth devices is enabled and discoverable before starting server."); BluetoothAdapter adapter = BluetoothAdapter.getDefaultAdapter(); - if (adapter != null) + if (adapter != null) { if (adapter.isEnabled()) { Utils.debugLog(TAG, "Bluetooth enabled, will check if device is discoverable with device."); ensureBluetoothDiscoverableThenStart(); @@ -612,6 +612,7 @@ public class SwapWorkflowActivity extends AppCompatActivity { Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE); startActivityForResult(enableBtIntent, REQUEST_BLUETOOTH_ENABLE_FOR_SWAP); } + } } private void ensureBluetoothDiscoverableThenStart() { diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/WifiQrView.java b/F-Droid/src/org/fdroid/fdroid/views/swap/WifiQrView.java index 6fce8959f..c745c463d 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/WifiQrView.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/WifiQrView.java @@ -118,8 +118,9 @@ public class WifiQrView extends ScrollView implements SwapWorkflowActivity.Inner private void setUIFromWifi() { - if (TextUtils.isEmpty(FDroidApp.repo.address)) + if (TextUtils.isEmpty(FDroidApp.repo.address)) { return; + } String scheme = Preferences.get().isLocalRepoHttpsEnabled() ? "https://" : "http://"; diff --git a/F-Droid/test/src/org/fdroid/fdroid/ApkProviderHelperTest.java b/F-Droid/test/src/org/fdroid/fdroid/ApkProviderHelperTest.java index 856bddd81..6919b0479 100644 --- a/F-Droid/test/src/org/fdroid/fdroid/ApkProviderHelperTest.java +++ b/F-Droid/test/src/org/fdroid/fdroid/ApkProviderHelperTest.java @@ -17,14 +17,17 @@ public class ApkProviderHelperTest extends BaseApkProviderTest { public void testKnownApks() { - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { TestUtils.insertApk(this, "org.fdroid.fdroid", i); + } - for (int i = 0; i < 9; i++) + for (int i = 0; i < 9; i++) { TestUtils.insertApk(this, "org.example", i); + } - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { TestUtils.insertApk(this, "com.example", i); + } TestUtils.insertApk(this, "com.apk.thingo", 1); @@ -64,20 +67,24 @@ public class ApkProviderHelperTest extends BaseApkProviderTest { assertResultCount(known.length, knownApks); - for (Apk knownApk : knownApks) + for (Apk knownApk : knownApks) { assertContains(knownApks, knownApk); + } } public void testFindByApp() { - for (int i = 0; i < 7; i++) + for (int i = 0; i < 7; i++) { TestUtils.insertApk(this, "org.fdroid.fdroid", i); + } - for (int i = 0; i < 9; i++) + for (int i = 0; i < 9; i++) { TestUtils.insertApk(this, "org.example", i); + } - for (int i = 0; i < 3; i++) + for (int i = 0; i < 3; i++) { TestUtils.insertApk(this, "com.example", i); + } TestUtils.insertApk(this, "com.apk.thingo", 1); @@ -157,8 +164,9 @@ public class ApkProviderHelperTest extends BaseApkProviderTest { // Insert some random apks either side of the "com.example", so that // the Helper.find() method doesn't stumble upon the app we are interested // in by shear dumb luck... - for (int i = 0; i < 10; i++) + for (int i = 0; i < 10; i++) { TestUtils.insertApk(this, "org.fdroid.apk." + i, i); + } ContentValues values = new ContentValues(); values.put(ApkProvider.DataColumns.VERSION, "v1.1"); @@ -167,8 +175,9 @@ public class ApkProviderHelperTest extends BaseApkProviderTest { TestUtils.insertApk(this, "com.example", 11, values); // ...and a few more for good measure... - for (int i = 15; i < 20; i++) + for (int i = 15; i < 20; i++) { TestUtils.insertApk(this, "com.other.thing." + i, i); + } Apk apk = ApkProvider.Helper.find(getMockContext(), "com.example", 11); diff --git a/F-Droid/test/src/org/fdroid/fdroid/MultiRepoUpdaterTest.java b/F-Droid/test/src/org/fdroid/fdroid/MultiRepoUpdaterTest.java index d60589f89..b6f1e6c81 100644 --- a/F-Droid/test/src/org/fdroid/fdroid/MultiRepoUpdaterTest.java +++ b/F-Droid/test/src/org/fdroid/fdroid/MultiRepoUpdaterTest.java @@ -433,8 +433,9 @@ public class MultiRepoUpdaterTest extends InstrumentationTestCase { } private boolean updateRepo(RepoUpdater updater, String indexJarPath) throws UpdateException { - if (!testFilesDir.canWrite()) + if (!testFilesDir.canWrite()) { return false; + } File indexJar = TestUtils.copyAssetToDir(context, indexJarPath, testFilesDir); updater.processDownloadedFile(indexJar); diff --git a/F-Droid/test/src/org/fdroid/fdroid/RepoUpdaterTest.java b/F-Droid/test/src/org/fdroid/fdroid/RepoUpdaterTest.java index a7fdfd6b4..b8d755724 100644 --- a/F-Droid/test/src/org/fdroid/fdroid/RepoUpdaterTest.java +++ b/F-Droid/test/src/org/fdroid/fdroid/RepoUpdaterTest.java @@ -28,8 +28,9 @@ public class RepoUpdaterTest extends InstrumentationTestCase { } public void testExtractIndexFromJar() { - if (!testFilesDir.canWrite()) + if (!testFilesDir.canWrite()) { return; + } File simpleIndexJar = TestUtils.copyAssetToDir(context, "simpleIndex.jar", testFilesDir); // these are supposed to succeed @@ -42,8 +43,9 @@ public class RepoUpdaterTest extends InstrumentationTestCase { } public void testExtractIndexFromJarWithoutSignatureJar() { - if (!testFilesDir.canWrite()) + if (!testFilesDir.canWrite()) { return; + } // this is supposed to fail try { File jarFile = TestUtils.copyAssetToDir(context, "simpleIndexWithoutSignature.jar", testFilesDir); @@ -55,8 +57,9 @@ public class RepoUpdaterTest extends InstrumentationTestCase { } public void testExtractIndexFromJarWithCorruptedManifestJar() { - if (!testFilesDir.canWrite()) + if (!testFilesDir.canWrite()) { return; + } // this is supposed to fail try { File jarFile = TestUtils.copyAssetToDir(context, "simpleIndexWithCorruptedManifest.jar", testFilesDir); @@ -71,8 +74,9 @@ public class RepoUpdaterTest extends InstrumentationTestCase { } public void testExtractIndexFromJarWithCorruptedSignature() { - if (!testFilesDir.canWrite()) + if (!testFilesDir.canWrite()) { return; + } // this is supposed to fail try { File jarFile = TestUtils.copyAssetToDir(context, "simpleIndexWithCorruptedSignature.jar", testFilesDir); @@ -87,8 +91,9 @@ public class RepoUpdaterTest extends InstrumentationTestCase { } public void testExtractIndexFromJarWithCorruptedCertificate() { - if (!testFilesDir.canWrite()) + if (!testFilesDir.canWrite()) { return; + } // this is supposed to fail try { File jarFile = TestUtils.copyAssetToDir(context, "simpleIndexWithCorruptedCertificate.jar", testFilesDir); @@ -103,8 +108,9 @@ public class RepoUpdaterTest extends InstrumentationTestCase { } public void testExtractIndexFromJarWithCorruptedEverything() { - if (!testFilesDir.canWrite()) + if (!testFilesDir.canWrite()) { return; + } // this is supposed to fail try { File jarFile = TestUtils.copyAssetToDir(context, "simpleIndexWithCorruptedEverything.jar", testFilesDir); @@ -119,8 +125,9 @@ public class RepoUpdaterTest extends InstrumentationTestCase { } public void testExtractIndexFromMasterKeyIndexJar() { - if (!testFilesDir.canWrite()) + if (!testFilesDir.canWrite()) { return; + } // this is supposed to fail try { File jarFile = TestUtils.copyAssetToDir(context, "masterKeyIndex.jar", testFilesDir); diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml index dca763dba..a7d6ee2c9 100644 --- a/config/checkstyle/checkstyle.xml +++ b/config/checkstyle/checkstyle.xml @@ -86,7 +86,9 @@ - + + +