Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f7cdcb98 authored by Mathew Inwood's avatar Mathew Inwood Committed by android-build-merger
Browse files

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

am: 96b2f3ce

Change-Id: I2e4fc91b53606f701682e4fad0bb17616cb58d7e
parents 2fe0e01f 96b2f3ce
Loading
Loading
Loading
Loading
+13 −6
Original line number Diff line number Diff line
@@ -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;
        }
    }

+5 −1
Original line number Diff line number Diff line
@@ -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);