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

Commit 917c592e authored by Mike Yu's avatar Mike Yu Committed by Gerrit Code Review
Browse files

Merge "Add support for getting binder via stable runtime ABI"

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