From 35f1c396f2a043057cbb532210cbd063a791a4dd Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 2 Aug 2018 04:27:01 +0800 Subject: [PATCH] Request write external storage permission --- .../topjohnwu/magisk/asyncs/InstallMagisk.java | 13 +++++++++++++ .../com/topjohnwu/magisk/asyncs/ParallelTask.java | 15 +-------------- .../topjohnwu/magisk/asyncs/ProcessRepoZip.java | 6 ++---- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java index 111e78d4b..3257972d0 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java @@ -1,5 +1,6 @@ package com.topjohnwu.magisk.asyncs; +import android.Manifest; import android.app.Activity; import android.app.ProgressDialog; import android.net.Uri; @@ -14,6 +15,7 @@ import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.R; +import com.topjohnwu.magisk.components.BaseActivity; import com.topjohnwu.magisk.container.TarEntry; import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.Utils; @@ -76,6 +78,11 @@ public class InstallMagisk extends ParallelTask { bootUri = boot; } + @Override + protected BaseActivity getActivity() { + return (BaseActivity) super.getActivity(); + } + @Override protected void onPreExecute() { if (mode == FIX_ENV_MODE) { @@ -382,4 +389,10 @@ public class InstallMagisk extends ParallelTask { activity.buttonPanel.setVisibility(View.VISIBLE); } } + + @Override + public void exec(Void... voids) { + getActivity().runWithPermission( + new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, super::exec); + } } diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/ParallelTask.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/ParallelTask.java index bd94e6365..e7049c848 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/ParallelTask.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/ParallelTask.java @@ -9,8 +9,6 @@ public abstract class ParallelTask extends AsyncTask

weakActivity; - private Runnable callback = null; - public ParallelTask() {} public ParallelTask(Activity context) { @@ -22,18 +20,7 @@ public abstract class ParallelTask extends AsyncTask

exec(Params... params) { + public void exec(Params... params) { executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); - return this; - } - - @Override - protected void onPostExecute(Result result) { - if (callback != null) callback.run(); - } - - public ParallelTask setCallBack(Runnable next) { - callback = next; - return this; } } diff --git a/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java b/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java index a54233174..c006d7a22 100644 --- a/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java +++ b/app/src/full/java/com/topjohnwu/magisk/asyncs/ProcessRepoZip.java @@ -154,11 +154,9 @@ public class ProcessRepoZip extends ParallelTask { } @Override - public ParallelTask exec(Void... voids) { + public void exec(Void... voids) { getActivity().runWithPermission( - new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, - () -> super.exec(voids)); - return this; + new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, super::exec); } private class ProgressInputStream extends FilterInputStream {