use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class FlashZip method doInBackground.
@Override
protected Integer doInBackground(Void... voids) {
MagiskManager mm = MagiskManager.get();
try {
console.add("- Copying zip to temp directory");
mCachedFile.delete();
try (InputStream in = mm.getContentResolver().openInputStream(mUri);
OutputStream out = new BufferedOutputStream(new FileOutputStream(mCachedFile))) {
if (in == null)
throw new FileNotFoundException();
InputStream buf = new BufferedInputStream(in);
ShellUtils.pump(buf, out);
} catch (FileNotFoundException e) {
console.add("! Invalid Uri");
throw e;
} catch (IOException e) {
console.add("! Cannot copy to cache");
throw e;
}
if (!unzipAndCheck())
return 0;
console.add("- Installing " + Utils.getNameFromUri(mm, mUri));
Shell.Sync.su(console, logs, "cd " + mCachedFile.getParent(), "BOOTMODE=true sh update-binary dummy 1 " + mCachedFile + " || echo 'Failed!'");
if (TextUtils.equals(console.get(console.size() - 1), "Failed!"))
return -1;
} catch (Exception e) {
e.printStackTrace();
return -1;
}
console.add("- All done!");
return 1;
}
use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class HideManager method doInBackground.
@Override
protected Boolean doInBackground(Void... voids) {
MagiskManager mm = MagiskManager.get();
// Generate a new unhide app with random package name
SuFile repack = new SuFile("/data/local/tmp/repack.apk", true);
String pkg = genPackageName("com.", Const.ORIG_PKG_NAME.length());
try {
// Read whole APK into memory
JarMap apk = new JarMap(new FileInputStream(mm.getPackageCodePath()));
JarEntry je = new JarEntry(Const.ANDROID_MANIFEST);
byte[] xml = apk.getRawData(je);
if (!findAndPatch(xml, Const.ORIG_PKG_NAME, pkg))
return false;
if (!findAndPatch(xml, Const.ORIG_PKG_NAME + ".provider", pkg + ".provider"))
return false;
// Write in changes
apk.getOutputStream(je).write(xml);
// Sign the APK
ZipUtils.signZip(apk, new SuFileOutputStream(repack));
} catch (Exception e) {
e.printStackTrace();
return false;
}
// Install the application
if (!ShellUtils.fastCmdResult(Shell.getShell(), "pm install " + repack))
return false;
repack.delete();
mm.suDB.setStrings(Const.Key.SU_REQUESTER, pkg);
Utils.dumpPrefs();
Utils.uninstallPkg(Const.ORIG_PKG_NAME);
return true;
}
use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class CheckUpdates method doInBackground.
@Override
protected Void doInBackground(Void... voids) {
MagiskManager mm = MagiskManager.get();
String jsonStr = "";
switch(mm.updateChannel) {
case Const.Value.STABLE_CHANNEL:
jsonStr = WebService.getString(Const.Url.STABLE_URL);
break;
case Const.Value.BETA_CHANNEL:
jsonStr = WebService.getString(Const.Url.BETA_URL);
break;
case Const.Value.CUSTOM_CHANNEL:
jsonStr = WebService.getString(mm.prefs.getString(Const.Key.CUSTOM_CHANNEL, ""));
break;
}
try {
JSONObject json = new JSONObject(jsonStr);
JSONObject magisk = json.getJSONObject("magisk");
mm.remoteMagiskVersionString = magisk.getString("version");
mm.remoteMagiskVersionCode = magisk.getInt("versionCode");
mm.magiskLink = magisk.getString("link");
mm.releaseNoteLink = magisk.getString("note");
JSONObject manager = json.getJSONObject("app");
mm.remoteManagerVersionString = manager.getString("version");
mm.remoteManagerVersionCode = manager.getInt("versionCode");
mm.managerLink = manager.getString("link");
} catch (JSONException ignored) {
}
return null;
}
use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class LoadModules method doInBackground.
@Override
protected Void doInBackground(Void... voids) {
MagiskManager mm = MagiskManager.get();
mm.moduleMap = new ValueSortedMap<>();
for (String path : getModList()) {
Module module = new Module(path);
mm.moduleMap.put(module.getId(), module);
}
return null;
}
use of com.topjohnwu.magisk.MagiskManager in project MagiskManager by topjohnwu.
the class Activity method onRequestPermissionsResult.
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
MagiskManager mm = getMagiskManager();
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (mm.permissionGrantCallback != null) {
mm.permissionGrantCallback.run();
}
}
mm.permissionGrantCallback = null;
}
Aggregations