From d6d2be2535ab9dfc254b356e10d2374b6950a5ab Mon Sep 17 00:00:00 2001 From: Martin Brabham Date: Wed, 11 May 2016 13:24:29 -0400 Subject: Alter download flow to request permissions before anything else. Change-Id: I6ccbdbcc39a631035b4f8a8d6edae0f5a4dc8e36 Ticket-Id: CYNGNOS-2266 Ticket-Id: FEIJ-368 --- src/com/android/browser/DownloadSettings.java | 90 +++++++++++++++------------ 1 file changed, 49 insertions(+), 41 deletions(-) diff --git a/src/com/android/browser/DownloadSettings.java b/src/com/android/browser/DownloadSettings.java index aa528d22..ee602102 100644 --- a/src/com/android/browser/DownloadSettings.java +++ b/src/com/android/browser/DownloadSettings.java @@ -212,54 +212,62 @@ public class DownloadSettings extends Activity { }; private OnClickListener downloadStartListener = new OnClickListener() { - @Override public void onClick(View v) { - filenameBase = getFilenameBaseFromUserEnter(); - // check the filename user enter is null or not - if (TextUtils.isEmpty(filenameBase) || TextUtils.isEmpty(downloadPath)) { - DownloadHandler.showFilenameEmptyDialog(DownloadSettings.this); - return; - } + onHandleDownload(); + } + }; - filenameExtension = DownloadHandler.getFilenameExtension(filename); - filename = filenameBase + "." + filenameExtension; + private void onHandleDownload() { - // check the storage status - if (!DownloadHandler.isStorageStatusOK(DownloadSettings.this, filename, downloadPath)) { - return; - } + filenameBase = getFilenameBaseFromUserEnter(); - // check the storage memory enough or not - try { - DownloadHandler.setAppointedFolder(downloadPath); - } catch (Exception e) { - DownloadHandler.showNoEnoughMemoryDialog(DownloadSettings.this); - return; - } - boolean isNoEnoughMemory = DownloadHandler.manageNoEnoughMemory(contentLength, - downloadPath); - if (isNoEnoughMemory) { - DownloadHandler.showNoEnoughMemoryDialog(DownloadSettings.this); - return; - } + // check the filename user enter is null or not + if (TextUtils.isEmpty(filenameBase) || TextUtils.isEmpty(downloadPath)) { + DownloadHandler.showFilenameEmptyDialog(DownloadSettings.this); + return; + } - // check the download file is exist or not - String fullFilename = downloadPath + "/" + filename; - if (mimetype != null && new File(fullFilename).exists()) { - DownloadHandler.fileExistQueryDialog(DownloadSettings.this); - return; - } + // check for permission + if (!hasPermission(permission.WRITE_EXTERNAL_STORAGE)) { + requestPermissions(new String[] {permission.WRITE_EXTERNAL_STORAGE}, + ++nextRequestCode); + return; + } - // check for permission - if (!hasPermission(permission.WRITE_EXTERNAL_STORAGE)) { - requestPermissions(new String[] {permission.WRITE_EXTERNAL_STORAGE}, - ++nextRequestCode); - } else { - download(); - } + filenameExtension = DownloadHandler.getFilenameExtension(filename); + filename = filenameBase + "." + filenameExtension; + + // check the storage status + if (!DownloadHandler.isStorageStatusOK(DownloadSettings.this, filename, downloadPath)) { + return; } - }; + + // check the storage memory enough or not + try { + DownloadHandler.setAppointedFolder(downloadPath); + } catch (Exception e) { + DownloadHandler.showNoEnoughMemoryDialog(DownloadSettings.this); + return; + } + boolean isNoEnoughMemory = DownloadHandler.manageNoEnoughMemory(contentLength, + downloadPath); + if (isNoEnoughMemory) { + DownloadHandler.showNoEnoughMemoryDialog(DownloadSettings.this); + return; + } + + // check the download file is exist or not + String fullFilename = downloadPath + "/" + filename; + if (mimetype != null && new File(fullFilename).exists()) { + DownloadHandler.fileExistQueryDialog(DownloadSettings.this); + return; + } + + download(); + + } + @Override public void onRequestPermissionsResult(int requestCode, @@ -267,7 +275,7 @@ public class DownloadSettings extends Activity { if (nextRequestCode == requestCode) { if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) { - download(); + onHandleDownload(); } else { finish(); } -- cgit v1.2.3