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

Commit 7c3fb7c7 authored by Kholoud Mohamed's avatar Kholoud Mohamed
Browse files

Add ability to retrieve bugreport multiple times

If specified by the caller, it keeps the bugreport stored in the framework
after it's retrieved, allowing it to be retrieved multiple times.

Bug: 304272173
Bug: 302517677
Test: manual testing
Change-Id: I2aaf0a7bea629bdad92aab567c96b2a9e7d64633
parent 796ed47a
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -104,6 +104,8 @@ cc_defaults {
        "libvintf",
        "libbinderdebug",
        "packagemanager_aidl-cpp",
        "server_configurable_flags",
        "device_policy_aconfig_flags_c_lib",
    ],
    srcs: [
        "DumpstateService.cpp",
+7 −2
Original line number Diff line number Diff line
@@ -37,6 +37,8 @@ struct DumpstateInfo {
    Dumpstate* ds = nullptr;
    int32_t calling_uid = -1;
    std::string calling_package;
    int32_t user_id = -1;
    bool keep_bugreport_on_retrieval = false;
};

static binder::Status exception(uint32_t code, const std::string& msg,
@@ -60,7 +62,7 @@ static binder::Status exception(uint32_t code, const std::string& msg,

[[noreturn]] static void* dumpstate_thread_retrieve(void* data) {
    std::unique_ptr<DumpstateInfo> ds_info(static_cast<DumpstateInfo*>(data));
    ds_info->ds->Retrieve(ds_info->calling_uid, ds_info->calling_package);
    ds_info->ds->Retrieve(ds_info->calling_uid, ds_info->calling_package, ds_info->keep_bugreport_on_retrieval);
    MYLOGD("Finished retrieving a bugreport. Exiting.\n");
    exit(0);
}
@@ -201,9 +203,10 @@ binder::Status DumpstateService::cancelBugreport(int32_t calling_uid,
}

binder::Status DumpstateService::retrieveBugreport(
    int32_t calling_uid, const std::string& calling_package,
    int32_t calling_uid, const std::string& calling_package, int32_t user_id,
    android::base::unique_fd bugreport_fd,
    const std::string& bugreport_file,
    const bool keep_bugreport_on_retrieval,
    const sp<IDumpstateListener>& listener) {

    ds_ = &(Dumpstate::GetInstance());
@@ -211,6 +214,8 @@ binder::Status DumpstateService::retrieveBugreport(
    ds_info->ds = ds_;
    ds_info->calling_uid = calling_uid;
    ds_info->calling_package = calling_package;
    ds_info->user_id = user_id;
    ds_info->keep_bugreport_on_retrieval = keep_bugreport_on_retrieval;
    ds_->listener_ = listener;
    std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
    // Use a /dev/null FD when initializing options since none is provided.
+2 −0
Original line number Diff line number Diff line
@@ -48,8 +48,10 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst

    binder::Status retrieveBugreport(int32_t calling_uid,
                                     const std::string& calling_package,
                                     int32_t user_id,
                                     android::base::unique_fd bugreport_fd,
                                     const std::string& bugreport_file,
                                     const bool keep_bugreport_on_retrieval,
                                     const sp<IDumpstateListener>& listener)
                                     override;

+8 −1
Original line number Diff line number Diff line
@@ -58,6 +58,9 @@ interface IDumpstate {
    // Defer user consent.
    const int BUGREPORT_FLAG_DEFER_CONSENT = 0x2;

    // Keep bugreport stored after retrieval.
    const int BUGREPORT_FLAG_KEEP_BUGREPORT_ON_RETRIEVAL = 0x4;

    /**
     * Speculatively pre-dumps UI data for a bugreport request that might come later.
     *
@@ -116,12 +119,16 @@ interface IDumpstate {
     *
     * @param callingUid UID of the original application that requested the report.
     * @param callingPackage package of the original application that requested the report.
     * @param userId user Id of the original package that requested the report.
     * @param bugreportFd the file to which the zipped bugreport should be written
     * @param bugreportFile the path of the bugreport file
     * @param keepBugreportOnRetrieval boolean to indicate if the bugreport should be kept in the
     * platform after it has been retrieved by the caller.
     * @param listener callback for updates; optional
     */
    void retrieveBugreport(int callingUid, @utf8InCpp String callingPackage,
    void retrieveBugreport(int callingUid, @utf8InCpp String callingPackage, int userId,
                           FileDescriptor bugreportFd,
                           @utf8InCpp String bugreportFile,
                           boolean keepBugreportOnRetrieval,
                           IDumpstateListener listener);
}
+12 −5
Original line number Diff line number Diff line
@@ -59,6 +59,7 @@
#include <vector>

#include <aidl/android/hardware/dumpstate/IDumpstateDevice.h>
#include <android_app_admin_flags.h>
#include <android-base/file.h>
#include <android-base/properties.h>
#include <android-base/scopeguard.h>
@@ -2977,14 +2978,17 @@ Dumpstate::RunStatus Dumpstate::Run(int32_t calling_uid, const std::string& call
    return status;
}

Dumpstate::RunStatus Dumpstate::Retrieve(int32_t calling_uid, const std::string& calling_package) {
    Dumpstate::RunStatus status = RetrieveInternal(calling_uid, calling_package);
Dumpstate::RunStatus Dumpstate::Retrieve(int32_t calling_uid, const std::string& calling_package,
                                         const bool keep_bugreport_on_retrieval) {
    Dumpstate::RunStatus status = RetrieveInternal(calling_uid, calling_package,
                                                    keep_bugreport_on_retrieval);
    HandleRunStatus(status);
    return status;
}

Dumpstate::RunStatus  Dumpstate::RetrieveInternal(int32_t calling_uid,
                                                  const std::string& calling_package) {
                                                  const std::string& calling_package,
                                                  const bool keep_bugreport_on_retrieval) {
  consent_callback_ = new ConsentCallback();
  const String16 incidentcompanion("incidentcompanion");
  sp<android::IBinder> ics(
@@ -3019,9 +3023,12 @@ Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid,

  bool copy_succeeded =
      android::os::CopyFileToFd(path_, options_->bugreport_fd.get());
  if (copy_succeeded) {

  if (copy_succeeded && (!android::app::admin::flags::onboarding_bugreport_v2_enabled()
                         || !keep_bugreport_on_retrieval)) {
        android::os::UnlinkAndLogOnError(path_);
  }

  return copy_succeeded ? Dumpstate::RunStatus::OK
                        : Dumpstate::RunStatus::ERROR;
}
Loading