Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4933)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/omaha/VersionNumberGetter.java

Issue 2005623002: Logic for the Data Saver InfoBar Promo (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: missing returns Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/omaha/VersionNumberGetter.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/omaha/VersionNumberGetter.java b/chrome/android/java/src/org/chromium/chrome/browser/omaha/VersionNumberGetter.java
index f6a47daa2cb84061dda32dd60b54167be6de70b1..447892042948e69a7cc238d0abc945db96dfd3a2 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/omaha/VersionNumberGetter.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/omaha/VersionNumberGetter.java
@@ -34,4 +34,31 @@ public class VersionNumberGetter {
public String getCurrentlyUsedVersion(Context context) {
return BuildInfo.getPackageVersionName(context);
}
+
+ /**
+ * Gets the milestone from an AboutVersionStrings#getApplicationVersion string. These strings
+ * are of the format "ProductName xx.xx.xx.xx".
+ *
+ * @param version The version to extract the milestone number from.
+ * @return The milestone of the given version string.
+ */
+ public static int getMilestoneFromVersionNumber(String version) {
+ if (version.isEmpty()) {
+ throw new IllegalArgumentException("Application version incorrectly formatted");
+ }
+
+ version = version.replaceAll("[^\\d.]", "");
+
+ // Parse out the version numbers.
+ String[] pieces = version.split("\\.");
+ if (pieces.length != 4) {
+ throw new IllegalArgumentException("Application version incorrectly formatted");
+ }
+
+ try {
+ return Integer.parseInt(pieces[0]);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Application version incorrectly formatted");
+ }
+ }
}

Powered by Google App Engine
This is Rietveld 408576698