Move kernelToTag to NetworkStatsFactory.

... to prepare for the deletion of NetworkManagementSocketTagger.

Test: atest FrameworksNetTests
Change-Id: Id3ad67fa640ddb9ab446e10dcf8e6a588d661dd9
This commit is contained in:
Lorenzo Colitti
2022-01-29 21:37:59 +09:00
parent a8ac57607e
commit e91d76c5df

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.