mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-27 20:15:29 +00:00
Directly stream APK into install session
This commit is contained in:
parent
6dabd3bb2d
commit
945de8d9a0
@ -116,29 +116,25 @@ public class DownloadActivity extends Activity {
|
|||||||
|
|
||||||
private void dlAPK() {
|
private void dlAPK() {
|
||||||
dialog = ProgressDialog.show(themed, getString(dling), getString(dling) + " " + APP_NAME, true);
|
dialog = ProgressDialog.show(themed, getString(dling), getString(dling) + " " + APP_NAME, true);
|
||||||
Runnable onSuccess = () -> {
|
|
||||||
dialog.dismiss();
|
|
||||||
StubApk.restartProcess(this);
|
|
||||||
finish();
|
|
||||||
};
|
|
||||||
// Download and upgrade the app
|
// Download and upgrade the app
|
||||||
File apk = dynLoad ? StubApk.current(this) : new File(getCacheDir(), "manager.apk");
|
var request = request(apkLink).setExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||||
request(apkLink).setExecutor(AsyncTask.THREAD_POOL_EXECUTOR).getAsFile(apk, file -> {
|
|
||||||
if (dynLoad) {
|
if (dynLoad) {
|
||||||
runOnUiThread(onSuccess);
|
request.getAsFile(StubApk.current(this), file -> StubApk.restartProcess(this));
|
||||||
} else {
|
} else {
|
||||||
|
request.getAsInputStream(input -> {
|
||||||
var session = APKInstall.startSession(this);
|
var session = APKInstall.startSession(this);
|
||||||
try {
|
try (input; var out = session.openStream(this)) {
|
||||||
session.install(this, file);
|
if (out != null)
|
||||||
|
APKInstall.transfer(input, out);
|
||||||
|
} catch (IOException e) {
|
||||||
|
error(e);
|
||||||
|
}
|
||||||
Intent intent = session.waitIntent();
|
Intent intent = session.waitIntent();
|
||||||
if (intent != null)
|
if (intent != null)
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void loadResources() {
|
private void loadResources() {
|
||||||
File apk = new File(getCacheDir(), "res.apk");
|
File apk = new File(getCacheDir(), "res.apk");
|
||||||
|
@ -94,6 +94,10 @@ public class Request implements Closeable {
|
|||||||
return exec(this::getInputStream);
|
return exec(this::getInputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void getAsInputStream(ResponseListener<InputStream> rs) {
|
||||||
|
submit(this::getInputStream, rs);
|
||||||
|
}
|
||||||
|
|
||||||
public void getAsFile(File out, ResponseListener<File> rs) {
|
public void getAsFile(File out, ResponseListener<File> rs) {
|
||||||
submit(() -> dlFile(out), rs);
|
submit(() -> dlFile(out), rs);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user