Update formatting in `UserAgentTagUtil`
This commit is contained in:
parent
f592201e4c
commit
c315b34395
|
@ -13,11 +13,7 @@ import org.whispersystems.textsecuregcm.util.ua.UnrecognizedUserAgentException;
|
||||||
import org.whispersystems.textsecuregcm.util.ua.UserAgent;
|
import org.whispersystems.textsecuregcm.util.ua.UserAgent;
|
||||||
import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil;
|
import org.whispersystems.textsecuregcm.util.ua.UserAgentUtil;
|
||||||
|
|
||||||
import java.util.EnumMap;
|
import java.util.*;
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for extracting platform/version metrics tags from User-Agent strings.
|
* Utility class for extracting platform/version metrics tags from User-Agent strings.
|
||||||
|
@ -27,7 +23,8 @@ public class UserAgentTagUtil {
|
||||||
public static final String PLATFORM_TAG = "platform";
|
public static final String PLATFORM_TAG = "platform";
|
||||||
public static final String VERSION_TAG = "clientVersion";
|
public static final String VERSION_TAG = "clientVersion";
|
||||||
static final List<Tag> OVERFLOW_TAGS = List.of(Tag.of(PLATFORM_TAG, "overflow"), Tag.of(VERSION_TAG, "overflow"));
|
static final List<Tag> OVERFLOW_TAGS = List.of(Tag.of(PLATFORM_TAG, "overflow"), Tag.of(VERSION_TAG, "overflow"));
|
||||||
static final List<Tag> UNRECOGNIZED_TAGS = List.of(Tag.of(PLATFORM_TAG, "unrecognized"), Tag.of(VERSION_TAG, "unrecognized"));
|
static final List<Tag> UNRECOGNIZED_TAGS = List.of(Tag.of(PLATFORM_TAG, "unrecognized"),
|
||||||
|
Tag.of(VERSION_TAG, "unrecognized"));
|
||||||
|
|
||||||
private static final Map<ClientPlatform, Semver> MINIMUM_VERSION_BY_PLATFORM = new EnumMap<>(ClientPlatform.class);
|
private static final Map<ClientPlatform, Semver> MINIMUM_VERSION_BY_PLATFORM = new EnumMap<>(ClientPlatform.class);
|
||||||
|
|
||||||
|
@ -48,9 +45,11 @@ public class UserAgentTagUtil {
|
||||||
final UserAgent userAgent = UserAgentUtil.parseUserAgentString(userAgentString);
|
final UserAgent userAgent = UserAgentUtil.parseUserAgentString(userAgentString);
|
||||||
final List<Tag> tags;
|
final List<Tag> tags;
|
||||||
|
|
||||||
if (userAgent.getVersion().isStable() && userAgent.getVersion().isGreaterThanOrEqualTo(MINIMUM_VERSION_BY_PLATFORM.get(userAgent.getPlatform()))) {
|
if (userAgent.getVersion().isStable() && userAgent.getVersion()
|
||||||
|
.isGreaterThanOrEqualTo(MINIMUM_VERSION_BY_PLATFORM.get(userAgent.getPlatform()))) {
|
||||||
if (allowVersion(userAgent.getPlatform(), userAgent.getVersion())) {
|
if (allowVersion(userAgent.getPlatform(), userAgent.getVersion())) {
|
||||||
tags = List.of(Tag.of(PLATFORM_TAG, userAgent.getPlatform().name().toLowerCase()), Tag.of(VERSION_TAG, userAgent.getVersion().toString()));
|
tags = List.of(Tag.of(PLATFORM_TAG, userAgent.getPlatform().name().toLowerCase()),
|
||||||
|
Tag.of(VERSION_TAG, userAgent.getVersion().toString()));
|
||||||
} else {
|
} else {
|
||||||
tags = OVERFLOW_TAGS;
|
tags = OVERFLOW_TAGS;
|
||||||
}
|
}
|
||||||
|
@ -80,7 +79,8 @@ public class UserAgentTagUtil {
|
||||||
final Pair<ClientPlatform, Semver> platformAndVersion = new Pair<>(platform, version);
|
final Pair<ClientPlatform, Semver> platformAndVersion = new Pair<>(platform, version);
|
||||||
|
|
||||||
synchronized (SEEN_VERSIONS) {
|
synchronized (SEEN_VERSIONS) {
|
||||||
return SEEN_VERSIONS.contains(platformAndVersion) || (SEEN_VERSIONS.size() < MAX_VERSIONS && SEEN_VERSIONS.add(platformAndVersion));
|
return SEEN_VERSIONS.contains(platformAndVersion) || (SEEN_VERSIONS.size() < MAX_VERSIONS && SEEN_VERSIONS.add(
|
||||||
|
platformAndVersion));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue