mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-11-15 11:55:26 +00:00
MagiskHide Fragment complete refactor
This commit is contained in:
@@ -1,116 +0,0 @@
|
||||
package com.topjohnwu.magisk.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.topjohnwu.magisk.R;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class ApplicationAdapter extends ArrayAdapter<ApplicationInfo> {
|
||||
private List<ApplicationInfo> appsList = null;
|
||||
private Context context;
|
||||
private PackageManager packageManager;
|
||||
public SharedPreferences prefs;
|
||||
|
||||
public ApplicationAdapter(Context context, int textViewResourceId,
|
||||
List<ApplicationInfo> appsList) {
|
||||
super(context, textViewResourceId, appsList);
|
||||
this.context = context;
|
||||
this.appsList = appsList;
|
||||
packageManager = context.getPackageManager();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return ((null != appsList) ? appsList.size() : 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ApplicationInfo getItem(int position) {
|
||||
return ((null != appsList) ? appsList.get(position) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
View view = convertView;
|
||||
|
||||
prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
if (null == view) {
|
||||
LayoutInflater layoutInflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = layoutInflater.inflate(R.layout.list_item_app, null);
|
||||
}
|
||||
|
||||
ApplicationInfo applicationInfo = appsList.get(position);
|
||||
if (null != applicationInfo) {
|
||||
TextView appName = (TextView) view.findViewById(R.id.app_name);
|
||||
TextView packageName = (TextView) view.findViewById(R.id.app_paackage);
|
||||
ImageView iconview = (ImageView) view.findViewById(R.id.app_icon);
|
||||
CheckBox statusview = (CheckBox) view.findViewById(R.id.checkbox);
|
||||
appName.setText(applicationInfo.loadLabel(packageManager));
|
||||
packageName.setText(applicationInfo.packageName);
|
||||
iconview.setImageDrawable(applicationInfo.loadIcon(packageManager));
|
||||
if (CheckApp(applicationInfo.packageName)) {
|
||||
statusview.setChecked(true);
|
||||
} else {
|
||||
statusview.setChecked(false);
|
||||
}
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public void UpdateRootStatusView(int position, View convertView) {
|
||||
View view = convertView;
|
||||
if (null == view) {
|
||||
LayoutInflater layoutInflater = (LayoutInflater) context
|
||||
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||
view = layoutInflater.inflate(R.layout.list_item_app, null);
|
||||
}
|
||||
ApplicationInfo applicationInfo = appsList.get(position);
|
||||
if (null != applicationInfo) {
|
||||
CheckBox statusview = (CheckBox) view.findViewById(R.id.checkbox);
|
||||
if (CheckApp(applicationInfo.packageName)) {
|
||||
statusview.setChecked(true);
|
||||
} else {
|
||||
statusview.setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean CheckApp(String appToCheck) {
|
||||
boolean starter = false;
|
||||
Set<String> set = prefs.getStringSet("auto_blacklist", null);
|
||||
if (set != null) {
|
||||
for (String string : set) {
|
||||
if (string.contains(appToCheck)) {
|
||||
starter = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return starter;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,9 +31,24 @@ import java.util.List;
|
||||
|
||||
public class Async {
|
||||
|
||||
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
|
||||
public abstract static class RootTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
|
||||
@SafeVarargs
|
||||
public final void exec(Params... params) {
|
||||
executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, params);
|
||||
}
|
||||
}
|
||||
|
||||
public static class constructEnv extends AsyncTask<Void, Void, Void> {
|
||||
public abstract static class NormalTask<Params, Progress, Result> extends AsyncTask<Params, Progress, Result> {
|
||||
@SafeVarargs
|
||||
public final void exec(Params... params) {
|
||||
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
|
||||
}
|
||||
}
|
||||
|
||||
public static final String UPDATE_JSON = "https://raw.githubusercontent.com/topjohnwu/MagiskManager/updates/magisk_update.json";
|
||||
public static final String MAGISK_HIDE_PATH = "/magisk/.core/magiskhide/";
|
||||
|
||||
public static class constructEnv extends NormalTask<Void, Void, Void> {
|
||||
|
||||
ApplicationInfo mInfo;
|
||||
|
||||
@@ -59,12 +74,23 @@ public class Async {
|
||||
"ln -s " + zip + " zip"
|
||||
);
|
||||
}
|
||||
Shell.su("PATH=" + toolPath + ":$PATH");
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
super.onPostExecute(aVoid);
|
||||
new RootTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... voids) {
|
||||
Shell.su("PATH=" + mInfo.dataDir + "/tools:$PATH");
|
||||
return null;
|
||||
}
|
||||
}.exec();
|
||||
}
|
||||
}
|
||||
|
||||
public static class CheckUpdates extends AsyncTask<Void, Void, Void> {
|
||||
public static class CheckUpdates extends NormalTask<Void, Void, Void> {
|
||||
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
@@ -102,7 +128,7 @@ public class Async {
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoadModules extends AsyncTask<Void, Void, Void> {
|
||||
public static class LoadModules extends RootTask<Void, Void, Void> {
|
||||
|
||||
private SharedPreferences mPrefs;
|
||||
|
||||
@@ -122,7 +148,7 @@ public class Async {
|
||||
}
|
||||
}
|
||||
|
||||
public static class LoadRepos extends AsyncTask<Void, Void, Void> {
|
||||
public static class LoadRepos extends NormalTask<Void, Void, Void> {
|
||||
|
||||
private Context mContext;
|
||||
|
||||
@@ -143,7 +169,7 @@ public class Async {
|
||||
}
|
||||
}
|
||||
|
||||
public static class FlashZIP extends AsyncTask<Void, Void, Integer> {
|
||||
public static class FlashZIP extends RootTask<Void, Void, Integer> {
|
||||
|
||||
protected Uri mUri;
|
||||
protected File mFile, sdFile;
|
||||
@@ -306,7 +332,7 @@ public class Async {
|
||||
protected void done() {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
|
||||
prefs.edit().putBoolean("module_done", false).putBoolean("update_check_done", true).apply();
|
||||
new LoadModules(prefs).executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
|
||||
new LoadModules(prefs).exec();
|
||||
|
||||
AlertDialog.Builder builder;
|
||||
String theme = prefs.getString("theme", "");
|
||||
@@ -345,4 +371,23 @@ public class Async {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static class MagiskHide extends RootTask<Object, Void, Void> {
|
||||
@Override
|
||||
protected Void doInBackground(Object... params) {
|
||||
boolean add = (boolean) params[0];
|
||||
String packageName = (String) params[1];
|
||||
Shell.su(MAGISK_HIDE_PATH + (add ? "add " : "rm ") + packageName);
|
||||
return null;
|
||||
}
|
||||
|
||||
public void add(CharSequence packageName) {
|
||||
exec(true, packageName);
|
||||
}
|
||||
|
||||
public void rm(CharSequence packageName) {
|
||||
exec(false, packageName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.io.UnsupportedEncodingException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.security.spec.InvalidKeySpecException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.crypto.BadPaddingException;
|
||||
|
||||
Reference in New Issue
Block a user