blob: 7ada0bfc841f6213a0e98bb0c3426c98fca4c3a0 [file] [log] [blame]
Michal Karpinskibe581e22016-10-06 16:56:04 +01001/*
2 * Copyright (C) 2016 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
Michal Karpinskibe581e22016-10-06 16:56:04 +010017#include "EventReporter.h"
Michal Karpinskibe581e22016-10-06 16:56:04 +010018
19using android::interface_cast;
20using android::net::metrics::INetdEventListener;
21
Michal Karpinskibe581e22016-10-06 16:56:04 +010022android::sp<INetdEventListener> EventReporter::getNetdEventListener() {
Bernie Innocentiabf8a342018-08-10 15:17:16 +090023 std::lock_guard lock(mutex);
Michal Karpinskibe581e22016-10-06 16:56:04 +010024 if (mNetdEventListener == nullptr) {
25 // Use checkService instead of getService because getService waits for 5 seconds for the
26 // service to become available. The DNS resolver inside netd is started much earlier in the
27 // boot sequence than the framework DNS listener, and we don't want to delay all DNS lookups
28 // for 5 seconds until the DNS listener starts up.
29 android::sp<android::IBinder> b = android::defaultServiceManager()->checkService(
30 android::String16("netd_listener"));
31 if (b != nullptr) {
32 mNetdEventListener = interface_cast<INetdEventListener>(b);
33 }
34 }
35 // If the netd listener service is dead, the binder call will just return an error, which should
36 // be fine because the only impact is that we can't log netd events. In any case, this should
37 // only happen if the system server is going down, which means it will shortly be taking us down
38 // with it.
39 return mNetdEventListener;
40}