Request write external storage permission

This commit is contained in:
topjohnwu 2018-08-02 04:27:01 +08:00
parent 6acb950990
commit 35f1c396f2
3 changed files with 16 additions and 18 deletions

View File

@ -1,5 +1,6 @@
package com.topjohnwu.magisk.asyncs; package com.topjohnwu.magisk.asyncs;
import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.app.ProgressDialog; import android.app.ProgressDialog;
import android.net.Uri; import android.net.Uri;
@ -14,6 +15,7 @@ import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.FlashActivity;
import com.topjohnwu.magisk.MagiskManager; import com.topjohnwu.magisk.MagiskManager;
import com.topjohnwu.magisk.R; import com.topjohnwu.magisk.R;
import com.topjohnwu.magisk.components.BaseActivity;
import com.topjohnwu.magisk.container.TarEntry; import com.topjohnwu.magisk.container.TarEntry;
import com.topjohnwu.magisk.utils.Download; import com.topjohnwu.magisk.utils.Download;
import com.topjohnwu.magisk.utils.Utils; import com.topjohnwu.magisk.utils.Utils;
@ -76,6 +78,11 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
bootUri = boot; bootUri = boot;
} }
@Override
protected BaseActivity getActivity() {
return (BaseActivity) super.getActivity();
}
@Override @Override
protected void onPreExecute() { protected void onPreExecute() {
if (mode == FIX_ENV_MODE) { if (mode == FIX_ENV_MODE) {
@ -382,4 +389,10 @@ public class InstallMagisk extends ParallelTask<Void, Void, Boolean> {
activity.buttonPanel.setVisibility(View.VISIBLE); activity.buttonPanel.setVisibility(View.VISIBLE);
} }
} }
@Override
public void exec(Void... voids) {
getActivity().runWithPermission(
new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, super::exec);
}
} }

View File

@ -9,8 +9,6 @@ public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<P
private WeakReference<Activity> weakActivity; private WeakReference<Activity> weakActivity;
private Runnable callback = null;
public ParallelTask() {} public ParallelTask() {}
public ParallelTask(Activity context) { public ParallelTask(Activity context) {
@ -22,18 +20,7 @@ public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<P
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ParallelTask<Params, Progress, Result> exec(Params... params) { public void exec(Params... params) {
executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params); executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, params);
return this;
}
@Override
protected void onPostExecute(Result result) {
if (callback != null) callback.run();
}
public ParallelTask<Params, Progress, Result> setCallBack(Runnable next) {
callback = next;
return this;
} }
} }

View File

@ -154,11 +154,9 @@ public class ProcessRepoZip extends ParallelTask<Void, Object, Boolean> {
} }
@Override @Override
public ParallelTask<Void, Object, Boolean> exec(Void... voids) { public void exec(Void... voids) {
getActivity().runWithPermission( getActivity().runWithPermission(
new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, super::exec);
() -> super.exec(voids));
return this;
} }
private class ProgressInputStream extends FilterInputStream { private class ProgressInputStream extends FilterInputStream {