Move native netd calls to varargs.
Uses argument escaping inside NativeDaemonConnector, using varargs to separate boundaries. Also introduces Command object to help build argument lists. Bug: 5472606 Change-Id: I357979fc19bb0171a056e690064e01b5a7119501
This commit is contained in:
@@ -16,6 +16,10 @@
|
||||
|
||||
package com.android.server;
|
||||
|
||||
import com.google.android.collect.Lists;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Parsed event from native side of {@link NativeDaemonConnector}.
|
||||
*/
|
||||
@@ -88,6 +92,17 @@ public class NativeDaemonEvent {
|
||||
return mCode >= 600 && mCode < 700;
|
||||
}
|
||||
|
||||
/**
|
||||
* Verify this event matches the given code.
|
||||
*
|
||||
* @throws IllegalStateException if {@link #getCode()} doesn't match.
|
||||
*/
|
||||
public void checkCode(int code) {
|
||||
if (mCode != code) {
|
||||
throw new IllegalStateException("Expected " + code + " but was: " + this);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse the given raw event into {@link NativeDaemonEvent} instance.
|
||||
*
|
||||
@@ -110,4 +125,18 @@ public class NativeDaemonEvent {
|
||||
final String message = rawEvent.substring(splitIndex + 1);
|
||||
return new NativeDaemonEvent(code, message, rawEvent);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter the given {@link NativeDaemonEvent} list, returning
|
||||
* {@link #getMessage()} for any events matching the requested code.
|
||||
*/
|
||||
public static String[] filterMessageList(NativeDaemonEvent[] events, int matchCode) {
|
||||
final ArrayList<String> result = Lists.newArrayList();
|
||||
for (NativeDaemonEvent event : events) {
|
||||
if (event.getCode() == matchCode) {
|
||||
result.add(event.getMessage());
|
||||
}
|
||||
}
|
||||
return result.toArray(new String[result.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user