mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-04-21 10:21:28 +00:00
Improve static data management
This commit is contained in:
parent
bfec381933
commit
b9495cd1bb
@ -2,6 +2,7 @@ package com.topjohnwu.magisk;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
|
import android.content.pm.ApplicationInfo;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.SparseArray;
|
import android.util.SparseArray;
|
||||||
|
|
||||||
@ -16,9 +17,6 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Global {
|
public class Global {
|
||||||
|
|
||||||
public static class Constant {
|
|
||||||
// No global constants now
|
|
||||||
}
|
|
||||||
public static class Info {
|
public static class Info {
|
||||||
public static double magiskVersion;
|
public static double magiskVersion;
|
||||||
public static String magiskVersionString = "(none)";
|
public static String magiskVersionString = "(none)";
|
||||||
@ -34,6 +32,15 @@ public class Global {
|
|||||||
public static ValueSortedMap<String, Repo> repoMap;
|
public static ValueSortedMap<String, Repo> repoMap;
|
||||||
public static ValueSortedMap<String, Module> moduleMap;
|
public static ValueSortedMap<String, Module> moduleMap;
|
||||||
public static List<String> blockList;
|
public static List<String> blockList;
|
||||||
|
public static List<ApplicationInfo> appList;
|
||||||
|
public static List<String> magiskHideList;
|
||||||
|
public static void clear() {
|
||||||
|
repoMap = null;
|
||||||
|
moduleMap = null;
|
||||||
|
blockList = null;
|
||||||
|
appList = null;
|
||||||
|
magiskHideList = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
public static class Events {
|
public static class Events {
|
||||||
public static final CallbackHandler.Event blockDetectionDone = new CallbackHandler.Event();
|
public static final CallbackHandler.Event blockDetectionDone = new CallbackHandler.Event();
|
||||||
|
@ -106,8 +106,7 @@ public class MagiskHideFragment extends Fragment implements CallbackHandler.Even
|
|||||||
@Override
|
@Override
|
||||||
public void onTrigger(CallbackHandler.Event event) {
|
public void onTrigger(CallbackHandler.Event event) {
|
||||||
Logger.dev("MagiskHideFragment: UI refresh");
|
Logger.dev("MagiskHideFragment: UI refresh");
|
||||||
Async.LoadApps.Result result = (Async.LoadApps.Result) event.getResult();
|
appAdapter.setLists(Global.Data.appList, Global.Data.magiskHideList);
|
||||||
appAdapter.setLists(result.listApps, result.hideList);
|
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
mSwipeRefreshLayout.setRefreshing(false);
|
||||||
if (!TextUtils.isEmpty(lastFilter)) {
|
if (!TextUtils.isEmpty(lastFilter)) {
|
||||||
appAdapter.filter(lastFilter);
|
appAdapter.filter(lastFilter);
|
||||||
|
@ -87,9 +87,8 @@ public class MainActivity extends AppCompatActivity
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
CallbackHandler.register(Global.Events.updateCheckDone, this);
|
CallbackHandler.register(Global.Events.updateCheckDone, this);
|
||||||
if (Global.Events.updateCheckDone.isTriggered) {
|
if (Global.Events.updateCheckDone.isTriggered)
|
||||||
onTrigger(Global.Events.updateCheckDone);
|
onTrigger(Global.Events.updateCheckDone);
|
||||||
}
|
|
||||||
checkHideSection();
|
checkHideSection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,17 +101,18 @@ public class MainActivity extends AppCompatActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
CallbackHandler.unRegister(Global.Events.reloadMainActivity, this);
|
CallbackHandler.unRegister(Global.Events.reloadMainActivity, this);
|
||||||
|
// Let garbage collector remove them
|
||||||
|
Global.Data.clear();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public void onBackPressed() {
|
||||||
if (drawer.isDrawerOpen(navigationView)) {
|
if (drawer.isDrawerOpen(navigationView))
|
||||||
drawer.closeDrawer(navigationView);
|
drawer.closeDrawer(navigationView);
|
||||||
} else {
|
else
|
||||||
finish();
|
finish();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) {
|
public boolean onNavigationItemSelected(@NonNull final MenuItem menuItem) {
|
||||||
|
@ -114,7 +114,7 @@ public class Async {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class LoadApps extends RootTask<Void, Void, LoadApps.Result> {
|
public static class LoadApps extends RootTask<Void, Void, Void> {
|
||||||
|
|
||||||
private PackageManager pm;
|
private PackageManager pm;
|
||||||
|
|
||||||
@ -123,33 +123,22 @@ public class Async {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Result doInBackground(Void... voids) {
|
protected Void doInBackground(Void... voids) {
|
||||||
List<ApplicationInfo> listApps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
|
Global.Data.appList = pm.getInstalledApplications(0);
|
||||||
for (Iterator<ApplicationInfo> i = listApps.iterator(); i.hasNext(); ) {
|
for (Iterator<ApplicationInfo> i = Global.Data.appList.iterator(); i.hasNext(); ) {
|
||||||
ApplicationInfo info = i.next();
|
ApplicationInfo info = i.next();
|
||||||
if (ApplicationAdapter.BLACKLIST.contains(info.packageName) || !info.enabled)
|
if (ApplicationAdapter.BLACKLIST.contains(info.packageName) || !info.enabled)
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
Collections.sort(listApps, (a, b) -> a.loadLabel(pm).toString().toLowerCase()
|
Collections.sort(Global.Data.appList, (a, b) -> a.loadLabel(pm).toString().toLowerCase()
|
||||||
.compareTo(b.loadLabel(pm).toString().toLowerCase()));
|
.compareTo(b.loadLabel(pm).toString().toLowerCase()));
|
||||||
List<String> hideList = Shell.su(Async.MAGISK_HIDE_PATH + "list");
|
Global.Data.magiskHideList = Shell.su(Async.MAGISK_HIDE_PATH + "list");
|
||||||
return new Result(listApps, hideList);
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Result result) {
|
protected void onPostExecute(Void v) {
|
||||||
Global.Events.packageLoadDone.trigger(result);
|
Global.Events.packageLoadDone.trigger();
|
||||||
}
|
|
||||||
|
|
||||||
public static class Result {
|
|
||||||
|
|
||||||
public final List<ApplicationInfo> listApps;
|
|
||||||
public final List<String> hideList;
|
|
||||||
|
|
||||||
Result(List<ApplicationInfo> listApps, List<String> hideList) {
|
|
||||||
this.listApps = listApps;
|
|
||||||
this.hideList = hideList;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user