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

Commit 8af9115c authored by Yifan Hong's avatar Yifan Hong Committed by Automerger Merge Worker
Browse files

Merge changes from topic "binder_tls" am: ab281ec6

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1792851

Change-Id: I0912ce1bd2652894a310678f1abe71403fd8f2fc
parents 1fe4c3d9 ab281ec6
Loading
Loading
Loading
Loading
+36 −0
Original line number Diff line number Diff line
@@ -235,6 +235,42 @@ cc_library {
    },
}

cc_defaults {
    name: "libbinder_tls_shared_deps",
    shared_libs: [
        "libbinder",
        "libcrypto",
        "liblog",
        "libssl",
        "libutils",
    ],
}

cc_defaults {
    name: "libbinder_tls_defaults",
    defaults: ["libbinder_tls_shared_deps"],
    host_supported: true,

    header_libs: [
        "libbinder_headers",
    ],
    export_header_lib_headers: [
        "libbinder_headers",
    ],
    export_include_dirs: ["include_tls"],
    static_libs: [
        "libbase",
    ],
    srcs: [
        "RpcTransportTls.cpp",
    ],
}

cc_library_shared {
    name: "libbinder_tls",
    defaults: ["libbinder_tls_defaults"],
}

// AIDL interface between libbinder and framework.jar
filegroup {
    name: "libbinder_aidl",
+15 −0
Original line number Diff line number Diff line
@@ -59,4 +59,19 @@ status_t FdTrigger::triggerablePoll(base::borrowed_fd fd, int16_t event) {
    }
}

android::base::Result<bool> FdTrigger::isTriggeredPolled() {
    pollfd pfd{.fd = mRead.get(), .events = 0, .revents = 0};
    int ret = TEMP_FAILURE_RETRY(poll(&pfd, 1, 0));
    if (ret < 0) {
        return android::base::ErrnoError() << "FdTrigger::isTriggeredPolled: Error in poll()";
    }
    if (ret == 0) {
        return false;
    }
    if (pfd.revents & POLLHUP) {
        return true;
    }
    return android::base::Error() << "FdTrigger::isTriggeredPolled: poll() returns " << pfd.revents;
}

} // namespace android
+12 −1
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

#include <memory>

#include <android-base/result.h>
#include <android-base/unique_fd.h>
#include <utils/Errors.h>

@@ -34,7 +35,7 @@ public:
    void trigger();

    /**
     * Whether this has been triggered.
     * Check whether this has been triggered by checking the write end.
     */
    bool isTriggered();

@@ -49,6 +50,16 @@ public:
     */
    status_t triggerablePoll(base::borrowed_fd fd, int16_t event);

    /**
     * Check whether this has been triggered by poll()ing the read end.
     *
     * Return:
     *   true - triggered
     *   false - not triggered
     *   error - error when polling
     */
    android::base::Result<bool> isTriggeredPolled();

private:
    base::unique_fd mWrite;
    base::unique_fd mRead;
+535 −0

File added.

Preview size limit exceeded, changes collapsed.

+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2021 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// Wraps the transport layer of RPC. Implementation uses TLS.

#pragma once

#include <binder/RpcTransport.h>

namespace android {

// RpcTransportCtxFactory with TLS enabled with self-signed certificate.
class RpcTransportCtxFactoryTls : public RpcTransportCtxFactory {
public:
    static std::unique_ptr<RpcTransportCtxFactory> make();

    std::unique_ptr<RpcTransportCtx> newServerCtx() const override;
    std::unique_ptr<RpcTransportCtx> newClientCtx() const override;
    const char* toCString() const override;

private:
    RpcTransportCtxFactoryTls() = default;
};

} // namespace android