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

Commit e0ca67f2 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "libstatssocket_lazy: add isAvailable()" into main

parents bf7e0df4 ec54595a
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -7,6 +7,12 @@ package {

cc_library_static {
    name: "libstatssocket_lazy",
    local_include_dirs: [
        "include",
    ],
    export_include_dirs: [
        "include",
    ],
    header_libs: [
        "libstatssocket_headers",
    ],
@@ -28,7 +34,10 @@ cc_test {
        "-Wall",
        "-Werror",
    ],
    test_suites: ["device-tests", "mts-statsd"],
    test_suites: [
        "device-tests",
        "mts-statsd",
    ],
    test_config: "libstatssocket_lazy_test.xml",
    // TODO(b/153588990): Remove when the build system properly separates.
    // 32bit and 64bit architectures.
+25 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.
 */

#pragma once

namespace android::statssocket::lazy {

// See if libstatssocket.so is available. Early processes relying on _lazy might not have access
// to libstatssocket.so when they start before the StatsD APEX is available.
bool IsAvailable();

}  // namespace android::statssocket::lazy
+11 −2
Original line number Diff line number Diff line
@@ -23,8 +23,10 @@

#include "log/log.h"

#include "stats_event.h"
#include "stats_socket.h"
#include <stats_event.h>
#include <stats_socket.h>

#include "statssocket_lazy.h"

// This file provides a lazy interface to libstatssocket.so to address early boot dependencies.
// Specifically bootanimation, surfaceflinger, and lmkd run before the statsd APEX is loaded and
@@ -77,6 +79,13 @@ static void* LoadLibstatssocket(int dlopen_flags) {
    return dlopen("libstatssocket.so", dlopen_flags);
}

namespace android::statssocket::lazy {
bool IsAvailable() {
    static const void* handle = LoadLibstatssocket(RTLD_NOW);
    return handle != nullptr;
}
}  // namespace android::statssocket::lazy

//
// Initialization and symbol binding.

+6 −0
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@
#include "stats_event.h"
#include "stats_socket.h"

#include "statssocket_lazy.h"

// The tests here are just for the case when libstatssocket.so cannot be loaded by
// libstatssocket_lazy.
class LibstatssocketLazyTest : public ::testing::Test {
@@ -57,3 +59,7 @@ TEST_F(LibstatssocketLazyTest, NoLibstatssocketForStatsEvent) {
TEST_F(LibstatssocketLazyTest, NoLibstatssocketForStatsSocket) {
    EXPECT_DEATH(AStatsSocket_close(), kLoadFailed);
}

TEST_F(LibstatssocketLazyTest, IsAvailableFalse) {
    EXPECT_FALSE(android::statssocket::lazy::IsAvailable());
}