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

Commit c0834768 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Public API: Incident report section registration"

parents 7cd44675 c2ab45a2
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -8342,8 +8342,11 @@ package android.os {
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.DUMP, android.Manifest.permission.PACKAGE_USAGE_STATS}) public android.os.IncidentManager.IncidentReport getIncidentReport(android.net.Uri);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.DUMP, android.Manifest.permission.PACKAGE_USAGE_STATS}) public java.util.List<android.net.Uri> getIncidentReportList(String);
    method @RequiresPermission(android.Manifest.permission.APPROVE_INCIDENT_REPORTS) public java.util.List<android.os.IncidentManager.PendingReport> getPendingReports();
    method public void registerSection(int, @NonNull String, @NonNull android.os.IncidentManager.DumpCallback);
    method public void registerSection(int, @NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.os.IncidentManager.DumpCallback);
    method @RequiresPermission(allOf={android.Manifest.permission.DUMP, android.Manifest.permission.PACKAGE_USAGE_STATS}) public void reportIncident(android.os.IncidentReportArgs);
    method @RequiresPermission("android.permission.REQUEST_INCIDENT_REPORT_APPROVAL") public void requestAuthorization(int, String, int, android.os.IncidentManager.AuthListener);
    method public void unregisterSection(int);
    field public static final int FLAG_CONFIRMATION_DIALOG = 1; // 0x1
    field public static final int PRIVACY_POLICY_AUTO = 200; // 0xc8
    field public static final int PRIVACY_POLICY_EXPLICIT = 100; // 0x64
@@ -8356,6 +8359,11 @@ package android.os {
    method public void onReportDenied();
  }
  public static class IncidentManager.DumpCallback {
    ctor public IncidentManager.DumpCallback();
    method public void onDumpSection(int, @NonNull java.io.OutputStream);
  }
  public static class IncidentManager.IncidentReport implements java.io.Closeable android.os.Parcelable {
    ctor public IncidentManager.IncidentReport(android.os.Parcel);
    method public void close();
+8 −0
Original line number Diff line number Diff line
@@ -2037,8 +2037,11 @@ package android.os {
    method @Nullable @RequiresPermission(allOf={android.Manifest.permission.DUMP, android.Manifest.permission.PACKAGE_USAGE_STATS}) public android.os.IncidentManager.IncidentReport getIncidentReport(android.net.Uri);
    method @NonNull @RequiresPermission(allOf={android.Manifest.permission.DUMP, android.Manifest.permission.PACKAGE_USAGE_STATS}) public java.util.List<android.net.Uri> getIncidentReportList(String);
    method @RequiresPermission(android.Manifest.permission.APPROVE_INCIDENT_REPORTS) public java.util.List<android.os.IncidentManager.PendingReport> getPendingReports();
    method public void registerSection(int, @NonNull String, @NonNull android.os.IncidentManager.DumpCallback);
    method public void registerSection(int, @NonNull String, @NonNull java.util.concurrent.Executor, @NonNull android.os.IncidentManager.DumpCallback);
    method @RequiresPermission(allOf={android.Manifest.permission.DUMP, android.Manifest.permission.PACKAGE_USAGE_STATS}) public void reportIncident(android.os.IncidentReportArgs);
    method @RequiresPermission("android.permission.REQUEST_INCIDENT_REPORT_APPROVAL") public void requestAuthorization(int, String, int, android.os.IncidentManager.AuthListener);
    method public void unregisterSection(int);
    field public static final int FLAG_CONFIRMATION_DIALOG = 1; // 0x1
    field public static final int PRIVACY_POLICY_AUTO = 200; // 0xc8
    field public static final int PRIVACY_POLICY_EXPLICIT = 100; // 0x64
@@ -2051,6 +2054,11 @@ package android.os {
    method public void onReportDenied();
  }

  public static class IncidentManager.DumpCallback {
    ctor public IncidentManager.DumpCallback();
    method public void onDumpSection(int, @NonNull java.io.OutputStream);
  }

  public static class IncidentManager.IncidentReport implements java.io.Closeable android.os.Parcelable {
    ctor public IncidentManager.IncidentReport(android.os.Parcel);
    method public void close();
+4 −3
Original line number Diff line number Diff line
@@ -350,11 +350,11 @@ Status IncidentService::reportIncidentToDumpstate(unique_fd stream,
Status IncidentService::registerSection(const int id, const String16& name16,
        const sp<IIncidentDumpCallback>& callback) {
    const char* name = String8(name16).c_str();
    ALOGI("Register section %d: %s", id, name);
    const uid_t callingUid = IPCThreadState::self()->getCallingUid();
    ALOGI("Uid %d registers section %d '%s'", callingUid, id, name);
    if (callback == nullptr) {
        return Status::fromExceptionCode(Status::EX_NULL_POINTER);
    }
    const uid_t callingUid = IPCThreadState::self()->getCallingUid();
    for (int i = 0; i < mRegisteredSections.size(); i++) {
        if (mRegisteredSections.at(i)->id == id) {
            if (mRegisteredSections.at(i)->uid != callingUid) {
@@ -370,8 +370,9 @@ Status IncidentService::registerSection(const int id, const String16& name16,
}

Status IncidentService::unregisterSection(const int id) {
    ALOGI("Unregister section %d", id);
    uid_t callingUid = IPCThreadState::self()->getCallingUid();
    ALOGI("Uid %d unregisters section %d", callingUid, id);

    for (auto it = mRegisteredSections.begin(); it != mRegisteredSections.end(); it++) {
        if ((*it)->id == id) {
            if ((*it)->uid != callingUid) {
+39 −17
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;

/**
@@ -426,10 +427,9 @@ public class IncidentManager {
     *
     * @see #registerSection
     * @see #unregisterSection
     *
     * @hide
     */
    public static class DumpCallback {
        private int mId;
        private Executor mExecutor;

        IIncidentDumpCallback.Stub mBinder = new IIncidentDumpCallback.Stub() {
@@ -437,20 +437,25 @@ public class IncidentManager {
            public void onDumpSection(ParcelFileDescriptor pfd) {
                if (mExecutor != null) {
                    mExecutor.execute(() -> {
                        DumpCallback.this.onDumpSection(
                        DumpCallback.this.onDumpSection(mId,
                                new ParcelFileDescriptor.AutoCloseOutputStream(pfd));
                    });
                } else {
                    DumpCallback.this.onDumpSection(
                    DumpCallback.this.onDumpSection(mId,
                            new ParcelFileDescriptor.AutoCloseOutputStream(pfd));
                }
            }
        };

        /**
         * Called when incidentd requests to dump this section.
         * Dump the registered section as a protobuf message to the given OutputStream. Called when
         * incidentd requests to dump this section.
         *
         * @param id  the id of the registered section. The same id used in calling
         *            {@link #registerSection(int, String, DumpCallback)} will be passed in here.
         * @param out the OutputStream to write the protobuf message
         */
        public void onDumpSection(OutputStream out) {
        public void onDumpSection(int id, @NonNull OutputStream out) {
        }
    }

@@ -563,12 +568,20 @@ public class IncidentManager {

    /**
     * Register a callback to dump an extended incident report section with the given id and name.
     * The callback function will be invoked when an incident report with all sections or sections
     * matching the given id is being taken.
     *
     * @hide
     */
    public void registerSection(int id, String name, @NonNull DumpCallback callback) {
     * Calling <code>registerSection</code> with a duplicate id will override previous registration.
     * However, the request must come from the same calling uid.
     *
     * @param id       the ID of the extended section. It should be unique system-wide, and be
     *                 different from IDs of all existing section in
     *                 frameworks/base/core/proto/android/os/incident.proto.
     *                 Also see incident.proto for other rules about the ID.
     * @param name     the name to display in logs and/or stderr when taking an incident report
     *                 containing this section, mainly for debugging purpose
     * @param callback the callback function to be invoked when an incident report with all sections
     *                 or sections matching the given id is being taken
     */
    public void registerSection(int id, @NonNull String name, @NonNull DumpCallback callback) {
        registerSection(id, name, mContext.getMainExecutor(), callback);
    }

@@ -576,16 +589,27 @@ public class IncidentManager {
     * Register a callback to dump an extended incident report section with the given id and name,
     * running on the supplied executor.
     *
     * @hide
     */
    public void registerSection(int id, String name, @NonNull @CallbackExecutor Executor executor,
            @NonNull DumpCallback callback) {
     * @param id       the ID of the extended section. It should be unique system-wide, and be
     *                 different from IDs of all existing section in
     *                 frameworks/base/core/proto/android/os/incident.proto.
     *                 Also see incident.proto for other rules about the ID.
     * @param name     the name to display in logs and/or stderr when taking an incident report
     *                 containing this section, mainly for debugging purpose
     * @param executor the executor used to run the callback
     * @param callback the callback function to be invoked when an incident report with all sections
     *                 or sections matching the given id is being taken
     */
    public void registerSection(int id, @NonNull String name,
                @NonNull @CallbackExecutor Executor executor, @NonNull DumpCallback callback) {
        Objects.requireNonNull(executor, "executor cannot be null");
        Objects.requireNonNull(callback, "callback cannot be null");
        try {
            if (callback.mExecutor != null) {
                throw new RuntimeException("Do not reuse DumpCallback objects when calling"
                        + " registerSection");
            }
            callback.mExecutor = executor;
            callback.mId = id;
            final IIncidentManager service = getIIncidentManagerLocked();
            if (service == null) {
                Slog.e(TAG, "registerSection can't find incident binder service");
@@ -599,9 +623,7 @@ public class IncidentManager {

    /**
     * Unregister an extended section dump function. The section must be previously registered with
     * {@link #registerSection(int, String, DumpCallback)}
     *
     * @hide
     * {@link #registerSection(int, String, DumpCallback)} by the same calling uid.
     */
    public void unregisterSection(int id) {
        try {