summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Alex Naidis <alex.naidis@linux.com> 2017-01-04 18:52:36 +0100
committer Alex Naidis <alex.naidis@linux.com> 2017-01-09 16:27:52 +0000
commit19d9c2d03c478c755eddbe7ac55d0dc778f332fd (patch)
tree848487c77e443729c207f49c07db7e2bd4479234
parentf6f36d7d9a12fa6affd22bdadcb70ba940ac3812 (diff)
StorageManager: Improve exception handling
When "getPrimaryStorageSize" provides a path to "readLong", the option that the path doesn't exist is expected, since it tries all paths from "INTERNAL_STORAGE_SIZE_PATHS" until there is success. This patch makes us catch the "FileNotFoundException" and "NumberFormatException" seperately. For the above reason a "FileNotFoundException" is now treated as an information only. The "NumberFormatException" and other exceptions are now treated as error since those are not expected to happen. Change-Id: I5316f9c3108e36c31b27dc5df8bf8ac4d4257629 Signed-off-by: Alex Naidis <alex.naidis@linux.com>
-rw-r--r--core/java/android/os/storage/StorageManager.java12
1 files changed, 10 insertions, 2 deletions
diff --git a/core/java/android/os/storage/StorageManager.java b/core/java/android/os/storage/StorageManager.java
index 2bc05655b55c..925288764562 100644
--- a/core/java/android/os/storage/StorageManager.java
+++ b/core/java/android/os/storage/StorageManager.java
@@ -50,6 +50,7 @@ import com.android.internal.util.Preconditions;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.ref.WeakReference;
@@ -952,10 +953,17 @@ public class StorageManager {
try (final FileInputStream fis = new FileInputStream(path);
final BufferedReader reader = new BufferedReader(new InputStreamReader(fis));) {
return Long.parseLong(reader.readLine());
+ } catch (FileNotFoundException e) {
+ // This is expected since we are trying to parse multiple paths.
+ Slog.i(TAG, "readLong(): Path doesn't exist: " + path + ": " + e);
+ return 0;
+ } catch (NumberFormatException e) {
+ Slog.e(TAG, "readLong(): Could not parse " + path + ": " + e);
+ return 0;
} catch (Exception e) {
- Slog.w(TAG, "readLong(): could not read " + path + ": " + e);
+ Slog.e(TAG, "readLong(): Unknown exception while opening " + path + ": " + e);
return 0;
- }
+ }
}
/** @removed */