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

Commit 8b919d0e authored by Xin Li's avatar Xin Li Committed by Gerrit Code Review
Browse files

Merge "Merge Android 14" into main

parents e4b64ebe 1961b2f7
Loading
Loading
Loading
Loading
+3 −99
Original line number Diff line number Diff line
@@ -4,55 +4,10 @@
      "name": "SurfaceFlinger_test",
      "options": [
        {
          "include-filter": "*CredentialsTest.*"
          "include-filter": "*"
        },
        {
          "include-filter": "*SurfaceFlingerStress.*"
        },
        {
          "include-filter": "*SurfaceInterceptorTest.*"
        },
        {
          "include-filter": "*LayerTransactionTest.*"
        },
        {
          "include-filter": "*LayerTypeTransactionTest.*"
        },
        {
          "include-filter": "*LayerUpdateTest.*"
        },
        {
          "include-filter": "*GeometryLatchingTest.*"
        },
        {
          "include-filter": "*CropLatchingTest.*"
        },
        {
          "include-filter": "*ScreenCaptureTest.*"
        },
        {
          "include-filter": "*ScreenCaptureChildOnlyTest.*"
        },
        {
          "include-filter": "*DereferenceSurfaceControlTest.*"
        },
        {
          "include-filter": "*BoundlessLayerTest.*"
        },
        {
          "include-filter": "*MultiDisplayLayerBoundsTest.*"
        },
        {
          "include-filter": "*InvalidHandleTest.*"
        },
        {
          "include-filter": "*VirtualDisplayTest.*"
        },
        {
          "include-filter": "*RelativeZTest.*"
        },
        {
          "include-filter": "*RefreshRateOverlayTest.*"
          "exclude-filter": "*ChildLayerTest#ChildrenSurviveParentDestruction"
        }
      ]
    },
@@ -70,58 +25,7 @@
      "name": "SurfaceFlinger_test",
      "options": [
        {
          "include-filter": "*CredentialsTest.*"
        },
        {
          "include-filter": "*SurfaceFlingerStress.*"
        },
        {
          "include-filter": "*SurfaceInterceptorTest.*"
        },
        {
          "include-filter": "*LayerTransactionTest.*"
        },
        {
          "include-filter": "*LayerTypeTransactionTest.*"
        },
        {
          "include-filter": "*LayerUpdateTest.*"
        },
        {
          "include-filter": "*GeometryLatchingTest.*"
        },
        {
          "include-filter": "*CropLatchingTest.*"
        },
        {
          "include-filter": "*ChildLayerTest.*"
        },
        {
          "include-filter": "*ScreenCaptureTest.*"
        },
        {
          "include-filter": "*ScreenCaptureChildOnlyTest.*"
        },
        {
          "include-filter": "*DereferenceSurfaceControlTest.*"
        },
        {
          "include-filter": "*BoundlessLayerTest.*"
        },
        {
          "include-filter": "*MultiDisplayLayerBoundsTest.*"
        },
        {
          "include-filter": "*InvalidHandleTest.*"
        },
        {
          "include-filter": "*VirtualDisplayTest.*"
        },
        {
          "include-filter": "*RelativeZTest.*"
        },
        {
          "include-filter": "*RefreshRateOverlayTest.*"
          "include-filter": "*"
        }
      ]
    }
+4 −1
Original line number Diff line number Diff line
@@ -155,7 +155,10 @@ cc_test {
        "dumpstate.cpp",
        "tests/dumpstate_test.cpp",
    ],
    static_libs: ["libgmock"],
    static_libs: [
        "libc++fs",
        "libgmock",
    ],
    test_config: "dumpstate_test.xml",
    data: [
        ":dumpstate_test_fixture",
+65 −7
Original line number Diff line number Diff line
@@ -51,13 +51,20 @@ static binder::Status exception(uint32_t code, const std::string& msg,

// Creates a bugreport and exits, thus preserving the oneshot nature of the service.
// Note: takes ownership of data.
[[noreturn]] static void* dumpstate_thread_main(void* data) {
[[noreturn]] static void* dumpstate_thread_bugreport(void* data) {
    std::unique_ptr<DumpstateInfo> ds_info(static_cast<DumpstateInfo*>(data));
    ds_info->ds->Run(ds_info->calling_uid, ds_info->calling_package);
    MYLOGD("Finished taking a bugreport. Exiting.\n");
    exit(0);
}

[[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);
    MYLOGD("Finished retrieving a bugreport. Exiting.\n");
    exit(0);
}

[[noreturn]] static void signalErrorAndExit(sp<IDumpstateListener> listener, int error_code) {
    listener->onError(error_code);
    exit(0);
@@ -84,11 +91,28 @@ status_t DumpstateService::Start() {
    return android::OK;
}

binder::Status DumpstateService::preDumpUiData(const std::string&) {
    std::lock_guard<std::mutex> lock(lock_);
    MYLOGI("preDumpUiData()");

    if (ds_ != nullptr) {
        MYLOGE("Error! DumpstateService is currently already being used. Returning.");
        return exception(binder::Status::EX_SERVICE_SPECIFIC,
                         "DumpstateService is already being used");
    }

    ds_ = &(Dumpstate::GetInstance());
    ds_->PreDumpUiData();

    return binder::Status::ok();
}

binder::Status DumpstateService::startBugreport(int32_t calling_uid,
                                                const std::string& calling_package,
                                                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) {
    MYLOGI("startBugreport() with mode: %d\n", bugreport_mode);
@@ -96,12 +120,12 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid,
    // Ensure there is only one bugreport in progress at a time.
    std::lock_guard<std::mutex> lock(lock_);
    if (ds_ != nullptr) {
        MYLOGE("Error! There is already a bugreport in progress. Returning.");
        MYLOGE("Error! DumpstateService is currently already being used. Returning.");
        if (listener != nullptr) {
            listener->onError(IDumpstateListener::BUGREPORT_ERROR_ANOTHER_REPORT_IN_PROGRESS);
        }
        return exception(binder::Status::EX_SERVICE_SPECIFIC,
                         "There is already a bugreport in progress");
                         "DumpstateService is already being used");
    }

    // From here on, all conditions that indicate we are done with this incoming request should
@@ -123,8 +147,8 @@ 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_fd,
                        screenshot_fd, is_screenshot_requested);
    options->Initialize(static_cast<Dumpstate::BugreportMode>(bugreport_mode), bugreport_flags,
                        bugreport_fd, screenshot_fd, is_screenshot_requested);

    if (bugreport_fd.get() == -1 || (options->do_screenshot && screenshot_fd.get() == -1)) {
        MYLOGE("Invalid filedescriptor");
@@ -148,10 +172,9 @@ binder::Status DumpstateService::startBugreport(int32_t calling_uid,
    pthread_t thread;
    // Initialize dumpstate
    ds_->Initialize();
    status_t err = pthread_create(&thread, nullptr, dumpstate_thread_main, ds_info);
    status_t err = pthread_create(&thread, nullptr, dumpstate_thread_bugreport, ds_info);
    if (err != 0) {
        delete ds_info;
        ds_info = nullptr;
        MYLOGE("Could not create a thread");
        signalErrorAndExit(listener, IDumpstateListener::BUGREPORT_ERROR_RUNTIME_ERROR);
    }
@@ -176,6 +199,41 @@ binder::Status DumpstateService::cancelBugreport(int32_t calling_uid,
    return binder::Status::ok();
}

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

    ds_ = &(Dumpstate::GetInstance());
    DumpstateInfo* ds_info = new DumpstateInfo();
    ds_info->ds = ds_;
    ds_info->calling_uid = calling_uid;
    ds_info->calling_package = calling_package;
    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.
    android::base::unique_fd devnull_fd(
        TEMP_FAILURE_RETRY(open("/dev/null", O_WRONLY | O_CLOEXEC)));

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

    if (bugreport_fd.get() == -1) {
        MYLOGE("Invalid filedescriptor");
        signalErrorAndExit(listener, IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT);
    }
    ds_->SetOptions(std::move(options));
    ds_->path_ = bugreport_file;
    pthread_t thread;
    status_t err = pthread_create(&thread, nullptr, dumpstate_thread_retrieve, ds_info);
    if (err != 0) {
        MYLOGE("Could not create a thread");
        signalErrorAndExit(listener, IDumpstateListener::BUGREPORT_ERROR_RUNTIME_ERROR);
    }
    return binder::Status::ok();
}

status_t DumpstateService::dump(int fd, const Vector<String16>&) {
    std::lock_guard<std::mutex> lock(lock_);
    if (ds_ == nullptr) {
+12 −2
Original line number Diff line number Diff line
@@ -38,13 +38,23 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst

    status_t dump(int fd, const Vector<String16>& args) override;

    binder::Status preDumpUiData(const std::string& callingPackage) override;

    binder::Status startBugreport(int32_t calling_uid, const std::string& calling_package,
                                  android::base::unique_fd bugreport_fd,
                                  android::base::unique_fd screenshot_fd, int bugreport_mode,
                                  const sp<IDumpstateListener>& listener,
                                  int bugreport_flags, const sp<IDumpstateListener>& listener,
                                  bool is_screenshot_requested) override;

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

    binder::Status cancelBugreport(int32_t calling_uid,
                                   const std::string& calling_package) override;

  private:
    // Dumpstate object which contains all the bugreporting logic.
+41 −2
Original line number Diff line number Diff line
@@ -49,6 +49,26 @@ interface IDumpstate {
    // Default mode.
    const int BUGREPORT_MODE_DEFAULT = 6;

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

    // Defer user consent.
    const int BUGREPORT_FLAG_DEFER_CONSENT = 0x2;

    /**
     * Speculatively pre-dumps UI data for a bugreport request that might come later.
     *
     * <p>Triggers the dump of certain critical UI data, e.g. traces stored in short
     * ring buffers that might get lost by the time the actual bugreport is requested.
     *
     * <p>{@code startBugreport} will then pick the pre-dumped data if:
     * - {@link BUGREPORT_FLAG_USE_PREDUMPED_UI_DATA} is specified.
     * - {@code preDumpUiData} and {@code startBugreport} were called by the same UID.
     *
     * @param callingPackage package of the original application that requested the report.
     */
    void preDumpUiData(@utf8InCpp String callingPackage);

    /**
     * Starts a bugreport in the background.
     *
@@ -63,13 +83,14 @@ interface IDumpstate {
     * @param bugreportFd the file to which the zipped bugreport should be written
     * @param screenshotFd the file to which screenshot should be written
     * @param bugreportMode the mode that specifies other run time options; must be one of above
     * @param bugreportFlags flags to customize the bugreport generation
     * @param listener callback for updates; optional
     * @param isScreenshotRequested indicates screenshot is requested or not
     */
    void startBugreport(int callingUid, @utf8InCpp String callingPackage,
                        FileDescriptor bugreportFd, FileDescriptor screenshotFd,
                        int bugreportMode, IDumpstateListener listener,
                        boolean isScreenshotRequested);
                        int bugreportMode, int bugreportFlags,
                        IDumpstateListener listener, boolean isScreenshotRequested);

    /**
     * Cancels the bugreport currently in progress.
@@ -82,4 +103,22 @@ interface IDumpstate {
     * @param callingPackage package of the original application that requested the cancellation.
     */
    void cancelBugreport(int callingUid, @utf8InCpp String callingPackage);

    /**
     * Retrieves a previously generated bugreport.
     *
     * <p>The caller must have previously generated a bugreport using
     * {@link #startBugreport} with the {@link BUGREPORT_FLAG_DEFER_CONSENT}
     * flag set.
     *
     * @param callingUid UID of the original application that requested the report.
     * @param callingPackage package of the original application 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 listener callback for updates; optional
     */
    void retrieveBugreport(int callingUid, @utf8InCpp String callingPackage,
                           FileDescriptor bugreportFd,
                           @utf8InCpp String bugreportFile,
                           IDumpstateListener listener);
}
Loading