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

Commit 96c424ea authored by Kholoud Mohamed's avatar Kholoud Mohamed Committed by Android (Google) Code Review
Browse files

Merge "Skip user consent for subsequent reports" into main

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

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) {
    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");
    exit(0);
}
@@ -116,7 +118,8 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid,
                                                int bugreport_mode,
                                                int bugreport_flags,
                                                const sp<IDumpstateListener>& listener,
                                                bool is_screenshot_requested) {
                                                bool is_screenshot_requested,
                                                bool skip_user_consent) {
    MYLOGI("startBugreport() with mode: %d\n", bugreport_mode);

    // 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>();
    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)) {
        MYLOGE("Invalid filedescriptor");
@@ -207,6 +210,7 @@ binder::Status DumpstateService::retrieveBugreport(
    android::base::unique_fd bugreport_fd,
    const std::string& bugreport_file,
    const bool keep_bugreport_on_retrieval,
    const bool skip_user_consent,
    const sp<IDumpstateListener>& listener) {

    ds_ = &(Dumpstate::GetInstance());
@@ -216,6 +220,7 @@ binder::Status DumpstateService::retrieveBugreport(
    ds_info->calling_package = calling_package;
    ds_info->user_id = user_id;
    ds_info->keep_bugreport_on_retrieval = keep_bugreport_on_retrieval;
    ds_info->skip_user_consent = skip_user_consent;
    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.
@@ -223,7 +228,7 @@ binder::Status DumpstateService::retrieveBugreport(
        TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY | O_CLOEXEC)));

    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) {
        MYLOGE("Invalid filedescriptor");
+2 −1
Original line number 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 screenshot_fd, int bugreport_mode,
                                  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,
                                     const std::string& calling_package,
@@ -52,6 +52,7 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst
                                     android::base::unique_fd bugreport_fd,
                                     const std::string& bugreport_file,
                                     const bool keep_bugreport_on_retrieval,
                                     const bool skip_user_consent,
                                     const sp<IDumpstateListener>& listener)
                                     override;

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

    /**
     * Cancels the bugreport currently in progress.
@@ -130,5 +131,6 @@ interface IDumpstate {
                           FileDescriptor bugreportFd,
                           @utf8InCpp String bugreportFile,
                           boolean keepBugreportOnRetrieval,
                           boolean skipUserConsent,
                           IDumpstateListener listener);
}
+47 −36
Original line number Diff line number Diff line
@@ -2902,9 +2902,11 @@ void Dumpstate::DumpOptions::Initialize(BugreportMode bugreport_mode,
                                        int bugreport_flags,
                                        const android::base::unique_fd& bugreport_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->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.
    bugreport_fd.reset(fcntl(bugreport_fd_in.get(), F_DUPFD_CLOEXEC, 0));
    screenshot_fd.reset(fcntl(screenshot_fd_in.get(), F_DUPFD_CLOEXEC, 0));
@@ -2992,16 +2994,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,
                                         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,
                                                    keep_bugreport_on_retrieval);
                                                    keep_bugreport_on_retrieval,
                                                    skip_user_consent);
    HandleRunStatus(status);
    return status;
}

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

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

  bool copy_succeeded =
      android::os::CopyFileToFd(path_, options_->bugreport_fd.get());
@@ -3510,7 +3518,9 @@ void Dumpstate::onUiIntensiveBugreportDumpsFinished(int32_t calling_uid) {

void Dumpstate::MaybeCheckUserConsent(int32_t calling_uid, const std::string& calling_package) {
    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
        // through bugreporting API (i.e. no fd to copy back), or when consent
        // is deferred.
@@ -3596,7 +3606,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
    // user consent (unless the caller is Shell).
    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;
    } else {
        consent_result = consent_callback_->getResult();
+6 −3
Original line number Diff line number Diff line
@@ -364,7 +364,7 @@ class Dumpstate {
     * Initialize() dumpstate before calling this method.
     */
    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 is_screenshot_copied = false;
        bool is_consent_deferred = false;
        bool skip_user_consent = false;
        bool is_remote_mode = false;
        bool show_header_only = false;
        bool telephony_only = false;
@@ -448,7 +449,8 @@ class Dumpstate {
        void Initialize(BugreportMode bugreport_mode, int bugreport_flags,
                        const android::base::unique_fd& bugreport_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. */
        bool ValidateOptions() const;
@@ -564,7 +566,8 @@ class Dumpstate {
  private:
    RunStatus RunInternal(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 dumpstate();
Loading