use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class MarkDownWindow method doInBackground.
@Override
protected String doInBackground(Void... voids) {
MagiskManager mm = MagiskManager.get();
String md;
if (mUrl != null) {
md = WebService.getString(mUrl);
} else {
try (ByteArrayOutputStream out = new ByteArrayOutputStream()) {
ShellUtils.pump(is, out);
md = out.toString();
is.close();
} catch (IOException e) {
e.printStackTrace();
return "";
}
}
String css;
try (InputStream in = mm.getResources().openRawResource(mm.isDarkTheme ? R.raw.dark : R.raw.light);
ByteArrayOutputStream out = new ByteArrayOutputStream()) {
ShellUtils.pump(in, out);
css = out.toString();
in.close();
} catch (IOException e) {
e.printStackTrace();
return "";
}
Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build();
Node doc = parser.parse(md);
return String.format("<style>%s</style>%s", css, renderer.render(doc));
}
use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class CheckSafetyNet method onPostExecute.
@Override
protected void onPostExecute(Exception err) {
MagiskManager mm = MagiskManager.get();
try {
if (err != null)
throw err;
Object helper = helperClazz.getConstructors()[0].newInstance(getActivity(), dexPath.getPath(), Proxy.newProxyInstance(loader, new Class[] { callbackClazz }, (proxy, method, args) -> {
mm.safetyNetDone.publish(false, args[0]);
return null;
}));
helperClazz.getMethod("attest").invoke(helper);
} catch (Exception e) {
e.printStackTrace();
mm.safetyNetDone.publish(false, -1);
}
super.onPostExecute(err);
}
use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class CheckUpdates method onPostExecute.
@Override
protected void onPostExecute(Void v) {
MagiskManager mm = MagiskManager.get();
if (showNotification) {
if (BuildConfig.VERSION_CODE < mm.remoteManagerVersionCode) {
ShowUI.managerUpdateNotification();
} else if (mm.magiskVersionCode < mm.remoteMagiskVersionCode) {
ShowUI.magiskUpdateNotification();
}
}
mm.updateCheckDone.publish();
super.onPostExecute(v);
}
use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class SuReceiver method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
int fromUid, toUid, pid, mode;
String command, action;
Policy policy;
MagiskManager mm = Utils.getMagiskManager(context);
if (intent == null)
return;
mode = intent.getIntExtra("mode", -1);
if (mode < 0)
return;
if (mode == Const.Value.NOTIFY_USER_TO_OWNER) {
MagiskManager.toast(R.string.multiuser_hint_owner_request, Toast.LENGTH_LONG);
return;
}
fromUid = intent.getIntExtra("from.uid", -1);
if (fromUid < 0)
return;
// Don't show anything if it's Magisk Manager
if (fromUid == Process.myUid())
return;
action = intent.getStringExtra("action");
if (action == null)
return;
policy = mm.suDB.getPolicy(fromUid);
if (policy == null) {
try {
policy = new Policy(fromUid, context.getPackageManager());
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
return;
}
}
SuLogEntry log = new SuLogEntry(policy);
String message;
switch(action) {
case "allow":
message = context.getString(R.string.su_allow_toast, policy.appName);
log.action = true;
break;
case "deny":
message = context.getString(R.string.su_deny_toast, policy.appName);
log.action = false;
break;
default:
return;
}
if (policy.notification && mm.suNotificationType == Const.Value.NOTIFICATION_TOAST) {
MagiskManager.toast(message, Toast.LENGTH_SHORT);
}
if (mode == Const.Value.NOTIFY_NORMAL_LOG && policy.logging) {
toUid = intent.getIntExtra("to.uid", -1);
if (toUid < 0)
return;
pid = intent.getIntExtra("pid", -1);
if (pid < 0)
return;
command = intent.getStringExtra("command");
if (command == null)
return;
log.toUid = toUid;
log.fromPid = pid;
log.command = command;
log.date = new Date();
mm.suDB.addLog(log);
}
}
use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class ShowUI method uninstallDialog.
public static void uninstallDialog(Activity activity) {
MagiskManager mm = Utils.getMagiskManager(activity);
new AlertDialogBuilder(activity).setTitle(R.string.uninstall_magisk_title).setMessage(R.string.uninstall_magisk_msg).setPositiveButton(R.string.complete_uninstall, (d, i) -> {
ByteArrayOutputStream uninstaller = new ByteArrayOutputStream();
try (InputStream in = mm.getAssets().open(Const.UNINSTALLER)) {
ShellUtils.pump(in, uninstaller);
} catch (IOException e) {
e.printStackTrace();
return;
}
ByteArrayOutputStream utils = new ByteArrayOutputStream();
try (InputStream in = mm.getAssets().open(Const.UTIL_FUNCTIONS)) {
ShellUtils.pump(in, utils);
} catch (IOException e) {
e.printStackTrace();
return;
}
Shell.Sync.su(Utils.fmt("echo '%s' > /cache/%s", uninstaller.toString().replace("'", "'\\''"), Const.UNINSTALLER), Utils.fmt("echo '%s' > %s/%s", utils.toString().replace("'", "'\\''"), mm.magiskVersionCode >= 1464 ? "/data/adb/magisk" : "/data/magisk", Const.UTIL_FUNCTIONS));
try {
uninstaller.close();
utils.close();
} catch (IOException ignored) {
}
MagiskManager.toast(R.string.uninstall_toast, Toast.LENGTH_LONG);
new Handler().postDelayed(() -> Utils.uninstallPkg(mm.getPackageName()), 5000);
}).setNeutralButton(R.string.restore_img, (d, i) -> new RestoreImages().exec()).setNegativeButton(R.string.uninstall_app, (d, i) -> Utils.uninstallPkg(mm.getPackageName())).show();
}
Aggregations