frameworks/base
Révision | eb71e821edd929d48a824a9a4bbdfb710b50d324 (tree) |
---|---|
l'heure | 2018-12-05 14:16:39 |
Auteur | android-build-team Robot <android-build-team-robot@goog...> |
Commiter | android-build-team Robot |
Merge cherrypicks of [5704859, 5705300, 5704034, 5704195, 5705082, 5704058, 5704059, 5704932, 5705340, 5705341, 5705342, 5705343, 5705344, 5705361, 5705362, 5705363, 5705364, 5704870, 5704196, 5705083, 5701785, 5701786, 5701787, 5704035, 5705261, 5705281, 5704036, 5704037, 5704038, 5704871, 5704933, 5704872, 5705347, 5705262, 5704934] into pi-qpr2-release
Change-Id: Ifb7d048c4deb34b18e69173fd09e91c45980e2d9
@@ -18,6 +18,7 @@ package android.bluetooth; | ||
18 | 18 | |
19 | 19 | import android.os.Parcel; |
20 | 20 | import android.os.Parcelable; |
21 | +import android.util.EventLog; | |
21 | 22 | |
22 | 23 | |
23 | 24 | /** |
@@ -30,6 +31,8 @@ import android.os.Parcelable; | ||
30 | 31 | */ |
31 | 32 | public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { |
32 | 33 | |
34 | + private static final int MAX_DESCRIPTOR_SIZE = 2048; | |
35 | + | |
33 | 36 | private final String mName; |
34 | 37 | private final String mDescription; |
35 | 38 | private final String mProvider; |
@@ -55,6 +58,12 @@ public final class BluetoothHidDeviceAppSdpSettings implements Parcelable { | ||
55 | 58 | mDescription = description; |
56 | 59 | mProvider = provider; |
57 | 60 | mSubclass = subclass; |
61 | + | |
62 | + if (descriptors == null || descriptors.length > MAX_DESCRIPTOR_SIZE) { | |
63 | + EventLog.writeEvent(0x534e4554, "119819889", -1, ""); | |
64 | + throw new IllegalArgumentException("descriptors must be not null and shorter than " | |
65 | + + MAX_DESCRIPTOR_SIZE); | |
66 | + } | |
58 | 67 | mDescriptors = descriptors.clone(); |
59 | 68 | } |
60 | 69 |
@@ -776,14 +776,19 @@ public class NetworkStats implements Parcelable { | ||
776 | 776 | * packet needs to be subtracted from the root UID on the base interface both for tx |
777 | 777 | * and rx traffic (http://b/12249687, http:/b/33681750). |
778 | 778 | * |
779 | + * As for eBPF, the per uid stats is collected by different hook, the rx packets on base | |
780 | + * interface will not be counted. Thus, the adjustment on root uid is only needed in tx | |
781 | + * direction. | |
782 | + * | |
779 | 783 | * <p>This method will behave fine if {@code stackedIfaces} is an non-synchronized but add-only |
780 | 784 | * {@code ConcurrentHashMap} |
781 | 785 | * @param baseTraffic Traffic on the base interfaces. Will be mutated. |
782 | 786 | * @param stackedTraffic Stats with traffic stacked on top of our ifaces. Will also be mutated. |
783 | 787 | * @param stackedIfaces Mapping ipv6if -> ipv4if interface where traffic is counted on both. |
788 | + * @param useBpfStats True if eBPF is in use. | |
784 | 789 | */ |
785 | 790 | public static void apply464xlatAdjustments(NetworkStats baseTraffic, |
786 | - NetworkStats stackedTraffic, Map<String, String> stackedIfaces) { | |
791 | + NetworkStats stackedTraffic, Map<String, String> stackedIfaces, boolean useBpfStats) { | |
787 | 792 | // Total 464xlat traffic to subtract from uid 0 on all base interfaces. |
788 | 793 | // stackedIfaces may grow afterwards, but NetworkStats will just be resized automatically. |
789 | 794 | final NetworkStats adjustments = new NetworkStats(0, stackedIfaces.size()); |
@@ -802,15 +807,20 @@ public class NetworkStats implements Parcelable { | ||
802 | 807 | continue; |
803 | 808 | } |
804 | 809 | // Subtract any 464lat traffic seen for the root UID on the current base interface. |
810 | + // However, for eBPF, the per uid stats is collected by different hook, the rx packets | |
811 | + // on base interface will not be counted. Thus, the adjustment on root uid is only | |
812 | + // needed in tx direction. | |
805 | 813 | adjust.iface = baseIface; |
806 | - adjust.rxBytes = -(entry.rxBytes + entry.rxPackets * IPV4V6_HEADER_DELTA); | |
814 | + if (!useBpfStats) { | |
815 | + adjust.rxBytes = -(entry.rxBytes + entry.rxPackets * IPV4V6_HEADER_DELTA); | |
816 | + adjust.rxPackets = -entry.rxPackets; | |
817 | + } | |
807 | 818 | adjust.txBytes = -(entry.txBytes + entry.txPackets * IPV4V6_HEADER_DELTA); |
808 | - adjust.rxPackets = -entry.rxPackets; | |
809 | 819 | adjust.txPackets = -entry.txPackets; |
810 | 820 | adjustments.combineValues(adjust); |
811 | 821 | |
812 | - // For 464xlat traffic, xt_qtaguid only counts the bytes of the native IPv4 packet sent | |
813 | - // on the stacked interface with prefix "v4-" and drops the IPv6 header size after | |
822 | + // For 464xlat traffic, per uid stats only counts the bytes of the native IPv4 packet | |
823 | + // sent on the stacked interface with prefix "v4-" and drops the IPv6 header size after | |
814 | 824 | // unwrapping. To account correctly for on-the-wire traffic, add the 20 additional bytes |
815 | 825 | // difference for all packets (http://b/12249687, http:/b/33681750). |
816 | 826 | entry.rxBytes += entry.rxPackets * IPV4V6_HEADER_DELTA; |
@@ -829,8 +839,8 @@ public class NetworkStats implements Parcelable { | ||
829 | 839 | * base and stacked traffic. |
830 | 840 | * @param stackedIfaces Mapping ipv6if -> ipv4if interface where traffic is counted on both. |
831 | 841 | */ |
832 | - public void apply464xlatAdjustments(Map<String, String> stackedIfaces) { | |
833 | - apply464xlatAdjustments(this, this, stackedIfaces); | |
842 | + public void apply464xlatAdjustments(Map<String, String> stackedIfaces, boolean useBpfStats) { | |
843 | + apply464xlatAdjustments(this, this, stackedIfaces, useBpfStats); | |
834 | 844 | } |
835 | 845 | |
836 | 846 | /** |
@@ -113,11 +113,12 @@ public class NetworkStatsFactory { | ||
113 | 113 | |
114 | 114 | /** |
115 | 115 | * Applies 464xlat adjustments with ifaces noted with {@link #noteStackedIface(String, String)}. |
116 | - * @see NetworkStats#apply464xlatAdjustments(NetworkStats, NetworkStats, Map) | |
116 | + * @see NetworkStats#apply464xlatAdjustments(NetworkStats, NetworkStats, Map, boolean) | |
117 | 117 | */ |
118 | 118 | public static void apply464xlatAdjustments(NetworkStats baseTraffic, |
119 | - NetworkStats stackedTraffic) { | |
120 | - NetworkStats.apply464xlatAdjustments(baseTraffic, stackedTraffic, sStackedIfaces); | |
119 | + NetworkStats stackedTraffic, boolean useBpfStats) { | |
120 | + NetworkStats.apply464xlatAdjustments(baseTraffic, stackedTraffic, sStackedIfaces, | |
121 | + useBpfStats); | |
121 | 122 | } |
122 | 123 | |
123 | 124 | @VisibleForTesting |
@@ -263,7 +264,7 @@ public class NetworkStatsFactory { | ||
263 | 264 | |
264 | 265 | // No locking here: apply464xlatAdjustments behaves fine with an add-only ConcurrentHashMap. |
265 | 266 | // TODO: remove this and only apply adjustments in NetworkStatsService. |
266 | - stats.apply464xlatAdjustments(sStackedIfaces); | |
267 | + stats.apply464xlatAdjustments(sStackedIfaces, mUseBpfStats); | |
267 | 268 | |
268 | 269 | return stats; |
269 | 270 | } |
@@ -175,7 +175,7 @@ static int legacyReadNetworkStatsDetail(std::vector<stats_line>* lines, | ||
175 | 175 | } |
176 | 176 | } |
177 | 177 | s.tag = rawTag >> 32; |
178 | - if (limitTag != -1 && s.tag != limitTag) { | |
178 | + if (limitTag != -1 && s.tag != static_cast<uint32_t>(limitTag)) { | |
179 | 179 | //ALOGI("skipping due to tag: %s", buffer); |
180 | 180 | continue; |
181 | 181 | } |
@@ -188,7 +188,7 @@ static int legacyReadNetworkStatsDetail(std::vector<stats_line>* lines, | ||
188 | 188 | if (sscanf(pos, "%u %u %" PRIu64 " %" PRIu64 " %" PRIu64 " %" PRIu64, |
189 | 189 | &s.uid, &s.set, &s.rxBytes, &s.rxPackets, |
190 | 190 | &s.txBytes, &s.txPackets) == 6) { |
191 | - if (limitUid != -1 && limitUid != s.uid) { | |
191 | + if (limitUid != -1 && static_cast<uint32_t>(limitUid) != s.uid) { | |
192 | 192 | //ALOGI("skipping due to uid: %s", buffer); |
193 | 193 | continue; |
194 | 194 | } |
@@ -8768,6 +8768,14 @@ public class ActivityManagerService extends IActivityManager.Stub | ||
8768 | 8768 | |
8769 | 8769 | @Override |
8770 | 8770 | public boolean isAppForeground(int uid) { |
8771 | + int callerUid = Binder.getCallingUid(); | |
8772 | + if (UserHandle.isCore(callerUid) || callerUid == uid) { | |
8773 | + return isAppForegroundInternal(uid); | |
8774 | + } | |
8775 | + return false; | |
8776 | + } | |
8777 | + | |
8778 | + private boolean isAppForegroundInternal(int uid) { | |
8771 | 8779 | synchronized (this) { |
8772 | 8780 | UidRecord uidRec = mActiveUids.get(uid); |
8773 | 8781 | if (uidRec == null || uidRec.idle) { |
@@ -1622,7 +1622,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { | ||
1622 | 1622 | // fold tethering stats and operations into uid snapshot |
1623 | 1623 | final NetworkStats tetherSnapshot = getNetworkStatsTethering(STATS_PER_UID); |
1624 | 1624 | tetherSnapshot.filter(UID_ALL, ifaces, TAG_ALL); |
1625 | - NetworkStatsFactory.apply464xlatAdjustments(uidSnapshot, tetherSnapshot); | |
1625 | + NetworkStatsFactory.apply464xlatAdjustments(uidSnapshot, tetherSnapshot, | |
1626 | + mUseBpfTrafficStats); | |
1626 | 1627 | uidSnapshot.combineAllValues(tetherSnapshot); |
1627 | 1628 | |
1628 | 1629 | final TelephonyManager telephonyManager = (TelephonyManager) mContext.getSystemService( |
@@ -1632,7 +1633,8 @@ public class NetworkStatsService extends INetworkStatsService.Stub { | ||
1632 | 1633 | final NetworkStats vtStats = telephonyManager.getVtDataUsage(STATS_PER_UID); |
1633 | 1634 | if (vtStats != null) { |
1634 | 1635 | vtStats.filter(UID_ALL, ifaces, TAG_ALL); |
1635 | - NetworkStatsFactory.apply464xlatAdjustments(uidSnapshot, vtStats); | |
1636 | + NetworkStatsFactory.apply464xlatAdjustments(uidSnapshot, vtStats, | |
1637 | + mUseBpfTrafficStats); | |
1636 | 1638 | uidSnapshot.combineAllValues(vtStats); |
1637 | 1639 | } |
1638 | 1640 |
@@ -39,6 +39,7 @@ import static org.junit.Assert.assertEquals; | ||
39 | 39 | import static org.junit.Assert.assertTrue; |
40 | 40 | import static org.junit.Assert.fail; |
41 | 41 | |
42 | +import android.net.NetworkStats.Entry; | |
42 | 43 | import android.os.Process; |
43 | 44 | import android.support.test.runner.AndroidJUnit4; |
44 | 45 | import android.support.test.filters.SmallTest; |
@@ -785,7 +786,38 @@ public class NetworkStatsTest { | ||
785 | 786 | ArrayMap<String, String> stackedIface = new ArrayMap<>(); |
786 | 787 | stackedIface.put(v4Iface, baseIface); |
787 | 788 | |
788 | - NetworkStats.Entry otherEntry = new NetworkStats.Entry( | |
789 | + // Ipv4 traffic sent/received by an app on stacked interface. | |
790 | + final NetworkStats.Entry appEntry = new NetworkStats.Entry( | |
791 | + v4Iface, appUid, SET_DEFAULT, TAG_NONE, | |
792 | + 30501490 /* rxBytes */, | |
793 | + 22401 /* rxPackets */, | |
794 | + 876235 /* txBytes */, | |
795 | + 13805 /* txPackets */, | |
796 | + 0 /* operations */); | |
797 | + | |
798 | + // Traffic measured for the root uid on the base interface if eBPF is in use. | |
799 | + // Incorrectly includes appEntry's bytes and packets, plus IPv4-IPv6 translation | |
800 | + // overhead (20 bytes per packet), only for TX traffic. | |
801 | + final NetworkStats.Entry ebpfRootUidEntry = new NetworkStats.Entry( | |
802 | + baseIface, rootUid, SET_DEFAULT, TAG_NONE, | |
803 | + 163577 /* rxBytes */, | |
804 | + 187 /* rxPackets */, | |
805 | + 1169942 /* txBytes */, | |
806 | + 13902 /* txPackets */, | |
807 | + 0 /* operations */); | |
808 | + | |
809 | + // Traffic measured for the root uid on the base interface if xt_qtaguid is in use. | |
810 | + // Incorrectly includes appEntry's bytes and packets, plus IPv4-IPv6 translation | |
811 | + // overhead (20 bytes per packet), in both directions. | |
812 | + final NetworkStats.Entry xtRootUidEntry = new NetworkStats.Entry( | |
813 | + baseIface, rootUid, SET_DEFAULT, TAG_NONE, | |
814 | + 31113087 /* rxBytes */, | |
815 | + 22588 /* rxPackets */, | |
816 | + 1169942 /* txBytes */, | |
817 | + 13902 /* txPackets */, | |
818 | + 0 /* operations */); | |
819 | + | |
820 | + final NetworkStats.Entry otherEntry = new NetworkStats.Entry( | |
789 | 821 | otherIface, appUid, SET_DEFAULT, TAG_NONE, |
790 | 822 | 2600 /* rxBytes */, |
791 | 823 | 2 /* rxPackets */, |
@@ -793,39 +825,41 @@ public class NetworkStatsTest { | ||
793 | 825 | 3 /* txPackets */, |
794 | 826 | 0 /* operations */); |
795 | 827 | |
796 | - NetworkStats stats = new NetworkStats(TEST_START, 3) | |
797 | - .addValues(v4Iface, appUid, SET_DEFAULT, TAG_NONE, | |
798 | - 30501490 /* rxBytes */, | |
799 | - 22401 /* rxPackets */, | |
800 | - 876235 /* txBytes */, | |
801 | - 13805 /* txPackets */, | |
802 | - 0 /* operations */) | |
803 | - .addValues(baseIface, rootUid, SET_DEFAULT, TAG_NONE, | |
804 | - 31113087, | |
805 | - 22588, | |
806 | - 1169942, | |
807 | - 13902, | |
808 | - 0) | |
828 | + final NetworkStats statsXt = new NetworkStats(TEST_START, 3) | |
829 | + .addValues(appEntry) | |
830 | + .addValues(xtRootUidEntry) | |
809 | 831 | .addValues(otherEntry); |
810 | 832 | |
811 | - stats.apply464xlatAdjustments(stackedIface); | |
833 | + final NetworkStats statsEbpf = new NetworkStats(TEST_START, 3) | |
834 | + .addValues(appEntry) | |
835 | + .addValues(ebpfRootUidEntry) | |
836 | + .addValues(otherEntry); | |
812 | 837 | |
813 | - assertEquals(3, stats.size()); | |
814 | - assertValues(stats, 0, v4Iface, appUid, SET_DEFAULT, TAG_NONE, | |
815 | - METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, | |
838 | + statsXt.apply464xlatAdjustments(stackedIface, false); | |
839 | + statsEbpf.apply464xlatAdjustments(stackedIface, true); | |
840 | + | |
841 | + assertEquals(3, statsXt.size()); | |
842 | + assertEquals(3, statsEbpf.size()); | |
843 | + final NetworkStats.Entry expectedAppUid = new NetworkStats.Entry( | |
844 | + v4Iface, appUid, SET_DEFAULT, TAG_NONE, | |
816 | 845 | 30949510, |
817 | 846 | 22401, |
818 | 847 | 1152335, |
819 | 848 | 13805, |
820 | 849 | 0); |
821 | - assertValues(stats, 1, baseIface, 0, SET_DEFAULT, TAG_NONE, | |
822 | - METERED_NO, ROAMING_NO, DEFAULT_NETWORK_NO, | |
850 | + final NetworkStats.Entry expectedRootUid = new NetworkStats.Entry( | |
851 | + baseIface, 0, SET_DEFAULT, TAG_NONE, | |
823 | 852 | 163577, |
824 | 853 | 187, |
825 | 854 | 17607, |
826 | 855 | 97, |
827 | 856 | 0); |
828 | - assertEquals(otherEntry, stats.getValues(2, null)); | |
857 | + assertEquals(expectedAppUid, statsXt.getValues(0, null)); | |
858 | + assertEquals(expectedRootUid, statsXt.getValues(1, null)); | |
859 | + assertEquals(otherEntry, statsXt.getValues(2, null)); | |
860 | + assertEquals(expectedAppUid, statsEbpf.getValues(0, null)); | |
861 | + assertEquals(expectedRootUid, statsEbpf.getValues(1, null)); | |
862 | + assertEquals(otherEntry, statsEbpf.getValues(2, null)); | |
829 | 863 | } |
830 | 864 | |
831 | 865 | @Test |
@@ -850,7 +884,7 @@ public class NetworkStatsTest { | ||
850 | 884 | .addValues(secondEntry); |
851 | 885 | |
852 | 886 | // Empty map: no adjustment |
853 | - stats.apply464xlatAdjustments(new ArrayMap<>()); | |
887 | + stats.apply464xlatAdjustments(new ArrayMap<>(), false); | |
854 | 888 | |
855 | 889 | assertEquals(2, stats.size()); |
856 | 890 | assertEquals(firstEntry, stats.getValues(0, null)); |