Commit b66db7c4 authored by Paul Miller's avatar Paul Miller Committed by Commit Bot

Unify Android version and channel info

Android has 2 mechanisms for getting the channel: in Java, there's
ChromeVersionConstants, which is generated at build-time using
chrome/VERSION and the $android_channel GN variable. In native, there's
channel_android.cc, which determines channel at run-time from the
package name. Replace the native side with a JNI call to get the Java
constant, to avoid requiring the package name.

WebView needs channel and version info as well as Chrome, so move that
info from ChromeVersionConstants into a new VersionConstants base class
in version_info/. WebView currently adds channel info to UMA data, and
plans to use channel and major version for downloading Finch seeds.

Move Android-specific parts of version_info/ into version_info/android/.

Remove remnants of the "work" channel, which were missed by commit
0d9dc4f2.

BUG=733857

Change-Id: I61c952862e907ae666f910f4d386e712f6a52f2e
Reviewed-on: https://chromium-review.googlesource.com/927212
Commit-Queue: Paul Miller <paulmiller@chromium.org>
Reviewed-by: default avatarRichard Coles <torne@chromium.org>
Reviewed-by: default avatarNico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/master@{#540003}
parent d7b61d89
......@@ -717,7 +717,8 @@ source_set("common") {
"//components/supervised_user_error_page:gin",
"//components/url_matcher",
"//components/variations/service",
"//components/version_info",
"//components/version_info:channel",
"//components/version_info/android:channel_getter",
"//components/visitedlink/browser",
"//components/visitedlink/renderer",
"//components/viz/service",
......@@ -860,6 +861,7 @@ android_library("android_webview_java") {
"//components/navigation_interception/android:navigation_interception_java",
"//components/policy/android:policy_java",
"//components/safe_browsing/android:safe_browsing_java",
"//components/version_info/android:version_constants_java",
"//components/web_contents_delegate_android:web_contents_delegate_android_java",
"//components/web_restrictions:client_java",
"//content/public/android:content_java",
......
......@@ -29,7 +29,7 @@
#include "components/metrics/url_constants.h"
#include "components/metrics/version_utils.h"
#include "components/prefs/pref_service.h"
#include "components/version_info/channel_android.h"
#include "components/version_info/android/channel_getter.h"
#include "components/version_info/version_info.h"
#include "content/public/browser/browser_thread.h"
......@@ -57,15 +57,6 @@ std::unique_ptr<metrics::ClientInfo> LoadClientInfo() {
return client_info;
}
version_info::Channel GetChannelFromPackageName() {
JNIEnv* env = base::android::AttachCurrentThread();
std::string package_name = base::android::ConvertJavaStringToUTF8(
env, Java_AwMetricsServiceClient_getWebViewPackageName(env));
// We can't determine the channel for stand-alone WebView, since it has the
// same package name across channels. It will always be "unknown".
return version_info::ChannelFromPackageName(package_name.c_str());
}
// WebView Metrics are sampled based on GUID value.
// TODO(paulmiller) Sample with Finch, once we have Finch.
bool IsInSample(const std::string& client_id) {
......@@ -142,7 +133,6 @@ void AwMetricsServiceClient::Initialize(
DCHECK(request_context_ == nullptr);
pref_service_ = pref_service;
request_context_ = request_context;
channel_ = GetChannelFromPackageName();
// If variations are enabled for WebView the GUID will already have been read
// at startup
......@@ -240,7 +230,7 @@ bool AwMetricsServiceClient::GetBrand(std::string* brand_code) {
}
metrics::SystemProfileProto::Channel AwMetricsServiceClient::GetChannel() {
return metrics::AsProtobufChannel(channel_);
return metrics::AsProtobufChannel(version_info::GetChannel());
}
std::string AwMetricsServiceClient::GetVersionString() {
......@@ -275,7 +265,6 @@ base::TimeDelta AwMetricsServiceClient::GetStandardUploadInterval() {
AwMetricsServiceClient::AwMetricsServiceClient()
: pref_service_(nullptr),
request_context_(nullptr),
channel_(version_info::Channel::UNKNOWN),
consent_(false),
in_sample_(false) {}
......
......@@ -90,7 +90,6 @@ class AwMetricsServiceClient : public metrics::MetricsServiceClient,
std::unique_ptr<metrics::MetricsService> metrics_service_;
PrefService* pref_service_;
net::URLRequestContextGetter* request_context_;
version_info::Channel channel_;
bool consent_; // = (user has consented) && !(app has opted out)
bool in_sample_; // Is this client enabled by sampling?
......
......@@ -79,10 +79,5 @@ public class AwMetricsServiceClient {
}
}
@CalledByNative
public static String getWebViewPackageName() {
return AwBrowserProcess.getWebViewPackageName();
}
public static native void nativeSetHaveMetricsConsent(boolean enabled);
}
......@@ -225,6 +225,7 @@ android_library("chrome_java") {
"//components/sync/android:sync_java",
"//components/url_formatter/android:url_formatter_java",
"//components/variations/android:variations_java",
"//components/version_info/android:version_constants_java",
"//components/web_contents_delegate_android:web_contents_delegate_android_java",
"//components/web_restrictions:provider_java",
"//content/public/android:content_java",
......@@ -463,14 +464,9 @@ chrome_version_java_file = "$chrome_version_java_dir/org/chromium/chrome/browser
process_version("chrome_version_java") {
template_file = "java/ChromeVersionConstants.java.version"
sources = [
"//chrome/VERSION",
branding_file_path,
]
output = chrome_version_java_file
extra_args = [
"-e",
"CHANNEL=str.upper('$android_channel')",
]
}
zip("chrome_version_srcjar") {
......
......@@ -4,19 +4,9 @@
package org.chromium.chrome.browser;
class ChromeVersionConstants {
static final String PRODUCT_NAME = "@PRODUCT_FULLNAME@";
static final String PRODUCT_VERSION = "@MAJOR@.@MINOR@.@BUILD@.@PATCH@";
@SuppressWarnings({"ComplexBooleanConstant", "IdentityBinaryExpression"})
static final boolean IS_OFFICIAL_BUILD = @OFFICIAL_BUILD@ == 1;
static final int PRODUCT_MAJOR_VERSION = @MAJOR@;
import org.chromium.components.version_info.VersionConstants;
static final int CHANNEL_DEFAULT = 0;
static final int CHANNEL_CANARY = 1;
static final int CHANNEL_DEV = 2;
static final int CHANNEL_BETA = 3;
static final int CHANNEL_STABLE = 4;
static final int CHANNEL_WORK = 5;
static final int CHANNEL = CHANNEL_@CHANNEL@;
// Constants specific to Chrome. Common constants are in VersionConstants.
class ChromeVersionConstants extends VersionConstants {
static final String PRODUCT_NAME = "@PRODUCT_FULLNAME@";
}
......@@ -12,6 +12,7 @@ import com.google.android.gms.common.GoogleApiAvailability;
import org.chromium.base.ContextUtils;
import org.chromium.base.annotations.CalledByNative;
import org.chromium.chrome.browser.externalauth.ExternalAuthUtils;
import org.chromium.components.version_info.Channel;
import java.util.Locale;
......@@ -25,36 +26,35 @@ public class ChromeVersionInfo {
* @return Whether this build is a local build.
*/
public static boolean isLocalBuild() {
return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_DEFAULT;
return ChromeVersionConstants.CHANNEL == Channel.DEFAULT;
}
/**
* @return Whether this build is a canary build.
*/
public static boolean isCanaryBuild() {
return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_CANARY;
return ChromeVersionConstants.CHANNEL == Channel.CANARY;
}
/**
* @return Whether this build is a dev build.
*/
public static boolean isDevBuild() {
return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_DEV;
return ChromeVersionConstants.CHANNEL == Channel.DEV;
}
/**
* @return Whether this build is a beta build.
*/
public static boolean isBetaBuild() {
return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_BETA;
return ChromeVersionConstants.CHANNEL == Channel.BETA;
}
/**
* @return Whether this build is a stable build.
*/
public static boolean isStableBuild() {
return ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_STABLE
|| ChromeVersionConstants.CHANNEL == ChromeVersionConstants.CHANNEL_WORK;
return ChromeVersionConstants.CHANNEL == Channel.STABLE;
}
/**
......
......@@ -72,6 +72,9 @@ source_set("channel_info") {
if (is_win) {
public_deps += [ "//chrome/install_static:install_static_util" ]
}
if (is_android) {
public_deps += [ "//components/version_info/android:channel_getter" ]
}
}
source_set("ini_parser") {
......
......@@ -7,7 +7,7 @@
#include "base/android/build_info.h"
#include "base/logging.h"
#include "base/strings/string_util.h"
#include "components/version_info/channel_android.h"
#include "components/version_info/android/channel_getter.h"
#include "components/version_info/version_info.h"
namespace chrome {
......@@ -25,9 +25,7 @@ std::string GetChannelString() {
}
version_info::Channel GetChannel() {
const base::android::BuildInfo* bi = base::android::BuildInfo::GetInstance();
DCHECK(bi && bi->package_name());
return version_info::ChannelFromPackageName(bi->package_name());
return version_info::GetChannel();
}
} // namespace chrome
......@@ -47,8 +47,6 @@ static_library("version_string") {
source_set("channel") {
sources = [
"channel.h",
"channel_android.cc",
"channel_android.h",
]
}
......
include_rules = [
"+components/strings/grit/components_strings.h",
"+jni",
"+ui/base",
# version_info is used on iOS and thus cannot depend on //content.
......
# Copyright 2018 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.
import("//build/config/android/rules.gni")
import("//build/config/zip.gni")
import("//build/util/process_version.gni")
import("//chrome/android/channel.gni")
# Depend on this on the Java side to get org.components.version_info.Channel and
# org.components.version_info.VersionConstants.
android_library("version_constants_java") {
java_files = [
"java/src/org/chromium/components/version_info/VersionConstantsBridge.java",
]
deps = [
"//base:base_java",
]
srcjar_deps = [
":channel_enum_srcjar",
":version_constants_srcjar",
]
}
# Depend on this on the native side to get version_info::GetChannel. It requires
# version_constants_java for its JNI call.
static_library("channel_getter") {
sources = [
"channel_getter.cc",
"channel_getter.h",
]
deps = [
":version_constants_bridge_jni",
"..:channel",
]
}
java_cpp_enum("channel_enum_srcjar") {
sources = [
"../channel.h",
]
}
version_constants_java_file = "$target_gen_dir/java/org/chromium/components/version_info/VersionConstants.java"
zip("version_constants_srcjar") {
inputs = [
version_constants_java_file,
]
output = "$target_gen_dir/$target_name.srcjar"
base_dir = "$target_gen_dir/java"
deps = [
":generate_version_constants_java",
]
}
process_version("generate_version_constants_java") {
template_file = "java/VersionConstants.java.version"
output = version_constants_java_file
sources = [
"//chrome/VERSION",
]
extra_args = [
"-e",
"CHANNEL=str.upper('$android_channel')",
]
}
generate_jni("version_constants_bridge_jni") {
sources = [
"java/src/org/chromium/components/version_info/VersionConstantsBridge.java",
]
jni_package = "version_constants_bridge"
}
paulmiller@chromium.org
torne@chromium.org
// Copyright 2018 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.
#include "components/version_info/android/channel_getter.h"
#include "jni/VersionConstantsBridge_jni.h"
namespace version_info {
Channel GetChannel() {
JNIEnv* env = base::android::AttachCurrentThread();
return static_cast<Channel>(Java_VersionConstantsBridge_getChannel(env));
}
} // namespace version_info
// Copyright 2017 The Chromium Authors. All rights reserved.
// Copyright 2018 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.
#ifndef COMPONENTS_VERSION_INFO_CHANNEL_ANDROID_H_
#define COMPONENTS_VERSION_INFO_CHANNEL_ANDROID_H_
#ifndef COMPONENTS_VERSION_INFO_ANDROID_CHANNEL_GETTER_H_
#define COMPONENTS_VERSION_INFO_ANDROID_CHANNEL_GETTER_H_
#include "components/version_info/channel.h"
namespace version_info {
// Determine channel based on Chrome's package name.
Channel ChannelFromPackageName(const char* package_name);
Channel GetChannel();
} // namespace version_info
}
#endif // COMPONENTS_VERSION_INFO_CHANNEL_ANDROID_H_
#endif // COMPONENTS_VERSION_INFO_ANDROID_CHANNEL_GETTER_H_
// Copyright 2018 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.components.version_info;
// Constants shared by Android Chrome and WebView. Chrome specific constants are
// in ChromeVersionConstants.
public class VersionConstants {
public static final String PRODUCT_VERSION = "@MAJOR@.@MINOR@.@BUILD@.@PATCH@";
@SuppressWarnings({"ComplexBooleanConstant", "IdentityBinaryExpression"})
public static final boolean IS_OFFICIAL_BUILD = @OFFICIAL_BUILD@ == 1;
public static final int PRODUCT_MAJOR_VERSION = @MAJOR@;
public static final int CHANNEL = Channel.@CHANNEL@;
}
// Copyright 2018 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.components.version_info;
import org.chromium.base.annotations.CalledByNative;
/**
* Bridge between native and VersionConstants.java.
*/
public class VersionConstantsBridge {
@CalledByNative
public static int getChannel() {
return VersionConstants.CHANNEL;
}
}
......@@ -8,7 +8,17 @@
namespace version_info {
// The possible channels for an installation, from most fun to most stable.
enum class Channel { UNKNOWN = 0, CANARY, DEV, BETA, STABLE };
// GENERATED_JAVA_ENUM_PACKAGE: org.chromium.components.version_info
enum class Channel {
UNKNOWN = 0,
// DEFAULT is an alias for UNKNOWN because the build files use DEFAULT but the
// code uses UNKNOWN. TODO(paulmiller): Combine DEFAULT & UNKNOWN.
DEFAULT = UNKNOWN,
CANARY = 1,
DEV = 2,
BETA = 3,
STABLE = 4,
};
} // namespace version_info
......
// Copyright 2017 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.
#include "components/version_info/channel_android.h"
#include <cstring>
namespace version_info {
Channel ChannelFromPackageName(const char* package_name) {
if (!strcmp(package_name, "com.android.chrome"))
return Channel::STABLE;
if (!strcmp(package_name, "com.chrome.beta"))
return Channel::BETA;
if (!strcmp(package_name, "com.chrome.dev"))
return Channel::DEV;
if (!strcmp(package_name, "com.chrome.canary"))
return Channel::CANARY;
return Channel::UNKNOWN;
}
} // namespace version_info
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment