diff options
author | yfriedman <yfriedman@chromium.org> | 2014-10-03 16:11:24 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-10-03 23:11:43 +0000 |
commit | 9f7cc9935d1ba9143e61e2a74e288c866053722d (patch) | |
tree | 06cb033daa6ff506575c2d13e343821ee2ddceb3 | |
parent | f87ca626e7a7e4af82d8de7a5fc3c5c3798bac97 (diff) | |
download | chromium_src-9f7cc9935d1ba9143e61e2a74e288c866053722d.zip chromium_src-9f7cc9935d1ba9143e61e2a74e288c866053722d.tar.gz chromium_src-9f7cc9935d1ba9143e61e2a74e288c866053722d.tar.bz2 |
[Android] Upstream native-free channel information class.
This was used in the internal repo but now will be needed upstream as
well. Provides information on the current channel of Chrome without
depending on the native shared library being loaded.
Review URL: https://codereview.chromium.org/626943002
Cr-Commit-Position: refs/heads/master@{#298114}
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/ChromeVersionInfo.java | 108 | ||||
-rw-r--r-- | chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java | 6 |
2 files changed, 114 insertions, 0 deletions
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromeVersionInfo.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromeVersionInfo.java new file mode 100644 index 0000000..64c11be --- /dev/null +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromeVersionInfo.java @@ -0,0 +1,108 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.chrome.browser; + +import android.content.Context; + +import org.chromium.base.BuildInfo; + +/** + * A utility class for determining information about the current Chrome build. + * Intentionally doesn't depend on native so that the data can be accessed before + * libchrome.so is loaded. + */ +public class ChromeVersionInfo { + /** Local builds. */ + private static final int CHANNEL_UNKNOWN = 0x1; + + /** Canary builds. */ + private static final int CHANNEL_CANARY = 0x10; + + /** Dev builds. */ + private static final int CHANNEL_DEV = 0x100; + + /** Beta builds. */ + private static final int CHANNEL_BETA = 0x1000; + + /** Stable builds. */ + private static final int CHANNEL_STABLE = 0x10000; + + /** Signifies that init() hasn't been called yet. */ + private static final int INVALID_CHANNEL = 0x10000000; + + private static final String CHANNEL_STRING_CANARY = "Chrome Canary"; + private static final String CHANNEL_STRING_DEV = "Chrome Dev"; + private static final String CHANNEL_STRING_BETA = "Chrome Beta"; + private static final String CHANNEL_STRING_STABLE = "Chrome"; + + private static int sChannel = INVALID_CHANNEL; + + /** + * This must be called before any other method in this class is called. + * @param context The context to query the build channel from. + */ + public static void init(Context context) { + final String channel = BuildInfo.getPackageLabel(context); + if (CHANNEL_STRING_STABLE.equals(channel)) { + sChannel = CHANNEL_STABLE; + } else if (CHANNEL_STRING_BETA.equals(channel)) { + sChannel = CHANNEL_BETA; + } else if (CHANNEL_STRING_DEV.equals(channel)) { + sChannel = CHANNEL_DEV; + } else if (CHANNEL_STRING_CANARY.equals(channel)) { + sChannel = CHANNEL_CANARY; + } else { + sChannel = CHANNEL_UNKNOWN; + } + } + + /** + * @return Whether this build is a local build. + */ + public static boolean isLocalBuild() { + return getBuildChannel() == CHANNEL_UNKNOWN; + } + + /** + * @return Whether this build is a canary build. + */ + public static boolean isCanaryBuild() { + return getBuildChannel() == CHANNEL_CANARY; + } + + /** + * @return Whether this build is a dev build. + */ + public static boolean isDevBuild() { + return getBuildChannel() == CHANNEL_DEV; + } + + /** + * @return Whether this build is a beta build. + */ + public static boolean isBetaBuild() { + return getBuildChannel() == CHANNEL_BETA; + } + + /** + * @return Whether this build is a stable build. + */ + public static boolean isStableBuild() { + return getBuildChannel() == CHANNEL_STABLE; + } + + /** + * Determines which channel this build is. + * @return What channel this build is. Can be one of {@link #CHANNEL_UNKNOWN}, + * {@link #CHANNEL_CANARY}, {@link #CHANNEL_DEV}, {@link #CHANNEL_BETA}, or + * {@link #CHANNEL_STABLE}. + */ + public static int getBuildChannel() { + if (sChannel == INVALID_CHANNEL) { + throw new RuntimeException("ChannelInfo.init() was not called"); + } + return sChannel; + } +}
\ No newline at end of file diff --git a/chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java b/chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java index b7436a2..ebe4737 100644 --- a/chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java +++ b/chrome/android/java/src/org/chromium/chrome/browser/ChromiumApplication.java @@ -12,6 +12,12 @@ import org.chromium.content.app.ContentApplication; * chrome layer. */ public abstract class ChromiumApplication extends ContentApplication { + @Override + public void onCreate() { + super.onCreate(); + ChromeVersionInfo.init(this); + } + /** * Opens a protected content settings page, if available. */ |