Ask permissions to read internal storage

This commit is contained in:
topjohnwu 2018-10-20 19:42:46 -04:00
parent d7d80d3fc1
commit 8a1292b295
2 changed files with 27 additions and 29 deletions

View File

@ -134,9 +134,8 @@ public class FlashActivity extends BaseActivity {
new InstallMagisk(this, console, logs, InstallMagisk.SECOND_SLOT_MODE).exec(); new InstallMagisk(this, console, logs, InstallMagisk.SECOND_SLOT_MODE).exec();
break; break;
case Const.Value.PATCH_BOOT: case Const.Value.PATCH_BOOT:
runWithPermission(new String[] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, new InstallMagisk(this, console, logs,
() -> new InstallMagisk(this, console, logs, intent.getParcelableExtra(Const.Key.FLASH_SET_BOOT)).exec();
intent.getParcelableExtra(Const.Key.FLASH_SET_BOOT)).exec());
break; break;
} }
} }

View File

@ -1,11 +1,12 @@
package com.topjohnwu.magisk.components; package com.topjohnwu.magisk.components;
import android.Manifest;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.widget.Toast; import android.widget.Toast;
import com.google.android.material.snackbar.Snackbar;
import com.topjohnwu.magisk.Const; import com.topjohnwu.magisk.Const;
import com.topjohnwu.magisk.Data; import com.topjohnwu.magisk.Data;
import com.topjohnwu.magisk.FlashActivity; import com.topjohnwu.magisk.FlashActivity;
@ -27,23 +28,21 @@ class InstallMethodDialog extends AlertDialog.Builder {
Intent intent; Intent intent;
switch (idx) { switch (idx) {
case 1: case 1:
if (Data.remoteMagiskVersionCode < 1400) {
SnackbarMaker.make(activity, R.string.no_boot_file_patch_support,
Snackbar.LENGTH_LONG).show();
return;
}
Utils.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG); Utils.toast(R.string.boot_file_patch_msg, Toast.LENGTH_LONG);
intent = new Intent(Intent.ACTION_GET_CONTENT).setType("*/*"); intent = new Intent(Intent.ACTION_GET_CONTENT).setType("*/*");
activity.startActivityForResult(intent, Const.ID.SELECT_BOOT, activity.runWithPermission(new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, () ->
(requestCode, resultCode, data) -> { activity.startActivityForResult(intent, Const.ID.SELECT_BOOT,
if (requestCode == Const.ID.SELECT_BOOT && (requestCode, resultCode, data) -> {
resultCode == BaseActivity.RESULT_OK && data != null) { if (requestCode == Const.ID.SELECT_BOOT &&
Intent i = new Intent(activity, Data.classMap.get(FlashActivity.class)) resultCode == Activity.RESULT_OK && data != null) {
.putExtra(Const.Key.FLASH_SET_BOOT, data.getData()) Intent i = new Intent(activity, Data.classMap.get(FlashActivity.class))
.putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_BOOT); .putExtra(Const.Key.FLASH_SET_BOOT, data.getData())
activity.startActivity(i); .putExtra(Const.Key.FLASH_ACTION, Const.Value.PATCH_BOOT);
} activity.startActivity(i);
}); }
})
);
break; break;
case 0: case 0:
String filename = Utils.fmt("Magisk-v%s(%d).zip", String filename = Utils.fmt("Magisk-v%s(%d).zip",
@ -62,16 +61,16 @@ class InstallMethodDialog extends AlertDialog.Builder {
break; break;
case 3: case 3:
new CustomAlertDialog(activity) new CustomAlertDialog(activity)
.setTitle(R.string.warning) .setTitle(R.string.warning)
.setMessage(R.string.install_inactive_slot_msg) .setMessage(R.string.install_inactive_slot_msg)
.setCancelable(true) .setCancelable(true)
.setPositiveButton(R.string.yes, (d, i) -> { .setPositiveButton(R.string.yes, (d, i) -> {
Intent it = new Intent(activity, Data.classMap.get(FlashActivity.class)) Intent it = new Intent(activity, Data.classMap.get(FlashActivity.class))
.putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_INACTIVE_SLOT); .putExtra(Const.Key.FLASH_ACTION, Const.Value.FLASH_INACTIVE_SLOT);
activity.startActivity(it); activity.startActivity(it);
}) })
.setNegativeButton(R.string.no_thanks, null) .setNegativeButton(R.string.no_thanks, null)
.show(); .show();
break; break;
default: default:
} }