blob: a011692be37c5a5a179df1a7c8429af51bd1f573 [file] [log] [blame]
Hugo Benichi50a84c62016-09-02 09:00:59 +09001/*
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
17package com.android.server.connectivity;
18
Hugo Benichi73fd4d12017-03-15 23:05:01 +090019import static android.net.NetworkCapabilities.MAX_TRANSPORT;
20import static android.net.NetworkCapabilities.TRANSPORT_BLUETOOTH;
21import static android.net.NetworkCapabilities.TRANSPORT_CELLULAR;
22import static android.net.NetworkCapabilities.TRANSPORT_ETHERNET;
Hugo Benichi27a51172017-07-18 11:35:18 +090023import static android.net.NetworkCapabilities.TRANSPORT_LOWPAN;
Hugo Benichi73fd4d12017-03-15 23:05:01 +090024import static android.net.NetworkCapabilities.TRANSPORT_VPN;
25import static android.net.NetworkCapabilities.TRANSPORT_WIFI;
26import static android.net.NetworkCapabilities.TRANSPORT_WIFI_AWARE;
Hugo Benichi73fd4d12017-03-15 23:05:01 +090027
Hugo Benichi380a0632017-10-20 09:25:29 +090028import android.net.ConnectivityManager;
Hugo Benichi50a84c62016-09-02 09:00:59 +090029import android.net.ConnectivityMetricsEvent;
30import android.net.metrics.ApfProgramEvent;
31import android.net.metrics.ApfStats;
32import android.net.metrics.DefaultNetworkEvent;
33import android.net.metrics.DhcpClientEvent;
34import android.net.metrics.DhcpErrorEvent;
35import android.net.metrics.DnsEvent;
Hugo Benichi5eb90532017-03-23 18:38:22 +090036import android.net.metrics.ConnectStats;
Hugo Benichi50a84c62016-09-02 09:00:59 +090037import android.net.metrics.IpManagerEvent;
38import android.net.metrics.IpReachabilityEvent;
39import android.net.metrics.NetworkEvent;
40import android.net.metrics.RaEvent;
41import android.net.metrics.ValidationProbeEvent;
Hugo Benichi60c9f632017-09-05 13:34:48 +090042import android.net.metrics.WakeupStats;
Hugo Benichi50a84c62016-09-02 09:00:59 +090043import android.os.Parcelable;
Hugo Benichi73fd4d12017-03-15 23:05:01 +090044import android.util.SparseArray;
Hugo Benichi5eb90532017-03-23 18:38:22 +090045import android.util.SparseIntArray;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +010046import com.android.server.connectivity.metrics.nano.IpConnectivityLogClass;
Hugo Benichi5eb90532017-03-23 18:38:22 +090047import com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.IpConnectivityEvent;
48import com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.IpConnectivityLog;
49import com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.NetworkId;
50import com.android.server.connectivity.metrics.nano.IpConnectivityLogClass.Pair;
Hugo Benichi50a84c62016-09-02 09:00:59 +090051import java.io.IOException;
52import java.util.ArrayList;
53import java.util.List;
54
Hugo Benichi50a84c62016-09-02 09:00:59 +090055
56/** {@hide} */
57final public class IpConnectivityEventBuilder {
58 private IpConnectivityEventBuilder() {
59 }
60
Hugo Benichi0d4a3982016-11-25 11:24:22 +090061 public static byte[] serialize(int dropped, List<IpConnectivityEvent> events)
Hugo Benichi50a84c62016-09-02 09:00:59 +090062 throws IOException {
63 final IpConnectivityLog log = new IpConnectivityLog();
Hugo Benichi0d4a3982016-11-25 11:24:22 +090064 log.events = events.toArray(new IpConnectivityEvent[events.size()]);
Hugo Benichi50a84c62016-09-02 09:00:59 +090065 log.droppedEvents = dropped;
Hugo Benichid680d4c2016-10-13 13:16:16 +090066 if ((log.events.length > 0) || (dropped > 0)) {
67 // Only write version number if log has some information at all.
68 log.version = IpConnectivityMetrics.VERSION;
69 }
Hugo Benichi50a84c62016-09-02 09:00:59 +090070 return IpConnectivityLog.toByteArray(log);
71 }
72
Hugo Benichi0d4a3982016-11-25 11:24:22 +090073 public static List<IpConnectivityEvent> toProto(List<ConnectivityMetricsEvent> eventsIn) {
Hugo Benichi50a84c62016-09-02 09:00:59 +090074 final ArrayList<IpConnectivityEvent> eventsOut = new ArrayList<>(eventsIn.size());
75 for (ConnectivityMetricsEvent in : eventsIn) {
76 final IpConnectivityEvent out = toProto(in);
77 if (out == null) {
78 continue;
79 }
80 eventsOut.add(out);
81 }
Hugo Benichi0d4a3982016-11-25 11:24:22 +090082 return eventsOut;
Hugo Benichi50a84c62016-09-02 09:00:59 +090083 }
84
85 public static IpConnectivityEvent toProto(ConnectivityMetricsEvent ev) {
Hugo Benichi5eb90532017-03-23 18:38:22 +090086 final IpConnectivityEvent out = buildEvent(ev.netId, ev.transports, ev.ifname);
87 out.timeMs = ev.timestamp;
Hugo Benichi50a84c62016-09-02 09:00:59 +090088 if (!setEvent(out, ev.data)) {
89 return null;
90 }
Hugo Benichi50a84c62016-09-02 09:00:59 +090091 return out;
92 }
93
Hugo Benichi5eb90532017-03-23 18:38:22 +090094 public static IpConnectivityEvent toProto(ConnectStats in) {
95 IpConnectivityLogClass.ConnectStatistics stats =
96 new IpConnectivityLogClass.ConnectStatistics();
97 stats.connectCount = in.connectCount;
98 stats.connectBlockingCount = in.connectBlockingCount;
99 stats.ipv6AddrCount = in.ipv6ConnectCount;
100 stats.latenciesMs = in.latencies.toArray();
101 stats.errnosCounters = toPairArray(in.errnos);
102 final IpConnectivityEvent out = buildEvent(in.netId, in.transports, null);
103 out.setConnectStatistics(stats);
104 return out;
105 }
106
107
Hugo Benichi2a5cfb92017-03-22 22:21:44 +0900108 public static IpConnectivityEvent toProto(DnsEvent in) {
Hugo Benichi2a5cfb92017-03-22 22:21:44 +0900109 IpConnectivityLogClass.DNSLookupBatch dnsLookupBatch =
110 new IpConnectivityLogClass.DNSLookupBatch();
111 in.resize(in.eventCount);
112 dnsLookupBatch.eventTypes = bytesToInts(in.eventTypes);
113 dnsLookupBatch.returnCodes = bytesToInts(in.returnCodes);
114 dnsLookupBatch.latenciesMs = in.latenciesMs;
Hugo Benichi5eb90532017-03-23 18:38:22 +0900115 final IpConnectivityEvent out = buildEvent(in.netId, in.transports, null);
Hugo Benichi2a5cfb92017-03-22 22:21:44 +0900116 out.setDnsLookupBatch(dnsLookupBatch);
Hugo Benichi2a5cfb92017-03-22 22:21:44 +0900117 return out;
118 }
119
Hugo Benichi60c9f632017-09-05 13:34:48 +0900120 public static IpConnectivityEvent toProto(WakeupStats in) {
121 IpConnectivityLogClass.WakeupStats wakeupStats =
122 new IpConnectivityLogClass.WakeupStats();
123 in.updateDuration();
124 wakeupStats.durationSec = in.durationSec;
125 wakeupStats.totalWakeups = in.totalWakeups;
126 wakeupStats.rootWakeups = in.rootWakeups;
127 wakeupStats.systemWakeups = in.systemWakeups;
128 wakeupStats.nonApplicationWakeups = in.nonApplicationWakeups;
129 wakeupStats.applicationWakeups = in.applicationWakeups;
Hugo Benichi175b5742017-09-19 13:15:26 +0900130 wakeupStats.noUidWakeups = in.noUidWakeups;
Hugo Benichi60c9f632017-09-05 13:34:48 +0900131 final IpConnectivityEvent out = buildEvent(0, 0, in.iface);
132 out.setWakeupStats(wakeupStats);
133 return out;
134 }
135
Hugo Benichi1193a9c2017-10-19 14:58:15 +0900136 public static IpConnectivityEvent toProto(DefaultNetworkEvent in) {
137 IpConnectivityLogClass.DefaultNetworkEvent ev =
138 new IpConnectivityLogClass.DefaultNetworkEvent();
Hugo Benichi380a0632017-10-20 09:25:29 +0900139 ev.finalScore = in.finalScore;
140 ev.initialScore = in.initialScore;
141 ev.ipSupport = ipSupportOf(in);
142 ev.defaultNetworkDurationMs = in.durationMs;
143 ev.validationDurationMs = in.validatedMs;
144 ev.previousDefaultNetworkLinkLayer = transportsToLinkLayer(in.previousTransports);
145 final IpConnectivityEvent out = buildEvent(in.netId, in.transports, null);
146 if (in.transports == 0) {
147 // Set link layer to NONE for events representing the absence of a default network.
148 out.linkLayer = IpConnectivityLogClass.NONE;
149 }
Hugo Benichi1193a9c2017-10-19 14:58:15 +0900150 out.setDefaultNetworkEvent(ev);
151 return out;
152 }
153
Hugo Benichi5eb90532017-03-23 18:38:22 +0900154 private static IpConnectivityEvent buildEvent(int netId, long transports, String ifname) {
155 final IpConnectivityEvent ev = new IpConnectivityEvent();
156 ev.networkId = netId;
157 ev.transports = transports;
158 if (ifname != null) {
159 ev.ifName = ifname;
160 }
161 inferLinkLayer(ev);
162 return ev;
163 }
164
Hugo Benichi50a84c62016-09-02 09:00:59 +0900165 private static boolean setEvent(IpConnectivityEvent out, Parcelable in) {
166 if (in instanceof DhcpErrorEvent) {
167 setDhcpErrorEvent(out, (DhcpErrorEvent) in);
168 return true;
169 }
170
171 if (in instanceof DhcpClientEvent) {
172 setDhcpClientEvent(out, (DhcpClientEvent) in);
173 return true;
174 }
175
Hugo Benichi50a84c62016-09-02 09:00:59 +0900176 if (in instanceof IpManagerEvent) {
177 setIpManagerEvent(out, (IpManagerEvent) in);
178 return true;
179 }
180
181 if (in instanceof IpReachabilityEvent) {
182 setIpReachabilityEvent(out, (IpReachabilityEvent) in);
183 return true;
184 }
185
Hugo Benichi50a84c62016-09-02 09:00:59 +0900186 if (in instanceof NetworkEvent) {
187 setNetworkEvent(out, (NetworkEvent) in);
188 return true;
189 }
190
191 if (in instanceof ValidationProbeEvent) {
192 setValidationProbeEvent(out, (ValidationProbeEvent) in);
193 return true;
194 }
195
196 if (in instanceof ApfProgramEvent) {
197 setApfProgramEvent(out, (ApfProgramEvent) in);
198 return true;
199 }
200
201 if (in instanceof ApfStats) {
202 setApfStats(out, (ApfStats) in);
203 return true;
204 }
205
206 if (in instanceof RaEvent) {
207 setRaEvent(out, (RaEvent) in);
208 return true;
209 }
210
211 return false;
212 }
213
214 private static void setDhcpErrorEvent(IpConnectivityEvent out, DhcpErrorEvent in) {
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100215 IpConnectivityLogClass.DHCPEvent dhcpEvent = new IpConnectivityLogClass.DHCPEvent();
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100216 dhcpEvent.setErrorCode(in.errorCode);
217 out.setDhcpEvent(dhcpEvent);
Hugo Benichi50a84c62016-09-02 09:00:59 +0900218 }
219
220 private static void setDhcpClientEvent(IpConnectivityEvent out, DhcpClientEvent in) {
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100221 IpConnectivityLogClass.DHCPEvent dhcpEvent = new IpConnectivityLogClass.DHCPEvent();
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100222 dhcpEvent.setStateTransition(in.msg);
223 dhcpEvent.durationMs = in.durationMs;
224 out.setDhcpEvent(dhcpEvent);
Hugo Benichi50a84c62016-09-02 09:00:59 +0900225 }
226
Hugo Benichi50a84c62016-09-02 09:00:59 +0900227 private static void setIpManagerEvent(IpConnectivityEvent out, IpManagerEvent in) {
Hugo Benichi22d9b2d2017-02-22 13:02:27 +0900228 IpConnectivityLogClass.IpProvisioningEvent ipProvisioningEvent =
229 new IpConnectivityLogClass.IpProvisioningEvent();
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100230 ipProvisioningEvent.eventType = in.eventType;
231 ipProvisioningEvent.latencyMs = (int) in.durationMs;
232 out.setIpProvisioningEvent(ipProvisioningEvent);
Hugo Benichi50a84c62016-09-02 09:00:59 +0900233 }
234
235 private static void setIpReachabilityEvent(IpConnectivityEvent out, IpReachabilityEvent in) {
Hugo Benichi22d9b2d2017-02-22 13:02:27 +0900236 IpConnectivityLogClass.IpReachabilityEvent ipReachabilityEvent =
237 new IpConnectivityLogClass.IpReachabilityEvent();
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100238 ipReachabilityEvent.eventType = in.eventType;
239 out.setIpReachabilityEvent(ipReachabilityEvent);
Hugo Benichi50a84c62016-09-02 09:00:59 +0900240 }
241
Hugo Benichi50a84c62016-09-02 09:00:59 +0900242 private static void setNetworkEvent(IpConnectivityEvent out, NetworkEvent in) {
Hugo Benichi22d9b2d2017-02-22 13:02:27 +0900243 IpConnectivityLogClass.NetworkEvent networkEvent =
244 new IpConnectivityLogClass.NetworkEvent();
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100245 networkEvent.networkId = netIdOf(in.netId);
246 networkEvent.eventType = in.eventType;
247 networkEvent.latencyMs = (int) in.durationMs;
248 out.setNetworkEvent(networkEvent);
Hugo Benichi50a84c62016-09-02 09:00:59 +0900249 }
250
251 private static void setValidationProbeEvent(IpConnectivityEvent out, ValidationProbeEvent in) {
Hugo Benichi22d9b2d2017-02-22 13:02:27 +0900252 IpConnectivityLogClass.ValidationProbeEvent validationProbeEvent =
253 new IpConnectivityLogClass.ValidationProbeEvent();
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100254 validationProbeEvent.latencyMs = (int) in.durationMs;
255 validationProbeEvent.probeType = in.probeType;
256 validationProbeEvent.probeResult = in.returnCode;
257 out.setValidationProbeEvent(validationProbeEvent);
Hugo Benichi50a84c62016-09-02 09:00:59 +0900258 }
259
260 private static void setApfProgramEvent(IpConnectivityEvent out, ApfProgramEvent in) {
Hugo Benichi22d9b2d2017-02-22 13:02:27 +0900261 IpConnectivityLogClass.ApfProgramEvent apfProgramEvent =
262 new IpConnectivityLogClass.ApfProgramEvent();
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100263 apfProgramEvent.lifetime = in.lifetime;
Hugo Benichi22d9b2d2017-02-22 13:02:27 +0900264 apfProgramEvent.effectiveLifetime = in.actualLifetime;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100265 apfProgramEvent.filteredRas = in.filteredRas;
266 apfProgramEvent.currentRas = in.currentRas;
267 apfProgramEvent.programLength = in.programLength;
Hugo Benichi50a84c62016-09-02 09:00:59 +0900268 if (isBitSet(in.flags, ApfProgramEvent.FLAG_MULTICAST_FILTER_ON)) {
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100269 apfProgramEvent.dropMulticast = true;
Hugo Benichi50a84c62016-09-02 09:00:59 +0900270 }
271 if (isBitSet(in.flags, ApfProgramEvent.FLAG_HAS_IPV4_ADDRESS)) {
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100272 apfProgramEvent.hasIpv4Addr = true;
Hugo Benichi50a84c62016-09-02 09:00:59 +0900273 }
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100274 out.setApfProgramEvent(apfProgramEvent);
Hugo Benichi50a84c62016-09-02 09:00:59 +0900275 }
276
277 private static void setApfStats(IpConnectivityEvent out, ApfStats in) {
Hugo Benichi22d9b2d2017-02-22 13:02:27 +0900278 IpConnectivityLogClass.ApfStatistics apfStatistics =
279 new IpConnectivityLogClass.ApfStatistics();
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100280 apfStatistics.durationMs = in.durationMs;
281 apfStatistics.receivedRas = in.receivedRas;
282 apfStatistics.matchingRas = in.matchingRas;
283 apfStatistics.droppedRas = in.droppedRas;
284 apfStatistics.zeroLifetimeRas = in.zeroLifetimeRas;
285 apfStatistics.parseErrors = in.parseErrors;
286 apfStatistics.programUpdates = in.programUpdates;
Hugo Benichi22d9b2d2017-02-22 13:02:27 +0900287 apfStatistics.programUpdatesAll = in.programUpdatesAll;
288 apfStatistics.programUpdatesAllowingMulticast = in.programUpdatesAllowingMulticast;
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100289 apfStatistics.maxProgramSize = in.maxProgramSize;
290 out.setApfStatistics(apfStatistics);
Hugo Benichi50a84c62016-09-02 09:00:59 +0900291 }
292
293 private static void setRaEvent(IpConnectivityEvent out, RaEvent in) {
Tamas Berghammer383db5eb2016-06-22 15:21:38 +0100294 IpConnectivityLogClass.RaEvent raEvent = new IpConnectivityLogClass.RaEvent();
295 raEvent.routerLifetime = in.routerLifetime;
296 raEvent.prefixValidLifetime = in.prefixValidLifetime;
297 raEvent.prefixPreferredLifetime = in.prefixPreferredLifetime;
298 raEvent.routeInfoLifetime = in.routeInfoLifetime;
299 raEvent.rdnssLifetime = in.rdnssLifetime;
300 raEvent.dnsslLifetime = in.dnsslLifetime;
301 out.setRaEvent(raEvent);
Hugo Benichi50a84c62016-09-02 09:00:59 +0900302 }
303
304 private static int[] bytesToInts(byte[] in) {
305 final int[] out = new int[in.length];
306 for (int i = 0; i < in.length; i++) {
307 out[i] = in[i] & 0xFF;
308 }
309 return out;
310 }
311
Hugo Benichi5eb90532017-03-23 18:38:22 +0900312 private static Pair[] toPairArray(SparseIntArray counts) {
313 final int s = counts.size();
314 Pair[] pairs = new Pair[s];
315 for (int i = 0; i < s; i++) {
316 Pair p = new Pair();
317 p.key = counts.keyAt(i);
318 p.value = counts.valueAt(i);
319 pairs[i] = p;
320 }
321 return pairs;
322 }
323
Hugo Benichi50a84c62016-09-02 09:00:59 +0900324 private static NetworkId netIdOf(int netid) {
325 final NetworkId ni = new NetworkId();
326 ni.networkId = netid;
327 return ni;
328 }
329
330 private static int ipSupportOf(DefaultNetworkEvent in) {
Hugo Benichi380a0632017-10-20 09:25:29 +0900331 if (in.ipv4 && in.ipv6) {
Hugo Benichi50a84c62016-09-02 09:00:59 +0900332 return IpConnectivityLogClass.DefaultNetworkEvent.DUAL;
333 }
Hugo Benichi380a0632017-10-20 09:25:29 +0900334 if (in.ipv6) {
Hugo Benichi50a84c62016-09-02 09:00:59 +0900335 return IpConnectivityLogClass.DefaultNetworkEvent.IPV6;
336 }
Hugo Benichi380a0632017-10-20 09:25:29 +0900337 if (in.ipv4) {
Hugo Benichi50a84c62016-09-02 09:00:59 +0900338 return IpConnectivityLogClass.DefaultNetworkEvent.IPV4;
339 }
340 return IpConnectivityLogClass.DefaultNetworkEvent.NONE;
341 }
342
343 private static boolean isBitSet(int flags, int bit) {
344 return (flags & (1 << bit)) != 0;
345 }
Hugo Benichi73fd4d12017-03-15 23:05:01 +0900346
347 private static void inferLinkLayer(IpConnectivityEvent ev) {
348 int linkLayer = IpConnectivityLogClass.UNKNOWN;
349 if (ev.transports != 0) {
350 linkLayer = transportsToLinkLayer(ev.transports);
351 } else if (ev.ifName != null) {
352 linkLayer = ifnameToLinkLayer(ev.ifName);
353 }
354 if (linkLayer == IpConnectivityLogClass.UNKNOWN) {
355 return;
356 }
357 ev.linkLayer = linkLayer;
358 ev.ifName = "";
359 }
360
361 private static int transportsToLinkLayer(long transports) {
362 switch (Long.bitCount(transports)) {
363 case 0:
364 return IpConnectivityLogClass.UNKNOWN;
365 case 1:
366 int t = Long.numberOfTrailingZeros(transports);
367 return transportToLinkLayer(t);
368 default:
369 return IpConnectivityLogClass.MULTIPLE;
370 }
371 }
372
373 private static int transportToLinkLayer(int transport) {
374 if (0 <= transport && transport < TRANSPORT_LINKLAYER_MAP.length) {
375 return TRANSPORT_LINKLAYER_MAP[transport];
376 }
377 return IpConnectivityLogClass.UNKNOWN;
378 }
379
380 private static final int[] TRANSPORT_LINKLAYER_MAP = new int[MAX_TRANSPORT + 1];
381 static {
382 TRANSPORT_LINKLAYER_MAP[TRANSPORT_CELLULAR] = IpConnectivityLogClass.CELLULAR;
383 TRANSPORT_LINKLAYER_MAP[TRANSPORT_WIFI] = IpConnectivityLogClass.WIFI;
384 TRANSPORT_LINKLAYER_MAP[TRANSPORT_BLUETOOTH] = IpConnectivityLogClass.BLUETOOTH;
385 TRANSPORT_LINKLAYER_MAP[TRANSPORT_ETHERNET] = IpConnectivityLogClass.ETHERNET;
386 TRANSPORT_LINKLAYER_MAP[TRANSPORT_VPN] = IpConnectivityLogClass.UNKNOWN;
Hugo Benichi27a51172017-07-18 11:35:18 +0900387 TRANSPORT_LINKLAYER_MAP[TRANSPORT_WIFI_AWARE] = IpConnectivityLogClass.WIFI_NAN;
388 TRANSPORT_LINKLAYER_MAP[TRANSPORT_LOWPAN] = IpConnectivityLogClass.LOWPAN;
Hugo Benichi73fd4d12017-03-15 23:05:01 +0900389 };
390
391 private static int ifnameToLinkLayer(String ifname) {
392 // Do not try to catch all interface names with regexes, instead only catch patterns that
393 // are cheap to check, and otherwise fallback on postprocessing in aggregation layer.
Hugo Benichi27a51172017-07-18 11:35:18 +0900394 for (int i = 0; i < KNOWN_PREFIX; i++) {
395 String pattern = IFNAME_PREFIXES[i];
Hugo Benichi73fd4d12017-03-15 23:05:01 +0900396 if (ifname.startsWith(pattern)) {
Hugo Benichi27a51172017-07-18 11:35:18 +0900397 return IFNAME_LINKLAYERS[i];
Hugo Benichi73fd4d12017-03-15 23:05:01 +0900398 }
399 }
400 return IpConnectivityLogClass.UNKNOWN;
401 }
402
Hugo Benichi27a51172017-07-18 11:35:18 +0900403 private static final int KNOWN_PREFIX = 7;
404 private static final String[] IFNAME_PREFIXES = new String[KNOWN_PREFIX];
405 private static final int[] IFNAME_LINKLAYERS = new int[KNOWN_PREFIX];
Hugo Benichi73fd4d12017-03-15 23:05:01 +0900406 static {
Hugo Benichi27a51172017-07-18 11:35:18 +0900407 // Ordered from most likely link layer to least likely.
408 IFNAME_PREFIXES[0] = "rmnet";
409 IFNAME_LINKLAYERS[0] = IpConnectivityLogClass.CELLULAR;
410
411 IFNAME_PREFIXES[1] = "wlan";
412 IFNAME_LINKLAYERS[1] = IpConnectivityLogClass.WIFI;
413
414 IFNAME_PREFIXES[2] = "bt-pan";
415 IFNAME_LINKLAYERS[2] = IpConnectivityLogClass.BLUETOOTH;
416
417 IFNAME_PREFIXES[3] = "p2p";
418 IFNAME_LINKLAYERS[3] = IpConnectivityLogClass.WIFI_P2P;
419
420 IFNAME_PREFIXES[4] = "aware";
421 IFNAME_LINKLAYERS[4] = IpConnectivityLogClass.WIFI_NAN;
422
423 IFNAME_PREFIXES[5] = "eth";
424 IFNAME_LINKLAYERS[5] = IpConnectivityLogClass.ETHERNET;
425
426 IFNAME_PREFIXES[6] = "wpan";
427 IFNAME_LINKLAYERS[6] = IpConnectivityLogClass.LOWPAN;
Hugo Benichi73fd4d12017-03-15 23:05:01 +0900428 }
Hugo Benichi50a84c62016-09-02 09:00:59 +0900429}