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

Commit 39cc689a authored by Mike Yu's avatar Mike Yu
Browse files

Add support for getting binder via stable runtime ABI

Change netd_event_listener_interface to use platform C++ instead of
NDK C++ so that libnetd_resolv can call the APIs from libbinder_ndk
to get binder service.

Test: builts, booted
Change-Id: I9559545d3f08eda44f839894a93bcdc8c76dce5c
parent ba7bef92
Loading
Loading
Loading
Loading
+5 −1
Original line number Original line Diff line number Diff line
@@ -27,6 +27,7 @@ cc_library {
        "DnsTlsSessionCache.cpp",
        "DnsTlsSessionCache.cpp",
        "DnsTlsSocket.cpp",
        "DnsTlsSocket.cpp",
        "PrivateDnsConfiguration.cpp",
        "PrivateDnsConfiguration.cpp",
        "ResolverEventReporter.cpp",
    ],
    ],
    // Link everything statically (except for libc) to minimize our dependence
    // Link everything statically (except for libc) to minimize our dependence
    // on system ABIs
    // on system ABIs
@@ -37,7 +38,10 @@ cc_library {
        "liblog",
        "liblog",
        "libnetdutils",
        "libnetdutils",
        "libssl",
        "libssl",
        "netd_event_listener_interface-ndk",
        "netd_event_listener_interface-ndk_platform",
    ],
    shared_libs: [
        "libbinder_ndk",
    ],
    ],
    export_include_dirs: ["include"],
    export_include_dirs: ["include"],
    // TODO: pie in the sky: make this code clang-tidy clean
    // TODO: pie in the sky: make this code clang-tidy clean
+33 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

#include <android/binder_manager.h>

#include "netd_resolv/ResolverEventReporter.h"

using aidl::android::net::metrics::INetdEventListener;

std::shared_ptr<INetdEventListener> ResolverEventReporter::getListener() {
    // It should be initialized only once.
    static ResolverEventReporter reporter;

    return reporter.mListener;
}

ResolverEventReporter::ResolverEventReporter() {
    ndk::SpAIBinder binder = ndk::SpAIBinder(AServiceManager_getService("netd_listener"));
    mListener = INetdEventListener::fromBinder(binder);
}
+38 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2018 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.
 */

#ifndef NETD_RESOLV_EVENT_REPORTER_H
#define NETD_RESOLV_EVENT_REPORTER_H

#include "aidl/android/net/metrics/INetdEventListener.h"

/*
 * This class can be used to get the binder reference to the netd events listener service
 * via stable runtime ABI which is achieved from libbinder_ndk.
 */
class ResolverEventReporter {
  public:
    // Returns the binder from the singleton ResolverEventReporter. This method is threadsafe.
    static std::shared_ptr<aidl::android::net::metrics::INetdEventListener> getListener();

  private:
    // Get netd events listener binder.
    ResolverEventReporter();

    std::shared_ptr<aidl::android::net::metrics::INetdEventListener> mListener;
};

#endif  // NETD_RESOLV_EVENT_REPORTER_H