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

Commit 9f408681 authored by Xin Li's avatar Xin Li Committed by Gerrit Code Review
Browse files

Merge "Merge 24Q3 to AOSP main" into main

parents 5a473e26 60d226fc
Loading
Loading
Loading
Loading
+9 −4
Original line number Original line Diff line number Diff line
@@ -39,6 +39,7 @@ struct DumpstateInfo {
    std::string calling_package;
    std::string calling_package;
    int32_t user_id = -1;
    int32_t user_id = -1;
    bool keep_bugreport_on_retrieval = false;
    bool keep_bugreport_on_retrieval = false;
    bool skip_user_consent = false;
};
};


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


[[noreturn]] static void* dumpstate_thread_retrieve(void* data) {
[[noreturn]] static void* dumpstate_thread_retrieve(void* data) {
    std::unique_ptr<DumpstateInfo> ds_info(static_cast<DumpstateInfo*>(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->keep_bugreport_on_retrieval);
    ds_info->ds->Retrieve(ds_info->calling_uid, ds_info->calling_package,
    ds_info->keep_bugreport_on_retrieval, ds_info->skip_user_consent);
    MYLOGD("Finished retrieving a bugreport. Exiting.\n");
    MYLOGD("Finished retrieving a bugreport. Exiting.\n");
    exit(0);
    exit(0);
}
}
@@ -116,7 +118,8 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid,
                                                int bugreport_mode,
                                                int bugreport_mode,
                                                int bugreport_flags,
                                                int bugreport_flags,
                                                const sp<IDumpstateListener>& listener,
                                                const sp<IDumpstateListener>& listener,
                                                bool is_screenshot_requested) {
                                                bool is_screenshot_requested,
                                                bool skip_user_consent) {
    MYLOGI("startBugreport() with mode: %d\n", bugreport_mode);
    MYLOGI("startBugreport() with mode: %d\n", bugreport_mode);


    // Ensure there is only one bugreport in progress at a time.
    // Ensure there is only one bugreport in progress at a time.
@@ -151,7 +154,7 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid,


    std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
    std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
    options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_flags,
    options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_flags,
                        bugreport_fd, screenshot_fd, is_screenshot_requested);
                        bugreport_fd, screenshot_fd, is_screenshot_requested, skip_user_consent);


    if (bugreport_fd.get() == -1 || (options->do_screenshot && screenshot_fd.get() == -1)) {
    if (bugreport_fd.get() == -1 || (options->do_screenshot && screenshot_fd.get() == -1)) {
        MYLOGE("Invalid filedescriptor");
        MYLOGE("Invalid filedescriptor");
@@ -207,6 +210,7 @@ binder::Status DumpstateService::retrieveBugreport(
    android::base::unique_fd bugreport_fd,
    android::base::unique_fd bugreport_fd,
    const std::string& bugreport_file,
    const std::string& bugreport_file,
    const bool keep_bugreport_on_retrieval,
    const bool keep_bugreport_on_retrieval,
    const bool skip_user_consent,
    const sp<IDumpstateListener>& listener) {
    const sp<IDumpstateListener>& listener) {


    ds_ = &(Dumpstate::GetInstance());
    ds_ = &(Dumpstate::GetInstance());
@@ -216,6 +220,7 @@ binder::Status DumpstateService::retrieveBugreport(
    ds_info->calling_package = calling_package;
    ds_info->calling_package = calling_package;
    ds_info->user_id = user_id;
    ds_info->user_id = user_id;
    ds_info->keep_bugreport_on_retrieval = keep_bugreport_on_retrieval;
    ds_info->keep_bugreport_on_retrieval = keep_bugreport_on_retrieval;
    ds_info->skip_user_consent = skip_user_consent;
    ds_->listener_ = listener;
    ds_->listener_ = listener;
    std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
    std::unique_ptr<Dumpstate::DumpOptions> options = std::make_unique<Dumpstate::DumpOptions>();
    // Use a /dev/null FD when initializing options since none is provided.
    // Use a /dev/null FD when initializing options since none is provided.
@@ -223,7 +228,7 @@ binder::Status DumpstateService::retrieveBugreport(
        TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY | O_CLOEXEC)));
        TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY | O_CLOEXEC)));


    options->Initialize(Dumpstate::BugreportMode::BUGREPORT_DEFAULT,
    options->Initialize(Dumpstate::BugreportMode::BUGREPORT_DEFAULT,
                        0, bugreport_fd, devnull_fd, false);
                        0, bugreport_fd, devnull_fd, false, skip_user_consent);


    if (bugreport_fd.get() == -1) {
    if (bugreport_fd.get() == -1) {
        MYLOGE("Invalid filedescriptor");
        MYLOGE("Invalid filedescriptor");
+2 −1
Original line number Original line Diff line number Diff line
@@ -44,7 +44,7 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst
                                  android::base::unique_fd bugreport_fd,
                                  android::base::unique_fd bugreport_fd,
                                  android::base::unique_fd screenshot_fd, int bugreport_mode,
                                  android::base::unique_fd screenshot_fd, int bugreport_mode,
                                  int bugreport_flags, const sp<IDumpstateListener>& listener,
                                  int bugreport_flags, const sp<IDumpstateListener>& listener,
                                  bool is_screenshot_requested) override;
                                  bool is_screenshot_requested, bool skip_user_consent) override;


    binder::Status retrieveBugreport(int32_t calling_uid,
    binder::Status retrieveBugreport(int32_t calling_uid,
                                     const std::string& calling_package,
                                     const std::string& calling_package,
@@ -52,6 +52,7 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst
                                     android::base::unique_fd bugreport_fd,
                                     android::base::unique_fd bugreport_fd,
                                     const std::string& bugreport_file,
                                     const std::string& bugreport_file,
                                     const bool keep_bugreport_on_retrieval,
                                     const bool keep_bugreport_on_retrieval,
                                     const bool skip_user_consent,
                                     const sp<IDumpstateListener>& listener)
                                     const sp<IDumpstateListener>& listener)
                                     override;
                                     override;


+3 −1
Original line number Original line Diff line number Diff line
@@ -96,7 +96,8 @@ interface IDumpstate {
    void startBugreport(int callingUid, @utf8InCpp String callingPackage,
    void startBugreport(int callingUid, @utf8InCpp String callingPackage,
                        FileDescriptor bugreportFd, FileDescriptor screenshotFd,
                        FileDescriptor bugreportFd, FileDescriptor screenshotFd,
                        int bugreportMode, int bugreportFlags,
                        int bugreportMode, int bugreportFlags,
                        IDumpstateListener listener, boolean isScreenshotRequested);
                        IDumpstateListener listener, boolean isScreenshotRequested,
                        boolean skipUserConsent);


    /**
    /**
     * Cancels the bugreport currently in progress.
     * Cancels the bugreport currently in progress.
@@ -130,5 +131,6 @@ interface IDumpstate {
                           FileDescriptor bugreportFd,
                           FileDescriptor bugreportFd,
                           @utf8InCpp String bugreportFile,
                           @utf8InCpp String bugreportFile,
                           boolean keepBugreportOnRetrieval,
                           boolean keepBugreportOnRetrieval,
                           boolean skipUserConsent,
                           IDumpstateListener listener);
                           IDumpstateListener listener);
}
}
+54 −36
Original line number Original line Diff line number Diff line
@@ -1570,6 +1570,7 @@ static void DumpstateLimitedOnly() {
    printf("== ANR Traces\n");
    printf("== ANR Traces\n");
    printf("========================================================\n");
    printf("========================================================\n");


    ds.anr_data_ = GetDumpFds(ANR_DIR, ANR_FILE_PREFIX);
    AddAnrTraceFiles();
    AddAnrTraceFiles();


    printf("========================================================\n");
    printf("========================================================\n");
@@ -2979,9 +2980,11 @@ void Dumpstate::DumpOptions::Initialize(BugreportMode bugreport_mode,
                                        int bugreport_flags,
                                        int bugreport_flags,
                                        const android::base::unique_fd& bugreport_fd_in,
                                        const android::base::unique_fd& bugreport_fd_in,
                                        const android::base::unique_fd& screenshot_fd_in,
                                        const android::base::unique_fd& screenshot_fd_in,
                                        bool is_screenshot_requested) {
                                        bool is_screenshot_requested,
                                        bool skip_user_consent) {
    this->use_predumped_ui_data = bugreport_flags & BugreportFlag::BUGREPORT_USE_PREDUMPED_UI_DATA;
    this->use_predumped_ui_data = bugreport_flags & BugreportFlag::BUGREPORT_USE_PREDUMPED_UI_DATA;
    this->is_consent_deferred = bugreport_flags & BugreportFlag::BUGREPORT_FLAG_DEFER_CONSENT;
    this->is_consent_deferred = bugreport_flags & BugreportFlag::BUGREPORT_FLAG_DEFER_CONSENT;
    this->skip_user_consent = skip_user_consent;
    // Duplicate the fds because the passed in fds don't outlive the binder transaction.
    // Duplicate the fds because the passed in fds don't outlive the binder transaction.
    bugreport_fd.reset(fcntl(bugreport_fd_in.get(), F_DUPFD_CLOEXEC, 0));
    bugreport_fd.reset(fcntl(bugreport_fd_in.get(), F_DUPFD_CLOEXEC, 0));
    screenshot_fd.reset(fcntl(screenshot_fd_in.get(), F_DUPFD_CLOEXEC, 0));
    screenshot_fd.reset(fcntl(screenshot_fd_in.get(), F_DUPFD_CLOEXEC, 0));
@@ -3069,16 +3072,20 @@ Dumpstate::RunStatus Dumpstate::Run(int32_t calling_uid, const std::string& call
}
}


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


Dumpstate::RunStatus  Dumpstate::RetrieveInternal(int32_t calling_uid,
Dumpstate::RunStatus  Dumpstate::RetrieveInternal(int32_t calling_uid,
                                                  const std::string& calling_package,
                                                  const std::string& calling_package,
                                                  const bool keep_bugreport_on_retrieval) {
                                                  const bool keep_bugreport_on_retrieval,
                                                  const bool skip_user_consent) {
  if (!android::app::admin::flags::onboarding_consentless_bugreports() || !skip_user_consent) {
      consent_callback_ = new ConsentCallback();
      consent_callback_ = new ConsentCallback();
      const String16 incidentcompanion("incidentcompanion");
      const String16 incidentcompanion("incidentcompanion");
      sp<android::IBinder> ics(
      sp<android::IBinder> ics(
@@ -3086,6 +3093,7 @@ Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid,
      android::String16 package(calling_package.c_str());
      android::String16 package(calling_package.c_str());
      if (ics != nullptr) {
      if (ics != nullptr) {
        MYLOGD("Checking user consent via incidentcompanion service\n");
        MYLOGD("Checking user consent via incidentcompanion service\n");

        android::interface_cast<android::os::IIncidentCompanion>(ics)->authorizeReport(
        android::interface_cast<android::os::IIncidentCompanion>(ics)->authorizeReport(
            calling_uid, package, String16(), String16(),
            calling_uid, package, String16(), String16(),
            0x1 /* FLAG_CONFIRMATION_DIALOG */, consent_callback_.get());
            0x1 /* FLAG_CONFIRMATION_DIALOG */, consent_callback_.get());
@@ -3110,6 +3118,7 @@ Dumpstate::RunStatus Dumpstate::RetrieveInternal(int32_t calling_uid,
            consent_callback_.get());
            consent_callback_.get());
        return RunStatus::USER_CONSENT_TIMED_OUT;
        return RunStatus::USER_CONSENT_TIMED_OUT;
      }
      }
  }


  bool copy_succeeded =
  bool copy_succeeded =
      android::os::CopyFileToFd(path_, options_->bugreport_fd.get());
      android::os::CopyFileToFd(path_, options_->bugreport_fd.get());
@@ -3357,6 +3366,12 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
    // duration is logged into MYLOG instead.
    // duration is logged into MYLOG instead.
    PrintHeader();
    PrintHeader();


    bool system_trace_exists = access(SYSTEM_TRACE_SNAPSHOT, F_OK) == 0;
    if (options_->use_predumped_ui_data && !system_trace_exists) {
        MYLOGW("Ignoring 'use predumped data' flag because no predumped data is available");
        options_->use_predumped_ui_data = false;
    }

    std::future<std::string> snapshot_system_trace;
    std::future<std::string> snapshot_system_trace;


    bool is_dumpstate_restricted =
    bool is_dumpstate_restricted =
@@ -3581,7 +3596,9 @@ void Dumpstate::onUiIntensiveBugreportDumpsFinished(int32_t calling_uid) {


void Dumpstate::MaybeCheckUserConsent(int32_t calling_uid, const std::string& calling_package) {
void Dumpstate::MaybeCheckUserConsent(int32_t calling_uid, const std::string& calling_package) {
    if (multiuser_get_app_id(calling_uid) == AID_SHELL ||
    if (multiuser_get_app_id(calling_uid) == AID_SHELL ||
        !CalledByApi() || options_->is_consent_deferred) {
        !CalledByApi() || options_->is_consent_deferred ||
        (android::app::admin::flags::onboarding_consentless_bugreports() &&
        options_->skip_user_consent)) {
        // No need to get consent for shell triggered dumpstates, or not
        // No need to get consent for shell triggered dumpstates, or not
        // through bugreporting API (i.e. no fd to copy back), or when consent
        // through bugreporting API (i.e. no fd to copy back), or when consent
        // is deferred.
        // is deferred.
@@ -3667,7 +3684,8 @@ Dumpstate::RunStatus Dumpstate::CopyBugreportIfUserConsented(int32_t calling_uid
    // If the caller has asked to copy the bugreport over to their directory, we need explicit
    // If the caller has asked to copy the bugreport over to their directory, we need explicit
    // user consent (unless the caller is Shell).
    // user consent (unless the caller is Shell).
    UserConsentResult consent_result;
    UserConsentResult consent_result;
    if (multiuser_get_app_id(calling_uid) == AID_SHELL) {
    if (multiuser_get_app_id(calling_uid) == AID_SHELL || (options_->skip_user_consent
    && android::app::admin::flags::onboarding_consentless_bugreports())) {
        consent_result = UserConsentResult::APPROVED;
        consent_result = UserConsentResult::APPROVED;
    } else {
    } else {
        consent_result = consent_callback_->getResult();
        consent_result = consent_callback_->getResult();
+6 −3
Original line number Original line Diff line number Diff line
@@ -364,7 +364,7 @@ class Dumpstate {
     * Initialize() dumpstate before calling this method.
     * Initialize() dumpstate before calling this method.
     */
     */
    RunStatus Retrieve(int32_t calling_uid, const std::string& calling_package,
    RunStatus Retrieve(int32_t calling_uid, const std::string& calling_package,
                        const bool keep_bugreport_on_retrieval);
                        const bool keep_bugreport_on_retrieval, const bool skip_user_consent);






@@ -412,6 +412,7 @@ class Dumpstate {
        bool do_screenshot = false;
        bool do_screenshot = false;
        bool is_screenshot_copied = false;
        bool is_screenshot_copied = false;
        bool is_consent_deferred = false;
        bool is_consent_deferred = false;
        bool skip_user_consent = false;
        bool is_remote_mode = false;
        bool is_remote_mode = false;
        bool show_header_only = false;
        bool show_header_only = false;
        bool telephony_only = false;
        bool telephony_only = false;
@@ -448,7 +449,8 @@ class Dumpstate {
        void Initialize(BugreportMode bugreport_mode, int bugreport_flags,
        void Initialize(BugreportMode bugreport_mode, int bugreport_flags,
                        const android::base::unique_fd& bugreport_fd,
                        const android::base::unique_fd& bugreport_fd,
                        const android::base::unique_fd& screenshot_fd,
                        const android::base::unique_fd& screenshot_fd,
                        bool is_screenshot_requested);
                        bool is_screenshot_requested,
                        bool skip_user_consent);


        /* Returns true if the options set so far are consistent. */
        /* Returns true if the options set so far are consistent. */
        bool ValidateOptions() const;
        bool ValidateOptions() const;
@@ -564,7 +566,8 @@ class Dumpstate {
  private:
  private:
    RunStatus RunInternal(int32_t calling_uid, const std::string& calling_package);
    RunStatus RunInternal(int32_t calling_uid, const std::string& calling_package);
    RunStatus RetrieveInternal(int32_t calling_uid, const std::string& calling_package,
    RunStatus RetrieveInternal(int32_t calling_uid, const std::string& calling_package,
                                const bool keep_bugreport_on_retrieval);
                                const bool keep_bugreport_on_retrieval,
                                const bool skip_user_consent);


    RunStatus DumpstateDefaultAfterCritical();
    RunStatus DumpstateDefaultAfterCritical();
    RunStatus dumpstate();
    RunStatus dumpstate();
Loading