Apply some PMD fixes
This commit is contained in:
parent
90822e9258
commit
be87a31b84
@ -150,7 +150,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
|
||||
}
|
||||
|
||||
private String getDefaultLocalRepoName() {
|
||||
return (Build.BRAND + " " + Build.MODEL + String.valueOf(new Random().nextInt(9999)))
|
||||
return (Build.BRAND + " " + Build.MODEL + new Random().nextInt(9999))
|
||||
.replaceAll(" ", "-");
|
||||
}
|
||||
|
||||
|
@ -291,13 +291,13 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
*/
|
||||
private boolean verifyIsTimeForScheduledRun() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
||||
long lastUpdate = prefs.getLong(Preferences.PREF_UPD_LAST, 0);
|
||||
String sint = prefs.getString(Preferences.PREF_UPD_INTERVAL, "0");
|
||||
int interval = Integer.parseInt(sint);
|
||||
if (interval == 0) {
|
||||
Log.i(TAG, "Skipping update - disabled");
|
||||
return false;
|
||||
}
|
||||
long lastUpdate = prefs.getLong(Preferences.PREF_UPD_LAST, 0);
|
||||
long elapsed = System.currentTimeMillis() - lastUpdate;
|
||||
if (elapsed < interval * 60 * 60 * 1000) {
|
||||
Log.i(TAG, "Skipping update - done " + elapsed
|
||||
@ -312,7 +312,6 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
* If we are to update the repos only on wifi, make sure that connection is active
|
||||
*/
|
||||
public static boolean isNetworkAvailableForUpdate(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
|
||||
// this could be cellular or wifi
|
||||
@ -320,6 +319,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
if (activeNetwork == null)
|
||||
return false;
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
if (activeNetwork.getType() != ConnectivityManager.TYPE_WIFI
|
||||
&& prefs.getBoolean(Preferences.PREF_UPD_WIFI_ONLY, false)) {
|
||||
Log.i(TAG, "Skipping update - wifi not available");
|
||||
@ -336,8 +336,6 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
boolean manualUpdate = intent.getBooleanExtra(EXTRA_MANUAL_UPDATE, false);
|
||||
|
||||
try {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
||||
|
||||
// See if it's time to actually do anything yet...
|
||||
if (manualUpdate) {
|
||||
Utils.debugLog(TAG, "Unscheduled (manually requested) update");
|
||||
@ -345,6 +343,8 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
return;
|
||||
}
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
|
||||
|
||||
// Grab some preliminary information, then we can release the
|
||||
// database while we do all the downloading, etc...
|
||||
List<Repo> repos = RepoProvider.Helper.all(this);
|
||||
@ -505,9 +505,9 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
return stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
}
|
||||
|
||||
private NotificationCompat.Style createNotificationBigStyle(Cursor hasUpdates) {
|
||||
private static final int MAX_UPDATES_TO_SHOW = 5;
|
||||
|
||||
final int MAX_UPDATES_TO_SHOW = 5;
|
||||
private NotificationCompat.Style createNotificationBigStyle(Cursor hasUpdates) {
|
||||
|
||||
final String contentText = hasUpdates.getCount() > 1
|
||||
? getString(R.string.many_updates_available, hasUpdates.getCount())
|
||||
@ -553,7 +553,7 @@ public class UpdateService extends IntentService implements ProgressListener {
|
||||
|
||||
private List<String> getKnownAppIds(List<App> apps) {
|
||||
List<String> knownAppIds = new ArrayList<>();
|
||||
if (apps.size() == 0) {
|
||||
if (apps.isEmpty()) {
|
||||
return knownAppIds;
|
||||
}
|
||||
if (apps.size() > AppProvider.MAX_APPS_TO_QUERY) {
|
||||
|
@ -359,11 +359,11 @@ public final class Utils {
|
||||
public static String calcFingerprint(byte[] key) {
|
||||
if (key == null)
|
||||
return null;
|
||||
String ret = null;
|
||||
if (key.length < 256) {
|
||||
Log.e(TAG, "key was shorter than 256 bytes (" + key.length + "), cannot be valid!");
|
||||
return null;
|
||||
}
|
||||
String ret = null;
|
||||
try {
|
||||
// keytool -list -v gives you the SHA-256 fingerprint
|
||||
MessageDigest digest = MessageDigest.getInstance("SHA-256");
|
||||
@ -427,7 +427,7 @@ public final class Utils {
|
||||
}
|
||||
|
||||
public static CommaSeparatedList make(List<String> list) {
|
||||
if (list == null || list.size() == 0)
|
||||
if (list == null || list.isEmpty())
|
||||
return null;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
|
@ -121,7 +121,7 @@ public class ApkProvider extends FDroidProvider {
|
||||
* one of the apks in the "apks" argument.
|
||||
*/
|
||||
public static List<Apk> knownApks(Context context, List<Apk> apks, String[] fields) {
|
||||
if (apks.size() == 0) {
|
||||
if (apks.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
@ -362,13 +362,13 @@ public class ApkProvider extends FDroidProvider {
|
||||
|
||||
private QuerySelection queryApks(String apkKeys) {
|
||||
final String[] apkDetails = apkKeys.split(",");
|
||||
final String[] args = new String[apkDetails.length * 2];
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (apkDetails.length > MAX_APKS_TO_QUERY) {
|
||||
throw new IllegalArgumentException(
|
||||
"Cannot query more than " + MAX_APKS_TO_QUERY + ". " +
|
||||
"You tried to query " + apkDetails.length);
|
||||
}
|
||||
final String[] args = new String[apkDetails.length * 2];
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 0; i < apkDetails.length; i++) {
|
||||
String[] parts = apkDetails[i].split(":");
|
||||
String id = parts[0];
|
||||
|
@ -287,8 +287,6 @@ public class App extends ValueObject implements Comparable<App> {
|
||||
apk.features = Utils.CommaSeparatedList.make(featureNames);
|
||||
}
|
||||
|
||||
byte[] rawCertBytes;
|
||||
|
||||
final JarFile apkJar = new JarFile(apkFile);
|
||||
final JarEntry aSignedEntry = (JarEntry) apkJar.getEntry("AndroidManifest.xml");
|
||||
|
||||
@ -297,6 +295,8 @@ public class App extends ValueObject implements Comparable<App> {
|
||||
throw new CertificateEncodingException("null signed entry!");
|
||||
}
|
||||
|
||||
byte[] rawCertBytes;
|
||||
|
||||
// Due to a bug in android 5.0 lollipop, the inclusion of BouncyCastle causes
|
||||
// breakage when verifying the signature of most .jars. For more
|
||||
// details, check out https://gitlab.com/fdroid/fdroidclient/issues/111.
|
||||
|
@ -677,7 +677,6 @@ public class AppProvider extends FDroidProvider {
|
||||
|
||||
@Override
|
||||
public Cursor query(Uri uri, String[] projection, String customSelection, String[] selectionArgs, String sortOrder) {
|
||||
Query query = new Query();
|
||||
AppQuerySelection selection = new AppQuerySelection(customSelection, selectionArgs);
|
||||
|
||||
// Queries which are for the main list of apps should not include swap apps.
|
||||
@ -758,6 +757,8 @@ public class AppProvider extends FDroidProvider {
|
||||
sortOrder = " lower( fdroid_app." + sortOrder + " ) ";
|
||||
}
|
||||
|
||||
Query query = new Query();
|
||||
|
||||
query.addSelection(selection);
|
||||
query.addFields(projection); // TODO: Make the order of addFields/addSelection not dependent on each other...
|
||||
query.addOrderBy(sortOrder);
|
||||
|
@ -352,7 +352,7 @@ public class PrivilegedInstaller extends Installer {
|
||||
return false;
|
||||
}
|
||||
|
||||
public final int INSTALL_REPLACE_EXISTING = 2;
|
||||
public static final int INSTALL_REPLACE_EXISTING = 2;
|
||||
|
||||
/**
|
||||
* Following return codes are copied from Android 5.1 source code
|
||||
|
@ -132,7 +132,7 @@ public class Response {
|
||||
|
||||
public String readContents() throws IOException {
|
||||
int size = getFileSize();
|
||||
if (contentStream == null || getFileSize() <= 0) {
|
||||
if (contentStream == null || size <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
@ -436,8 +436,6 @@ public class AppSecurityPermissions {
|
||||
final boolean isDangerous = (base == PermissionInfo.PROTECTION_DANGEROUS);
|
||||
final boolean isRequired =
|
||||
((newReqFlags&PackageInfo.REQUESTED_PERMISSION_REQUIRED) != 0);
|
||||
final boolean isDevelopment =
|
||||
((pInfo.protectionLevel&PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0);
|
||||
final boolean wasGranted =
|
||||
((existingReqFlags&PackageInfo.REQUESTED_PERMISSION_GRANTED) != 0);
|
||||
final boolean isGranted =
|
||||
@ -450,6 +448,9 @@ public class AppSecurityPermissions {
|
||||
return true;
|
||||
}
|
||||
|
||||
final boolean isDevelopment =
|
||||
((pInfo.protectionLevel&PermissionInfo.PROTECTION_FLAG_DEVELOPMENT) != 0);
|
||||
|
||||
// Development permissions are only shown to the user if they are already
|
||||
// granted to the app -- if we are installing an app and they are not
|
||||
// already granted, they will not be granted as part of the install.
|
||||
|
@ -86,8 +86,6 @@ public class InstallConfirmActivity extends Activity implements OnCancelListener
|
||||
mOkCanInstall = false;
|
||||
int msg = 0;
|
||||
AppSecurityPermissions perms = new AppSecurityPermissions(this, mAppDiff.mPkgInfo);
|
||||
final int NP = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL);
|
||||
final int ND = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE);
|
||||
if (mAppDiff.mInstalledAppInfo != null) {
|
||||
msg = (mAppDiff.mInstalledAppInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0
|
||||
? R.string.install_confirm_update_system
|
||||
@ -109,6 +107,8 @@ public class InstallConfirmActivity extends Activity implements OnCancelListener
|
||||
findViewById(R.id.tabscontainer).setVisibility(View.GONE);
|
||||
findViewById(R.id.divider).setVisibility(View.VISIBLE);
|
||||
}
|
||||
final int NP = perms.getPermissionCount(AppSecurityPermissions.WHICH_PERSONAL);
|
||||
final int ND = perms.getPermissionCount(AppSecurityPermissions.WHICH_DEVICE);
|
||||
if (NP > 0 || ND > 0) {
|
||||
permVisible = true;
|
||||
LayoutInflater inflater = (LayoutInflater) getSystemService(
|
||||
|
@ -127,13 +127,12 @@ abstract public class AppListAdapter extends CursorAdapter {
|
||||
}
|
||||
|
||||
final String installedVersionString = app.installedVersionName;
|
||||
int installedVersionCode = app.installedVersionCode;
|
||||
|
||||
if (app.canAndWantToUpdate() && showStatusUpdate()) {
|
||||
return installedVersionString + " → " + app.getSuggestedVersion();
|
||||
}
|
||||
|
||||
if (installedVersionCode > 0 && showStatusInstalled()) {
|
||||
if (app.installedVersionCode > 0 && showStatusInstalled()) {
|
||||
return installedVersionString + " ✔";
|
||||
}
|
||||
|
||||
|
@ -275,7 +275,6 @@ public class ManageReposActivity extends ActionBarActivity {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
|
||||
String fp = fingerprintEditText.getText().toString();
|
||||
String url = uriEditText.getText().toString();
|
||||
|
||||
try {
|
||||
@ -285,6 +284,8 @@ public class ManageReposActivity extends ActionBarActivity {
|
||||
return;
|
||||
}
|
||||
|
||||
String fp = fingerprintEditText.getText().toString();
|
||||
|
||||
switch (addRepoState) {
|
||||
case DOESNT_EXIST:
|
||||
prepareToCreateNewRepo(url, fp);
|
||||
|
Loading…
x
Reference in New Issue
Block a user