From 7b4cee35c7950b783cc42f973b4c15728f983e16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Thu, 30 Apr 2015 20:40:19 +0200 Subject: [PATCH] Throw some more final keywords in --- .../src/org/fdroid/fdroid/Preferences.java | 8 +++---- .../src/org/fdroid/fdroid/RepoXMLHandler.java | 2 +- F-Droid/src/org/fdroid/fdroid/data/App.java | 22 +++++++++---------- .../org/fdroid/fdroid/data/AppProvider.java | 2 +- .../fdroid/fdroid/updater/RepoUpdater.java | 8 +++---- .../fdroid/updater/SignedRepoUpdater.java | 4 ++-- 6 files changed, 22 insertions(+), 24 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/Preferences.java b/F-Droid/src/org/fdroid/fdroid/Preferences.java index 9c5f8253d..05e86eb2b 100644 --- a/F-Droid/src/org/fdroid/fdroid/Preferences.java +++ b/F-Droid/src/org/fdroid/fdroid/Preferences.java @@ -160,7 +160,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi } public int getProxyPort() { - String port = preferences.getString(PREF_PROXY_PORT, String.valueOf(DEFAULT_PROXY_PORT)); + final String port = preferences.getString(PREF_PROXY_PORT, String.valueOf(DEFAULT_PROXY_PORT)); try { return Integer.parseInt(port); } catch (NumberFormatException e) { @@ -194,7 +194,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi * Updated... */ public Date calcMaxHistory() { - String daysString = preferences.getString(PREF_UPD_HISTORY, Integer.toString(DEFAULT_UPD_HISTORY)); + final String daysString = preferences.getString(PREF_UPD_HISTORY, Integer.toString(DEFAULT_UPD_HISTORY)); int maxHistoryDays; try { maxHistoryDays = Integer.parseInt(daysString); @@ -307,7 +307,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi public static void setup(Context context) { if (instance != null) { - String error = "Attempted to reinitialize preferences after it " + + final String error = "Attempted to reinitialize preferences after it " + "has already been initialized in FDroidApp"; Log.e(TAG, error); throw new RuntimeException(error); @@ -317,7 +317,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi public static Preferences get() { if (instance == null) { - String error = "Attempted to access preferences before it " + + final String error = "Attempted to access preferences before it " + "has been initialized in FDroidApp"; Log.e(TAG, error); throw new RuntimeException(error); diff --git a/F-Droid/src/org/fdroid/fdroid/RepoXMLHandler.java b/F-Droid/src/org/fdroid/fdroid/RepoXMLHandler.java index 01d294a89..1ff88554f 100644 --- a/F-Droid/src/org/fdroid/fdroid/RepoXMLHandler.java +++ b/F-Droid/src/org/fdroid/fdroid/RepoXMLHandler.java @@ -97,7 +97,7 @@ public class RepoXMLHandler extends DefaultHandler { super.endElement(uri, localName, qName); final String curel = localName; - String str = curchars.toString().trim(); + final String str = curchars.toString().trim(); if (curel.equals("application") && curapp != null) { apps.add(curapp); diff --git a/F-Droid/src/org/fdroid/fdroid/data/App.java b/F-Droid/src/org/fdroid/fdroid/data/App.java index d7bddf755..93be6b3cc 100644 --- a/F-Droid/src/org/fdroid/fdroid/data/App.java +++ b/F-Droid/src/org/fdroid/fdroid/data/App.java @@ -106,9 +106,7 @@ public class App extends ValueObject implements Comparable { return name.compareToIgnoreCase(app.name); } - public App() { - - } + public App() { } public App(Cursor cursor) { @@ -254,7 +252,7 @@ public class App extends ValueObject implements Comparable { this.name = (String) appInfo.loadLabel(pm); - SanitizedFile apkFile = SanitizedFile.knownSanitized(appInfo.publicSourceDir); + final SanitizedFile apkFile = SanitizedFile.knownSanitized(appInfo.publicSourceDir); final Apk apk = new Apk(); apk.version = packageInfo.versionName; apk.vercode = packageInfo.versionCode; @@ -274,7 +272,7 @@ public class App extends ValueObject implements Comparable { final FeatureInfo[] features = packageInfo.reqFeatures; if (features != null && features.length > 0) { - List featureNames = new ArrayList<>(features.length); + final List featureNames = new ArrayList<>(features.length); for (FeatureInfo feature : features) { featureNames.add(feature.name); @@ -287,8 +285,8 @@ public class App extends ValueObject implements Comparable { byte[] rawCertBytes; - JarFile apkJar = new JarFile(apkFile); - JarEntry aSignedEntry = (JarEntry) apkJar.getEntry("AndroidManifest.xml"); + final JarFile apkJar = new JarFile(apkFile); + final JarEntry aSignedEntry = (JarEntry) apkJar.getEntry("AndroidManifest.xml"); if (aSignedEntry == null) { apkJar.close(); @@ -300,7 +298,7 @@ public class App extends ValueObject implements Comparable { // details, check out https://gitlab.com/fdroid/fdroidclient/issues/111. try { FDroidApp.disableSpongyCastleOnLollipop(); - InputStream tmpIn = apkJar.getInputStream(aSignedEntry); + final InputStream tmpIn = apkJar.getInputStream(aSignedEntry); byte[] buff = new byte[2048]; while (tmpIn.read(buff, 0, buff.length) != -1) { /* @@ -316,7 +314,7 @@ public class App extends ValueObject implements Comparable { throw new CertificateEncodingException("No Certificates found!"); } - Certificate signer = aSignedEntry.getCertificates()[0]; + final Certificate signer = aSignedEntry.getCertificates()[0]; rawCertBytes = signer.getEncoded(); } finally { FDroidApp.enableSpongyCastleOnLollipop(); @@ -332,7 +330,7 @@ public class App extends ValueObject implements Comparable { * if I'm right... If I'm not right, I really don't know! see lines * 67->75 in getsig.java bundled with Fdroidserver */ - byte[] fdroidSig = new byte[rawCertBytes.length * 2]; + final byte[] fdroidSig = new byte[rawCertBytes.length * 2]; for (int j = 0; j < rawCertBytes.length; j++) { byte v = rawCertBytes[j]; int d = (v >> 4) & 0xF; @@ -356,7 +354,7 @@ public class App extends ValueObject implements Comparable { if (TextUtils.isEmpty(this.installedApk.sig)) return false; - File apkFile = this.installedApk.installedFile; + final File apkFile = this.installedApk.installedFile; if (apkFile == null || !apkFile.canRead()) return false; @@ -365,7 +363,7 @@ public class App extends ValueObject implements Comparable { public ContentValues toContentValues() { - ContentValues values = new ContentValues(); + final ContentValues values = new ContentValues(); values.put(AppProvider.DataColumns.APP_ID, id); values.put(AppProvider.DataColumns.NAME, name); values.put(AppProvider.DataColumns.SUMMARY, summary); diff --git a/F-Droid/src/org/fdroid/fdroid/data/AppProvider.java b/F-Droid/src/org/fdroid/fdroid/data/AppProvider.java index 591a3834e..80633d670 100644 --- a/F-Droid/src/org/fdroid/fdroid/data/AppProvider.java +++ b/F-Droid/src/org/fdroid/fdroid/data/AppProvider.java @@ -108,7 +108,7 @@ public class AppProvider extends FDroidProvider { } cursor.close(); } - List categories = new ArrayList<>(categorySet); + final List categories = new ArrayList<>(categorySet); Collections.sort(categories); // Populate the category list with the real categories, and the diff --git a/F-Droid/src/org/fdroid/fdroid/updater/RepoUpdater.java b/F-Droid/src/org/fdroid/fdroid/updater/RepoUpdater.java index c5e4ef015..9f5c84614 100644 --- a/F-Droid/src/org/fdroid/fdroid/updater/RepoUpdater.java +++ b/F-Droid/src/org/fdroid/fdroid/updater/RepoUpdater.java @@ -135,7 +135,7 @@ abstract public class RepoUpdater { File indexFile = null; try { - Downloader downloader = downloadIndex(); + final Downloader downloader = downloadIndex(); hasChanged = downloader.hasChanged(); if (hasChanged) { @@ -144,9 +144,9 @@ abstract public class RepoUpdater { indexFile = getIndexFromFile(downloadedFile); // Process the index... - SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); - XMLReader reader = parser.getXMLReader(); - RepoXMLHandler handler = new RepoXMLHandler(repo, progressListener); + final SAXParser parser = SAXParserFactory.newInstance().newSAXParser(); + final XMLReader reader = parser.getXMLReader(); + final RepoXMLHandler handler = new RepoXMLHandler(repo, progressListener); if (progressListener != null) { // Only bother spending the time to count the expected apps diff --git a/F-Droid/src/org/fdroid/fdroid/updater/SignedRepoUpdater.java b/F-Droid/src/org/fdroid/fdroid/updater/SignedRepoUpdater.java index d42429000..4601f39a1 100644 --- a/F-Droid/src/org/fdroid/fdroid/updater/SignedRepoUpdater.java +++ b/F-Droid/src/org/fdroid/fdroid/updater/SignedRepoUpdater.java @@ -28,14 +28,14 @@ public class SignedRepoUpdater extends RepoUpdater { } private boolean verifyCerts(JarEntry item) throws UpdateException { - Certificate[] certs = item.getCertificates(); + final Certificate[] certs = item.getCertificates(); if (certs == null || certs.length == 0) { throw new UpdateException(repo, "No signature found in index"); } Log.d(TAG, "Index has " + certs.length + " signature(s)"); boolean match = false; - for (Certificate cert : certs) { + for (final Certificate cert : certs) { String certdata = Hasher.hex(cert); if (repo.pubkey == null && repo.fingerprint != null) { String certFingerprint = Utils.calcFingerprint(cert);