Merge "Refactor ZygoteProcess to deal in LocalSocketAddress."
This commit is contained in:
@@ -61,18 +61,27 @@ public class ZygoteProcess {
|
|||||||
/**
|
/**
|
||||||
* The name of the socket used to communicate with the primary zygote.
|
* The name of the socket used to communicate with the primary zygote.
|
||||||
*/
|
*/
|
||||||
private final String mSocket;
|
private final LocalSocketAddress mSocket;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The name of the secondary (alternate ABI) zygote socket.
|
* The name of the secondary (alternate ABI) zygote socket.
|
||||||
*/
|
*/
|
||||||
private final String mSecondarySocket;
|
private final LocalSocketAddress mSecondarySocket;
|
||||||
|
|
||||||
public ZygoteProcess(String primarySocket, String secondarySocket) {
|
public ZygoteProcess(String primarySocket, String secondarySocket) {
|
||||||
|
this(new LocalSocketAddress(primarySocket, LocalSocketAddress.Namespace.RESERVED),
|
||||||
|
new LocalSocketAddress(secondarySocket, LocalSocketAddress.Namespace.RESERVED));
|
||||||
|
}
|
||||||
|
|
||||||
|
public ZygoteProcess(LocalSocketAddress primarySocket, LocalSocketAddress secondarySocket) {
|
||||||
mSocket = primarySocket;
|
mSocket = primarySocket;
|
||||||
mSecondarySocket = secondarySocket;
|
mSecondarySocket = secondarySocket;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LocalSocketAddress getPrimarySocketAddress() {
|
||||||
|
return mSocket;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* State for communicating with the zygote process.
|
* State for communicating with the zygote process.
|
||||||
*/
|
*/
|
||||||
@@ -92,14 +101,13 @@ public class ZygoteProcess {
|
|||||||
this.abiList = abiList;
|
this.abiList = abiList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ZygoteState connect(String socketAddress) throws IOException {
|
public static ZygoteState connect(LocalSocketAddress address) throws IOException {
|
||||||
DataInputStream zygoteInputStream = null;
|
DataInputStream zygoteInputStream = null;
|
||||||
BufferedWriter zygoteWriter = null;
|
BufferedWriter zygoteWriter = null;
|
||||||
final LocalSocket zygoteSocket = new LocalSocket();
|
final LocalSocket zygoteSocket = new LocalSocket();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
zygoteSocket.connect(new LocalSocketAddress(socketAddress,
|
zygoteSocket.connect(address);
|
||||||
LocalSocketAddress.Namespace.RESERVED));
|
|
||||||
|
|
||||||
zygoteInputStream = new DataInputStream(zygoteSocket.getInputStream());
|
zygoteInputStream = new DataInputStream(zygoteSocket.getInputStream());
|
||||||
|
|
||||||
@@ -115,8 +123,8 @@ public class ZygoteProcess {
|
|||||||
}
|
}
|
||||||
|
|
||||||
String abiListString = getAbiList(zygoteWriter, zygoteInputStream);
|
String abiListString = getAbiList(zygoteWriter, zygoteInputStream);
|
||||||
Log.i("Zygote", "Process: zygote socket " + socketAddress + " opened, supported ABIS: "
|
Log.i("Zygote", "Process: zygote socket " + address.getNamespace() + "/"
|
||||||
+ abiListString);
|
+ address.getName() + " opened, supported ABIS: " + abiListString);
|
||||||
|
|
||||||
return new ZygoteState(zygoteSocket, zygoteInputStream, zygoteWriter,
|
return new ZygoteState(zygoteSocket, zygoteInputStream, zygoteWriter,
|
||||||
Arrays.asList(abiListString.split(",")));
|
Arrays.asList(abiListString.split(",")));
|
||||||
@@ -514,9 +522,19 @@ public class ZygoteProcess {
|
|||||||
* @param socketName The name of the socket to connect to.
|
* @param socketName The name of the socket to connect to.
|
||||||
*/
|
*/
|
||||||
public static void waitForConnectionToZygote(String socketName) {
|
public static void waitForConnectionToZygote(String socketName) {
|
||||||
|
final LocalSocketAddress address =
|
||||||
|
new LocalSocketAddress(socketName, LocalSocketAddress.Namespace.RESERVED);
|
||||||
|
waitForConnectionToZygote(address);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Try connecting to the Zygote over and over again until we hit a time-out.
|
||||||
|
* @param address The name of the socket to connect to.
|
||||||
|
*/
|
||||||
|
public static void waitForConnectionToZygote(LocalSocketAddress address) {
|
||||||
for (int n = 20; n >= 0; n--) {
|
for (int n = 20; n >= 0; n--) {
|
||||||
try {
|
try {
|
||||||
final ZygoteState zs = ZygoteState.connect(socketName);
|
final ZygoteState zs = ZygoteState.connect(address);
|
||||||
zs.close();
|
zs.close();
|
||||||
return;
|
return;
|
||||||
} catch (IOException ioe) {
|
} catch (IOException ioe) {
|
||||||
@@ -529,6 +547,6 @@ public class ZygoteProcess {
|
|||||||
} catch (InterruptedException ie) {
|
} catch (InterruptedException ie) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Slog.wtf(LOG_TAG, "Failed to connect to Zygote through socket " + socketName);
|
Slog.wtf(LOG_TAG, "Failed to connect to Zygote through socket " + address.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user