Skip to content

Commit

Permalink
Do not use ThreadLocalRandom for shuffle.
Browse files Browse the repository at this point in the history
Fixes #52.
  • Loading branch information
AndreyPavlenko committed Oct 25, 2021
1 parent 3b9efa5 commit 22e13f7
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

import me.aap.fermata.R;
Expand Down Expand Up @@ -285,7 +284,7 @@ private void setSeqNum(SortedItems sorted) {
}

private void shuffle(List<?> l) {
Random rnd = ThreadLocalRandom.current();
Random rnd = new Random();

for (int i = 0, s = l.size(); i < s; i++) {
int next = rnd.nextInt(s - i);
Expand Down
19 changes: 17 additions & 2 deletions fermata/src/main/java/me/aap/fermata/ui/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,18 +218,23 @@ private FutureSupplier<Void> update(String uri, PreferenceStore ps,
Pref<Supplier<String[]>> deletePref) {
if (!BuildConfig.AUTO) return completedVoid();
try {
File tmp;
File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);

if (dir == null) {
if ((tmp = createTempFile(dir)) == null) {
App app = App.get();
File cache = app.getExternalCacheDir();
if (cache == null) cache = app.getCacheDir();
dir = new File(cache, "updates");
//noinspection ResultOfMethodCallIgnored
dir.mkdirs();
if ((tmp = createTempFile(dir)) == null) {
App.get().run(() -> showAlert(this, "Update failed - unable to create a temporary file"));
return completedVoid();
}
}

File f = File.createTempFile("Fermata-", ".apk", dir);
File f = tmp;

synchronized (this) {
List<String> l = new ArrayList<>(Arrays.asList(ps.getStringArrayPref(deletePref)));
Expand Down Expand Up @@ -262,4 +267,14 @@ private FutureSupplier<Void> update(String uri, PreferenceStore ps,
return failed(ex);
}
}

private static File createTempFile(File dir) {
try {
if (dir == null) return null;
return File.createTempFile("Fermata-", ".apk", dir);
} catch (Exception ex) {
Log.e(ex, "Failed to create a temporary file in the directory ", dir);
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ private void failedToLoadModule(@StringRes int name, Throwable ex) {

App.get().getHandler().post(() -> {
String n = getString(name);
Log.e(ex, "Failed to load add folder: ", name);
Log.e(ex, "Failed to add folder: ", name);

if (ex instanceof InstallException) {
UiUtils.showAlert(getContext(), getString(R.string.err_failed_install_module, n));
Expand Down

0 comments on commit 22e13f7

Please sign in to comment.