diff --git a/app/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java b/app/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java deleted file mode 100644 index 41f3a0bb2..000000000 --- a/app/src/main/java/com/topjohnwu/magisk/tasks/UpdateRepos.java +++ /dev/null @@ -1,177 +0,0 @@ -package com.topjohnwu.magisk.tasks; - -import android.database.Cursor; -import android.util.Pair; - -import com.topjohnwu.magisk.App; -import com.topjohnwu.magisk.Config; -import com.topjohnwu.magisk.Const; -import com.topjohnwu.magisk.model.entity.Repo; -import com.topjohnwu.magisk.utils.Event; -import com.topjohnwu.magisk.utils.Logger; -import com.topjohnwu.magisk.utils.Utils; -import com.topjohnwu.net.Networking; -import com.topjohnwu.net.Request; - -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.net.HttpURLConnection; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Collections; -import java.util.Date; -import java.util.Locale; -import java.util.Queue; -import java.util.Set; -import java.util.TimeZone; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -@Deprecated -public class UpdateRepos { - private static final DateFormat DATE_FORMAT; - - private final App app = App.self; - private Set cached; - private Queue> moduleQueue; - - static { - DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'", Locale.US); - DATE_FORMAT.setTimeZone(TimeZone.getTimeZone("UTC")); - } - - private void runTasks(Runnable task) { - Future[] futures = new Future[App.THREAD_POOL.getMaximumPoolSize() - 1]; - for (int i = 0; i < futures.length; ++i) { - futures[i] = App.THREAD_POOL.submit(task); - } - for (Future f : futures) { - while (true) { - try { - f.get(); - } catch (InterruptedException e) { - continue; - } catch (ExecutionException ignored) {} - break; - } - } - } - - /* We sort repos by last push, which means that we only need to check whether the - * first page is updated to determine whether the online repo database is changed - */ - private boolean parsePage(int page) { - Request req = Networking.get(Utils.fmt(Const.Url.REPO_URL, page + 1)); - if (page == 0) { - String etag = Config.get(Config.Key.ETAG_KEY); - if (etag != null) - req.addHeaders(Const.Key.IF_NONE_MATCH, etag); - } - Request.Result res = req.execForJSONArray(); - // JSON not updated - if (res.getCode() == HttpURLConnection.HTTP_NOT_MODIFIED) - return false; - // Network error - if (res.getResult() == null) { - cached.clear(); - return true; - } - // Current page is the last page - if (res.getResult().length() == 0) - return true; - - try { - for (int i = 0; i < res.getResult().length(); i++) { - JSONObject rawRepo = res.getResult().getJSONObject(i); - String id = rawRepo.getString("name"); - Date date = DATE_FORMAT.parse(rawRepo.getString("pushed_at")); - moduleQueue.offer(new Pair<>(id, date)); - } - } catch (JSONException | ParseException e) { - // Should not happen, but if exception occurs, page load fails - return false; - } - - // Update ETAG - if (page == 0) { - String etag = res.getConnection().getHeaderField(Config.Key.ETAG_KEY); - if (etag != null) { - etag = etag.substring(etag.indexOf('\"'), etag.lastIndexOf('\"') + 1); - Config.set(Config.Key.ETAG_KEY, etag); - } - } - - String links = res.getConnection().getHeaderField(Const.Key.LINK_KEY); - return links == null || !links.contains("next") || parsePage(page + 1); - } - - private boolean loadPages() { - if (!parsePage(0)) - return false; - runTasks(() -> { - while (true) { - Pair pair = moduleQueue.poll(); - if (pair == null) - return; - Repo repo = app.getRepoDB().getRepo(pair.first); - try { - if (repo == null) - repo = new Repo(pair.first); - else - cached.remove(pair.first); - repo.update(pair.second); - app.getRepoDB().addRepo(repo); - } catch (Repo.IllegalRepoException e) { - Logger.debug(e.getMessage()); - app.getRepoDB().removeRepo(pair.first); - } - } - }); - return true; - } - - private void fullReload() { - Cursor c = app.getRepoDB().getRawCursor(); - runTasks(() -> { - while (true) { - Repo repo; - synchronized (c) { - if (!c.moveToNext()) - return; - repo = new Repo(c); - } - try { - repo.update(); - app.getRepoDB().addRepo(repo); - } catch (Repo.IllegalRepoException e) { - Logger.debug(e.getMessage()); - app.getRepoDB().removeRepo(repo); - } - } - }); - } - - public void exec(boolean force) { - Event.reset(Event.REPO_LOAD_DONE); - App.THREAD_POOL.execute(() -> { - cached = Collections.synchronizedSet(app.getRepoDB().getRepoIDSet()); - moduleQueue = new ConcurrentLinkedQueue<>(); - - if (loadPages()) { - // The leftover cached means they are removed from online repo - app.getRepoDB().removeRepo(cached); - } else if (force) { - fullReload(); - } - Event.trigger(Event.REPO_LOAD_DONE); - }); - } - - public void exec() { - exec(false); - } -} diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt index 2b449bfb7..0e5492cb7 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/base/MagiskViewModel.kt @@ -6,19 +6,11 @@ import com.skoumal.teanity.viewmodel.LoadingViewModel import com.topjohnwu.magisk.model.events.BackPressEvent import com.topjohnwu.magisk.model.events.PermissionEvent import com.topjohnwu.magisk.model.events.ViewActionEvent -import com.topjohnwu.magisk.utils.Event import io.reactivex.Observable import io.reactivex.subjects.PublishSubject -import timber.log.Timber -abstract class MagiskViewModel : LoadingViewModel(), Event.AutoListener { - - @Deprecated("") - override fun onEvent(event: Int) = Timber.i("Event of $event was not handled") - - @Deprecated("") - override fun getListeningEvents(): IntArray = intArrayOf() +abstract class MagiskViewModel : LoadingViewModel() { fun withView(action: Activity.() -> Unit) { ViewActionEvent(action).publish() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt index 9681027c1..1935f3832 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt +++ b/app/src/main/java/com/topjohnwu/magisk/ui/home/HomeViewModel.kt @@ -10,7 +10,6 @@ import com.topjohnwu.magisk.data.repository.MagiskRepository import com.topjohnwu.magisk.model.events.* import com.topjohnwu.magisk.model.observer.Observer import com.topjohnwu.magisk.ui.base.MagiskViewModel -import com.topjohnwu.magisk.utils.Event import com.topjohnwu.magisk.utils.ISafetyNetHelper import com.topjohnwu.magisk.utils.toggle import com.topjohnwu.superuser.Shell @@ -87,8 +86,6 @@ class HomeViewModel( private val latest = resources.getString(R.string.latest_version) init { - Event.register(this) - isForceEncryption.addOnPropertyChangedCallback { Config.keepEnc = it ?: return@addOnPropertyChangedCallback } @@ -99,13 +96,6 @@ class HomeViewModel( refresh() } - override fun onEvent(event: Int) { - updateSelf() - ensureEnv() - } - - override fun getListeningEvents(): IntArray = intArrayOf(Event.UPDATE_CHECK_DONE) - fun paypalPressed() = OpenLinkEvent(Const.Url.PAYPAL_URL).publish() fun patreonPressed() = OpenLinkEvent(Const.Url.PATREON_URL).publish() fun twitterPressed() = OpenLinkEvent(Const.Url.TWITTER_URL).publish() diff --git a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java index dbc1f8991..6cee06511 100644 --- a/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java +++ b/app/src/main/java/com/topjohnwu/magisk/ui/settings/SettingsFragment.java @@ -79,7 +79,7 @@ public class SettingsFragment extends BasePreferenceFragment { }); findPreference("hosts").setOnPreferenceClickListener(pref -> { Shell.su("add_hosts_module").exec(); - Utils.loadModules(); + //Utils.loadModules(); Utils.toast(R.string.settings_hosts_toast, Toast.LENGTH_SHORT); return true; }); @@ -288,11 +288,13 @@ public class SettingsFragment extends BasePreferenceFragment { } @Override + @Deprecated public void onEvent(int event) { setLocalePreference((ListPreference) findPreference(Config.Key.LOCALE)); } @Override + @Deprecated public int[] getListeningEvents() { return new int[] {Event.LOCALE_FETCH_DONE}; } diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Event.java b/app/src/main/java/com/topjohnwu/magisk/utils/Event.java index fbce4530c..23d14013c 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Event.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Event.java @@ -12,14 +12,10 @@ import androidx.collection.ArraySet; @Deprecated public class Event { - public static final int MAGISK_HIDE_DONE = 0; - public static final int MODULE_LOAD_DONE = 1; - public static final int REPO_LOAD_DONE = 2; - public static final int UPDATE_CHECK_DONE = 3; + @Deprecated public static final int LOCALE_FETCH_DONE = 4; - @IntDef({MAGISK_HIDE_DONE, MODULE_LOAD_DONE, REPO_LOAD_DONE, - UPDATE_CHECK_DONE, LOCALE_FETCH_DONE}) + @IntDef(LOCALE_FETCH_DONE) @Retention(RetentionPolicy.SOURCE) public @interface EventID {} diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java b/app/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java index ea14f1c01..c9cae156d 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/LocaleManager.java @@ -7,8 +7,6 @@ import android.content.res.Resources; import android.os.Build; import android.text.TextUtils; -import androidx.annotation.StringRes; - import com.topjohnwu.magisk.App; import com.topjohnwu.magisk.Config; import com.topjohnwu.superuser.Shell; @@ -20,9 +18,11 @@ import java.util.HashSet; import java.util.List; import java.util.Locale; +import androidx.annotation.StringRes; + public class LocaleManager { public static Locale locale = Locale.getDefault(); - public final static Locale defaultLocale = Locale.getDefault(); + public static final Locale defaultLocale = Locale.getDefault(); public static List locales; public static Locale forLanguageTag(String tag) { @@ -44,7 +44,7 @@ public class LocaleManager { default: language = tok[0]; } - if ((language.length() != 2 && language.length() != 3)) + if (language.length() != 2 && language.length() != 3) return new Locale(""); if (tok.length == 1) return new Locale(language); @@ -114,6 +114,7 @@ public class LocaleManager { return getLocaleContext(locale).getString(id); } + @Deprecated public static void loadAvailableLocales(@StringRes int compareId) { Shell.EXECUTOR.execute(() -> { locales = new ArrayList<>(); diff --git a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java index 843d6469d..3033e9093 100644 --- a/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java +++ b/app/src/main/java/com/topjohnwu/magisk/utils/Utils.java @@ -85,24 +85,6 @@ public class Utils { .replace("#", "").replace("@", "").replace("\\", "_"); } - @Deprecated - public static void loadModules() { - loadModules(true); - } - - @Deprecated - public static void loadModules(boolean async) { - Event.reset(Event.MODULE_LOAD_DONE); - Runnable run = () -> { - Map moduleMap = loadModulesLeanback(); - Event.trigger(Event.MODULE_LOAD_DONE, moduleMap); - }; - if (async) - App.THREAD_POOL.execute(run); - else - run.run(); - } - @WorkerThread public static Map loadModulesLeanback() { final Map moduleMap = new ValueSortedMap<>();