Get java code closer to obeying PMD's java-basic

This commit is contained in:
Daniel Martí 2016-04-17 15:55:19 +01:00
parent 7b70560c9b
commit 2074718391
10 changed files with 53 additions and 68 deletions

View File

@ -79,6 +79,7 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
private static final boolean DEFAULT_EXPERT = false; private static final boolean DEFAULT_EXPERT = false;
private static final boolean DEFAULT_ENABLE_PROXY = false; private static final boolean DEFAULT_ENABLE_PROXY = false;
public static final String DEFAULT_THEME = "light"; public static final String DEFAULT_THEME = "light";
@SuppressWarnings("PMD.AvoidUsingHardCodedIP")
public static final String DEFAULT_PROXY_HOST = "127.0.0.1"; public static final String DEFAULT_PROXY_HOST = "127.0.0.1";
public static final int DEFAULT_PROXY_PORT = 8118; public static final int DEFAULT_PROXY_PORT = 8118;
private static final boolean DEFAULT_SHOW_NFC_DURING_SWAP = true; private static final boolean DEFAULT_SHOW_NFC_DURING_SWAP = true;

View File

@ -92,6 +92,15 @@ public class RepoUpdater {
return hasChanged; return hasChanged;
} }
private static void cleanupDownloader(Downloader d) {
if (d == null || d.outputFile == null) {
return;
}
if (!d.outputFile.delete()) {
Log.w(TAG, "Couldn't delete file: " + d.outputFile.getAbsolutePath());
}
}
private Downloader downloadIndex() throws UpdateException { private Downloader downloadIndex() throws UpdateException {
Downloader downloader = null; Downloader downloader = null;
try { try {
@ -106,11 +115,7 @@ public class RepoUpdater {
} }
} catch (IOException e) { } catch (IOException e) {
if (downloader != null && downloader.outputFile != null) { cleanupDownloader(downloader);
if (!downloader.outputFile.delete()) {
Log.w(TAG, "Couldn't delete file: " + downloader.outputFile.getAbsolutePath());
}
}
throw new UpdateException(repo, "Error getting index file", e); throw new UpdateException(repo, "Error getting index file", e);
} catch (InterruptedException e) { } catch (InterruptedException e) {
@ -197,10 +202,8 @@ public class RepoUpdater {
} finally { } finally {
FDroidApp.enableSpongyCastleOnLollipop(); FDroidApp.enableSpongyCastleOnLollipop();
Utils.closeQuietly(indexInputStream); Utils.closeQuietly(indexInputStream);
if (downloadedFile != null) { if (downloadedFile != null && !downloadedFile.delete()) {
if (!downloadedFile.delete()) { Log.w(TAG, "Couldn't delete file: " + downloadedFile.getAbsolutePath());
Log.w(TAG, "Couldn't delete file: " + downloadedFile.getAbsolutePath());
}
} }
} }
} }

View File

@ -673,11 +673,10 @@ public final class Utils {
} }
for (File f : files) { for (File f : files) {
if ((startsWith != null && f.getName().startsWith(startsWith)) if (((startsWith != null && f.getName().startsWith(startsWith))
|| (endsWith != null && f.getName().endsWith(endsWith))) { || (endsWith != null && f.getName().endsWith(endsWith)))
if (!f.delete()) { && !f.delete()) {
Log.w(TAG, "Couldn't delete cache file " + f); Log.w(TAG, "Couldn't delete cache file " + f);
}
} }
} }
} }

View File

@ -178,10 +178,8 @@ public abstract class Installer {
Map<String, Object> attributes = AndroidXMLDecompress.getManifestHeaderAttributes(apkFile.getAbsolutePath()); Map<String, Object> attributes = AndroidXMLDecompress.getManifestHeaderAttributes(apkFile.getAbsolutePath());
/* This isn't really needed, but might as well since we have the data already */ /* This isn't really needed, but might as well since we have the data already */
if (attributes.containsKey("packageName")) { if (attributes.containsKey("packageName") && !TextUtils.equals(packageName, (String) attributes.get("packageName"))) {
if (!TextUtils.equals(packageName, (String) attributes.get("packageName"))) { throw new InstallFailedException(apkFile + " has packageName that clashes with " + packageName);
throw new InstallFailedException(apkFile + " has packageName that clashes with " + packageName);
}
} }
if (!attributes.containsKey("versionCode")) { if (!attributes.containsKey("versionCode")) {

View File

@ -119,22 +119,16 @@ public final class LocalRepoManager {
xmlIndexJar = new SanitizedFile(repoDir, "index.jar"); xmlIndexJar = new SanitizedFile(repoDir, "index.jar");
xmlIndexJarUnsigned = new SanitizedFile(repoDir, "index.unsigned.jar"); xmlIndexJarUnsigned = new SanitizedFile(repoDir, "index.unsigned.jar");
if (!fdroidDir.exists()) { if (!fdroidDir.exists() && !fdroidDir.mkdir()) {
if (!fdroidDir.mkdir()) { Log.e(TAG, "Unable to create empty base: " + fdroidDir);
Log.e(TAG, "Unable to create empty base: " + fdroidDir);
}
} }
if (!repoDir.exists()) { if (!repoDir.exists() && !repoDir.mkdir()) {
if (!repoDir.mkdir()) { Log.e(TAG, "Unable to create empty repo: " + repoDir);
Log.e(TAG, "Unable to create empty repo: " + repoDir);
}
} }
if (!iconsDir.exists()) { if (!iconsDir.exists() && !iconsDir.mkdir()) {
if (!iconsDir.mkdir()) { Log.e(TAG, "Unable to create icons folder: " + iconsDir);
Log.e(TAG, "Unable to create icons folder: " + iconsDir);
}
} }
} }

View File

@ -228,17 +228,15 @@ public class LocalHTTPD extends NanoHTTPD {
long startFrom = 0; long startFrom = 0;
long endAt = -1; long endAt = -1;
String range = header.get("range"); String range = header.get("range");
if (range != null) { if (range != null && range.startsWith("bytes=")) {
if (range.startsWith("bytes=")) { range = range.substring("bytes=".length());
range = range.substring("bytes=".length()); int minus = range.indexOf('-');
int minus = range.indexOf('-'); try {
try { if (minus > 0) {
if (minus > 0) { startFrom = Long.parseLong(range.substring(0, minus));
startFrom = Long.parseLong(range.substring(0, minus)); endAt = Long.parseLong(range.substring(minus + 1));
endAt = Long.parseLong(range.substring(minus + 1));
}
} catch (NumberFormatException ignored) {
} }
} catch (NumberFormatException ignored) {
} }
} }

View File

@ -266,17 +266,15 @@ public class BluetoothServer extends Thread {
long startFrom = 0; long startFrom = 0;
long endAt = -1; long endAt = -1;
String range = header.get("range"); String range = header.get("range");
if (range != null) { if (range != null && range.startsWith("bytes=")) {
if (range.startsWith("bytes=")) { range = range.substring("bytes=".length());
range = range.substring("bytes=".length()); int minus = range.indexOf('-');
int minus = range.indexOf('-'); try {
try { if (minus > 0) {
if (minus > 0) { startFrom = Long.parseLong(range.substring(0, minus));
startFrom = Long.parseLong(range.substring(0, minus)); endAt = Long.parseLong(range.substring(minus + 1));
endAt = Long.parseLong(range.substring(minus + 1));
}
} catch (NumberFormatException ignored) {
} }
} catch (NumberFormatException ignored) {
} }
} }

View File

@ -29,15 +29,13 @@ public class InstallExtensionBootReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { if (intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED) && Preferences.get().isPostPrivilegedInstall()) {
if (Preferences.get().isPostPrivilegedInstall()) { Preferences.get().setPostPrivilegedInstall(false);
Preferences.get().setPostPrivilegedInstall(false);
Intent postInstall = new Intent(context.getApplicationContext(), InstallExtensionDialogActivity.class); Intent postInstall = new Intent(context.getApplicationContext(), InstallExtensionDialogActivity.class);
postInstall.setAction(InstallExtensionDialogActivity.ACTION_POST_INSTALL); postInstall.setAction(InstallExtensionDialogActivity.ACTION_POST_INSTALL);
postInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); postInstall.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(postInstall); context.startActivity(postInstall);
}
} }
} }
} }

View File

@ -269,10 +269,8 @@ public class AppSecurityPermissions {
String permName = strList[i]; String permName = strList[i];
// If we are only looking at an existing app, then we only // If we are only looking at an existing app, then we only
// care about permissions that have actually been granted to it. // care about permissions that have actually been granted to it.
if (installedPkgInfo != null && info == installedPkgInfo) { if (installedPkgInfo != null && info == installedPkgInfo && (flagsList[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0) {
if ((flagsList[i] & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0) { continue;
continue;
}
} }
try { try {
PermissionInfo tmpPermInfo = mPm.getPermissionInfo(permName, 0); PermissionInfo tmpPermInfo = mPm.getPermissionInfo(permName, 0);

View File

@ -290,11 +290,9 @@ public class SwapWorkflowActivity extends AppCompatActivity {
return; return;
} }
if (!forceReload) { if (!forceReload && (container.getVisibility() == View.GONE || currentView != null && currentView.getStep() == service.getStep())) {
if (container.getVisibility() == View.GONE || currentView != null && currentView.getStep() == service.getStep()) { // Already showing the correct step, so don't bother changing anything.
// Already showing the correct step, so don't bother changing anything. return;
return;
}
} }
switch (service.getStep()) { switch (service.getStep()) {