blob: fd09b8a3cc91e6ad6e2bc0792fc4cf3a0ff4e178 [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
17#define LOG_TAG "Netd"
18
19#include "EventReporter.h"
20#include "log/log.h"
21
22using android::interface_cast;
23using android::net::metrics::INetdEventListener;
24
25int EventReporter::setMetricsReportingLevel(const int level) {
26 if (level < INetdEventListener::REPORTING_LEVEL_NONE
27 || level > INetdEventListener::REPORTING_LEVEL_FULL) {
28 ALOGE("Invalid metrics reporting level %d", level);
29 return -EINVAL;
30 }
31 mReportingLevel = level;
32 return 0;
33}
34
35int EventReporter::getMetricsReportingLevel() const {
36 return mReportingLevel;
37}
38
39android::sp<INetdEventListener> EventReporter::getNetdEventListener() {
40 if (mNetdEventListener == nullptr) {
41 // Use checkService instead of getService because getService waits for 5 seconds for the
42 // service to become available. The DNS resolver inside netd is started much earlier in the
43 // boot sequence than the framework DNS listener, and we don't want to delay all DNS lookups
44 // for 5 seconds until the DNS listener starts up.
45 android::sp<android::IBinder> b = android::defaultServiceManager()->checkService(
46 android::String16("netd_listener"));
47 if (b != nullptr) {
48 mNetdEventListener = interface_cast<INetdEventListener>(b);
49 }
50 }
51 // If the netd listener service is dead, the binder call will just return an error, which should
52 // be fine because the only impact is that we can't log netd events. In any case, this should
53 // only happen if the system server is going down, which means it will shortly be taking us down
54 // with it.
55 return mNetdEventListener;
56}