From 85300331e05ddd55d4361da1a91cbf1e9b362076 Mon Sep 17 00:00:00 2001 From: Peter Serwylo Date: Wed, 18 Mar 2015 07:15:58 +1100 Subject: [PATCH] Minor cleanup after CR. Formatting, spelling, NonNull/Nullable annotations, removing unused imports, and adding SuppressWarning for unused logging "TAG" properties. --- .../src/org/fdroid/fdroid/UpdateService.java | 5 +- F-Droid/src/org/fdroid/fdroid/Utils.java | 3 + .../org/fdroid/fdroid/data/RepoProvider.java | 1 + .../fdroid/localrepo/LocalRepoManager.java | 76 +++++++++---------- .../fdroid/views/swap/SwapActivity.java | 9 +++ .../views/swap/SwapAppListActivity.java | 2 + .../fdroid/views/swap/WifiQrFragment.java | 4 +- 7 files changed, 58 insertions(+), 42 deletions(-) diff --git a/F-Droid/src/org/fdroid/fdroid/UpdateService.java b/F-Droid/src/org/fdroid/fdroid/UpdateService.java index 2213ddb2f..6520106b4 100644 --- a/F-Droid/src/org/fdroid/fdroid/UpdateService.java +++ b/F-Droid/src/org/fdroid/fdroid/UpdateService.java @@ -356,15 +356,16 @@ public class UpdateService extends IntentService implements ProgressListener { ArrayList repoErrors = new ArrayList<>(); List repoUpdateRememberers = new ArrayList<>(); boolean changes = false; + boolean singleRepoUpdate = !TextUtils.isEmpty(address); for (final Repo repo : repos) { if (!repo.inuse) { disabledRepos.add(repo); continue; - } else if (!TextUtils.isEmpty(address) && !repo.address.equals(address)) { + } else if (singleRepoUpdate && !repo.address.equals(address)) { unchangedRepos.add(repo); continue; - } else if (TextUtils.isEmpty(address) && repo.isSwap) { + } else if (!singleRepoUpdate && repo.isSwap) { swapRepos.add(repo); continue; } diff --git a/F-Droid/src/org/fdroid/fdroid/Utils.java b/F-Droid/src/org/fdroid/fdroid/Utils.java index 3f4472a43..164faf3d3 100644 --- a/F-Droid/src/org/fdroid/fdroid/Utils.java +++ b/F-Droid/src/org/fdroid/fdroid/Utils.java @@ -23,6 +23,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.AssetManager; import android.content.res.XmlResourceParser; import android.net.Uri; +import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.Editable; import android.text.Html; @@ -59,6 +60,7 @@ import java.util.Locale; public final class Utils { + @SuppressWarnings("UnusedDeclaration") private static final String TAG = "org.fdroid.fdroid.Utils"; public static final int BUFFER_SIZE = 4096; @@ -280,6 +282,7 @@ public final class Utils { return displayFP; } + @NonNull public static Uri getSharingUri(Repo repo) { if (TextUtils.isEmpty(repo.address)) return Uri.parse("http://wifi-not-enabled"); diff --git a/F-Droid/src/org/fdroid/fdroid/data/RepoProvider.java b/F-Droid/src/org/fdroid/fdroid/data/RepoProvider.java index 1dce6b415..0497460d0 100644 --- a/F-Droid/src/org/fdroid/fdroid/data/RepoProvider.java +++ b/F-Droid/src/org/fdroid/fdroid/data/RepoProvider.java @@ -277,6 +277,7 @@ public class RepoProvider extends FDroidProvider { switch (matcher.match(uri)) { case CODE_LIST: + // Do nothing (don't restrict query) break; case CODE_SINGLE: diff --git a/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java b/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java index f1a238d97..cedd6d8a9 100644 --- a/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java +++ b/F-Droid/src/org/fdroid/fdroid/localrepo/LocalRepoManager.java @@ -314,44 +314,6 @@ public class LocalRepoManager { return new File(iconsDir, packageName + "_" + versionCode + ".png"); } - public void writeIndexJar() throws IOException { - try { - new IndexXmlBuilder(context, apps).build(new FileWriter(xmlIndex)); - } catch (Exception e) { - Log.e(TAG, Log.getStackTraceString(e)); - Toast.makeText(context, R.string.failed_to_create_index, Toast.LENGTH_LONG).show(); - return; - } - - BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(xmlIndexJarUnsigned)); - JarOutputStream jo = new JarOutputStream(bo); - - BufferedInputStream bi = new BufferedInputStream(new FileInputStream(xmlIndex)); - - JarEntry je = new JarEntry("index.xml"); - jo.putNextEntry(je); - - byte[] buf = new byte[1024]; - int bytesRead; - - while ((bytesRead = bi.read(buf)) != -1) { - jo.write(buf, 0, bytesRead); - } - - bi.close(); - jo.close(); - bo.close(); - - try { - LocalRepoKeyStore.get(context).signZip(xmlIndexJarUnsigned, xmlIndexJar); - } catch (LocalRepoKeyStore.InitException e) { - throw new IOException("Could not sign index - keystore failed to initialize"); - } finally { - attemptToDelete(xmlIndexJarUnsigned); - } - - } - /** * Helper class to aid in constructing index.xml file. * It uses the PullParser API, because the DOM api is only able to be serialized from @@ -514,4 +476,42 @@ public class LocalRepoManager { } } + public void writeIndexJar() throws IOException { + try { + new IndexXmlBuilder(context, apps).build(new FileWriter(xmlIndex)); + } catch (Exception e) { + Log.e(TAG, Log.getStackTraceString(e)); + Toast.makeText(context, R.string.failed_to_create_index, Toast.LENGTH_LONG).show(); + return; + } + + BufferedOutputStream bo = new BufferedOutputStream(new FileOutputStream(xmlIndexJarUnsigned)); + JarOutputStream jo = new JarOutputStream(bo); + + BufferedInputStream bi = new BufferedInputStream(new FileInputStream(xmlIndex)); + + JarEntry je = new JarEntry("index.xml"); + jo.putNextEntry(je); + + byte[] buf = new byte[1024]; + int bytesRead; + + while ((bytesRead = bi.read(buf)) != -1) { + jo.write(buf, 0, bytesRead); + } + + bi.close(); + jo.close(); + bo.close(); + + try { + LocalRepoKeyStore.get(context).signZip(xmlIndexJarUnsigned, xmlIndexJar); + } catch (LocalRepoKeyStore.InitException e) { + throw new IOException("Could not sign index - keystore failed to initialize"); + } finally { + attemptToDelete(xmlIndexJarUnsigned); + } + + } + } diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapActivity.java index c2a474afb..6232cb17e 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapActivity.java @@ -84,6 +84,7 @@ public class SwapActivity extends ActionBarActivity implements SwapProcessManage setContentView(R.layout.swap_activity); + // Necessary to run on an Android 2.3.[something] device. new Handler().post(new Runnable() { @Override public void run() { @@ -207,9 +208,17 @@ public class SwapActivity extends ActionBarActivity implements SwapProcessManage } class UpdateAsyncTask extends AsyncTask { + + @SuppressWarnings("UnusedDeclaration") private static final String TAG = "fdroid.SwapActivity.UpdateAsyncTask"; + + @NonNull private final ProgressDialog progressDialog; + + @NonNull private final Set selectedApps; + + @NonNull private final Uri sharingUri; public UpdateAsyncTask(Context c, @NonNull Set apps) { diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppListActivity.java b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppListActivity.java index 862852ed8..f45670508 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppListActivity.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/SwapAppListActivity.java @@ -21,6 +21,8 @@ public class SwapAppListActivity extends ActionBarActivity { super.onCreate(savedInstanceState); if (savedInstanceState == null) { + + // Necessary to run on an Android 2.3.[something] device. new Handler().post(new Runnable() { @Override public void run() { diff --git a/F-Droid/src/org/fdroid/fdroid/views/swap/WifiQrFragment.java b/F-Droid/src/org/fdroid/fdroid/views/swap/WifiQrFragment.java index 4767fb4ee..543ccca1a 100644 --- a/F-Droid/src/org/fdroid/fdroid/views/swap/WifiQrFragment.java +++ b/F-Droid/src/org/fdroid/fdroid/views/swap/WifiQrFragment.java @@ -130,7 +130,7 @@ public class WifiQrFragment extends Fragment { * custom URI schemes, so we have to use http:// or https:// :-( */ Uri sharingUri = Utils.getSharingUri(FDroidApp.repo); - String qrUriString = ( scheme + sharingUri.getHost() ).toUpperCase(Locale.ENGLISH); + String qrUriString = (scheme + sharingUri.getHost()).toUpperCase(Locale.ENGLISH); if (sharingUri.getPort() != 80) { qrUriString += ":" + sharingUri.getPort(); } @@ -139,7 +139,7 @@ public class WifiQrFragment extends Fragment { // Andorid provides an API for getting the query parameters and iterating over them: // Uri.getQueryParameterNames() - // But it is only available on later Android versions. As such we URLEncodedUtils instead. + // But it is only available on later Android versions. As such we use URLEncodedUtils instead. List parameters = URLEncodedUtils.parse(URI.create(sharingUri.toString()), "UTF-8"); for (NameValuePair parameter : parameters) { if (!parameter.getName().equals("ssid")) {