Merge "Fail gracefully if we get a bad API whitelist." into pi-dev

am: 611443e984

Change-Id: I2ead19c8fda255d010aded3884aef0016e1cc74d
This commit is contained in:
Mathew Inwood
2018-04-19 09:43:15 -07:00
committed by android-build-merger
2 changed files with 18 additions and 7 deletions

View File

@@ -475,11 +475,14 @@ public class ZygoteProcess {
* @param exemptions List of hidden API exemption prefixes. Any matching members are treated as
* whitelisted/public APIs (i.e. allowed, no logging of usage).
*/
public void setApiBlacklistExemptions(List<String> exemptions) {
public boolean setApiBlacklistExemptions(List<String> exemptions) {
synchronized (mLock) {
mApiBlacklistExemptions = exemptions;
maybeSetApiBlacklistExemptions(primaryZygoteState, true);
maybeSetApiBlacklistExemptions(secondaryZygoteState, true);
boolean ok = maybeSetApiBlacklistExemptions(primaryZygoteState, true);
if (ok) {
ok = maybeSetApiBlacklistExemptions(secondaryZygoteState, true);
}
return ok;
}
}
@@ -499,12 +502,13 @@ public class ZygoteProcess {
}
@GuardedBy("mLock")
private void maybeSetApiBlacklistExemptions(ZygoteState state, boolean sendIfEmpty) {
private boolean maybeSetApiBlacklistExemptions(ZygoteState state, boolean sendIfEmpty) {
if (state == null || state.isClosed()) {
return;
Slog.e(LOG_TAG, "Can't set API blacklist exemptions: no zygote connection");
return false;
}
if (!sendIfEmpty && mApiBlacklistExemptions.isEmpty()) {
return;
return true;
}
try {
state.writer.write(Integer.toString(mApiBlacklistExemptions.size() + 1));
@@ -520,8 +524,11 @@ public class ZygoteProcess {
if (status != 0) {
Slog.e(LOG_TAG, "Failed to set API blacklist exemptions; status " + status);
}
return true;
} catch (IOException ioe) {
Slog.e(LOG_TAG, "Failed to set API blacklist exemptions", ioe);
mApiBlacklistExemptions = Collections.emptyList();
return false;
}
}

View File

@@ -2946,7 +2946,11 @@ public class ActivityManagerService extends IActivityManager.Stub
? Collections.emptyList()
: Arrays.asList(exemptions.split(","));
}
zygoteProcess.setApiBlacklistExemptions(mExemptions);
if (!zygoteProcess.setApiBlacklistExemptions(mExemptions)) {
Slog.e(TAG, "Failed to set API blacklist exemptions!");
// leave mExemptionsStr as is, so we don't try to send the same list again.
mExemptions = Collections.emptyList();
}
}
int logSampleRate = Settings.Global.getInt(mContext.getContentResolver(),
Settings.Global.HIDDEN_API_ACCESS_LOG_SAMPLING_RATE, -1);