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

Commit fda3ff04 authored by Jooyung Han's avatar Jooyung Han Committed by Automerger Merge Worker
Browse files

Merge "libbinder_ndk: expose updatable-via-apex" am: 4e841480 am: acb03f02

parents ac86a6bd acb03f02
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -142,6 +142,17 @@ void AServiceManager_forEachDeclaredInstance(const char* interface, void* contex
 */
bool AServiceManager_isUpdatableViaApex(const char* instance) __INTRODUCED_IN(31);

/**
 * Returns the APEX name if a service is declared as updatable via an APEX module.
 *
 * \param instance identifier of the service
 * \param context to pass to callback
 * \param callback taking the APEX name (e.g. 'com.android.foo') and context
 */
void AServiceManager_getUpdatableApexName(const char* instance, void* context,
                                          void (*callback)(const char*, void*))
        __INTRODUCED_IN(__ANDROID_API_U__);

/**
 * Prevent lazy services without client from shutting down their process
 *
+5 −0
Original line number Diff line number Diff line
@@ -152,6 +152,11 @@ LIBBINDER_NDK33 { # introduced=33
    AParcel_unmarshal;
};

LIBBINDER_NDK34 { # introduced=UpsideDownCake
  global:
    AServiceManager_getUpdatableApexName; # systemapi
};

LIBBINDER_NDK_PLATFORM {
  global:
    AParcel_getAllowFds;
+12 −0
Original line number Diff line number Diff line
@@ -113,6 +113,18 @@ bool AServiceManager_isUpdatableViaApex(const char* instance) {
    sp<IServiceManager> sm = defaultServiceManager();
    return sm->updatableViaApex(String16(instance)) != std::nullopt;
}
void AServiceManager_getUpdatableApexName(const char* instance, void* context,
                                          void (*callback)(const char*, void*)) {
    CHECK_NE(instance, nullptr);
    // context may be nullptr
    CHECK_NE(callback, nullptr);

    sp<IServiceManager> sm = defaultServiceManager();
    std::optional<String16> updatableViaApex = sm->updatableViaApex(String16(instance));
    if (updatableViaApex.has_value()) {
        callback(String8(updatableViaApex.value()).c_str(), context);
    }
}
void AServiceManager_forceLazyServicesPersist(bool persist) {
    auto serviceRegistrar = android::binder::LazyServiceRegistrar::getInstance();
    serviceRegistrar.forcePersist(persist);
+13 −1
Original line number Diff line number Diff line
@@ -33,13 +33,15 @@
#include <binder/IResultReceiver.h>
#include <binder/IServiceManager.h>
#include <binder/IShellCallback.h>

#include <sys/prctl.h>

#include <chrono>
#include <condition_variable>
#include <iostream>
#include <mutex>
#include <optional>
#include <thread>

#include "android/binder_ibinder.h"

using namespace android;
@@ -337,6 +339,16 @@ TEST(NdkBinder, IsUpdatable) {
    EXPECT_EQ(isUpdatable, false);
}

TEST(NdkBinder, GetUpdatableViaApex) {
    std::optional<std::string> updatableViaApex;
    AServiceManager_getUpdatableApexName(
            "android.hardware.light.ILights/default", &updatableViaApex,
            [](const char* apexName, void* context) {
                *static_cast<std::optional<std::string>*>(context) = apexName;
            });
    EXPECT_EQ(updatableViaApex, std::nullopt) << *updatableViaApex;
}

// This is too slow
TEST(NdkBinder, CheckLazyServiceShutDown) {
    ndk::SpAIBinder binder(AServiceManager_waitForService(kLazyBinderNdkUnitTestService));