Add more error checking for ndc

In NativeDaemonConnector.doCommand() calls, there was inconsistent error
checking. This change adds error checking for every call and makes it so
that any call to .doCommand() that gets an error code won't cause the
code to hang forever.

Change-Id: I4584953a759a48ad16adfe8ee9e564b5f5796680
This commit is contained in:
Kenny Root
2010-06-01 13:23:53 -07:00
parent 00e21f8eb5
commit a80ce06d4c
3 changed files with 279 additions and 112 deletions

View File

@@ -642,10 +642,20 @@ class MountService extends IMountService.Stub
}
private boolean doGetShareMethodAvailable(String method) {
ArrayList<String> rsp = mConnector.doCommand("share status " + method);
try {
ArrayList<String> rsp = mConnector.doCommand("share status " + method);
} catch (NativeDaemonConnectorException ex) {
Slog.e(TAG, "Failed to determine whether share method " + method + " is available.");
return false;
}
for (String line : rsp) {
String []tok = line.split(" ");
String[] tok = line.split(" ");
if (tok.length < 3) {
Slog.e(TAG, "Malformed response to share status " + method);
return false;
}
int code;
try {
code = Integer.parseInt(tok[0]);
@@ -770,10 +780,22 @@ class MountService extends IMountService.Stub
private boolean doGetVolumeShared(String path, String method) {
String cmd = String.format("volume shared %s %s", path, method);
ArrayList<String> rsp = mConnector.doCommand(cmd);
ArrayList<String> rsp;
try {
rsp = mConnector.doCommand(cmd);
} catch (NativeDaemonConnectorException ex) {
Slog.e(TAG, "Failed to read response to volume shared " + path + " " + method);
return false;
}
for (String line : rsp) {
String []tok = line.split(" ");
String[] tok = line.split(" ");
if (tok.length < 3) {
Slog.e(TAG, "Malformed response to volume shared " + path + " " + method + " command");
return false;
}
int code;
try {
code = Integer.parseInt(tok[0]);
@@ -782,9 +804,7 @@ class MountService extends IMountService.Stub
return false;
}
if (code == VoldResponseCode.ShareEnabledResult) {
if (tok[2].equals("enabled"))
return true;
return false;
return "enabled".equals(tok[2]);
} else {
Slog.e(TAG, String.format("Unexpected response code %d", code));
return false;