Merge changes from topics "move-kerneltotag", "move-socket-tagging-to-mainline"

* changes:
  Move socket tagging implementation to mainline.
  Move kernelToTag to NetworkStatsFactory.
This commit is contained in:
Lorenzo Colitti
2022-01-31 13:35:30 +00:00
committed by Gerrit Code Review
5 changed files with 203 additions and 15 deletions

View File

@@ -22,8 +22,6 @@ import static android.net.NetworkStats.TAG_ALL;
import static android.net.NetworkStats.TAG_NONE;
import static android.net.NetworkStats.UID_ALL;
import static com.android.server.NetworkManagementSocketTagger.kernelToTag;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
@@ -469,6 +467,19 @@ public class NetworkStatsFactory {
}
}
/**
* Convert {@code /proc/} tag format to {@link Integer}. Assumes incoming
* format like {@code 0x7fffffff00000000}.
*/
public static int kernelToTag(String string) {
int length = string.length();
if (length > 10) {
return Long.decode(string.substring(0, length - 8)).intValue();
} else {
return 0;
}
}
/**
* Parse statistics from file into given {@link NetworkStats} object. Values
* are expected to monotonically increase since device boot.