Skip to content

Commit

Permalink
Request write external storage permission
Browse files Browse the repository at this point in the history
  • Loading branch information
topjohnwu committed Aug 1, 2018
1 parent 6acb950 commit 35f1c39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
13 changes: 13 additions & 0 deletions app/src/full/java/com/topjohnwu/magisk/asyncs/InstallMagisk.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.topjohnwu.magisk.asyncs;

import android.Manifest;
import android.app.Activity;
import android.app.ProgressDialog;
import android.net.Uri;
Expand All @@ -14,6 +15,7 @@
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;
Expand Down Expand Up @@ -76,6 +78,11 @@ public InstallMagisk(FlashActivity context, List<String> console, List<String> l
bootUri = boot;
}

@Override
protected BaseActivity getActivity() {
return (BaseActivity) super.getActivity();
}

@Override
protected void onPreExecute() {
if (mode == FIX_ENV_MODE) {
Expand Down Expand Up @@ -382,4 +389,10 @@ protected void onPostExecute(Boolean result) {
activity.buttonPanel.setVisibility(View.VISIBLE);
}
}

@Override
public void exec(Void... voids) {
getActivity().runWithPermission(
new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, super::exec);
}
}
15 changes: 1 addition & 14 deletions app/src/full/java/com/topjohnwu/magisk/asyncs/ParallelTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ public abstract class ParallelTask<Params, Progress, Result> extends AsyncTask<P

private WeakReference<Activity> weakActivity;

private Runnable callback = null;

public ParallelTask() {}

public ParallelTask(Activity context) {
Expand All @@ -22,18 +20,7 @@ protected Activity getActivity() {
}

@SuppressWarnings("unchecked")
public ParallelTask<Params, Progress, Result> 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<Params, Progress, Result> setCallBack(Runnable next) {
callback = next;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ protected void onPostExecute(Boolean result) {
}

@Override
public ParallelTask<Void, Object, Boolean> 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 {
Expand Down

0 comments on commit 35f1c39

Please sign in to comment.