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

Commit 17be5904 authored by Xin Li's avatar Xin Li Committed by Gerrit Code Review
Browse files

Merge "Merge Android 14 QPR2 to AOSP main" into main

parents 3ef8cc8d df7e6218
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",
+8 −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);
}
@@ -141,6 +143,7 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid,
        bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_WEAR &&
        bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_TELEPHONY &&
        bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_WIFI &&
        bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_ONBOARDING &&
        bugreport_mode != Dumpstate::BugreportMode::BUGREPORT_DEFAULT) {
        MYLOGE("Invalid input: bad bugreport mode: %d", bugreport_mode);
        signalErrorAndExit(listener, IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT);
@@ -200,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());
@@ -210,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;

+11 −1
Original line number Diff line number Diff line
@@ -49,12 +49,18 @@ interface IDumpstate {
    // Default mode.
    const int BUGREPORT_MODE_DEFAULT = 6;

    // Bugreport taken for onboarding related flows.
    const int BUGREPORT_MODE_ONBOARDING = 7;

    // Use pre-dumped data.
    const int BUGREPORT_FLAG_USE_PREDUMPED_UI_DATA = 0x1;

    // 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.
     *
@@ -113,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);
}
+58 −59
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>
@@ -1088,8 +1089,14 @@ static void MaybeAddSystemTraceToZip() {
    // This function copies into the .zip the system trace that was snapshotted
    // by the early call to MaybeSnapshotSystemTrace(), if any background
    // tracing was happening.
    if (!ds.has_system_trace_) {
        // No background trace was happening at the time dumpstate was invoked.
    bool system_trace_exists = access(SYSTEM_TRACE_SNAPSHOT, F_OK) == 0;
    if (!system_trace_exists) {
        // No background trace was happening at the time MaybeSnapshotSystemTrace() was invoked.
        if (!PropertiesHelper::IsUserBuild()) {
            MYLOGI(
                "No system traces found. Check for previously uploaded traces by looking for "
                "go/trace-uuid in logcat")
        }
        return;
    }
    ds.AddZipEntry(
@@ -1653,8 +1660,6 @@ Dumpstate::RunStatus Dumpstate::dumpstate() {
        dump_board = ds.dump_pool_->enqueueTaskWithFd(
            DUMP_BOARD_TASK, &Dumpstate::DumpstateBoard, &ds, _1);
        dump_checkins = ds.dump_pool_->enqueueTaskWithFd(DUMP_CHECKINS_TASK, &DumpCheckins, _1);
        post_process_ui_traces = ds.dump_pool_->enqueueTask(
            POST_PROCESS_UI_TRACES_TASK, &Dumpstate::MaybePostProcessUiTraces, &ds);
    }

    // Dump various things. Note that anything that takes "long" (i.e. several seconds) should
@@ -1864,12 +1869,6 @@ Dumpstate::RunStatus Dumpstate::dumpstate() {
                DumpIncidentReport);
    }

    if (ds.dump_pool_) {
        WaitForTask(std::move(post_process_ui_traces));
    } else {
        RUN_SLOW_FUNCTION_AND_LOG(POST_PROCESS_UI_TRACES_TASK, MaybePostProcessUiTraces);
    }

    MaybeAddUiTracesToZip();

    return Dumpstate::RunStatus::OK;
@@ -2178,6 +2177,11 @@ static void DumpstateWifiOnly() {
    printf("========================================================\n");
}

// Collects a lightweight dumpstate to be used for debugging onboarding related flows.
static void DumpstateOnboardingOnly() {
    ds.AddDir(LOGPERSIST_DATA_DIR, false);
}

Dumpstate::RunStatus Dumpstate::DumpTraces(const char** path) {
    const std::string temp_file_pattern = ds.bugreport_internal_dir_ + "/dumptrace_XXXXXX";
    const size_t buf_size = temp_file_pattern.length() + 1;
@@ -2310,6 +2314,7 @@ static dumpstate_hal_hidl::DumpstateMode GetDumpstateHalModeHidl(
            return dumpstate_hal_hidl::DumpstateMode::CONNECTIVITY;
        case Dumpstate::BugreportMode::BUGREPORT_WIFI:
            return dumpstate_hal_hidl::DumpstateMode::WIFI;
        case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
        case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
            return dumpstate_hal_hidl::DumpstateMode::DEFAULT;
    }
@@ -2331,6 +2336,7 @@ static dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode GetDumpstateHalModeAi
            return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::CONNECTIVITY;
        case Dumpstate::BugreportMode::BUGREPORT_WIFI:
            return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::WIFI;
        case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
        case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
            return dumpstate_hal_aidl::IDumpstateDevice::DumpstateMode::DEFAULT;
    }
@@ -2814,6 +2820,8 @@ static inline const char* ModeToString(Dumpstate::BugreportMode mode) {
            return "BUGREPORT_TELEPHONY";
        case Dumpstate::BugreportMode::BUGREPORT_WIFI:
            return "BUGREPORT_WIFI";
        case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
            return "BUGREPORT_ONBOARDING";
        case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
            return "BUGREPORT_DEFAULT";
    }
@@ -2859,6 +2867,10 @@ static void SetOptionsFromMode(Dumpstate::BugreportMode mode, Dumpstate::DumpOpt
            options->wifi_only = true;
            options->do_screenshot = false;
            break;
        case Dumpstate::BugreportMode::BUGREPORT_ONBOARDING:
            options->onboarding_only = true;
            options->do_screenshot = false;
            break;
        case Dumpstate::BugreportMode::BUGREPORT_DEFAULT:
            break;
    }
@@ -2971,14 +2983,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(
@@ -3013,9 +3028,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;
}
@@ -3066,6 +3084,7 @@ void Dumpstate::Cancel() {
}

void Dumpstate::PreDumpUiData() {
    MaybeSnapshotSystemTrace();
    MaybeSnapshotUiTraces();
}

@@ -3252,25 +3271,23 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
    // duration is logged into MYLOG instead.
    PrintHeader();

    bool is_dumpstate_restricted = options_->telephony_only
                                   || options_->wifi_only
                                   || options_->limited_only;
    if (!is_dumpstate_restricted) {
        // Invoke critical dumpsys first to preserve system state, before doing anything else.
        RunDumpsysCritical();
    }
    MaybeTakeEarlyScreenshot();

    bool is_dumpstate_restricted =
        options_->telephony_only || options_->wifi_only || options_->limited_only;
    if (!is_dumpstate_restricted) {
        // Snapshot the system trace now (if running) to avoid that dumpstate's
        // own activity pushes out interesting data from the trace ring buffer.
        // The trace file is added to the zip by MaybeAddSystemTraceToZip().
        MaybeSnapshotSystemTrace();

        // Invoke critical dumpsys to preserve system state, before doing anything else.
        RunDumpsysCritical();

        // Snapshot the UI traces now (if running).
        // The trace files will be added to bugreport later.
        MaybeSnapshotUiTraces();
    }

    MaybeTakeEarlyScreenshot();
    onUiIntensiveBugreportDumpsFinished(calling_uid);
    MaybeCheckUserConsent(calling_uid, calling_package);
    if (options_->telephony_only) {
@@ -3279,6 +3296,8 @@ Dumpstate::RunStatus Dumpstate::RunInternal(int32_t calling_uid,
        DumpstateWifiOnly();
    } else if (options_->limited_only) {
        DumpstateLimitedOnly();
    } else if (options_->onboarding_only) {
        DumpstateOnboardingOnly();
    } else {
        // Dump state for the default case. This also drops root.
        RunStatus s = DumpstateDefaultAfterCritical();
@@ -3366,6 +3385,19 @@ void Dumpstate::MaybeTakeEarlyScreenshot() {
}

void Dumpstate::MaybeSnapshotSystemTrace() {
    // When capturing traces via bugreport handler (BH), this function will be invoked twice:
    // 1) When BH invokes IDumpstate::PreDumpUiData()
    // 2) When BH invokes IDumpstate::startBugreport(flags = BUGREPORT_USE_PREDUMPED_UI_DATA)
    // In this case we don't want to re-invoke perfetto in step 2.
    // In all other standard invocation states, this function is invoked once
    // without the flag BUGREPORT_USE_PREDUMPED_UI_DATA.
    if (options_->use_predumped_ui_data) {
        return;
    }

    // If a stale file exists already, remove it.
    unlink(SYSTEM_TRACE_SNAPSHOT);

    // If a background system trace is happening and is marked as "suitable for
    // bugreport" (i.e. bugreport_score > 0 in the trace config), this command
    // will stop it and serialize into SYSTEM_TRACE_SNAPSHOT. In the (likely)
@@ -3373,14 +3405,8 @@ void Dumpstate::MaybeSnapshotSystemTrace() {
    // Note: this should not be enqueued as we need to freeze the trace before
    // dumpstate starts. Otherwise the trace ring buffers will contain mostly
    // the dumpstate's own activity which is irrelevant.
    int res = RunCommand(
        "SERIALIZE PERFETTO TRACE",
        {"perfetto", "--save-for-bugreport"},
        CommandOptions::WithTimeout(10)
            .DropRoot()
            .CloseAllFileDescriptorsOnExec()
            .Build());
    has_system_trace_ = res == 0;
    RunCommand("SERIALIZE PERFETTO TRACE", {"perfetto", "--save-for-bugreport"},
               CommandOptions::WithTimeout(10).DropRoot().CloseAllFileDescriptorsOnExec().Build());
    // MaybeAddSystemTraceToZip() will take care of copying the trace in the zip
    // file in the later stages.
}
@@ -3407,33 +3433,6 @@ void Dumpstate::MaybeSnapshotUiTraces() {
            "", command,
            CommandOptions::WithTimeout(10).Always().DropRoot().RedirectStderr().Build());
    }

    // This command needs to be run as root
    static const auto SURFACEFLINGER_COMMAND_SAVE_ALL_TRACES = std::vector<std::string> {
        "service", "call", "SurfaceFlinger", "1042"
    };
    // Empty name because it's not intended to be classified as a bugreport section.
    // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport.
    RunCommand(
        "", SURFACEFLINGER_COMMAND_SAVE_ALL_TRACES,
        CommandOptions::WithTimeout(10).Always().AsRoot().RedirectStderr().Build());
}

void Dumpstate::MaybePostProcessUiTraces() {
    if (PropertiesHelper::IsUserBuild()) {
        return;
    }

    RunCommand(
        // Empty name because it's not intended to be classified as a bugreport section.
        // Actual tracing files can be found in "/data/misc/wmtrace/" in the bugreport.
        "", {
            "/system/xbin/su", "system",
            "/system/bin/layertracegenerator",
            "/data/misc/wmtrace/transactions_trace.winscope",
            "/data/misc/wmtrace/layers_trace_from_transactions.winscope"
        },
        CommandOptions::WithTimeout(120).Always().RedirectStderr().Build());
}

void Dumpstate::MaybeAddUiTracesToZip() {
Loading