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

Commit 788b58be authored by Charles Chen's avatar Charles Chen
Browse files

Enable isolated process to use graphics allocator

Add an LLNDK API for isolated process usage.

Bug: 268016157
Test: Manual - Service can be added with allowIsolated set to true.
Change-Id: I9d3c39e313978ccd6b01574b5533530d4f959904
parent 520797d3
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -22,6 +22,16 @@

__BEGIN_DECLS

enum AServiceManager_AddServiceFlag : uint32_t {
    /**
     * This allows processes with AID_ISOLATED to get the binder of the service added.
     *
     * Services with methods that perform file IO, web socket creation or ways to egress data must
     * not be added with this flag for privacy concerns.
     */
    ADD_SERVICE_ALLOW_ISOLATED = 1,
};

/**
 * This registers the service with the default service manager under this instance name. This does
 * not take ownership of binder.
@@ -46,12 +56,13 @@ __attribute__((warn_unused_result)) binder_exception_t AServiceManager_addServic
 *
 * \param binder object to register globally with the service manager.
 * \param instance identifier of the service. This will be used to lookup the service.
 * \param allowIsolated allows if this service can be isolated.
 * \param flag an AServiceManager_AddServiceFlag enum to denote how the service should be added.
 *
 * \return EX_NONE on success.
 */
__attribute__((warn_unused_result)) binder_exception_t AServiceManager_addServiceWithAllowIsolated(
        AIBinder* binder, const char* instance, bool allowIsolated) __INTRODUCED_IN(34);
__attribute__((warn_unused_result)) binder_exception_t AServiceManager_addServiceWithFlag(
        AIBinder* binder, const char* instance, const AServiceManager_AddServiceFlag flag)
        __INTRODUCED_IN(34);

/**
 * Gets a binder object with this specific instance name. Will return nullptr immediately if the
+1 −1
Original line number Diff line number Diff line
@@ -158,12 +158,12 @@ LIBBINDER_NDK34 { # introduced=UpsideDownCake
    AServiceManager_getUpdatableApexName; # systemapi
    AServiceManager_registerForServiceNotifications; # systemapi llndk
    AServiceManager_NotificationRegistration_delete; # systemapi llndk
    AServiceManager_addServiceWithFlag; # systemapi llndk
};

LIBBINDER_NDK_PLATFORM {
  global:
    AParcel_getAllowFds;
    AServiceManager_addServiceWithAllowIsolated;
    extern "C++" {
        AIBinder_fromPlatformBinder*;
        AIBinder_toPlatformBinder*;
+4 −3
Original line number Diff line number Diff line
@@ -42,14 +42,15 @@ binder_exception_t AServiceManager_addService(AIBinder* binder, const char* inst
    return PruneException(exception);
}

binder_exception_t AServiceManager_addServiceWithAllowIsolated(AIBinder* binder,
                                                               const char* instance,
                                                               bool allowIsolated) {
binder_exception_t AServiceManager_addServiceWithFlag(AIBinder* binder, const char* instance,
                                                      const AServiceManager_AddServiceFlag flag) {
    if (binder == nullptr || instance == nullptr) {
        return EX_ILLEGAL_ARGUMENT;
    }

    sp<IServiceManager> sm = defaultServiceManager();

    bool allowIsolated = flag & AServiceManager_AddServiceFlag::ADD_SERVICE_ALLOW_ISOLATED;
    status_t exception = sm->addService(String16(instance), binder->getBinder(), allowIsolated);
    return PruneException(exception);
}
+11 −2
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@
#include <aidlcommonsupport/NativeHandle.h>
#include <android/binder_enums.h>
#include <android/binder_manager.h>
#include <cutils/android_filesystem_config.h>
#include <cutils/multiuser.h>
#include <gralloctypes/Gralloc4.h>
#include <hidl/ServiceManagement.h>
#include <hwbinder/IPCThreadState.h>
@@ -1195,8 +1197,15 @@ Gralloc4Allocator::Gralloc4Allocator(const Gralloc4Mapper& mapper) : mMapper(map
    mAllocator = IAllocator::getService();
    if (__builtin_available(android 31, *)) {
        if (hasIAllocatorAidl()) {
            // TODO(b/269517338): Perform the isolated checking for this in service manager instead.
            uid_t aid = multiuser_get_app_id(getuid());
            if (aid >= AID_ISOLATED_START && aid <= AID_ISOLATED_END) {
                mAidlAllocator = AidlIAllocator::fromBinder(ndk::SpAIBinder(
                        AServiceManager_getService(kAidlAllocatorServiceName.c_str())));
            } else {
                mAidlAllocator = AidlIAllocator::fromBinder(ndk::SpAIBinder(
                        AServiceManager_waitForService(kAidlAllocatorServiceName.c_str())));
            }
            ALOGE_IF(!mAidlAllocator, "AIDL IAllocator declared but failed to get service");
        }
    }