mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-12-26 18:37:39 +00:00
Magisk Hide fragment improvements
This commit is contained in:
parent
5bb943f845
commit
fb0923f3ab
@ -17,24 +17,38 @@ import android.widget.SearchView;
|
||||
|
||||
import com.topjohnwu.magisk.adapters.ApplicationAdapter;
|
||||
import com.topjohnwu.magisk.utils.Async;
|
||||
import com.topjohnwu.magisk.utils.CallbackHandler;
|
||||
import com.topjohnwu.magisk.utils.Logger;
|
||||
import com.topjohnwu.magisk.utils.Shell;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class MagiskHideFragment extends Fragment {
|
||||
public class MagiskHideFragment extends Fragment implements CallbackHandler.EventListener {
|
||||
|
||||
@BindView(R.id.swipeRefreshLayout) SwipeRefreshLayout mSwipeRefreshLayout;
|
||||
@BindView(R.id.recyclerView) RecyclerView recyclerView;
|
||||
|
||||
public static List<ApplicationInfo> listApps, fListApps = new ArrayList<>();
|
||||
public static List<String> hideList = new ArrayList<>();
|
||||
// Don't show in list...
|
||||
public static final List<String> blacklist = Arrays.asList(
|
||||
"android",
|
||||
"com.topjohnwu.magisk",
|
||||
"com.google.android.gms",
|
||||
"com.google.android.apps.walletnfcrel",
|
||||
"com.nianticlabs.pokemongo"
|
||||
);
|
||||
public static CallbackHandler.Event packageLoadDone = new CallbackHandler.Event();
|
||||
|
||||
private PackageManager packageManager;
|
||||
private View mView;
|
||||
private List<ApplicationInfo> listApps = new ArrayList<>(), fListApps = new ArrayList<>();
|
||||
private List<String> hideList = new ArrayList<>();
|
||||
private ApplicationAdapter appAdapter = new ApplicationAdapter(fListApps, hideList);
|
||||
|
||||
private SearchView.OnQueryTextListener searchListener;
|
||||
@ -50,14 +64,15 @@ public class MagiskHideFragment extends Fragment {
|
||||
mSwipeRefreshLayout.setRefreshing(true);
|
||||
mSwipeRefreshLayout.setOnRefreshListener(() -> {
|
||||
recyclerView.setVisibility(View.GONE);
|
||||
new LoadApps().exec();
|
||||
new Async.LoadApps(packageManager).exec();
|
||||
});
|
||||
|
||||
recyclerView.swapAdapter(appAdapter, true);
|
||||
recyclerView.setAdapter(appAdapter);
|
||||
|
||||
searchListener = new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
new FilterApps().exec(query);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -68,7 +83,6 @@ public class MagiskHideFragment extends Fragment {
|
||||
}
|
||||
};
|
||||
|
||||
new LoadApps().exec();
|
||||
return mView;
|
||||
}
|
||||
|
||||
@ -85,26 +99,22 @@ public class MagiskHideFragment extends Fragment {
|
||||
setHasOptionsMenu(true);
|
||||
mView = this.getView();
|
||||
getActivity().setTitle(R.string.magiskhide);
|
||||
CallbackHandler.register(packageLoadDone, this);
|
||||
if (packageLoadDone.isTriggered) {
|
||||
onTrigger(packageLoadDone);
|
||||
}
|
||||
}
|
||||
|
||||
private class LoadApps extends Async.RootTask<Void, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
listApps.clear();
|
||||
hideList.clear();
|
||||
fListApps.clear();
|
||||
listApps.addAll(packageManager.getInstalledApplications(PackageManager.GET_META_DATA));
|
||||
Collections.sort(listApps, (a, b) -> a.loadLabel(packageManager).toString().toLowerCase()
|
||||
.compareTo(b.loadLabel(packageManager).toString().toLowerCase()));
|
||||
hideList.addAll(Shell.su(Async.MAGISK_HIDE_PATH + "list"));
|
||||
fListApps.addAll(listApps);
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
CallbackHandler.unRegister(packageLoadDone, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
updateUI();
|
||||
}
|
||||
@Override
|
||||
public void onTrigger(CallbackHandler.Event event) {
|
||||
Logger.dev("MagiskHideFragment: UI refresh");
|
||||
updateUI();
|
||||
}
|
||||
|
||||
private class FilterApps extends Async.NormalTask<String, Void, Void> {
|
||||
|
@ -42,6 +42,7 @@ public class SplashActivity extends AppCompatActivity {
|
||||
new Async.LoadRepos(getApplicationContext()).exec();
|
||||
}
|
||||
}.exec();
|
||||
new Async.LoadApps(getPackageManager()).exec();
|
||||
|
||||
// Start main activity
|
||||
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
|
||||
|
@ -29,19 +29,11 @@ public class ApplicationAdapter extends RecyclerView.Adapter<ApplicationAdapter.
|
||||
private Context context;
|
||||
private PackageManager packageManager;
|
||||
|
||||
// Don't show in list...
|
||||
private static final String[] blackList = {
|
||||
"com.topjohnwu.magisk",
|
||||
"com.google.android.gms"
|
||||
};
|
||||
|
||||
|
||||
public ApplicationAdapter(List<ApplicationInfo> list, List<String> hideList) {
|
||||
mList = list;
|
||||
mHideList = hideList;
|
||||
List<String> bl = Arrays.asList(blackList);
|
||||
for (int i = 0; i < mList.size(); ++i)
|
||||
if (bl.contains(mList.get(i).packageName))
|
||||
mList.remove(i);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -2,6 +2,8 @@ package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
@ -10,6 +12,7 @@ import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.topjohnwu.magisk.InstallFragment;
|
||||
import com.topjohnwu.magisk.MagiskHideFragment;
|
||||
import com.topjohnwu.magisk.MainActivity;
|
||||
import com.topjohnwu.magisk.ModulesFragment;
|
||||
import com.topjohnwu.magisk.R;
|
||||
@ -25,6 +28,8 @@ import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
public class Async {
|
||||
@ -114,6 +119,38 @@ public class Async {
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoadApps extends RootTask<Void, Void, Void> {
|
||||
|
||||
private PackageManager pm;
|
||||
|
||||
public LoadApps(PackageManager packageManager) {
|
||||
pm = packageManager;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
if (! Shell.rootAccess()) return null;
|
||||
MagiskHideFragment.hideList.clear();
|
||||
MagiskHideFragment.fListApps.clear();
|
||||
MagiskHideFragment.listApps = pm.getInstalledApplications(PackageManager.GET_META_DATA);
|
||||
for (Iterator<ApplicationInfo> i = MagiskHideFragment.listApps.iterator(); i.hasNext(); ) {
|
||||
ApplicationInfo info = i.next();
|
||||
if (MagiskHideFragment.blacklist.contains(info.packageName) || !info.enabled)
|
||||
i.remove();
|
||||
}
|
||||
Collections.sort(MagiskHideFragment.listApps, (a, b) -> a.loadLabel(pm).toString().toLowerCase()
|
||||
.compareTo(b.loadLabel(pm).toString().toLowerCase()));
|
||||
MagiskHideFragment.hideList.addAll(Shell.su(Async.MAGISK_HIDE_PATH + "list"));
|
||||
MagiskHideFragment.fListApps.addAll(MagiskHideFragment.listApps);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
MagiskHideFragment.packageLoadDone.trigger();
|
||||
}
|
||||
}
|
||||
|
||||
public static class FlashZIP extends RootTask<Void, String, Integer> {
|
||||
|
||||
protected Uri mUri;
|
||||
|
Loading…
x
Reference in New Issue
Block a user