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

Commit 61bd7277 authored by Kalesh Singh's avatar Kalesh Singh
Browse files

Add memtrackproxy system server service

Serve memtrackproxy service from system server.

This service enforces access control on requests for memory usage stats
to the memtrack HAL based on the call context's PID and UID.

Bug: 177664629
Test: memtrackproxy_test
Change-Id: I10829ffcf4e5b2813d4c622268b0b59da6f171b6
Merged-In: I10829ffcf4e5b2813d4c622268b0b59da6f171b6
parent 47f5317b
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ cc_defaults {
        "libaudioclient",
        "libbase",
        "libappfuse",
        "libbinder_ndk",
        "libbinder",
        "libcutils",
        "libcrypto",
@@ -110,6 +111,7 @@ cc_defaults {
        "libhardware",
        "libhardware_legacy",
        "libhidlbase",
        "libmemtrackproxy",
        "libmtp",
        "libnativehelper",
        "libprocessgroup",
@@ -154,6 +156,7 @@ cc_defaults {
        "android.hardware.input.classifier@1.0",
        "android.hardware.ir@1.0",
        "android.hardware.light@2.0",
        "android.hardware.memtrack-V1-ndk_platform",
        "android.hardware.power@1.0",
        "android.hardware.power@1.1",
        "android.hardware.power-V1-cpp",
+20 −0
Original line number Diff line number Diff line
@@ -23,11 +23,14 @@
#include <jni.h>
#include <nativehelper/JNIHelp.h>

#include <android/binder_manager.h>
#include <android/binder_stability.h>
#include <android/hidl/manager/1.2/IServiceManager.h>
#include <binder/IServiceManager.h>
#include <hidl/HidlTransportSupport.h>
#include <incremental_service.h>

#include <memtrackproxy/MemtrackProxy.h>
#include <schedulerservice/SchedulingPolicyService.h>
#include <sensorservice/SensorService.h>
#include <sensorservicehidl/SensorManager.h>
@@ -57,6 +60,21 @@ static void android_server_SystemServer_startSensorService(JNIEnv* /* env */, jo

}

static void android_server_SystemServer_startMemtrackProxyService(JNIEnv* env,
                                                                  jobject /* clazz */) {
    using aidl::android::hardware::memtrack::MemtrackProxy;

    const char* memtrackProxyService = "memtrack.proxy";

    std::shared_ptr<MemtrackProxy> memtrack_proxy = ndk::SharedRefBase::make<MemtrackProxy>();
    auto binder = memtrack_proxy->asBinder();

    AIBinder_forceDowngradeToLocalStability(binder.get());

    const binder_exception_t err = AServiceManager_addService(binder.get(), memtrackProxyService);
    LOG_ALWAYS_FATAL_IF(err != EX_NONE, "Cannot register %s: %d", memtrackProxyService, err);
}

static void android_server_SystemServer_startHidlServices(JNIEnv* env, jobject /* clazz */) {
    using ::android::frameworks::schedulerservice::V1_0::ISchedulingPolicyService;
    using ::android::frameworks::schedulerservice::V1_0::implementation::SchedulingPolicyService;
@@ -121,6 +139,8 @@ static void android_server_SystemServer_setIncrementalServiceSystemReady(JNIEnv*
static const JNINativeMethod gMethods[] = {
        /* name, signature, funcPtr */
        {"startSensorService", "()V", (void*)android_server_SystemServer_startSensorService},
        {"startMemtrackProxyService", "()V",
         (void*)android_server_SystemServer_startMemtrackProxyService},
        {"startHidlServices", "()V", (void*)android_server_SystemServer_startHidlServices},
        {"initZygoteChildHeapProfiling", "()V",
         (void*)android_server_SystemServer_initZygoteChildHeapProfiling},
+11 −0
Original line number Diff line number Diff line
@@ -391,6 +391,11 @@ public final class SystemServer {
     */
    private static native void startSensorService();

    /**
     * Start the memtrack proxy service.
     */
    private static native void startMemtrackProxyService();

    /**
     * Start all HIDL services that are run inside the system server. This may take some time.
     */
@@ -829,6 +834,12 @@ public final class SystemServer {
        mSystemServiceManager.startService(UriGrantsManagerService.Lifecycle.class);
        t.traceEnd();

        // Start MemtrackProxyService before ActivityManager, so that early calls
        // to Memtrack::getMemory() don't fail.
        t.traceBegin("MemtrackProxyService");
        startMemtrackProxyService();
        t.traceEnd();

        // Activity manager runs the show.
        t.traceBegin("StartActivityManager");
        // TODO: Might need to move after migration to WM.