16c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti/**
26c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * Copyright (c) 2016, The Android Open Source Project
36c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti *
46c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * Licensed under the Apache License, Version 2.0 (the "License");
56c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * you may not use this file except in compliance with the License.
66c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * You may obtain a copy of the License at
76c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti *
86c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti *     http://www.apache.org/licenses/LICENSE-2.0
96c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti *
106c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * Unless required by applicable law or agreed to in writing, software
116c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * distributed under the License is distributed on an "AS IS" BASIS,
126c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
136c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * See the License for the specific language governing permissions and
146c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * limitations under the License.
156c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti */
166c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti
176c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colittipackage android.net.metrics;
186c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti
196c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti/**
2001861793fcc00f67c19f0040939d2fb58561bb16Michal Karpinski * Logs netd events.
216c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti *
226c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti * {@hide}
236c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti */
2401861793fcc00f67c19f0040939d2fb58561bb16Michal Karpinskioneway interface INetdEventListener {
256c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti    const int EVENT_GETADDRINFO = 1;
266c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti    const int EVENT_GETHOSTBYNAME = 2;
276c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti
28d1da1b8a5e7d4d7de891af913c53b6f169a06f32Michal Karpinski    const int REPORTING_LEVEL_NONE = 0;
29d1da1b8a5e7d4d7de891af913c53b6f169a06f32Michal Karpinski    const int REPORTING_LEVEL_METRICS = 1;
30d1da1b8a5e7d4d7de891af913c53b6f169a06f32Michal Karpinski    const int REPORTING_LEVEL_FULL = 2;
318ef9907bdbbeaae00be914c77f3425e2e31c2f28Michal Karpinski
32fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski    // Maximum number of IP addresses logged for DNS lookups before we truncate the full list.
33fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski    const int DNS_REPORTED_IP_ADDRESSES_LIMIT = 10;
34fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski
35fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski    /**
36fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     * Logs a DNS lookup function call (getaddrinfo and gethostbyname).
37fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     *
38fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     * @param netId the ID of the network the lookup was performed on.
39fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     * @param eventType one of the EVENT_* constants in this interface.
40fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     * @param returnCode the return value of the function call.
41fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     * @param latencyMs the latency of the function call.
42fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     * @param hostname the name that was looked up.
43fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     * @param ipAddresses (possibly a subset of) the IP addresses returned.
44fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     *        At most {@link #DNS_REPORTED_IP_ADDRESSES_LIMIT} addresses are logged.
45fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     * @param ipAddressesCount the number of IP addresses returned. May be different from the length
46fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     *        of ipAddresses if there were too many addresses to log.
47fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     * @param uid the UID of the application that performed the query.
48fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski     */
49fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski    void onDnsEvent(int netId, int eventType, int returnCode, int latencyMs, String hostname,
50fa5d873bc5a1d361ab220025efbd5fc0072a0c54Michal Karpinski            in String[] ipAddresses, int ipAddressesCount, int uid);
51eced78ed33213f121268db02d84d49262bf09613Michal Karpinski
52eced78ed33213f121268db02d84d49262bf09613Michal Karpinski    /**
53eced78ed33213f121268db02d84d49262bf09613Michal Karpinski     * Logs a single connect library call.
54eced78ed33213f121268db02d84d49262bf09613Michal Karpinski     *
55483afa496bd0fc58aba0c56f1da8f059bd0fa85dHugo Benichi     * @param netId the ID of the network the connect was performed on.
56483afa496bd0fc58aba0c56f1da8f059bd0fa85dHugo Benichi     * @param error 0 if the connect call succeeded, otherwise errno if it failed.
57483afa496bd0fc58aba0c56f1da8f059bd0fa85dHugo Benichi     * @param latencyMs the latency of the connect call.
58eced78ed33213f121268db02d84d49262bf09613Michal Karpinski     * @param ipAddr destination IP address.
59eced78ed33213f121268db02d84d49262bf09613Michal Karpinski     * @param port destination port number.
60eced78ed33213f121268db02d84d49262bf09613Michal Karpinski     * @param uid the UID of the application that performed the connection.
61eced78ed33213f121268db02d84d49262bf09613Michal Karpinski     */
62483afa496bd0fc58aba0c56f1da8f059bd0fa85dHugo Benichi    void onConnectEvent(int netId, int error, int latencyMs, String ipAddr, int port, int uid);
6308b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz
6408b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz    /**
6508b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz     * Logs a single RX packet which caused the main CPU to exit sleep state.
6608b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz     * @param prefix arbitrary string provided via wakeupAddInterface()
6708b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz     * @param UID of the destination process or -1 if no UID is available.
6808b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz     * @param GID of the destination process or -1 if no GID is available.
6908b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz     * @param receive timestamp for the offending packet. In units of nanoseconds and
7008b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz     *        synchronized to CLOCK_MONOTONIC.
7108b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz     */
7208b84cd0d223ae3059ce7d4d55b389fdea187580Joel Scherpelz    void onWakeupEvent(String prefix, int uid, int gid, long timestampNs);
736c97716e41d751cb0ebf49c93943923a356d3a96Lorenzo Colitti}
74