aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Garnes <matt@cyngn.com>2015-01-20 19:09:06 +0800
committerMatt Garnes <matt@cyngn.com>2015-01-21 10:38:25 +0800
commitac44c19934998db6d9367a9f504996125140ee1c (patch)
treefea8445890b8c76410f3899c90c61000ab3c5db8
parentc21b4b78dafcc195ad801b0e41bff63fca0a6d22 (diff)
downloadandroid_packages_apps_CMFileManager-ac44c19934998db6d9367a9f504996125140ee1c.tar.gz
android_packages_apps_CMFileManager-ac44c19934998db6d9367a9f504996125140ee1c.tar.bz2
android_packages_apps_CMFileManager-ac44c19934998db6d9367a9f504996125140ee1c.zip
Inform the user if copy/move fails with no space remaining.
- Detect the specific IOException representing no space left on the device. Throw an ExecutionException for this particular case. - Support translatable ExecutionExceptions that specify a string resource as a message. Change-Id: I798cc3c194b78d3a2d13685d29cfbb580de3f30e
-rw-r--r--res/values/strings.xml2
-rw-r--r--src/com/cyanogenmod/filemanager/console/ExecutionException.java19
-rw-r--r--src/com/cyanogenmod/filemanager/util/ExceptionUtil.java22
-rw-r--r--src/com/cyanogenmod/filemanager/util/FileHelper.java13
4 files changed, 48 insertions, 8 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 2684aae6..9e4e7bac 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -103,6 +103,8 @@
<!-- When an operation requires elevated privileged (normally caused for the use of a
non-privileged console) -->
<string name="msgs_insufficient_permissions">This operation requires elevated permissions. Try changing to Root Access mode.</string>
+ <!-- When an operation fails because the device has run out of storage. -->
+ <string name="msgs_no_disk_space">This operation failed because there is no space left on the device.</string>
<!-- The file or directory was not found -->
<string name="msgs_file_not_found">The file or folder was not found.</string>
<!-- The command reference couldn't be created (not found or invalid definition)
diff --git a/src/com/cyanogenmod/filemanager/console/ExecutionException.java b/src/com/cyanogenmod/filemanager/console/ExecutionException.java
index e05d35e2..d480e0dc 100644
--- a/src/com/cyanogenmod/filemanager/console/ExecutionException.java
+++ b/src/com/cyanogenmod/filemanager/console/ExecutionException.java
@@ -23,6 +23,8 @@ public class ExecutionException extends Exception {
private static final long serialVersionUID = 5900809383615958749L;
+ private int mDetailMessageResId = 0;
+
/**
* Constructor of <code>ExecutionException</code>.
*
@@ -35,6 +37,16 @@ public class ExecutionException extends Exception {
/**
* Constructor of <code>ExecutionException</code>.
*
+ * @param detailMessageResId Res ID for Message associated to the exception
+ */
+ public ExecutionException(int detailMessageResId) {
+ super();
+ mDetailMessageResId = detailMessageResId;
+ }
+
+ /**
+ * Constructor of <code>ExecutionException</code>.
+ *
* @param detailMessage Message associated to the exception
* @param throwable The cause of the exception
*/
@@ -42,4 +54,11 @@ public class ExecutionException extends Exception {
super(detailMessage, throwable);
}
+ /**
+ * Returns the res ID that has been set to represent this error's message. Used for translation.
+ * @return The string resource id of this Exception's message.
+ */
+ public int getDetailMessageResId() {
+ return mDetailMessageResId;
+ }
}
diff --git a/src/com/cyanogenmod/filemanager/util/ExceptionUtil.java b/src/com/cyanogenmod/filemanager/util/ExceptionUtil.java
index edd876ae..723fc604 100644
--- a/src/com/cyanogenmod/filemanager/util/ExceptionUtil.java
+++ b/src/com/cyanogenmod/filemanager/util/ExceptionUtil.java
@@ -194,13 +194,21 @@ public final class ExceptionUtil {
//Get the appropriate message for the exception
int msgResId = R.string.msgs_unknown;
boolean toast = true;
- int cc = KNOWN_EXCEPTIONS.length;
- for (int i = 0; i < cc; i++) {
- if (KNOWN_EXCEPTIONS[i].getCanonicalName().compareTo(
- ex.getClass().getCanonicalName()) == 0) {
- msgResId = KNOWN_EXCEPTIONS_IDS[i];
- toast = KNOWN_EXCEPTIONS_TOAST[i];
- break;
+
+ // If an ExecutionException has specified a resource string to use,
+ // this is a special case and should be displayed as such.
+ if ((ex instanceof ExecutionException)
+ && ((ExecutionException)ex).getDetailMessageResId() != 0) {
+ msgResId = ((ExecutionException)ex).getDetailMessageResId();
+ } else {
+ int cc = KNOWN_EXCEPTIONS.length;
+ for (int i = 0; i < cc; i++) {
+ if (KNOWN_EXCEPTIONS[i].getCanonicalName().compareTo(
+ ex.getClass().getCanonicalName()) == 0) {
+ msgResId = KNOWN_EXCEPTIONS_IDS[i];
+ toast = KNOWN_EXCEPTIONS_TOAST[i];
+ break;
+ }
}
}
diff --git a/src/com/cyanogenmod/filemanager/util/FileHelper.java b/src/com/cyanogenmod/filemanager/util/FileHelper.java
index 3efa9ee4..ad16043c 100644
--- a/src/com/cyanogenmod/filemanager/util/FileHelper.java
+++ b/src/com/cyanogenmod/filemanager/util/FileHelper.java
@@ -19,6 +19,8 @@ package com.cyanogenmod.filemanager.util;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Resources;
+import android.system.ErrnoException;
+import android.system.OsConstants;
import android.util.Log;
import com.cyanogenmod.filemanager.FileManagerApplication;
@@ -1053,7 +1055,8 @@ public final class FileHelper {
* @param bufferSize The buffer size for the operation
* @return boolean If the operation complete successfully
*/
- public static boolean bufferedCopy(final File src, final File dst, int bufferSize) {
+ public static boolean bufferedCopy(final File src, final File dst,
+ int bufferSize) throws ExecutionException {
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
@@ -1069,6 +1072,14 @@ public final class FileHelper {
} catch (Throwable e) {
Log.e(TAG,
String.format(TAG, "Failed to copy from %s to %d", src, dst), e); //$NON-NLS-1$
+
+ // Check if this error is an out of space exception and throw that specifically.
+ // ENOSPC -> Error No Space
+ if (e.getCause() instanceof ErrnoException
+ && ((ErrnoException)e.getCause()).errno == OsConstants.ENOSPC) {
+ throw new ExecutionException(R.string.msgs_no_disk_space);
+ }
+
return false;
} finally {
try {