Skip to content

Commit

Permalink
Add Android SDK int, name, etc to chrome://version
Browse files Browse the repository at this point in the history
Update chrome://version on Android to include:
 - Device SDK int and codename
 - Chrome's targetSdkVersion
 - isAtLeastU and targetsAtLeastU

Low-Coverage-Reason:this UI addition is for an internal usage of a chrome:// page.

 Bug: 1345962

Change-Id: Ic94aa5553c178c1754eccc487e451cdeb247d7b8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4317492
Reviewed-by: Richard Coles <torne@chromium.org>
Reviewed-by: John Lee <johntlee@chromium.org>
Reviewed-by: Theresa Sullivan <twellington@chromium.org>
Commit-Queue: Donn Denman <donnd@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1118436}
  • Loading branch information
Donn Denman authored and Chromium LUCI CQ committed Mar 16, 2023
1 parent feb0366 commit f5b8641
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 22 deletions.
5 changes: 4 additions & 1 deletion base/android/build_info.cc
Expand Up @@ -82,7 +82,10 @@ BuildInfo::BuildInfo(const std::vector<std::string>& params)
version_incremental_(StrDupParam(params, 24)),
hardware_(StrDupParam(params, 25)),
is_at_least_t_(GetIntParam(params, 26)),
is_automotive_(GetIntParam(params, 27)) {}
is_automotive_(GetIntParam(params, 27)),
is_at_least_u_(GetIntParam(params, 28)),
targets_at_least_u_(GetIntParam(params, 29)),
codename_(StrDupParam(params, 30)) {}

// static
BuildInfo* BuildInfo::GetInstance() {
Expand Down
9 changes: 9 additions & 0 deletions base/android/build_info.h
Expand Up @@ -146,6 +146,12 @@ class BASE_EXPORT BuildInfo {

bool is_automotive() const { return is_automotive_; }

bool is_at_least_u() const { return is_at_least_u_; }

bool targets_at_least_u() const { return targets_at_least_u_; }

const char* codename() const { return codename_; }

private:
friend struct BuildInfoSingletonTraits;

Expand Down Expand Up @@ -184,6 +190,9 @@ class BASE_EXPORT BuildInfo {
const char* const hardware_;
const bool is_at_least_t_;
const bool is_automotive_;
const bool is_at_least_u_;
const bool targets_at_least_u_;
const char* const codename_;
};

} // namespace android
Expand Down
5 changes: 5 additions & 0 deletions base/android/java/src/org/chromium/base/BuildInfo.java
Expand Up @@ -75,8 +75,10 @@ private static String[] getAll() {

/** Returns a serialized string array of all properties of this class. */
@VisibleForTesting
@OptIn(markerClass = androidx.core.os.BuildCompat.PrereleaseSdkCheck.class)
String[] getAllProperties() {
String hostPackageName = ContextUtils.getApplicationContext().getPackageName();
// This implementation needs to be kept in sync with the native BuildInfo constructor.
return new String[] {
Build.BRAND,
Build.DEVICE,
Expand Down Expand Up @@ -107,6 +109,9 @@ String[] getAllProperties() {
Build.HARDWARE,
isAtLeastT() ? "1" : "0",
isAutomotive ? "1" : "0",
BuildCompat.isAtLeastU() ? "1" : "0",
targetsAtLeastU() ? "1" : "0",
Build.VERSION.CODENAME,
};
}

Expand Down
50 changes: 31 additions & 19 deletions base/android/junit/src/org/chromium/base/BuildInfoTest.java
Expand Up @@ -10,6 +10,7 @@

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build.VERSION_CODES;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -24,6 +25,13 @@
@RunWith(BaseRobolectricTestRunner.class)
@Config(manifest = Config.NONE)
public class BuildInfoTest {
// These indexes match the values in the constructor of base/android/build_info.cc.
private static final int IS_AT_LEAST_T = 26;
private static final int IS_AUTOMOTIVE = 27;
private static final int IS_AT_LEAST_U = 28;
private static final int TARGETS_AT_LEAST_U = 29;
private static final int SDK_CODENAME = 30;

private ShadowPackageManager mShadowPackageManager;

@Before
Expand All @@ -37,46 +45,50 @@ public void testIsAutomotive_trueIfFeatureAutomotiveTrue() {
mShadowPackageManager.setSystemFeature(
PackageManager.FEATURE_AUTOMOTIVE, /* supported= */ true);

BuildInfo buildInfo = new BuildInfo();

assertTrue(buildInfo.isAutomotive);
assertTrue(new BuildInfo().isAutomotive);
}

@Test
public void testIsAutomotive_falseIfFeatureAutomotiveFalse() {
mShadowPackageManager.setSystemFeature(
PackageManager.FEATURE_AUTOMOTIVE, /* supported= */ false);

BuildInfo buildInfo = new BuildInfo();

assertFalse(buildInfo.isAutomotive);
assertFalse(new BuildInfo().isAutomotive);
}

@Test
public void testIsAutomotive_isTrue_setsGetAllPropertesTo1() {
mShadowPackageManager.setSystemFeature(
PackageManager.FEATURE_AUTOMOTIVE, /* supported= */ true);
String[] properties = new BuildInfo().getAllProperties();

BuildInfo buildInfo = new BuildInfo();
String[] properties = buildInfo.getAllProperties();

// This index matches the value in the constructor of base/android/build_info.cc.
int isAutomotiveIndex = 27;

assertEquals("1", properties[isAutomotiveIndex]);
assertEquals("1", properties[IS_AUTOMOTIVE]);
}

@Test
public void testIsAutomotive_isFalse_setsGetAllPropertesTo0() {
mShadowPackageManager.setSystemFeature(
PackageManager.FEATURE_AUTOMOTIVE, /* supported= */ false);
String[] properties = new BuildInfo().getAllProperties();

BuildInfo buildInfo = new BuildInfo();
String[] properties = buildInfo.getAllProperties();

// This index matches the value in the constructor of base/android/build_info.cc.
int isAutomotiveIndex = 27;
assertEquals("0", properties[IS_AUTOMOTIVE]);
}

assertEquals("0", properties[isAutomotiveIndex]);
/**
* TODO(donnd, https://crbug.com/1345962) Create useful tests for T and U.
* This test hardly tests anything, so this is mostly a placeholder and sanity check for the
* java constructor.
* It would be better to add tests to the native BuildInfo for these releases and to check that
* the native code and java code consistently interpret the array.
*/
@Test
@Config(sdk = VERSION_CODES.S_V2)
public void testIsAtLeastX_OnS() {
String[] properties = new BuildInfo().getAllProperties();

assertEquals("0", properties[IS_AT_LEAST_T]);
assertEquals("0", properties[IS_AT_LEAST_U]);
assertEquals("REL", properties[SDK_CODENAME]);
assertEquals("0", properties[TARGETS_AT_LEAST_U]);
}
}
12 changes: 12 additions & 0 deletions chrome/browser/ui/android/android_about_app_info.cc
Expand Up @@ -6,6 +6,7 @@

#include <jni.h>

#include "base/android/build_info.h"
#include "base/android/jni_android.h"
#include "base/android/jni_string.h"
#include "base/system/sys_info.h"
Expand All @@ -24,3 +25,14 @@ std::string AndroidAboutAppInfo::GetOsInfo() {
content::GetAndroidOSInfo(content::IncludeAndroidBuildNumber::Include,
content::IncludeAndroidModel::Include);
}

std::string AndroidAboutAppInfo::GetTargetsUInfo() {
std::string targets_u_info =
base::android::BuildInfo::GetInstance()->is_at_least_u() ? "true"
: "false";
targets_u_info += "/";
targets_u_info +=
base::android::BuildInfo::GetInstance()->targets_at_least_u() ? "true"
: "false";
return targets_u_info;
}
4 changes: 4 additions & 0 deletions chrome/browser/ui/android/android_about_app_info.h
Expand Up @@ -15,6 +15,10 @@ class AndroidAboutAppInfo {

// Returns a string containing detailed info about the os environment.
static std::string GetOsInfo();

// Returns a string containing info about whether the device is at least
// Android U and whether Chrome targets at least U.
static std::string GetTargetsUInfo();
};

#endif // CHROME_BROWSER_UI_ANDROID_ANDROID_ABOUT_APP_INFO_H_
15 changes: 13 additions & 2 deletions chrome/browser/ui/webui/version/version_ui.cc
Expand Up @@ -40,6 +40,7 @@
#include "v8/include/v8-version-string.h"

#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#include "chrome/browser/ui/android/android_about_app_info.h"
#else
#include "chrome/browser/ui/webui/theme_source.h"
Expand Down Expand Up @@ -232,8 +233,18 @@ void VersionUI::AddVersionDetailStrings(content::WebUIDataSource* html_source) {
#endif // BUILDFLAG(IS_MAC)

#if BUILDFLAG(IS_ANDROID)
html_source->AddString(version_ui::kOSVersion,
AndroidAboutAppInfo::GetOsInfo());
std::string os_info = AndroidAboutAppInfo::GetOsInfo();
os_info += "; " + base::NumberToString(
base::android::BuildInfo::GetInstance()->sdk_int());
std::string code_name(base::android::BuildInfo::GetInstance()->codename());
os_info += "; " + code_name;
html_source->AddString(version_ui::kOSVersion, os_info);
html_source->AddString(
version_ui::kTargetSdkVersion,
base::NumberToString(
base::android::BuildInfo::GetInstance()->target_sdk_version()));
html_source->AddString(version_ui::kTargetsU,
AndroidAboutAppInfo::GetTargetsUInfo());
html_source->AddString(version_ui::kGmsVersion,
AndroidAboutAppInfo::GetGmsInfo());
#endif // BUILDFLAG(IS_ANDROID)
Expand Down
8 changes: 8 additions & 0 deletions components/version_ui/resources/about_version.html
Expand Up @@ -104,6 +104,14 @@
</tr>
</if>
<if expr="is_android">
<tr>
<td class="label">targetSdkVersion</td>
<td class="version">$i18n{target_sdk_version}</td>
</tr>
<tr>
<td class="label">isAtLeastU/targetsAtLeastU</td>
<td class="version">$i18n{targets_u}</td>
</tr>
<tr>
<td class="label">$i18n{gms_name}</td>
<td class="version" id="gms_version">
Expand Down
4 changes: 4 additions & 0 deletions components/version_ui/version_ui_constants.cc
Expand Up @@ -65,6 +65,10 @@ const char kOSType[] = "os_type";
#endif
#if BUILDFLAG(IS_ANDROID)
const char kOSVersion[] = "os_version";
const char kTargetSdkVersionName[] = "target_sdk_version_name";
const char kTargetSdkVersion[] = "target_sdk_version";
const char kTargetsUName[] = "targets_u_name";
const char kTargetsU[] = "targets_u";
const char kGmsName[] = "gms_name";
const char kGmsVersion[] = "gms_version";
#endif
Expand Down
4 changes: 4 additions & 0 deletions components/version_ui/version_ui_constants.h
Expand Up @@ -68,6 +68,10 @@ extern const char kOSType[];
#endif
#if BUILDFLAG(IS_ANDROID)
extern const char kOSVersion[];
extern const char kTargetSdkVersionName[];
extern const char kTargetSdkVersion[];
extern const char kTargetsUName[];
extern const char kTargetsU[];
extern const char kGmsName[];
extern const char kGmsVersion[];
#endif
Expand Down

0 comments on commit f5b8641

Please sign in to comment.