Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 1 | /* |
| 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 | package com.android.server.connectivity; |
| 18 | |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 19 | import static android.net.NetworkCapabilities.MAX_TRANSPORT; |
| 20 | import static android.net.NetworkCapabilities.TRANSPORT_BLUETOOTH; |
| 21 | import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR; |
| 22 | import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET; |
| 23 | import static android.net.NetworkCapabilities.TRANSPORT_VPN; |
| 24 | import static android.net.NetworkCapabilities.TRANSPORT_WIFI; |
| 25 | import static android.net.NetworkCapabilities.TRANSPORT_WIFI_AWARE; |
| 26 | import static com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.IpConnectivityEvent; |
| 27 | import static com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.IpConnectivityLog; |
| 28 | import static com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.NetworkId; |
| 29 | |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 30 | import android.net.ConnectivityMetricsEvent; |
| 31 | import android.net.metrics.ApfProgramEvent; |
| 32 | import android.net.metrics.ApfStats; |
| 33 | import android.net.metrics.DefaultNetworkEvent; |
| 34 | import android.net.metrics.DhcpClientEvent; |
| 35 | import android.net.metrics.DhcpErrorEvent; |
| 36 | import android.net.metrics.DnsEvent; |
| 37 | import android.net.metrics.IpManagerEvent; |
| 38 | import android.net.metrics.IpReachabilityEvent; |
| 39 | import android.net.metrics.NetworkEvent; |
| 40 | import android.net.metrics.RaEvent; |
| 41 | import android.net.metrics.ValidationProbeEvent; |
| 42 | import android.os.Parcelable; |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 43 | import android.util.SparseArray; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 44 | import com.android.server.connectivity.metrics.nano.IpConnectivityLogClass; |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 45 | import java.io.IOException; |
| 46 | import java.util.ArrayList; |
| 47 | import java.util.List; |
| 48 | |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 49 | |
| 50 | /** {@hide} */ |
| 51 | final public class IpConnectivityEventBuilder { |
| 52 | private IpConnectivityEventBuilder() { |
| 53 | } |
| 54 | |
Hugo Benichi | 0d4a398 | 2016-11-25 11:24:22 +0900 | [diff] [blame] | 55 | public static byte[] serialize(int dropped, List<IpConnectivityEvent> events) |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 56 | throws IOException { |
| 57 | final IpConnectivityLog log = new IpConnectivityLog(); |
Hugo Benichi | 0d4a398 | 2016-11-25 11:24:22 +0900 | [diff] [blame] | 58 | log.events = events.toArray(new IpConnectivityEvent[events.size()]); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 59 | log.droppedEvents = dropped; |
Hugo Benichi | d680d4c | 2016-10-13 13:16:16 +0900 | [diff] [blame] | 60 | if ((log.events.length > 0) || (dropped > 0)) { |
| 61 | // Only write version number if log has some information at all. |
| 62 | log.version = IpConnectivityMetrics.VERSION; |
| 63 | } |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 64 | return IpConnectivityLog.toByteArray(log); |
| 65 | } |
| 66 | |
Hugo Benichi | 0d4a398 | 2016-11-25 11:24:22 +0900 | [diff] [blame] | 67 | public static List<IpConnectivityEvent> toProto(List<ConnectivityMetricsEvent> eventsIn) { |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 68 | final ArrayList<IpConnectivityEvent> eventsOut = new ArrayList<>(eventsIn.size()); |
| 69 | for (ConnectivityMetricsEvent in : eventsIn) { |
| 70 | final IpConnectivityEvent out = toProto(in); |
| 71 | if (out == null) { |
| 72 | continue; |
| 73 | } |
| 74 | eventsOut.add(out); |
| 75 | } |
Hugo Benichi | 0d4a398 | 2016-11-25 11:24:22 +0900 | [diff] [blame] | 76 | return eventsOut; |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | public static IpConnectivityEvent toProto(ConnectivityMetricsEvent ev) { |
| 80 | final IpConnectivityEvent out = new IpConnectivityEvent(); |
| 81 | if (!setEvent(out, ev.data)) { |
| 82 | return null; |
| 83 | } |
| 84 | out.timeMs = ev.timestamp; |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 85 | out.networkId = ev.netId; |
| 86 | out.transports = ev.transports; |
| 87 | if (ev.ifname != null) { |
| 88 | out.ifName = ev.ifname; |
| 89 | } |
| 90 | inferLinkLayer(out); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 91 | return out; |
| 92 | } |
| 93 | |
Hugo Benichi | 2a5cfb9 | 2017-03-22 22:21:44 +0900 | [diff] [blame^] | 94 | public static IpConnectivityEvent toProto(DnsEvent in) { |
| 95 | final IpConnectivityEvent out = new IpConnectivityEvent(); |
| 96 | IpConnectivityLogClass.DNSLookupBatch dnsLookupBatch = |
| 97 | new IpConnectivityLogClass.DNSLookupBatch(); |
| 98 | in.resize(in.eventCount); |
| 99 | dnsLookupBatch.eventTypes = bytesToInts(in.eventTypes); |
| 100 | dnsLookupBatch.returnCodes = bytesToInts(in.returnCodes); |
| 101 | dnsLookupBatch.latenciesMs = in.latenciesMs; |
| 102 | out.setDnsLookupBatch(dnsLookupBatch); |
| 103 | out.networkId = in.netId; |
| 104 | out.transports = in.transports; |
| 105 | inferLinkLayer(out); |
| 106 | return out; |
| 107 | } |
| 108 | |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 109 | private static boolean setEvent(IpConnectivityEvent out, Parcelable in) { |
| 110 | if (in instanceof DhcpErrorEvent) { |
| 111 | setDhcpErrorEvent(out, (DhcpErrorEvent) in); |
| 112 | return true; |
| 113 | } |
| 114 | |
| 115 | if (in instanceof DhcpClientEvent) { |
| 116 | setDhcpClientEvent(out, (DhcpClientEvent) in); |
| 117 | return true; |
| 118 | } |
| 119 | |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 120 | if (in instanceof IpManagerEvent) { |
| 121 | setIpManagerEvent(out, (IpManagerEvent) in); |
| 122 | return true; |
| 123 | } |
| 124 | |
| 125 | if (in instanceof IpReachabilityEvent) { |
| 126 | setIpReachabilityEvent(out, (IpReachabilityEvent) in); |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | if (in instanceof DefaultNetworkEvent) { |
| 131 | setDefaultNetworkEvent(out, (DefaultNetworkEvent) in); |
| 132 | return true; |
| 133 | } |
| 134 | |
| 135 | if (in instanceof NetworkEvent) { |
| 136 | setNetworkEvent(out, (NetworkEvent) in); |
| 137 | return true; |
| 138 | } |
| 139 | |
| 140 | if (in instanceof ValidationProbeEvent) { |
| 141 | setValidationProbeEvent(out, (ValidationProbeEvent) in); |
| 142 | return true; |
| 143 | } |
| 144 | |
| 145 | if (in instanceof ApfProgramEvent) { |
| 146 | setApfProgramEvent(out, (ApfProgramEvent) in); |
| 147 | return true; |
| 148 | } |
| 149 | |
| 150 | if (in instanceof ApfStats) { |
| 151 | setApfStats(out, (ApfStats) in); |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | if (in instanceof RaEvent) { |
| 156 | setRaEvent(out, (RaEvent) in); |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | return false; |
| 161 | } |
| 162 | |
| 163 | private static void setDhcpErrorEvent(IpConnectivityEvent out, DhcpErrorEvent in) { |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 164 | IpConnectivityLogClass.DHCPEvent dhcpEvent = new IpConnectivityLogClass.DHCPEvent(); |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 165 | dhcpEvent.setErrorCode(in.errorCode); |
| 166 | out.setDhcpEvent(dhcpEvent); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 167 | } |
| 168 | |
| 169 | private static void setDhcpClientEvent(IpConnectivityEvent out, DhcpClientEvent in) { |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 170 | IpConnectivityLogClass.DHCPEvent dhcpEvent = new IpConnectivityLogClass.DHCPEvent(); |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 171 | dhcpEvent.setStateTransition(in.msg); |
| 172 | dhcpEvent.durationMs = in.durationMs; |
| 173 | out.setDhcpEvent(dhcpEvent); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 174 | } |
| 175 | |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 176 | private static void setIpManagerEvent(IpConnectivityEvent out, IpManagerEvent in) { |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 177 | IpConnectivityLogClass.IpProvisioningEvent ipProvisioningEvent = |
| 178 | new IpConnectivityLogClass.IpProvisioningEvent(); |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 179 | ipProvisioningEvent.eventType = in.eventType; |
| 180 | ipProvisioningEvent.latencyMs = (int) in.durationMs; |
| 181 | out.setIpProvisioningEvent(ipProvisioningEvent); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | private static void setIpReachabilityEvent(IpConnectivityEvent out, IpReachabilityEvent in) { |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 185 | IpConnectivityLogClass.IpReachabilityEvent ipReachabilityEvent = |
| 186 | new IpConnectivityLogClass.IpReachabilityEvent(); |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 187 | ipReachabilityEvent.eventType = in.eventType; |
| 188 | out.setIpReachabilityEvent(ipReachabilityEvent); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 189 | } |
| 190 | |
| 191 | private static void setDefaultNetworkEvent(IpConnectivityEvent out, DefaultNetworkEvent in) { |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 192 | IpConnectivityLogClass.DefaultNetworkEvent defaultNetworkEvent = |
| 193 | new IpConnectivityLogClass.DefaultNetworkEvent(); |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 194 | defaultNetworkEvent.networkId = netIdOf(in.netId); |
| 195 | defaultNetworkEvent.previousNetworkId = netIdOf(in.prevNetId); |
| 196 | defaultNetworkEvent.transportTypes = in.transportTypes; |
| 197 | defaultNetworkEvent.previousNetworkIpSupport = ipSupportOf(in); |
| 198 | out.setDefaultNetworkEvent(defaultNetworkEvent); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 199 | } |
| 200 | |
| 201 | private static void setNetworkEvent(IpConnectivityEvent out, NetworkEvent in) { |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 202 | IpConnectivityLogClass.NetworkEvent networkEvent = |
| 203 | new IpConnectivityLogClass.NetworkEvent(); |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 204 | networkEvent.networkId = netIdOf(in.netId); |
| 205 | networkEvent.eventType = in.eventType; |
| 206 | networkEvent.latencyMs = (int) in.durationMs; |
| 207 | out.setNetworkEvent(networkEvent); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | private static void setValidationProbeEvent(IpConnectivityEvent out, ValidationProbeEvent in) { |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 211 | IpConnectivityLogClass.ValidationProbeEvent validationProbeEvent = |
| 212 | new IpConnectivityLogClass.ValidationProbeEvent(); |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 213 | validationProbeEvent.latencyMs = (int) in.durationMs; |
| 214 | validationProbeEvent.probeType = in.probeType; |
| 215 | validationProbeEvent.probeResult = in.returnCode; |
| 216 | out.setValidationProbeEvent(validationProbeEvent); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | private static void setApfProgramEvent(IpConnectivityEvent out, ApfProgramEvent in) { |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 220 | IpConnectivityLogClass.ApfProgramEvent apfProgramEvent = |
| 221 | new IpConnectivityLogClass.ApfProgramEvent(); |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 222 | apfProgramEvent.lifetime = in.lifetime; |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 223 | apfProgramEvent.effectiveLifetime = in.actualLifetime; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 224 | apfProgramEvent.filteredRas = in.filteredRas; |
| 225 | apfProgramEvent.currentRas = in.currentRas; |
| 226 | apfProgramEvent.programLength = in.programLength; |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 227 | if (isBitSet(in.flags, ApfProgramEvent.FLAG_MULTICAST_FILTER_ON)) { |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 228 | apfProgramEvent.dropMulticast = true; |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 229 | } |
| 230 | if (isBitSet(in.flags, ApfProgramEvent.FLAG_HAS_IPV4_ADDRESS)) { |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 231 | apfProgramEvent.hasIpv4Addr = true; |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 232 | } |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 233 | out.setApfProgramEvent(apfProgramEvent); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 234 | } |
| 235 | |
| 236 | private static void setApfStats(IpConnectivityEvent out, ApfStats in) { |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 237 | IpConnectivityLogClass.ApfStatistics apfStatistics = |
| 238 | new IpConnectivityLogClass.ApfStatistics(); |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 239 | apfStatistics.durationMs = in.durationMs; |
| 240 | apfStatistics.receivedRas = in.receivedRas; |
| 241 | apfStatistics.matchingRas = in.matchingRas; |
| 242 | apfStatistics.droppedRas = in.droppedRas; |
| 243 | apfStatistics.zeroLifetimeRas = in.zeroLifetimeRas; |
| 244 | apfStatistics.parseErrors = in.parseErrors; |
| 245 | apfStatistics.programUpdates = in.programUpdates; |
Hugo Benichi | 22d9b2d | 2017-02-22 13:02:27 +0900 | [diff] [blame] | 246 | apfStatistics.programUpdatesAll = in.programUpdatesAll; |
| 247 | apfStatistics.programUpdatesAllowingMulticast = in.programUpdatesAllowingMulticast; |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 248 | apfStatistics.maxProgramSize = in.maxProgramSize; |
| 249 | out.setApfStatistics(apfStatistics); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | private static void setRaEvent(IpConnectivityEvent out, RaEvent in) { |
Tamas Berghammer | 383db5eb | 2016-06-22 15:21:38 +0100 | [diff] [blame] | 253 | IpConnectivityLogClass.RaEvent raEvent = new IpConnectivityLogClass.RaEvent(); |
| 254 | raEvent.routerLifetime = in.routerLifetime; |
| 255 | raEvent.prefixValidLifetime = in.prefixValidLifetime; |
| 256 | raEvent.prefixPreferredLifetime = in.prefixPreferredLifetime; |
| 257 | raEvent.routeInfoLifetime = in.routeInfoLifetime; |
| 258 | raEvent.rdnssLifetime = in.rdnssLifetime; |
| 259 | raEvent.dnsslLifetime = in.dnsslLifetime; |
| 260 | out.setRaEvent(raEvent); |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | private static int[] bytesToInts(byte[] in) { |
| 264 | final int[] out = new int[in.length]; |
| 265 | for (int i = 0; i < in.length; i++) { |
| 266 | out[i] = in[i] & 0xFF; |
| 267 | } |
| 268 | return out; |
| 269 | } |
| 270 | |
| 271 | private static NetworkId netIdOf(int netid) { |
| 272 | final NetworkId ni = new NetworkId(); |
| 273 | ni.networkId = netid; |
| 274 | return ni; |
| 275 | } |
| 276 | |
| 277 | private static int ipSupportOf(DefaultNetworkEvent in) { |
| 278 | if (in.prevIPv4 && in.prevIPv6) { |
| 279 | return IpConnectivityLogClass.DefaultNetworkEvent.DUAL; |
| 280 | } |
| 281 | if (in.prevIPv6) { |
| 282 | return IpConnectivityLogClass.DefaultNetworkEvent.IPV6; |
| 283 | } |
| 284 | if (in.prevIPv4) { |
| 285 | return IpConnectivityLogClass.DefaultNetworkEvent.IPV4; |
| 286 | } |
| 287 | return IpConnectivityLogClass.DefaultNetworkEvent.NONE; |
| 288 | } |
| 289 | |
| 290 | private static boolean isBitSet(int flags, int bit) { |
| 291 | return (flags & (1 << bit)) != 0; |
| 292 | } |
Hugo Benichi | 73fd4d1 | 2017-03-15 23:05:01 +0900 | [diff] [blame] | 293 | |
| 294 | private static void inferLinkLayer(IpConnectivityEvent ev) { |
| 295 | int linkLayer = IpConnectivityLogClass.UNKNOWN; |
| 296 | if (ev.transports != 0) { |
| 297 | linkLayer = transportsToLinkLayer(ev.transports); |
| 298 | } else if (ev.ifName != null) { |
| 299 | linkLayer = ifnameToLinkLayer(ev.ifName); |
| 300 | } |
| 301 | if (linkLayer == IpConnectivityLogClass.UNKNOWN) { |
| 302 | return; |
| 303 | } |
| 304 | ev.linkLayer = linkLayer; |
| 305 | ev.ifName = ""; |
| 306 | } |
| 307 | |
| 308 | private static int transportsToLinkLayer(long transports) { |
| 309 | switch (Long.bitCount(transports)) { |
| 310 | case 0: |
| 311 | return IpConnectivityLogClass.UNKNOWN; |
| 312 | case 1: |
| 313 | int t = Long.numberOfTrailingZeros(transports); |
| 314 | return transportToLinkLayer(t); |
| 315 | default: |
| 316 | return IpConnectivityLogClass.MULTIPLE; |
| 317 | } |
| 318 | } |
| 319 | |
| 320 | private static int transportToLinkLayer(int transport) { |
| 321 | if (0 <= transport && transport < TRANSPORT_LINKLAYER_MAP.length) { |
| 322 | return TRANSPORT_LINKLAYER_MAP[transport]; |
| 323 | } |
| 324 | return IpConnectivityLogClass.UNKNOWN; |
| 325 | } |
| 326 | |
| 327 | private static final int[] TRANSPORT_LINKLAYER_MAP = new int[MAX_TRANSPORT + 1]; |
| 328 | static { |
| 329 | TRANSPORT_LINKLAYER_MAP[TRANSPORT_CELLULAR] = IpConnectivityLogClass.CELLULAR; |
| 330 | TRANSPORT_LINKLAYER_MAP[TRANSPORT_WIFI] = IpConnectivityLogClass.WIFI; |
| 331 | TRANSPORT_LINKLAYER_MAP[TRANSPORT_BLUETOOTH] = IpConnectivityLogClass.BLUETOOTH; |
| 332 | TRANSPORT_LINKLAYER_MAP[TRANSPORT_ETHERNET] = IpConnectivityLogClass.ETHERNET; |
| 333 | TRANSPORT_LINKLAYER_MAP[TRANSPORT_VPN] = IpConnectivityLogClass.UNKNOWN; |
| 334 | // TODO: change mapping TRANSPORT_WIFI_AWARE -> WIFI_AWARE |
| 335 | TRANSPORT_LINKLAYER_MAP[TRANSPORT_WIFI_AWARE] = IpConnectivityLogClass.UNKNOWN; |
| 336 | }; |
| 337 | |
| 338 | private static int ifnameToLinkLayer(String ifname) { |
| 339 | // Do not try to catch all interface names with regexes, instead only catch patterns that |
| 340 | // are cheap to check, and otherwise fallback on postprocessing in aggregation layer. |
| 341 | for (int i = 0; i < IFNAME_LINKLAYER_MAP.size(); i++) { |
| 342 | String pattern = IFNAME_LINKLAYER_MAP.valueAt(i); |
| 343 | if (ifname.startsWith(pattern)) { |
| 344 | return IFNAME_LINKLAYER_MAP.keyAt(i); |
| 345 | } |
| 346 | } |
| 347 | return IpConnectivityLogClass.UNKNOWN; |
| 348 | } |
| 349 | |
| 350 | private static final SparseArray<String> IFNAME_LINKLAYER_MAP = new SparseArray<String>(); |
| 351 | static { |
| 352 | IFNAME_LINKLAYER_MAP.put(IpConnectivityLogClass.CELLULAR, "rmnet"); |
| 353 | IFNAME_LINKLAYER_MAP.put(IpConnectivityLogClass.WIFI, "wlan"); |
| 354 | IFNAME_LINKLAYER_MAP.put(IpConnectivityLogClass.BLUETOOTH, "bt-pan"); |
| 355 | // TODO: rekey to USB |
| 356 | IFNAME_LINKLAYER_MAP.put(IpConnectivityLogClass.ETHERNET, "usb"); |
| 357 | // TODO: add mappings for nan -> WIFI_AWARE and p2p -> WIFI_P2P |
| 358 | } |
Hugo Benichi | 50a84c6 | 2016-09-02 09:00:59 +0900 | [diff] [blame] | 359 | } |