LineageOS 18.1 patches & tweaks for Samsung S5 Neo (s5neolte)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
3.6 KiB

  1. Original commit: https://github.com/DerpFest-11/packages_modules_NetworkStack/commit/22fd53a977eeaf4e36be7bf6358ecf2c2737fa5e
  2. From 22fd53a977eeaf4e36be7bf6358ecf2c2737fa5e Mon Sep 17 00:00:00 2001
  3. From: Bruno Martins <bgcngm@gmail.com>
  4. Date: Wed, 14 Oct 2020 16:08:13 +0100
  5. Subject: [PATCH] TcpSocketTracker: Opt-out for TCP info parsing on legacy
  6. kernels
  7. This feature requires netlink features that are unsupported on
  8. kernel versions lower than 4.4, therefore opt-out for it in such
  9. cases and avoid constantly crashing TcpSocketTracker.
  10. Change-Id: I128ed1d0dcb6ca07eef1179f1ef036ccaad64e52
  11. ---
  12. .../netlink/TcpSocketTracker.java | 36 ++++++++++++++++++-
  13. 1 file changed, 35 insertions(+), 1 deletion(-)
  14. diff --git a/packages/modules/NetworkStack/src/com/android/networkstack/netlink/TcpSocketTracker.java b/packages/modules/NetworkStack/src/com/android/networkstack/netlink/TcpSocketTracker.java
  15. index ef33f13..f39518f 100644
  16. --- a/packages/modules/NetworkStack/src/com/android/networkstack/netlink/TcpSocketTracker.java
  17. +++ b/packages/modules/NetworkStack/src/com/android/networkstack/netlink/TcpSocketTracker.java
  18. @@ -57,8 +57,10 @@
  19. import android.system.ErrnoException;
  20. import android.system.Os;
  21. import android.system.StructTimeval;
  22. +import android.text.TextUtils;
  23. import android.util.Log;
  24. import android.util.LongSparseArray;
  25. +import android.util.Pair;
  26. import android.util.SparseArray;
  27. import androidx.annotation.NonNull;
  28. @@ -77,6 +79,8 @@
  29. import java.util.ArrayList;
  30. import java.util.Base64;
  31. import java.util.List;
  32. +import java.util.regex.Matcher;
  33. +import java.util.regex.Pattern;
  34. /**
  35. * Class for NetworkStack to send a SockDiag request and parse the returned tcp info.
  36. @@ -431,6 +435,35 @@ private void log(final String str) {
  37. if (DBG) Log.d(TAG, str);
  38. }
  39. + private static boolean isTcpInfoParsingSupportedByKernel() {
  40. + final String kVersionString = Os.uname().release;
  41. + return compareMajorMinorVersion(kVersionString, "4.4") >= 0;
  42. + }
  43. +
  44. + private static int compareMajorMinorVersion(final String s1, final String s2) {
  45. + final Pair<Integer, Integer> v1 = getVersionFromString(s1);
  46. + final Pair<Integer, Integer> v2 = getVersionFromString(s2);
  47. +
  48. + if (v1.first == v2.first) {
  49. + return Integer.compare(v1.second, v2.second);
  50. + } else {
  51. + return Integer.compare(v1.first, v2.first);
  52. + }
  53. + }
  54. +
  55. + private static Pair<Integer, Integer> getVersionFromString(String version) {
  56. + // Only gets major and minor number of the version string.
  57. + final Pattern versionPattern = Pattern.compile("^(\\d+)(\\.(\\d+))?.*");
  58. + final Matcher m = versionPattern.matcher(version);
  59. + if (m.matches()) {
  60. + final int major = Integer.parseInt(m.group(1));
  61. + final int minor = TextUtils.isEmpty(m.group(3)) ? 0 : Integer.parseInt(m.group(3));
  62. + return new Pair<>(major, minor);
  63. + } else {
  64. + return new Pair<>(0, 0);
  65. + }
  66. + }
  67. +
  68. /**
  69. * Corresponds to {@code struct rtattr} from bionic/libc/kernel/uapi/linux/rtnetlink.h
  70. *
  71. @@ -578,7 +611,8 @@ public int getDeviceConfigPropertyInt(@NonNull final String namespace,
  72. public boolean isTcpInfoParsingSupported() {
  73. // Request tcp info from NetworkStack directly needs extra SELinux permission added
  74. // after Q release.
  75. - return ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q);
  76. + return ShimUtils.isReleaseOrDevelopmentApiAbove(Build.VERSION_CODES.Q) &&
  77. + isTcpInfoParsingSupportedByKernel();
  78. }
  79. /**