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

Commit 3b25ae15 authored by Jiyong Park's avatar Jiyong Park
Browse files

unique_fd is passed by value in AIDL interfaces

FileDescriptor type in AIDL was translated into const unique_fd& in C++.
Now, it is unique_fd, i.e. passed by value, to make it easier to keep it
beyond the scope of the call.

Bug: 144943748
Test: m
Change-Id: Id0fead2717b1f6a3b9a1867efa8b588b59d3fbd2
parent 470eee76
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -81,8 +81,8 @@ status_t DumpstateService::Start() {

binder::Status DumpstateService::startBugreport(int32_t calling_uid,
                                                const std::string& calling_package,
                                                const android::base::unique_fd& bugreport_fd,
                                                const android::base::unique_fd& screenshot_fd,
                                                android::base::unique_fd bugreport_fd,
                                                android::base::unique_fd screenshot_fd,
                                                int bugreport_mode,
                                                const sp<IDumpstateListener>& listener) {
    MYLOGI("startBugreport() with mode: %d\n", bugreport_mode);
+2 −2
Original line number Diff line number Diff line
@@ -39,8 +39,8 @@ class DumpstateService : public BinderService<DumpstateService>, public BnDumpst
    status_t dump(int fd, const Vector<String16>& args) override;

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

    // No-op
+8 −4
Original line number Diff line number Diff line
@@ -444,7 +444,7 @@ TEST_F(DumpstateBinderTest, Baseline) {

    sp<DumpstateListener> listener(new DumpstateListener(dup(fileno(stdout))));
    android::binder::Status status =
        ds_binder->startBugreport(123, "com.dummy.package", bugreport_fd, screenshot_fd,
        ds_binder->startBugreport(123, "com.dummy.package", std::move(bugreport_fd), std::move(screenshot_fd),
                                  Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE, listener);
    // startBugreport is an async call. Verify binder call succeeded first, then wait till listener
    // gets expected callbacks.
@@ -480,7 +480,7 @@ TEST_F(DumpstateBinderTest, ServiceDies_OnInvalidInput) {
    // Call startBugreport with bad arguments.
    sp<DumpstateListener> listener(new DumpstateListener(dup(fileno(stdout))));
    android::binder::Status status =
        ds_binder->startBugreport(123, "com.dummy.package", bugreport_fd, screenshot_fd,
        ds_binder->startBugreport(123, "com.dummy.package", std::move(bugreport_fd), std::move(screenshot_fd),
                                  2000,  // invalid bugreport mode
                                  listener);
    EXPECT_EQ(listener->getErrorCode(), IDumpstateListener::BUGREPORT_ERROR_INVALID_INPUT);
@@ -501,20 +501,24 @@ TEST_F(DumpstateBinderTest, SimultaneousBugreportsNotAllowed) {

    // Prepare arguments
    unique_fd bugreport_fd(OpenForWrite("/data/local/tmp/tmp.zip"));
    unique_fd bugreport_fd2(dup(bugreport_fd.get()));
    unique_fd screenshot_fd(OpenForWrite("/data/local/tmp/tmp.png"));
    unique_fd screenshot_fd2(dup(screenshot_fd.get()));

    EXPECT_NE(bugreport_fd.get(), -1);
    EXPECT_NE(bugreport_fd2.get(), -1);
    EXPECT_NE(screenshot_fd.get(), -1);
    EXPECT_NE(screenshot_fd2.get(), -1);

    sp<DumpstateListener> listener1(new DumpstateListener(dup(fileno(stdout))));
    android::binder::Status status =
        ds_binder->startBugreport(123, "com.dummy.package", bugreport_fd, screenshot_fd,
        ds_binder->startBugreport(123, "com.dummy.package", std::move(bugreport_fd), std::move(screenshot_fd),
                                  Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE, listener1);
    EXPECT_TRUE(status.isOk());

    // try to make another call to startBugreport. This should fail.
    sp<DumpstateListener> listener2(new DumpstateListener(dup(fileno(stdout))));
    status = ds_binder->startBugreport(123, "com.dummy.package", bugreport_fd, screenshot_fd,
    status = ds_binder->startBugreport(123, "com.dummy.package", std::move(bugreport_fd2), std::move(screenshot_fd2),
                                       Dumpstate::BugreportMode::BUGREPORT_INTERACTIVE, listener2);
    EXPECT_FALSE(status.isOk());
    WaitTillExecutionComplete(listener2.get());
+1 −1
Original line number Diff line number Diff line
@@ -2401,7 +2401,7 @@ struct fsverity_measurement {
#endif

binder::Status InstalldNativeService::installApkVerity(const std::string& filePath,
        const ::android::base::unique_fd& verityInputAshmem, int32_t contentSize) {
        android::base::unique_fd verityInputAshmem, int32_t contentSize) {
    ENFORCE_UID(AID_SYSTEM);
    CHECK_ARGUMENT_PATH(filePath);
    std::lock_guard<std::recursive_mutex> lock(mLock);
+1 −1
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ public:
    binder::Status deleteOdex(const std::string& apkPath, const std::string& instructionSet,
            const std::unique_ptr<std::string>& outputPath);
    binder::Status installApkVerity(const std::string& filePath,
            const ::android::base::unique_fd& verityInput, int32_t contentSize);
            android::base::unique_fd verityInput, int32_t contentSize);
    binder::Status assertFsverityRootHashMatches(const std::string& filePath,
            const std::vector<uint8_t>& expectedHash);
    binder::Status reconcileSecondaryDexFile(const std::string& dexPath,