diff options
author | Justin Klaassen <justinklaassen@google.com> | 2017-09-18 17:38:50 -0400 |
---|---|---|
committer | Justin Klaassen <justinklaassen@google.com> | 2017-09-18 17:38:50 -0400 |
commit | bc81c7ada5aab3806dd0b17498f5c9672c9b33c4 (patch) | |
tree | 7fdcc541a9ac9e92134f1a80cec557fee772bcf8 /android/net | |
parent | 10d07c88d69cc64f73a069163e7ea5ba2519a099 (diff) | |
download | android-28-bc81c7ada5aab3806dd0b17498f5c9672c9b33c4.tar.gz |
Import Android SDK Platform P [4344336]
/google/data/ro/projects/android/fetch_artifact \
--bid 4344336 \
--target sdk_phone_armv7-win_sdk \
sdk-repo-linux-sources-4344336.zip
AndroidVersion.ApiLevel has been modified to appear as 28
Change-Id: If482fcd4cfaf6c5e544e5574926be25a293e9a6d
Diffstat (limited to 'android/net')
-rw-r--r-- | android/net/LinkProperties.java | 72 | ||||
-rw-r--r-- | android/net/metrics/WakeupEvent.java | 34 | ||||
-rw-r--r-- | android/net/metrics/WakeupStats.java | 87 |
3 files changed, 144 insertions, 49 deletions
diff --git a/android/net/LinkProperties.java b/android/net/LinkProperties.java index f527f77d..2c9fb23e 100644 --- a/android/net/LinkProperties.java +++ b/android/net/LinkProperties.java @@ -70,8 +70,23 @@ public final class LinkProperties implements Parcelable { * @hide */ public static class CompareResult<T> { - public List<T> removed = new ArrayList<T>(); - public List<T> added = new ArrayList<T>(); + public final List<T> removed = new ArrayList<T>(); + public final List<T> added = new ArrayList<T>(); + + public CompareResult() {} + + public CompareResult(Collection<T> oldItems, Collection<T> newItems) { + if (oldItems != null) { + removed.addAll(oldItems); + } + if (newItems != null) { + for (T newItem : newItems) { + if (!removed.remove(newItem)) { + added.add(newItem); + } + } + } + } @Override public String toString() { @@ -1000,17 +1015,8 @@ public final class LinkProperties implements Parcelable { * are in target but not in mLinkAddresses are placed in the * addedAddresses. */ - CompareResult<LinkAddress> result = new CompareResult<LinkAddress>(); - result.removed = new ArrayList<LinkAddress>(mLinkAddresses); - result.added.clear(); - if (target != null) { - for (LinkAddress newAddress : target.getLinkAddresses()) { - if (! result.removed.remove(newAddress)) { - result.added.add(newAddress); - } - } - } - return result; + return new CompareResult<>(mLinkAddresses, + target != null ? target.getLinkAddresses() : null); } /** @@ -1029,18 +1035,7 @@ public final class LinkProperties implements Parcelable { * are in target but not in mDnses are placed in the * addedAddresses. */ - CompareResult<InetAddress> result = new CompareResult<InetAddress>(); - - result.removed = new ArrayList<InetAddress>(mDnses); - result.added.clear(); - if (target != null) { - for (InetAddress newAddress : target.getDnsServers()) { - if (! result.removed.remove(newAddress)) { - result.added.add(newAddress); - } - } - } - return result; + return new CompareResult<>(mDnses, target != null ? target.getDnsServers() : null); } /** @@ -1058,18 +1053,7 @@ public final class LinkProperties implements Parcelable { * leaving the routes that are different. And route address which * are in target but not in mRoutes are placed in added. */ - CompareResult<RouteInfo> result = new CompareResult<RouteInfo>(); - - result.removed = getAllRoutes(); - result.added.clear(); - if (target != null) { - for (RouteInfo r : target.getAllRoutes()) { - if (! result.removed.remove(r)) { - result.added.add(r); - } - } - } - return result; + return new CompareResult<>(getAllRoutes(), target != null ? target.getAllRoutes() : null); } /** @@ -1087,18 +1071,8 @@ public final class LinkProperties implements Parcelable { * leaving the interface names that are different. And interface names which * are in target but not in this are placed in added. */ - CompareResult<String> result = new CompareResult<String>(); - - result.removed = getAllInterfaceNames(); - result.added.clear(); - if (target != null) { - for (String r : target.getAllInterfaceNames()) { - if (! result.removed.remove(r)) { - result.added.add(r); - } - } - } - return result; + return new CompareResult<>(getAllInterfaceNames(), + target != null ? target.getAllInterfaceNames() : null); } diff --git a/android/net/metrics/WakeupEvent.java b/android/net/metrics/WakeupEvent.java new file mode 100644 index 00000000..cbf3fc8c --- /dev/null +++ b/android/net/metrics/WakeupEvent.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.metrics; + +/** + * An event logged when NFLOG notifies userspace of a wakeup packet for + * watched interfaces. + * {@hide} + */ +public class WakeupEvent { + public String iface; + public long timestampMs; + public int uid; + + @Override + public String toString() { + return String.format("WakeupEvent(%tT.%tL, %s, uid: %d)", + timestampMs, timestampMs, iface, uid); + } +} diff --git a/android/net/metrics/WakeupStats.java b/android/net/metrics/WakeupStats.java new file mode 100644 index 00000000..d520b974 --- /dev/null +++ b/android/net/metrics/WakeupStats.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2017 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package android.net.metrics; + +import android.os.Process; +import android.os.SystemClock; + +/** + * An event logged per interface and that aggregates WakeupEvents for that interface. + * {@hide} + */ +public class WakeupStats { + + private static final int NO_UID = -1; + + public final long creationTimeMs = SystemClock.elapsedRealtime(); + public final String iface; + + public long totalWakeups = 0; + public long rootWakeups = 0; + public long systemWakeups = 0; + public long nonApplicationWakeups = 0; + public long applicationWakeups = 0; + public long unroutedWakeups = 0; + public long durationSec = 0; + + public WakeupStats(String iface) { + this.iface = iface; + } + + /** Update durationSec with current time. */ + public void updateDuration() { + durationSec = (SystemClock.elapsedRealtime() - creationTimeMs) / 1000; + } + + /** Update wakeup counters for the given WakeupEvent. */ + public void countEvent(WakeupEvent ev) { + totalWakeups++; + switch (ev.uid) { + case Process.ROOT_UID: + rootWakeups++; + break; + case Process.SYSTEM_UID: + systemWakeups++; + break; + case NO_UID: + unroutedWakeups++; + break; + default: + if (ev.uid >= Process.FIRST_APPLICATION_UID) { + applicationWakeups++; + } else { + nonApplicationWakeups++; + } + break; + } + } + + @Override + public String toString() { + updateDuration(); + return new StringBuilder() + .append("WakeupStats(").append(iface) + .append(", total: ").append(totalWakeups) + .append(", root: ").append(rootWakeups) + .append(", system: ").append(systemWakeups) + .append(", apps: ").append(applicationWakeups) + .append(", non-apps: ").append(nonApplicationWakeups) + .append(", unrouted: ").append(unroutedWakeups) + .append(", ").append(durationSec).append("s)") + .toString(); + } +} |