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

Commit 75749da5 authored by Android Build Coastguard Worker's avatar Android Build Coastguard Worker
Browse files

Snap for 12530792 from 84b7155f to 25Q1-release

Change-Id: I61b0ad7f19abc1f51199c515406c9d8c7edf2450
parents 7c3062bf 84b7155f
Loading
Loading
Loading
Loading
+40 −43
Original line number Diff line number Diff line
@@ -31,7 +31,8 @@ constexpr bool kUseCache = false;
#endif

using AidlServiceManager = android::os::IServiceManager;
using IAccessor = android::os::IAccessor;
using android::os::IAccessor;
using binder::Status;

static const char* kStaticCachableList[] = {
        // go/keep-sorted start
@@ -118,10 +119,10 @@ bool BinderCacheWithInvalidation::isClientSideCachingEnabled(const std::string&
    return false;
}

binder::Status BackendUnifiedServiceManager::updateCache(const std::string& serviceName,
Status BackendUnifiedServiceManager::updateCache(const std::string& serviceName,
                                                 const os::Service& service) {
    if (!kUseCache) {
        return binder::Status::ok();
        return Status::ok();
    }
    std::string traceStr;
    if (atrace_is_tag_enabled(ATRACE_TAG_AIDL)) {
@@ -149,7 +150,7 @@ binder::Status BackendUnifiedServiceManager::updateCache(const std::string& serv
                                          "caching_not_enabled");
        }
    }
    return binder::Status::ok();
    return Status::ok();
}

bool BackendUnifiedServiceManager::returnIfCached(const std::string& serviceName,
@@ -175,21 +176,20 @@ sp<AidlServiceManager> BackendUnifiedServiceManager::getImpl() {
    return mTheRealServiceManager;
}

binder::Status BackendUnifiedServiceManager::getService(const ::std::string& name,
Status BackendUnifiedServiceManager::getService(const ::std::string& name,
                                                sp<IBinder>* _aidl_return) {
    os::Service service;
    binder::Status status = getService2(name, &service);
    Status status = getService2(name, &service);
    *_aidl_return = service.get<os::Service::Tag::binder>();
    return status;
}

binder::Status BackendUnifiedServiceManager::getService2(const ::std::string& name,
                                                         os::Service* _out) {
Status BackendUnifiedServiceManager::getService2(const ::std::string& name, os::Service* _out) {
    if (returnIfCached(name, _out)) {
        return binder::Status::ok();
        return Status::ok();
    }
    os::Service service;
    binder::Status status = mTheRealServiceManager->getService2(name, &service);
    Status status = mTheRealServiceManager->getService2(name, &service);

    if (status.isOk()) {
        status = toBinderService(name, service, _out);
@@ -200,14 +200,13 @@ binder::Status BackendUnifiedServiceManager::getService2(const ::std::string& na
    return status;
}

binder::Status BackendUnifiedServiceManager::checkService(const ::std::string& name,
                                                          os::Service* _out) {
Status BackendUnifiedServiceManager::checkService(const ::std::string& name, os::Service* _out) {
    os::Service service;
    if (returnIfCached(name, _out)) {
        return binder::Status::ok();
        return Status::ok();
    }

    binder::Status status = mTheRealServiceManager->checkService(name, &service);
    Status status = mTheRealServiceManager->checkService(name, &service);
    if (status.isOk()) {
        status = toBinderService(name, service, _out);
        if (status.isOk()) {
@@ -217,16 +216,15 @@ binder::Status BackendUnifiedServiceManager::checkService(const ::std::string& n
    return status;
}

binder::Status BackendUnifiedServiceManager::toBinderService(const ::std::string& name,
                                                             const os::Service& in,
                                                             os::Service* _out) {
Status BackendUnifiedServiceManager::toBinderService(const ::std::string& name,
                                                     const os::Service& in, os::Service* _out) {
    switch (in.getTag()) {
        case os::Service::Tag::binder: {
            if (in.get<os::Service::Tag::binder>() == nullptr) {
                // failed to find a service. Check to see if we have any local
                // injected Accessors for this service.
                os::Service accessor;
                binder::Status status = getInjectedAccessor(name, &accessor);
                Status status = getInjectedAccessor(name, &accessor);
                if (!status.isOk()) {
                    *_out = os::Service::make<os::Service::Tag::binder>(nullptr);
                    return status;
@@ -242,7 +240,7 @@ binder::Status BackendUnifiedServiceManager::toBinderService(const ::std::string
            }

            *_out = in;
            return binder::Status::ok();
            return Status::ok();
        }
        case os::Service::Tag::accessor: {
            sp<IBinder> accessorBinder = in.get<os::Service::Tag::accessor>();
@@ -250,11 +248,11 @@ binder::Status BackendUnifiedServiceManager::toBinderService(const ::std::string
            if (accessor == nullptr) {
                ALOGE("Service#accessor doesn't have accessor. VM is maybe starting...");
                *_out = os::Service::make<os::Service::Tag::binder>(nullptr);
                return binder::Status::ok();
                return Status::ok();
            }
            auto request = [=] {
                os::ParcelFileDescriptor fd;
                binder::Status ret = accessor->addConnection(&fd);
                Status ret = accessor->addConnection(&fd);
                if (ret.isOk()) {
                    return base::unique_fd(fd.release());
                } else {
@@ -267,11 +265,11 @@ binder::Status BackendUnifiedServiceManager::toBinderService(const ::std::string
            if (status != OK) {
                ALOGE("Failed to set up preconnected binder RPC client: %s",
                      statusToString(status).c_str());
                return binder::Status::fromStatusT(status);
                return Status::fromStatusT(status);
            }
            session->setSessionSpecificRoot(accessorBinder);
            *_out = os::Service::make<os::Service::Tag::binder>(session->getRootObject());
            return binder::Status::ok();
            return Status::ok();
        }
        default: {
            LOG_ALWAYS_FATAL("Unknown service type: %d", in.getTag());
@@ -279,53 +277,52 @@ binder::Status BackendUnifiedServiceManager::toBinderService(const ::std::string
    }
}

binder::Status BackendUnifiedServiceManager::addService(const ::std::string& name,
                                                        const sp<IBinder>& service,
                                                        bool allowIsolated, int32_t dumpPriority) {
Status BackendUnifiedServiceManager::addService(const ::std::string& name,
                                                const sp<IBinder>& service, bool allowIsolated,
                                                int32_t dumpPriority) {
    return mTheRealServiceManager->addService(name, service, allowIsolated, dumpPriority);
}
binder::Status BackendUnifiedServiceManager::listServices(
        int32_t dumpPriority, ::std::vector<::std::string>* _aidl_return) {
Status BackendUnifiedServiceManager::listServices(int32_t dumpPriority,
                                                  ::std::vector<::std::string>* _aidl_return) {
    return mTheRealServiceManager->listServices(dumpPriority, _aidl_return);
}
binder::Status BackendUnifiedServiceManager::registerForNotifications(
Status BackendUnifiedServiceManager::registerForNotifications(
        const ::std::string& name, const sp<os::IServiceCallback>& callback) {
    return mTheRealServiceManager->registerForNotifications(name, callback);
}
binder::Status BackendUnifiedServiceManager::unregisterForNotifications(
Status BackendUnifiedServiceManager::unregisterForNotifications(
        const ::std::string& name, const sp<os::IServiceCallback>& callback) {
    return mTheRealServiceManager->unregisterForNotifications(name, callback);
}
binder::Status BackendUnifiedServiceManager::isDeclared(const ::std::string& name,
                                                        bool* _aidl_return) {
Status BackendUnifiedServiceManager::isDeclared(const ::std::string& name, bool* _aidl_return) {
    return mTheRealServiceManager->isDeclared(name, _aidl_return);
}
binder::Status BackendUnifiedServiceManager::getDeclaredInstances(
Status BackendUnifiedServiceManager::getDeclaredInstances(
        const ::std::string& iface, ::std::vector<::std::string>* _aidl_return) {
    return mTheRealServiceManager->getDeclaredInstances(iface, _aidl_return);
}
binder::Status BackendUnifiedServiceManager::updatableViaApex(
Status BackendUnifiedServiceManager::updatableViaApex(
        const ::std::string& name, ::std::optional<::std::string>* _aidl_return) {
    return mTheRealServiceManager->updatableViaApex(name, _aidl_return);
}
binder::Status BackendUnifiedServiceManager::getUpdatableNames(
        const ::std::string& apexName, ::std::vector<::std::string>* _aidl_return) {
Status BackendUnifiedServiceManager::getUpdatableNames(const ::std::string& apexName,
                                                       ::std::vector<::std::string>* _aidl_return) {
    return mTheRealServiceManager->getUpdatableNames(apexName, _aidl_return);
}
binder::Status BackendUnifiedServiceManager::getConnectionInfo(
Status BackendUnifiedServiceManager::getConnectionInfo(
        const ::std::string& name, ::std::optional<os::ConnectionInfo>* _aidl_return) {
    return mTheRealServiceManager->getConnectionInfo(name, _aidl_return);
}
binder::Status BackendUnifiedServiceManager::registerClientCallback(
Status BackendUnifiedServiceManager::registerClientCallback(
        const ::std::string& name, const sp<IBinder>& service,
        const sp<os::IClientCallback>& callback) {
    return mTheRealServiceManager->registerClientCallback(name, service, callback);
}
binder::Status BackendUnifiedServiceManager::tryUnregisterService(const ::std::string& name,
Status BackendUnifiedServiceManager::tryUnregisterService(const ::std::string& name,
                                                          const sp<IBinder>& service) {
    return mTheRealServiceManager->tryUnregisterService(name, service);
}
binder::Status BackendUnifiedServiceManager::getServiceDebugInfo(
Status BackendUnifiedServiceManager::getServiceDebugInfo(
        ::std::vector<os::ServiceDebugInfo>* _aidl_return) {
    return mTheRealServiceManager->getServiceDebugInfo(_aidl_return);
}
+2 −2
Original line number Diff line number Diff line
@@ -255,7 +255,7 @@ ABinderRpc_Accessor* ABinderRpc_Accessor_new(
                    "new variant was added to the ABinderRpc_ConnectionInfo and this needs to be "
                    "updated.");
        }
        return OK;
        return STATUS_OK;
    };
    sp<IBinder> accessorBinder = android::createAccessor(String16(instance), std::move(generate));
    if (accessorBinder == nullptr) {
@@ -321,7 +321,7 @@ binder_status_t ABinderRpc_Accessor_delegateAccessor(const char* instance, AIBin
    // This AIBinder needs a strong ref to pass ownership to the caller
    binder->incStrong(nullptr);
    *outDelegator = binder.get();
    return OK;
    return STATUS_OK;
}

ABinderRpc_ConnectionInfo* ABinderRpc_ConnectionInfo_new(const sockaddr* addr, socklen_t len) {
+5 −0
Original line number Diff line number Diff line
@@ -287,6 +287,11 @@ ABinderRpc_Accessor* _Nullable ABinderRpc_Accessor_fromBinder(const char* _Nonnu
 *        this object with one strong ref count and is responsible for removing
 *        that ref count with with AIBinder_decStrong when the caller wishes to
 *        drop the reference.
 * \return STATUS_OK on success.
 *         STATUS_UNEXPECTED_NULL if instance or binder arguments are null.
 *         STATUS_BAD_TYPE if the binder is not an IAccessor.
 *         STATUS_NAME_NOT_FOUND if the binder is an IAccessor, but not
 *         associated with the provided instance name.
 */
binder_status_t ABinderRpc_Accessor_delegateAccessor(const char* _Nonnull instance,
                                                     AIBinder* _Nonnull binder,
+0 −2
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@ rust_library {
        "libdowncast_rs",
        "liblibc",
        "liblog_rust",
        "libnix",
    ],
    host_supported: true,
    vendor_available: true,
@@ -200,7 +199,6 @@ rust_test {
        "libdowncast_rs",
        "liblibc",
        "liblog_rust",
        "libnix",
    ],
}

+14 −7
Original line number Diff line number Diff line
@@ -22,10 +22,9 @@ use crate::sys;
use std::ffi::{c_void, CStr, CString};
use std::os::raw::c_char;

use libc::sockaddr;
use nix::sys::socket::{SockaddrLike, UnixAddr, VsockAddr};
use libc::{sockaddr, sockaddr_un, sockaddr_vm, socklen_t};
use std::sync::Arc;
use std::{fmt, ptr};
use std::{fmt, mem, ptr};

/// Rust wrapper around ABinderRpc_Accessor objects for RPC binder service management.
///
@@ -44,9 +43,9 @@ impl fmt::Debug for Accessor {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ConnectionInfo {
    /// For vsock connection
    Vsock(VsockAddr),
    Vsock(sockaddr_vm),
    /// For unix domain socket connection
    Unix(UnixAddr),
    Unix(sockaddr_un),
}

/// Safety: A `Accessor` is a wrapper around `ABinderRpc_Accessor` which is
@@ -148,13 +147,21 @@ impl Accessor {
        match connection {
            ConnectionInfo::Vsock(addr) => {
                // Safety: The sockaddr is being copied in the NDK API
                unsafe { sys::ABinderRpc_ConnectionInfo_new(addr.as_ptr(), addr.len()) }
                unsafe {
                    sys::ABinderRpc_ConnectionInfo_new(
                        &addr as *const sockaddr_vm as *const sockaddr,
                        mem::size_of::<sockaddr_vm>() as socklen_t,
                    )
                }
            }
            ConnectionInfo::Unix(addr) => {
                // Safety: The sockaddr is being copied in the NDK API
                // The cast is from sockaddr_un* to sockaddr*.
                unsafe {
                    sys::ABinderRpc_ConnectionInfo_new(addr.as_ptr() as *const sockaddr, addr.len())
                    sys::ABinderRpc_ConnectionInfo_new(
                        &addr as *const sockaddr_un as *const sockaddr,
                        mem::size_of::<sockaddr_un>() as socklen_t,
                    )
                }
            }
        }
Loading