OSDN Git Service

Do not add unsolicited events to queue
authorIrfan Sheriff <isheriff@google.com>
Sun, 16 Jan 2011 22:31:55 +0000 (14:31 -0800)
committerIrfan Sheriff <isheriff@google.com>
Sun, 16 Jan 2011 22:31:55 +0000 (14:31 -0800)
Adding unsolicited events to response queue
results in doCommand() returning the wrong
result.

Pulling this change from master.

Bug: 3258529
Change-Id: I2a4b0bd8bb30b31682d7d61ee94a0d246bf10de2

services/java/com/android/server/NativeDaemonConnector.java

index 7b68d68..cf87a9d 100644 (file)
@@ -132,11 +132,12 @@ final class NativeDaemonConnector implements Runnable {
                                     Slog.e(TAG, String.format(
                                             "Error handling '%s'", event), ex);
                                 }
-                            }
-                            try {
-                                mResponseQueue.put(event);
-                            } catch (InterruptedException ex) {
-                                Slog.e(TAG, "Failed to put response onto queue", ex);
+                            } else {
+                                try {
+                                    mResponseQueue.put(event);
+                                } catch (InterruptedException ex) {
+                                    Slog.e(TAG, "Failed to put response onto queue", ex);
+                                }
                             }
                         } catch (NumberFormatException nfe) {
                             Slog.w(TAG, String.format("Bad msg (%s)", event));
@@ -219,6 +220,7 @@ final class NativeDaemonConnector implements Runnable {
      */
     public synchronized ArrayList<String> doCommand(String cmd)
             throws NativeDaemonConnectorException  {
+        mResponseQueue.clear();
         sendCommand(cmd);
 
         ArrayList<String> response = new ArrayList<String>();