Various small fixes

This commit is contained in:
topjohnwu
2016-12-27 14:30:26 +08:00
parent 0f254dca13
commit c7e64f40f9
8 changed files with 33 additions and 42 deletions
@@ -33,6 +33,8 @@ import javax.crypto.spec.DESKeySpec;
public class Utils {
public static boolean isDownloading = false;
private static final String cryptoPass = "MagiskRox666";
private static final String secret = "GTYybRBTYf5his9kQ16ZNO7qgkBJ/5MyVe4CGceAOIoXgSnnk8FTd4F1dE9p5Eus";
@@ -90,16 +92,25 @@ public class Utils {
}
public static void dlAndReceive(Context context, DownloadReceiver receiver, String link, String filename) {
File file = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename);
if (isDownloading) {
return;
}
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
Toast.makeText(context, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
return;
}
File file = new File(Environment.getExternalStorageDirectory() + "/MagiskManager/" + filename);
if ((!file.getParentFile().exists() && !file.getParentFile().mkdirs()) || (file.exists() && !file.delete())) {
Toast.makeText(context, R.string.permissionNotGranted, Toast.LENGTH_LONG).show();
return;
}
Toast.makeText(context, context.getString(R.string.downloading_toast, filename), Toast.LENGTH_LONG).show();
isDownloading = true;
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(link));
request.setDestinationUri(Uri.fromFile(file));