Minor cleanup after CR.

Formatting, spelling, NonNull/Nullable annotations, removing unused
imports, and adding SuppressWarning for unused logging "TAG" properties.
This commit is contained in:
Peter Serwylo 2015-03-18 07:15:58 +11:00
parent f5ce318be7
commit 85300331e0
7 changed files with 58 additions and 42 deletions

View File

@ -356,15 +356,16 @@ public class UpdateService extends IntentService implements ProgressListener {
ArrayList<CharSequence> repoErrors = new ArrayList<>();
List<RepoUpdater.RepoUpdateRememberer> 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;
}

View File

@ -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");

View File

@ -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:

View File

@ -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);
}
}
}

View File

@ -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<Void, String, Void> {
@SuppressWarnings("UnusedDeclaration")
private static final String TAG = "fdroid.SwapActivity.UpdateAsyncTask";
@NonNull
private final ProgressDialog progressDialog;
@NonNull
private final Set<String> selectedApps;
@NonNull
private final Uri sharingUri;
public UpdateAsyncTask(Context c, @NonNull Set<String> apps) {

View File

@ -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() {

View File

@ -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<NameValuePair> parameters = URLEncodedUtils.parse(URI.create(sharingUri.toString()), "UTF-8");
for (NameValuePair parameter : parameters) {
if (!parameter.getName().equals("ssid")) {