Merge branch 'random-fixes-2' into 'master'

Gradle fixes, enable PMD unusedcode rules



See merge request !246
This commit is contained in:
Hans-Christoph Steiner 2016-04-01 08:39:50 +00:00
commit 4485d7c2cb
22 changed files with 31 additions and 58 deletions

View File

@ -28,8 +28,6 @@ dependencies {
} }
compile 'io.reactivex:rxjava:1.1.0' compile 'io.reactivex:rxjava:1.1.0'
compile 'io.reactivex:rxandroid:0.23.0' compile 'io.reactivex:rxandroid:0.23.0'
androidTestCompile 'commons-io:commons-io:2.4'
} }
if (!hasProperty('sourceDeps')) { if (!hasProperty('sourceDeps')) {
@ -186,7 +184,7 @@ checkstyle {
task checkstyle(type: Checkstyle) { task checkstyle(type: Checkstyle) {
configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml") configFile file("${project.rootDir}/config/checkstyle/checkstyle.xml")
source 'src', 'test/src' source 'src/main/java', 'src/test/java', 'src/androidTest/java'
include '**/*.java' include '**/*.java'
classpath = files() classpath = files()
@ -206,8 +204,9 @@ task pmd(type: Pmd, dependsOn: assembleDebug) {
'java-finalizers', 'java-finalizers',
'java-imports', 'java-imports',
'java-migrating', 'java-migrating',
//'java-unnecessary', // too nitpicky with parenthesis
] ]
source 'src' source 'src/main/java'
include '**/org/fdroid/**/*.java' include '**/org/fdroid/**/*.java'
} }

View File

@ -526,7 +526,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
private void onAppChanged() { private void onAppChanged() {
if (!reset(app.packageName)) { if (!reset(app.packageName)) {
AppDetails.this.finish(); this.finish();
return; return;
} }

View File

@ -64,7 +64,7 @@ public class FDroid extends AppCompatActivity implements SearchView.OnQueryTextL
public static final String EXTRA_TAB_UPDATE = "extraTab"; public static final String EXTRA_TAB_UPDATE = "extraTab";
public static final String ACTION_ADD_REPO = "org.fdroid.fdroid.FDroid.ACTION_ADD_REPO"; private static final String ACTION_ADD_REPO = "org.fdroid.fdroid.FDroid.ACTION_ADD_REPO";
private static final String ADD_REPO_INTENT_HANDLED = "addRepoIntentHandled"; private static final String ADD_REPO_INTENT_HANDLED = "addRepoIntentHandled";

View File

@ -4,12 +4,12 @@ import android.content.Context;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo; import android.content.pm.PermissionInfo;
public class Permission { class Permission {
private final PackageManager packageManager; private final PackageManager packageManager;
private final PermissionInfo permissionInfo; private final PermissionInfo permissionInfo;
public Permission(Context context, String permission) Permission(Context context, String permission)
throws PackageManager.NameNotFoundException { throws PackageManager.NameNotFoundException {
this.packageManager = context.getPackageManager(); this.packageManager = context.getPackageManager();
this.permissionInfo = this.packageManager.getPermissionInfo( this.permissionInfo = this.packageManager.getPermissionInfo(

View File

@ -30,11 +30,9 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
private static final String TAG = "Preferences"; private static final String TAG = "Preferences";
private final Context context;
private final SharedPreferences preferences; private final SharedPreferences preferences;
private Preferences(Context context) { private Preferences(Context context) {
this.context = context;
preferences = PreferenceManager.getDefaultSharedPreferences(context); preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.registerOnSharedPreferenceChangeListener(this); preferences.registerOnSharedPreferenceChangeListener(this);
if (preferences.getString(PREF_LOCAL_REPO_NAME, null) == null) { if (preferences.getString(PREF_LOCAL_REPO_NAME, null) == null) {
@ -72,10 +70,10 @@ public final class Preferences implements SharedPreferences.OnSharedPreferenceCh
private static final boolean DEFAULT_ROOTED = true; private static final boolean DEFAULT_ROOTED = true;
private static final int DEFAULT_UPD_HISTORY = 14; private static final int DEFAULT_UPD_HISTORY = 14;
private static final boolean DEFAULT_PRIVILEGED_INSTALLER = false; private static final boolean DEFAULT_PRIVILEGED_INSTALLER = false;
private static final boolean DEFAULT_LOCAL_REPO_BONJOUR = true; //private static final boolean DEFAULT_LOCAL_REPO_BONJOUR = true;
private static final boolean DEFAULT_CACHE_APK = false; private static final boolean DEFAULT_CACHE_APK = false;
private static final boolean DEFAULT_UNSTABLE_UPDATES = false; private static final boolean DEFAULT_UNSTABLE_UPDATES = false;
private static final boolean DEFAULT_LOCAL_REPO_HTTPS = false; //private static final boolean DEFAULT_LOCAL_REPO_HTTPS = false;
private static final boolean DEFAULT_INCOMP_VER = false; private static final boolean DEFAULT_INCOMP_VER = false;
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;

View File

@ -9,7 +9,6 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public class ProgressBufferedInputStream extends BufferedInputStream { public class ProgressBufferedInputStream extends BufferedInputStream {
private static final String TAG = "ProgressBufferedInputSt";
private final ProgressListener progressListener; private final ProgressListener progressListener;
private final Bundle data; private final Bundle data;

View File

@ -14,7 +14,7 @@ public abstract class Compatibility {
return apiLevel < 1 || getApi() <= apiLevel; return apiLevel < 1 || getApi() <= apiLevel;
} }
protected static int getApi() { static int getApi() {
return Build.VERSION.SDK_INT; return Build.VERSION.SDK_INT;
} }

View File

@ -105,12 +105,10 @@ public final class PRNGFixes extends Compatibility {
// Install a Linux PRNG-based SecureRandom implementation as the // Install a Linux PRNG-based SecureRandom implementation as the
// default, if not yet installed. // default, if not yet installed.
Provider[] secureRandomProviders = Provider[] secureRandomProviders = Security.getProviders("SecureRandom.SHA1PRNG");
Security.getProviders("SecureRandom.SHA1PRNG"); if (secureRandomProviders == null
if ((secureRandomProviders == null) || secureRandomProviders.length < 1
|| (secureRandomProviders.length < 1) || !LinuxPRNGSecureRandomProvider.class.equals(secureRandomProviders[0].getClass())) {
|| (!LinuxPRNGSecureRandomProvider.class.equals(
secureRandomProviders[0].getClass()))) {
Security.insertProviderAt(new LinuxPRNGSecureRandomProvider(), 1); Security.insertProviderAt(new LinuxPRNGSecureRandomProvider(), 1);
} }

View File

@ -313,6 +313,7 @@ public class App extends ValueObject implements Comparable<App> {
FDroidApp.disableSpongyCastleOnLollipop(); FDroidApp.disableSpongyCastleOnLollipop();
final InputStream tmpIn = apkJar.getInputStream(aSignedEntry); final InputStream tmpIn = apkJar.getInputStream(aSignedEntry);
byte[] buff = new byte[2048]; byte[] buff = new byte[2048];
//noinspection StatementWithEmptyBody
while (tmpIn.read(buff, 0, buff.length) != -1) { while (tmpIn.read(buff, 0, buff.length) != -1) {
/* /*
* NOP - apparently have to READ from the JarEntry before you can * NOP - apparently have to READ from the JarEntry before you can

View File

@ -404,9 +404,11 @@ public class SwapService extends Service {
.commit(); .commit();
} }
/*
private boolean wasBluetoothEnabled() { private boolean wasBluetoothEnabled() {
return persistence().getBoolean(KEY_BLUETOOTH_ENABLED, false); return persistence().getBoolean(KEY_BLUETOOTH_ENABLED, false);
} }
*/
private boolean wasWifiEnabled() { private boolean wasWifiEnabled() {
return persistence().getBoolean(KEY_WIFI_ENABLED, false); return persistence().getBoolean(KEY_WIFI_ENABLED, false);
@ -537,11 +539,12 @@ public class SwapService extends Service {
filter.addAction(WIFI_STATE_CHANGE); filter.addAction(WIFI_STATE_CHANGE);
LocalBroadcastManager.getInstance(this).registerReceiver(receiveSwapStatusChanged, filter); LocalBroadcastManager.getInstance(this).registerReceiver(receiveSwapStatusChanged, filter);
/** /*
if (wasBluetoothEnabled()) { if (wasBluetoothEnabled()) {
Utils.debugLog(TAG, "Previously the user enabled Bluetooth swap, so enabling again automatically."); Utils.debugLog(TAG, "Previously the user enabled Bluetooth swap, so enabling again automatically.");
bluetoothSwap.startInBackground(); bluetoothSwap.startInBackground();
}*/ }
*/
if (wasWifiEnabled()) { if (wasWifiEnabled()) {
Utils.debugLog(TAG, "Previously the user enabled WiFi swap, so enabling again automatically."); Utils.debugLog(TAG, "Previously the user enabled WiFi swap, so enabling again automatically.");

View File

@ -7,7 +7,6 @@ import org.fdroid.fdroid.R;
import org.fdroid.fdroid.localrepo.type.BluetoothSwap; import org.fdroid.fdroid.localrepo.type.BluetoothSwap;
public class BluetoothPeer implements Peer { public class BluetoothPeer implements Peer {
private static final String TAG = "BluetoothPeer";
private final BluetoothDevice device; private final BluetoothDevice device;

View File

@ -79,8 +79,8 @@ class BonjourFinder extends PeerFinder implements ServiceListener {
} }
Utils.debugLog(TAG, "Adding mDNS service listeners for " + HTTP_SERVICE_TYPE + " and " + HTTPS_SERVICE_TYPE); Utils.debugLog(TAG, "Adding mDNS service listeners for " + HTTP_SERVICE_TYPE + " and " + HTTPS_SERVICE_TYPE);
jmdns.addServiceListener(HTTP_SERVICE_TYPE, BonjourFinder.this); jmdns.addServiceListener(HTTP_SERVICE_TYPE, this);
jmdns.addServiceListener(HTTPS_SERVICE_TYPE, BonjourFinder.this); jmdns.addServiceListener(HTTPS_SERVICE_TYPE, this);
listServices(); listServices();
} }

View File

@ -11,7 +11,6 @@ import java.io.IOException;
import java.net.URL; import java.net.URL;
public class DownloaderFactory { public class DownloaderFactory {
private static final String TAG = "DownloaderFactory";
private static LocalBroadcastManager localBroadcastManager; private static LocalBroadcastManager localBroadcastManager;
@ -69,8 +68,4 @@ public class DownloaderFactory {
URL url = new URL(urlString); URL url = new URL(urlString);
return new AsyncDownloadWrapper(create(context, url, destFile, credentials), listener); return new AsyncDownloadWrapper(create(context, url, destFile, credentials), listener);
} }
private static boolean isOnionAddress(URL url) {
return url.getHost().endsWith(".onion");
}
} }

View File

@ -206,7 +206,7 @@ public class LocalHTTPD extends NanoHTTPD {
} }
} }
Response response = serveFile(uri, headers, f, getMimeTypeForFile(uri)); Response response = serveFile(headers, f, getMimeTypeForFile(uri));
return response != null ? response : return response != null ? response :
createResponse(Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT, createResponse(Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
"Error 404, file not found."); "Error 404, file not found.");
@ -216,7 +216,7 @@ public class LocalHTTPD extends NanoHTTPD {
* Serves file from homeDir and its' subdirectories (only). Uses only URI, * Serves file from homeDir and its' subdirectories (only). Uses only URI,
* ignores all headers and HTTP parameters. * ignores all headers and HTTP parameters.
*/ */
private Response serveFile(String uri, Map<String, String> header, File file, String mime) { private Response serveFile(Map<String, String> header, File file, String mime) {
Response res; Response res;
try { try {
// Calculate etag // Calculate etag

View File

@ -122,11 +122,6 @@ public class AppSecurityPermissions {
private static class MyPermissionInfo extends PermissionInfo { private static class MyPermissionInfo extends PermissionInfo {
CharSequence mLabel; CharSequence mLabel;
/**
* PackageInfo.requestedPermissionsFlags for the new package being installed.
*/
int mNewReqFlags;
/** /**
* PackageInfo.requestedPermissionsFlags for the currently installed * PackageInfo.requestedPermissionsFlags for the currently installed
* package, if it is installed. * package, if it is installed.
@ -298,7 +293,7 @@ public class AppSecurityPermissions {
final int[] instFlagsList = getRequestedPermissionFlags(installedPkgInfo); final int[] instFlagsList = getRequestedPermissionFlags(installedPkgInfo);
existingFlags = instFlagsList[existingIndex]; existingFlags = instFlagsList[existingIndex];
} }
if (!isDisplayablePermission(tmpPermInfo, flagsList[i], existingFlags)) { if (!isDisplayablePermission(tmpPermInfo, existingFlags)) {
// This is not a permission that is interesting for the user // This is not a permission that is interesting for the user
// to see, so skip it. // to see, so skip it.
continue; continue;
@ -333,7 +328,6 @@ public class AppSecurityPermissions {
final boolean newPerm = installedPkgInfo != null final boolean newPerm = installedPkgInfo != null
&& (existingFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0; && (existingFlags & PackageInfo.REQUESTED_PERMISSION_GRANTED) == 0;
MyPermissionInfo myPerm = new MyPermissionInfo(tmpPermInfo); MyPermissionInfo myPerm = new MyPermissionInfo(tmpPermInfo);
myPerm.mNewReqFlags = flagsList[i];
myPerm.mExistingReqFlags = existingFlags; myPerm.mExistingReqFlags = existingFlags;
// This is a new permission if the app is already installed and // This is a new permission if the app is already installed and
// doesn't currently hold this permission. // doesn't currently hold this permission.
@ -424,8 +418,7 @@ public class AppSecurityPermissions {
} }
@TargetApi(Build.VERSION_CODES.JELLY_BEAN) @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private boolean isDisplayablePermission(PermissionInfo pInfo, int newReqFlags, private boolean isDisplayablePermission(PermissionInfo pInfo, int existingReqFlags) {
int existingReqFlags) {
final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE; final int base = pInfo.protectionLevel & PermissionInfo.PROTECTION_MASK_BASE;
final boolean isNormal = base == PermissionInfo.PROTECTION_NORMAL; final boolean isNormal = base == PermissionInfo.PROTECTION_NORMAL;
final boolean isDangerous = base == PermissionInfo.PROTECTION_DANGEROUS; final boolean isDangerous = base == PermissionInfo.PROTECTION_DANGEROUS;
@ -492,7 +485,7 @@ public class AppSecurityPermissions {
if (permList != null) { if (permList != null) {
// First pass to group permissions // First pass to group permissions
for (MyPermissionInfo pInfo : permList) { for (MyPermissionInfo pInfo : permList) {
if (!isDisplayablePermission(pInfo, pInfo.mNewReqFlags, pInfo.mExistingReqFlags)) { if (!isDisplayablePermission(pInfo, pInfo.mExistingReqFlags)) {
continue; continue;
} }
MyPermissionGroupInfo group = mPermGroups.get(pInfo.group); MyPermissionGroupInfo group = mPermGroups.get(pInfo.group);

View File

@ -197,11 +197,6 @@ public class InstallConfirmActivity extends Activity implements OnCancelListener
startInstallConfirm(); startInstallConfirm();
} }
@Override
public void onBackPressed() {
super.onBackPressed();
}
// Generic handling when pressing back key // Generic handling when pressing back key
public void onCancel(DialogInterface dialog) { public void onCancel(DialogInterface dialog) {
finish(); finish();

View File

@ -199,7 +199,7 @@ public class AvailableAppsFragment extends AppListFragment implements
private void setCurrentCategory(String category) { private void setCurrentCategory(String category) {
currentCategory = category; currentCategory = category;
Utils.debugLog(TAG, "Category '" + currentCategory + "' selected."); Utils.debugLog(TAG, "Category '" + currentCategory + "' selected.");
getLoaderManager().restartLoader(0, null, AvailableAppsFragment.this); getLoaderManager().restartLoader(0, null, this);
} }
@Override @Override

View File

@ -32,10 +32,6 @@ public class InitialLoadingView extends RelativeLayout implements SwapWorkflowAc
super(context, attrs, defStyleAttr, defStyleRes); super(context, attrs, defStyleAttr, defStyleRes);
} }
private SwapWorkflowActivity getActivity() {
return (SwapWorkflowActivity) getContext();
}
@Override @Override
public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) { public boolean buildMenu(Menu menu, @NonNull MenuInflater inflater) {
return true; return true;

View File

@ -211,9 +211,6 @@ public class SelectAppsView extends ListView implements
private class AppListAdapter extends CursorAdapter { private class AppListAdapter extends CursorAdapter {
@SuppressWarnings("UnusedDeclaration")
private static final String TAG = "AppListAdapter";
@Nullable @Nullable
private LayoutInflater inflater; private LayoutInflater inflater;

View File

@ -250,7 +250,7 @@ public class SwapAppsView extends ListView implements
Apk apk = getApkToInstall(); Apk apk = getApkToInstall();
String broadcastUrl = intent.getStringExtra(Downloader.EXTRA_ADDRESS); String broadcastUrl = intent.getStringExtra(Downloader.EXTRA_ADDRESS);
if (apk != null && apk.repoAddress != null && (!TextUtils.equals(Utils.getApkUrl(apk.repoAddress, apk), broadcastUrl))) { if (apk != null && apk.repoAddress != null && !TextUtils.equals(Utils.getApkUrl(apk.repoAddress, apk), broadcastUrl)) {
return; return;
} }

View File

@ -795,7 +795,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
private void handleDownloadComplete(File apkFile, String packageName) { private void handleDownloadComplete(File apkFile, String packageName) {
try { try {
Installer.getActivityInstaller(SwapWorkflowActivity.this, new Installer.InstallerCallback() { Installer.getActivityInstaller(this, new Installer.InstallerCallback() {
@Override @Override
public void onSuccess(int operation) { public void onSuccess(int operation) {
// TODO: Don't reload the view weely-neely, but rather get the view to listen // TODO: Don't reload the view weely-neely, but rather get the view to listen

View File

@ -170,7 +170,7 @@ public class WifiQrView extends ScrollView implements SwapWorkflowActivity.Inner
} }
private BroadcastReceiver onWifiStateChanged = new BroadcastReceiver() { private final BroadcastReceiver onWifiStateChanged = new BroadcastReceiver() {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
setUIFromWifi(); setUIFromWifi();