blob: da442eef988d21fbff74dfadc6518433f168da8b [file] [log] [blame]
/*
* 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 "ResolverEventReporter.h"
#include <android/binder_manager.h>
using aidl::android::net::metrics::INetdEventListener;
std::shared_ptr<INetdEventListener> ResolverEventReporter::getListener() {
// It should be initialized only once.
static ResolverEventReporter reporter;
return reporter.getNetdEventListener();
}
std::shared_ptr<INetdEventListener> ResolverEventReporter::getNetdEventListener() {
std::lock_guard lock(mEventMutex);
if (mListener == nullptr) {
// Use the non-blocking call AServiceManager_checkService in order not to delay DNS
// lookup threads when the netd_listener service is not ready.
ndk::SpAIBinder binder = ndk::SpAIBinder(AServiceManager_checkService("netd_listener"));
mListener = INetdEventListener::fromBinder(binder);
}
return mListener;
}