Don't reload ApplicationInfo list

Fix #94
This commit is contained in:
topjohnwu 2017-02-13 04:00:45 +08:00
parent 1ef5bd7076
commit 1bfafdb44f
5 changed files with 44 additions and 18 deletions

View File

@ -15,7 +15,7 @@ import android.view.ViewGroup;
import android.widget.SearchView; import android.widget.SearchView;
import com.topjohnwu.magisk.adapters.ApplicationAdapter; import com.topjohnwu.magisk.adapters.ApplicationAdapter;
import com.topjohnwu.magisk.asyncs.LoadApps; import com.topjohnwu.magisk.asyncs.MagiskHide;
import com.topjohnwu.magisk.components.Fragment; import com.topjohnwu.magisk.components.Fragment;
import com.topjohnwu.magisk.utils.CallbackEvent; import com.topjohnwu.magisk.utils.CallbackEvent;
import com.topjohnwu.magisk.utils.Logger; import com.topjohnwu.magisk.utils.Logger;
@ -50,7 +50,7 @@ public class MagiskHideFragment extends Fragment implements CallbackEvent.Listen
PackageManager packageManager = getActivity().getPackageManager(); PackageManager packageManager = getActivity().getPackageManager();
mSwipeRefreshLayout.setRefreshing(true); mSwipeRefreshLayout.setRefreshing(true);
mSwipeRefreshLayout.setOnRefreshListener(() -> new LoadApps(getActivity()).exec()); mSwipeRefreshLayout.setOnRefreshListener(() -> new MagiskHide(getActivity()).list());
appAdapter = new ApplicationAdapter(packageManager); appAdapter = new ApplicationAdapter(packageManager);
recyclerView.setAdapter(appAdapter); recyclerView.setAdapter(appAdapter);
@ -71,8 +71,8 @@ public class MagiskHideFragment extends Fragment implements CallbackEvent.Listen
} }
}; };
if (getApplication().packageLoadDone.isTriggered) if (getApplication().magiskHideDone.isTriggered)
onTrigger(getApplication().packageLoadDone); onTrigger(getApplication().magiskHideDone);
return view; return view;
} }
@ -88,12 +88,12 @@ public class MagiskHideFragment extends Fragment implements CallbackEvent.Listen
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
getActivity().setTitle(R.string.magiskhide); getActivity().setTitle(R.string.magiskhide);
getApplication().packageLoadDone.register(this); getApplication().magiskHideDone.register(this);
} }
@Override @Override
public void onStop() { public void onStop() {
getApplication().packageLoadDone.unRegister(this); getApplication().magiskHideDone.unRegister(this);
super.onStop(); super.onStop();
} }

View File

@ -28,7 +28,7 @@ public class MagiskManager extends Application {
// Events // Events
public final CallbackEvent<Void> blockDetectionDone = new CallbackEvent<>(); public final CallbackEvent<Void> blockDetectionDone = new CallbackEvent<>();
public final CallbackEvent<Void> packageLoadDone = new CallbackEvent<>(); public final CallbackEvent<Void> magiskHideDone = new CallbackEvent<>();
public final CallbackEvent<Void> reloadMainActivity = new CallbackEvent<>(); public final CallbackEvent<Void> reloadMainActivity = new CallbackEvent<>();
public final CallbackEvent<Void> moduleLoadDone = new CallbackEvent<>(); public final CallbackEvent<Void> moduleLoadDone = new CallbackEvent<>();
public final CallbackEvent<Void> repoLoadDone = new CallbackEvent<>(); public final CallbackEvent<Void> repoLoadDone = new CallbackEvent<>();

View File

@ -50,8 +50,8 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
} }
public void setLists(List<ApplicationInfo> listApps, List<String> hideList) { public void setLists(List<ApplicationInfo> listApps, List<String> hideList) {
mOriginalList = mList = Collections.unmodifiableList(listApps); mOriginalList = mList = listApps;
mHideList = new ArrayList<>(hideList); mHideList = hideList;
notifyDataSetChanged(); notifyDataSetChanged();
} }

View File

@ -4,14 +4,13 @@ import android.app.Activity;
import android.content.pm.ApplicationInfo; import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.adapters.ApplicationAdapter; import com.topjohnwu.magisk.adapters.ApplicationAdapter;
import com.topjohnwu.magisk.utils.Shell;
import java.util.Collections; import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List;
public class LoadApps extends SerialTask<Void, Void, Void> { public class LoadApps extends ParallelTask<Void, Void, Void> {
public LoadApps(Activity context) { public LoadApps(Activity context) {
super(context); super(context);
@ -20,20 +19,20 @@ public class LoadApps extends SerialTask<Void, Void, Void> {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
PackageManager pm = magiskManager.getPackageManager(); PackageManager pm = magiskManager.getPackageManager();
magiskManager.appList = pm.getInstalledApplications(0); List<ApplicationInfo> list = pm.getInstalledApplications(0);
for (Iterator<ApplicationInfo> i = magiskManager.appList.iterator(); i.hasNext(); ) { for (Iterator<ApplicationInfo> i = list.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(magiskManager.appList, (a, b) -> a.loadLabel(pm).toString().toLowerCase() Collections.sort(list, (a, b) -> a.loadLabel(pm).toString().toLowerCase()
.compareTo(b.loadLabel(pm).toString().toLowerCase())); .compareTo(b.loadLabel(pm).toString().toLowerCase()));
magiskManager.magiskHideList = Shell.su(MagiskManager.MAGISK_HIDE_PATH + "list"); magiskManager.appList = Collections.unmodifiableList(list);
return null; return null;
} }
@Override @Override
protected void onPostExecute(Void v) { protected void onPostExecute(Void v) {
magiskManager.packageLoadDone.trigger(); new MagiskHide(activity).list();
} }
} }

View File

@ -1,17 +1,37 @@
package com.topjohnwu.magisk.asyncs; package com.topjohnwu.magisk.asyncs;
import android.app.Activity;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.utils.Shell; import com.topjohnwu.magisk.utils.Shell;
import java.util.List;
public class MagiskHide extends SerialTask<Object, Void, Void> { public class MagiskHide extends SerialTask<Object, Void, Void> {
private boolean isList = false;
public MagiskHide() {}
public MagiskHide(Activity context) {
super(context);
}
@Override @Override
protected Void doInBackground(Object... params) { protected Void doInBackground(Object... params) {
String command = (String) params[0]; String command = (String) params[0];
Shell.su(MagiskManager.MAGISK_HIDE_PATH + command); List<String> ret = Shell.su(MagiskManager.MAGISK_HIDE_PATH + command);
if (isList)
magiskManager.magiskHideList = ret;
return null; return null;
} }
@Override
protected void onPostExecute(Void v) {
if (isList)
magiskManager.magiskHideDone.trigger();
}
public void add(CharSequence packageName) { public void add(CharSequence packageName) {
exec("add " + packageName); exec("add " + packageName);
} }
@ -28,4 +48,11 @@ public class MagiskHide extends SerialTask<Object, Void, Void> {
exec("disable; setprop persist.magisk.hide 0"); exec("disable; setprop persist.magisk.hide 0");
} }
public void list() {
isList = true;
if (magiskManager == null)
return;
exec("list");
}
} }