Merge "Configurable hidden API exemptions."

am: 4b8285b907

Change-Id: Ia61896bdedff170d75715094ce87b97dc96994ed
This commit is contained in:
Mathew Inwood
2018-03-27 22:05:14 +00:00
committed by android-build-merger
4 changed files with 105 additions and 6 deletions

View File

@@ -32,6 +32,7 @@ import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@@ -157,6 +158,13 @@ public class ZygoteProcess {
*/
private final Object mLock = new Object();
/**
* List of exemptions to the API blacklist. These are prefix matches on the runtime format
* symbol signature. Any matching symbol is treated by the runtime as being on the light grey
* list.
*/
private List<String> mApiBlacklistExemptions = Collections.emptyList();
/**
* The state of the connection to the primary zygote.
*/
@@ -175,7 +183,7 @@ public class ZygoteProcess {
* The process will continue running after this function returns.
*
* <p>If processes are not enabled, a new thread in the caller's
* process is created and main() of <var>processClass</var> called there.
* process is created and main() of <var>processclass</var> called there.
*
* <p>The niceName parameter, if not an empty string, is a custom name to
* give to the process instead of using processClass. This allows you to
@@ -453,6 +461,49 @@ public class ZygoteProcess {
}
}
/**
* Push hidden API blacklisting exemptions into the zygote process(es).
*
* <p>The list of exemptions will take affect for all new processes forked from the zygote after
* this call.
*
* @param exemptions List of hidden API exemption prefixes.
*/
public void setApiBlacklistExemptions(List<String> exemptions) {
synchronized (mLock) {
mApiBlacklistExemptions = exemptions;
maybeSetApiBlacklistExemptions(primaryZygoteState, true);
maybeSetApiBlacklistExemptions(secondaryZygoteState, true);
}
}
@GuardedBy("mLock")
private void maybeSetApiBlacklistExemptions(ZygoteState state, boolean sendIfEmpty) {
if (state == null || state.isClosed()) {
return;
}
if (!sendIfEmpty && mApiBlacklistExemptions.isEmpty()) {
return;
}
try {
state.writer.write(Integer.toString(mApiBlacklistExemptions.size() + 1));
state.writer.newLine();
state.writer.write("--set-api-blacklist-exemptions");
state.writer.newLine();
for (int i = 0; i < mApiBlacklistExemptions.size(); ++i) {
state.writer.write(mApiBlacklistExemptions.get(i));
state.writer.newLine();
}
state.writer.flush();
int status = state.inputStream.readInt();
if (status != 0) {
Slog.e(LOG_TAG, "Failed to set API blacklist exemptions; status " + status);
}
} catch (IOException ioe) {
Slog.e(LOG_TAG, "Failed to set API blacklist exemptions", ioe);
}
}
/**
* Tries to open socket to Zygote process if not already open. If
* already open, does nothing. May block and retry. Requires that mLock be held.
@@ -467,8 +518,8 @@ public class ZygoteProcess {
} catch (IOException ioe) {
throw new ZygoteStartFailedEx("Error connecting to primary zygote", ioe);
}
maybeSetApiBlacklistExemptions(primaryZygoteState, false);
}
if (primaryZygoteState.matches(abi)) {
return primaryZygoteState;
}
@@ -480,6 +531,7 @@ public class ZygoteProcess {
} catch (IOException ioe) {
throw new ZygoteStartFailedEx("Error connecting to secondary zygote", ioe);
}
maybeSetApiBlacklistExemptions(secondaryZygoteState, false);
}
if (secondaryZygoteState.matches(abi)) {