Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ianmacd committed Jul 27, 2018
2 parents 75bb495 + 546c7ce commit 7c977db
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 36 deletions.
11 changes: 8 additions & 3 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
# public *;
#}

# Keep all names, we are open source anyway :)
-keepnames class ** { *; }
# Don't obfuscate, we are open source anyway :)
-dontobfuscate

# BouncyCastle
-keep class org.bouncycastle.jcajce.provider.asymmetric.rsa.**SHA1** { *; }
Expand All @@ -26,4 +26,9 @@
-dontwarn javax.naming.**

# Gson
-keepattributes Signature
-keepattributes Signature

# Strip logging
-assumenosideeffects class com.topjohnwu.magisk.utils.Logger {
public *** debug(...);
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ public void saveLogs() {

public void clearLogs() {
Shell.su("echo -n > " + Const.MAGISK_LOG).submit();
txtLog.setText(R.string.log_is_empty);
SnackbarMaker.make(txtLog, R.string.logs_cleared, Snackbar.LENGTH_SHORT).show();
}
}
2 changes: 1 addition & 1 deletion app/src/full/java/com/topjohnwu/magisk/MagiskManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public void loadMagiskInfo() {
magiskVersionCode = Integer.parseInt(ShellUtils.fastCmd("magisk -V"));
String s = ShellUtils.fastCmd((magiskVersionCode >= Const.MAGISK_VER.RESETPROP_PERSIST ?
"resetprop -p " : "getprop ") + Const.MAGISKHIDE_PROP);
magiskHide = Integer.parseInt(s) != 0;
magiskHide = s.isEmpty() || Integer.parseInt(s) != 0;
} catch (Exception ignored) {}
}

Expand Down
45 changes: 13 additions & 32 deletions app/src/full/java/com/topjohnwu/magisk/asyncs/UpdateRepos.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.topjohnwu.magisk.asyncs;

import android.database.Cursor;
import android.os.AsyncTask;
import android.text.TextUtils;

import com.topjohnwu.magisk.MagiskManager;
Expand Down Expand Up @@ -29,55 +28,37 @@
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;

public class UpdateRepos extends ParallelTask<Void, Void, Void> {

private static final int CHECK_ETAG = 0;
private static final int LOAD_NEXT = 1;
private static final int LOAD_PREV = 2;
private static final DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US);
private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();
private static final int CORE_POOL_SIZE = Math.max(2, CPU_COUNT - 1);

private MagiskManager mm;
private List<String> etags, newEtags = new LinkedList<>();
private Set<String> cached;
private boolean forceUpdate;
private AtomicInteger taskCount = new AtomicInteger(0);
final private Object allDone = new Object();
private ExecutorService threadPool;

public UpdateRepos(boolean force) {
mm = MagiskManager.get();
mm.repoLoadDone.reset();
forceUpdate = force;
}

private void queueTask(Runnable task) {
// Thread pool's queue has an upper bound, batch it with 64 tasks
while (taskCount.get() >= 64) {
waitTasks();
}
taskCount.incrementAndGet();
AsyncTask.THREAD_POOL_EXECUTOR.execute(() -> {
task.run();
if (taskCount.decrementAndGet() == 0) {
synchronized (allDone) {
allDone.notify();
}
}
});
threadPool = Executors.newFixedThreadPool(CORE_POOL_SIZE);
}

private void waitTasks() {
if (taskCount.get() == 0)
return;
synchronized (allDone) {
try {
allDone.wait();
} catch (InterruptedException e) {
// Wait again
waitTasks();
}
}
threadPool.shutdown();
try {
threadPool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
} catch (InterruptedException ignored) {}
}

private boolean loadJSON(String jsonString) throws JSONException, ParseException {
Expand All @@ -93,7 +74,7 @@ private boolean loadJSON(String jsonString) throws JSONException, ParseException
String name = rawRepo.getString("name");
Date date = dateFormat.parse(rawRepo.getString("pushed_at"));
Set<String> set = Collections.synchronizedSet(cached);
queueTask(() -> {
threadPool.execute(() -> {
Repo repo = mm.repoDB.getRepo(id);
try {
if (repo == null)
Expand Down Expand Up @@ -187,7 +168,7 @@ protected Void doInBackground(Void... voids) {
Cursor c = mm.repoDB.getRawCursor();
while (c.moveToNext()) {
Repo repo = new Repo(c);
queueTask(() -> {
threadPool.execute(() -> {
try {
repo.update();
mm.repoDB.addRepo(repo);
Expand Down

0 comments on commit 7c977db

Please sign in to comment.