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: If714282b6642f278fb8137f652af1a012670253b
This commit is contained in:
Kenny Root
2010-06-01 13:23:53 -07:00
committed by android-build SharedAccount
parent e2fd45af93
commit eb2e095469
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;