blob: da442eef988d21fbff74dfadc6518433f168da8b [file] [log] [blame]
Mike Yuae7f9f72018-12-14 16:18:27 +08001/*
2 * Copyright (C) 2018 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Bernie Innocentiad4e26e2019-01-30 11:16:36 +090017#include "ResolverEventReporter.h"
Mike Yuae7f9f72018-12-14 16:18:27 +080018
Mike Yuc13aebd2019-02-15 16:03:02 +080019#include <android/binder_manager.h>
20
Mike Yuae7f9f72018-12-14 16:18:27 +080021using aidl::android::net::metrics::INetdEventListener;
22
23std::shared_ptr<INetdEventListener> ResolverEventReporter::getListener() {
24 // It should be initialized only once.
25 static ResolverEventReporter reporter;
Mike Yuc13aebd2019-02-15 16:03:02 +080026 return reporter.getNetdEventListener();
Mike Yuae7f9f72018-12-14 16:18:27 +080027}
28
Mike Yuc13aebd2019-02-15 16:03:02 +080029std::shared_ptr<INetdEventListener> ResolverEventReporter::getNetdEventListener() {
30 std::lock_guard lock(mEventMutex);
31 if (mListener == nullptr) {
32 // Use the non-blocking call AServiceManager_checkService in order not to delay DNS
33 // lookup threads when the netd_listener service is not ready.
34 ndk::SpAIBinder binder = ndk::SpAIBinder(AServiceManager_checkService("netd_listener"));
35 mListener = INetdEventListener::fromBinder(binder);
36 }
37 return mListener;
Mike Yuae7f9f72018-12-14 16:18:27 +080038}