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

View File

@ -526,7 +526,7 @@ public class AppDetails extends AppCompatActivity implements ProgressListener, A
private void onAppChanged() {
if (!reset(app.packageName)) {
AppDetails.this.finish();
this.finish();
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 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";

View File

@ -4,12 +4,12 @@ import android.content.Context;
import android.content.pm.PackageManager;
import android.content.pm.PermissionInfo;
public class Permission {
class Permission {
private final PackageManager packageManager;
private final PermissionInfo permissionInfo;
public Permission(Context context, String permission)
Permission(Context context, String permission)
throws PackageManager.NameNotFoundException {
this.packageManager = context.getPackageManager();
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 final Context context;
private final SharedPreferences preferences;
private Preferences(Context context) {
this.context = context;
preferences = PreferenceManager.getDefaultSharedPreferences(context);
preferences.registerOnSharedPreferenceChangeListener(this);
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 int DEFAULT_UPD_HISTORY = 14;
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_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_EXPERT = false;
private static final boolean DEFAULT_ENABLE_PROXY = false;

View File

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

View File

@ -14,7 +14,7 @@ public abstract class Compatibility {
return apiLevel < 1 || getApi() <= apiLevel;
}
protected static int getApi() {
static int getApi() {
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
// default, if not yet installed.
Provider[] secureRandomProviders =
Security.getProviders("SecureRandom.SHA1PRNG");
if ((secureRandomProviders == null)
|| (secureRandomProviders.length < 1)
|| (!LinuxPRNGSecureRandomProvider.class.equals(
secureRandomProviders[0].getClass()))) {
Provider[] secureRandomProviders = Security.getProviders("SecureRandom.SHA1PRNG");
if (secureRandomProviders == null
|| secureRandomProviders.length < 1
|| !LinuxPRNGSecureRandomProvider.class.equals(secureRandomProviders[0].getClass())) {
Security.insertProviderAt(new LinuxPRNGSecureRandomProvider(), 1);
}

View File

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

View File

@ -404,9 +404,11 @@ public class SwapService extends Service {
.commit();
}
/*
private boolean wasBluetoothEnabled() {
return persistence().getBoolean(KEY_BLUETOOTH_ENABLED, false);
}
*/
private boolean wasWifiEnabled() {
return persistence().getBoolean(KEY_WIFI_ENABLED, false);
@ -537,11 +539,12 @@ public class SwapService extends Service {
filter.addAction(WIFI_STATE_CHANGE);
LocalBroadcastManager.getInstance(this).registerReceiver(receiveSwapStatusChanged, filter);
/**
/*
if (wasBluetoothEnabled()) {
Utils.debugLog(TAG, "Previously the user enabled Bluetooth swap, so enabling again automatically.");
bluetoothSwap.startInBackground();
}*/
}
*/
if (wasWifiEnabled()) {
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;
public class BluetoothPeer implements Peer {
private static final String TAG = "BluetoothPeer";
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);
jmdns.addServiceListener(HTTP_SERVICE_TYPE, BonjourFinder.this);
jmdns.addServiceListener(HTTPS_SERVICE_TYPE, BonjourFinder.this);
jmdns.addServiceListener(HTTP_SERVICE_TYPE, this);
jmdns.addServiceListener(HTTPS_SERVICE_TYPE, this);
listServices();
}

View File

@ -11,7 +11,6 @@ import java.io.IOException;
import java.net.URL;
public class DownloaderFactory {
private static final String TAG = "DownloaderFactory";
private static LocalBroadcastManager localBroadcastManager;
@ -69,8 +68,4 @@ public class DownloaderFactory {
URL url = new URL(urlString);
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 :
createResponse(Response.Status.NOT_FOUND, NanoHTTPD.MIME_PLAINTEXT,
"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,
* 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;
try {
// Calculate etag

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -250,7 +250,7 @@ public class SwapAppsView extends ListView implements
Apk apk = getApkToInstall();
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;
}

View File

@ -795,7 +795,7 @@ public class SwapWorkflowActivity extends AppCompatActivity {
private void handleDownloadComplete(File apkFile, String packageName) {
try {
Installer.getActivityInstaller(SwapWorkflowActivity.this, new Installer.InstallerCallback() {
Installer.getActivityInstaller(this, new Installer.InstallerCallback() {
@Override
public void onSuccess(int operation) {
// 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
public void onReceive(Context context, Intent intent) {
setUIFromWifi();