Skip to content

Commit

Permalink
Generalize naming of CH properties, add Android Build Fingerprint (yo…
Browse files Browse the repository at this point in the history
…utube#480)

b/188060079
  • Loading branch information
gbournou authored May 26, 2023
1 parent 37d3132 commit ba6b0d1
Show file tree
Hide file tree
Showing 18 changed files with 139 additions and 58 deletions.
6 changes: 4 additions & 2 deletions cobalt/browser/client_hint_headers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ std::vector<std::string> GetClientHintHeaders(
const UserAgentPlatformInfo& platform_info) {
std::vector<std::string> headers;

AddHeader(headers, "Android-OS-Experience",
platform_info.android_os_experience());
AddHeader(headers, "Firmware-Version-Details",
platform_info.firmware_version_details());

AddHeader(headers, "OS-Experience", platform_info.os_experience());

return headers;
}
Expand Down
7 changes: 5 additions & 2 deletions cobalt/browser/client_hint_headers_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,14 @@ using ::testing::UnorderedElementsAre;

TEST(ClientHintHeadersTest, GetClientHintHeaders) {
UserAgentPlatformInfo platform_info;
platform_info.set_android_os_experience("Amati");
platform_info.set_firmware_version_details("abc/def:123.456/xy-z");
platform_info.set_os_experience("Amati");

std::vector<std::string> headers = GetClientHintHeaders(platform_info);
EXPECT_THAT(headers,
UnorderedElementsAre("Sec-CH-UA-Co-Android-OS-Experience:Amati"));
UnorderedElementsAre(
"Sec-CH-UA-Co-Firmware-Version-Details:abc/def:123.456/xy-z",
"Sec-CH-UA-Co-OS-Experience:Amati"));
}

} // namespace
Expand Down
44 changes: 29 additions & 15 deletions cobalt/browser/user_agent_platform_info.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "starboard/common/log.h"
#include "starboard/common/string.h"
#include "starboard/common/system_property.h"
#include "starboard/extension/android_info.h"
#include "starboard/extension/platform_info.h"
#if SB_IS(EVERGREEN)
#include "starboard/extension/installation_manager.h"
#endif // SB_IS(EVERGREEN)
Expand Down Expand Up @@ -271,15 +271,20 @@ void InitializeUserAgentPlatformInfoFields(UserAgentPlatformInfo& info) {
}
#endif

// Android Info
auto android_info_extension =
static_cast<const CobaltExtensionAndroidInfoApi*>(
SbSystemGetExtension(kCobaltExtensionAndroidInfoName));
if (android_info_extension &&
strcmp(android_info_extension->name, kCobaltExtensionAndroidInfoName) ==
// Additional Platform Info
auto platform_info_extension =
static_cast<const CobaltExtensionPlatformInfoApi*>(
SbSystemGetExtension(kCobaltExtensionPlatformInfoName));
if (platform_info_extension &&
strcmp(platform_info_extension->name, kCobaltExtensionPlatformInfoName) ==
0 &&
android_info_extension->version >= 1) {
info.set_android_os_experience(android_info_extension->GetOsExperience());
platform_info_extension->version >= 1) {
result = platform_info_extension->GetFirmwareVersionDetails(
value, kSystemPropertyMaxLength);
if (result) {
info.set_firmware_version_details(value);
}
info.set_os_experience(platform_info_extension->GetOsExperience());
}

info.set_cobalt_version(COBALT_VERSION);
Expand Down Expand Up @@ -417,9 +422,12 @@ void InitializeUserAgentPlatformInfoFields(UserAgentPlatformInfo& info) {
} else if (!input.first.compare("evergreen_version")) {
info.set_evergreen_version(input.second);
LOG(INFO) << "Set evergreen version to " << input.second;
} else if (!input.first.compare("android_os_experience")) {
info.set_android_os_experience(input.second);
LOG(INFO) << "Set evergreen version to " << input.second;
} else if (!input.first.compare("firmware_version_details")) {
info.set_firmware_version_details(input.second);
LOG(INFO) << "Set firmware version details to " << input.second;
} else if (!input.first.compare("os_experience")) {
info.set_os_experience(input.second);
LOG(INFO) << "Set os experience to " << input.second;
} else if (!input.first.compare("cobalt_version")) {
info.set_cobalt_version(input.second);
LOG(INFO) << "Set cobalt type to " << input.second;
Expand Down Expand Up @@ -534,9 +542,15 @@ void UserAgentPlatformInfo::set_evergreen_version(
evergreen_version_ = Sanitize(evergreen_version, isTCHAR);
}

void UserAgentPlatformInfo::set_android_os_experience(
const std::string& android_os_experience) {
android_os_experience_ = Sanitize(android_os_experience, isTCHAR);
void UserAgentPlatformInfo::set_firmware_version_details(
const std::string& firmware_version_details) {
firmware_version_details_ =
Sanitize(firmware_version_details, isVCHARorSpace);
}

void UserAgentPlatformInfo::set_os_experience(
const std::string& os_experience) {
os_experience_ = Sanitize(os_experience, isTCHAR);
}

void UserAgentPlatformInfo::set_cobalt_version(
Expand Down
12 changes: 8 additions & 4 deletions cobalt/browser/user_agent_platform_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,10 @@ class UserAgentPlatformInfo : public web::UserAgentPlatformInfo {
const std::string& evergreen_version() const override {
return evergreen_version_;
}
const std::string& android_os_experience() const override {
return android_os_experience_;
const std::string& firmware_version_details() const override {
return firmware_version_details_;
}
const std::string& os_experience() const override { return os_experience_; }
const std::string& cobalt_version() const override { return cobalt_version_; }
const std::string& cobalt_build_version_number() const override {
return cobalt_build_version_number_;
Expand Down Expand Up @@ -110,7 +111,9 @@ class UserAgentPlatformInfo : public web::UserAgentPlatformInfo {
void set_evergreen_type(const std::string& evergreen_type);
void set_evergreen_file_type(const std::string& evergreen_file_type);
void set_evergreen_version(const std::string& evergreen_version);
void set_android_os_experience(const std::string& android_os_experience);
void set_firmware_version_details(
const std::string& firmware_version_details);
void set_os_experience(const std::string& os_experience);
void set_cobalt_version(const std::string& cobalt_version);
void set_cobalt_build_version_number(
const std::string& cobalt_build_version_number);
Expand All @@ -135,7 +138,8 @@ class UserAgentPlatformInfo : public web::UserAgentPlatformInfo {
std::string evergreen_type_;
std::string evergreen_file_type_;
std::string evergreen_version_;
std::string android_os_experience_; // Only via Client Hints
std::string firmware_version_details_; // Only via Client Hints
std::string os_experience_; // Only via Client Hints

std::string cobalt_version_;
std::string cobalt_build_version_number_;
Expand Down
3 changes: 2 additions & 1 deletion cobalt/web/cobalt_ua_data_values.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ dictionary CobaltUADataValues : UADataValues {
DOMString evergreenType;
DOMString evergreenFileType;
DOMString evergreenVersion;
DOMString androidOsExperience;
DOMString firmwareVersionDetails;
DOMString osExperience;
DOMString starboardVersion;
DOMString originalDesignManufacturer;
DOMString deviceType;
Expand Down
7 changes: 5 additions & 2 deletions cobalt/web/cobalt_ua_data_values_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,11 @@ CobaltUADataValuesInterface::CobaltUADataValuesInterface(
if (init_dict.has_evergreen_version()) {
evergreen_version_ = init_dict.evergreen_version();
}
if (init_dict.has_android_os_experience()) {
android_os_experience_ = init_dict.android_os_experience();
if (init_dict.has_firmware_version_details()) {
firmware_version_details_ = init_dict.firmware_version_details();
}
if (init_dict.has_os_experience()) {
os_experience_ = init_dict.os_experience();
}
if (init_dict.has_starboard_version()) {
starboard_version_ = init_dict.starboard_version();
Expand Down
8 changes: 5 additions & 3 deletions cobalt/web/cobalt_ua_data_values_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,10 @@ class CobaltUADataValuesInterface : public script::Wrappable {
return evergreen_file_type_;
}
const std::string& evergreen_version() const { return evergreen_version_; }
const std::string& android_os_experience() const {
return android_os_experience_;
const std::string& firmware_version_details() const {
return firmware_version_details_;
}
const std::string& os_experience() const { return os_experience_; }
const std::string& starboard_version() const { return starboard_version_; }
const std::string& original_design_manufacturer() const {
return original_design_manufacturer_;
Expand Down Expand Up @@ -82,7 +83,8 @@ class CobaltUADataValuesInterface : public script::Wrappable {
std::string evergreen_type_;
std::string evergreen_file_type_;
std::string evergreen_version_;
std::string android_os_experience_;
std::string firmware_version_details_;
std::string os_experience_;
std::string starboard_version_;
std::string original_design_manufacturer_;
std::string device_type_;
Expand Down
3 changes: 2 additions & 1 deletion cobalt/web/cobalt_ua_data_values_interface.idl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ interface CobaltUADataValuesInterface {
readonly attribute DOMString evergreenType;
readonly attribute DOMString evergreenFileType;
readonly attribute DOMString evergreenVersion;
readonly attribute DOMString androidOsExperience;
readonly attribute DOMString firmwareVersionDetails;
readonly attribute DOMString osExperience;
readonly attribute DOMString starboardVersion;
readonly attribute DOMString originalDesignManufacturer;
readonly attribute DOMString deviceType;
Expand Down
5 changes: 3 additions & 2 deletions cobalt/web/navigator_ua_data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ NavigatorUAData::NavigatorUAData(
platform_info->evergreen_file_type());
all_high_entropy_values_.set_evergreen_version(
platform_info->evergreen_version());
all_high_entropy_values_.set_android_os_experience(
platform_info->android_os_experience());
all_high_entropy_values_.set_firmware_version_details(
platform_info->firmware_version_details());
all_high_entropy_values_.set_os_experience(platform_info->os_experience());
all_high_entropy_values_.set_starboard_version(
platform_info->starboard_version());
all_high_entropy_values_.set_original_design_manufacturer(
Expand Down
3 changes: 2 additions & 1 deletion cobalt/web/testing/mock_user_agent_platform_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ class MockUserAgentPlatformInfo : public web::UserAgentPlatformInfo {
const std::string& evergreen_version() const override {
return empty_string_;
}
const std::string& android_os_experience() const override {
const std::string& firmware_version_details() const override {
return empty_string_;
}
const std::string& os_experience() const override { return empty_string_; }
const std::string& cobalt_version() const override { return empty_string_; }
const std::string& cobalt_build_version_number() const override {
return empty_string_;
Expand Down
3 changes: 2 additions & 1 deletion cobalt/web/user_agent_platform_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ class UserAgentPlatformInfo {
virtual const std::string& evergreen_type() const = 0;
virtual const std::string& evergreen_file_type() const = 0;
virtual const std::string& evergreen_version() const = 0;
virtual const std::string& android_os_experience() const = 0;
virtual const std::string& firmware_version_details() const = 0;
virtual const std::string& os_experience() const = 0;

virtual const std::string& cobalt_version() const = 0;
virtual const std::string& cobalt_build_version_number() const = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -850,4 +850,10 @@ public void registerCrashContextUpdateHandler(CrashContextUpdateHandler handler)
protected boolean getIsAmatiDevice() {
return this.isAmatiDevice;
}

@SuppressWarnings("unused")
@UsedByNative
protected String getBuildFingerprint() {
return Build.FINGERPRINT;
}
}
4 changes: 2 additions & 2 deletions starboard/android/shared/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,6 @@ static_library("starboard_platform") {
"accessibility_get_display_settings.cc",
"accessibility_get_text_to_speech_settings.cc",
"accessibility_set_captions_enabled.cc",
"android_info.cc",
"android_info.h",
"android_main.cc",
"android_media_session_client.cc",
"application_android.cc",
Expand Down Expand Up @@ -352,6 +350,8 @@ static_library("starboard_platform") {
"media_is_video_supported.cc",
"microphone_impl.cc",
"network_status_impl.cc",
"platform_info.cc",
"platform_info.h",
"platform_service.cc",
"player_components_factory.cc",
"player_components_factory.h",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,35 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#include "starboard/android/shared/android_info.h"
#include "starboard/android/shared/platform_info.h"

#include <string>

#include "starboard/common/log.h"

#include "starboard/android/shared/application_android.h"
#include "starboard/android/shared/jni_env_ext.h"
#include "starboard/extension/android_info.h"
#include "starboard/android/shared/jni_utils.h"
#include "starboard/common/string.h"
#include "starboard/extension/platform_info.h"

namespace starboard {
namespace android {
namespace shared {

namespace {

bool GetFirmwareVersionDetails(char* out_value, int value_length) {
JniEnvExt* env = JniEnvExt::Get();
ScopedLocalJavaRef<jstring> id_string(env->CallStarboardObjectMethodOrAbort(
"getBuildFingerprint", "()Ljava/lang/String;"));
std::string utf_str = env->GetStringStandardUTFOrAbort(id_string.Get());
if (strlen(utf_str.c_str()) + 1 > value_length)
return false;
starboard::strlcpy(out_value, utf_str.c_str(), value_length);
return true;
}

const char* GetOsExperience() {
bool is_amati = JniEnvExt::Get()->CallStarboardBooleanMethodOrAbort(
"getIsAmatiDevice", "()Z");
Expand All @@ -35,16 +50,17 @@ const char* GetOsExperience() {
return "Watson";
}

const CobaltExtensionAndroidInfoApi kAndroidInfoApi = {
kCobaltExtensionAndroidInfoName,
const CobaltExtensionPlatformInfoApi kPlatformInfoApi = {
kCobaltExtensionPlatformInfoName,
1,
&GetFirmwareVersionDetails,
&GetOsExperience,
};

} // namespace

const void* GetAndroidInfoApi() {
return &kAndroidInfoApi;
const void* GetPlatformInfoApi() {
return &kPlatformInfoApi;
}

} // namespace shared
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef STARBOARD_ANDROID_SHARED_ANDROID_INFO_H_
#define STARBOARD_ANDROID_SHARED_ANDROID_INFO_H_
#ifndef STARBOARD_ANDROID_SHARED_PLATFORM_INFO_H_
#define STARBOARD_ANDROID_SHARED_PLATFORM_INFO_H_

namespace starboard {
namespace android {
namespace shared {

const void* GetAndroidInfoApi();
const void* GetPlatformInfoApi();

} // namespace shared
} // namespace android
} // namespace starboard

#endif // STARBOARD_ANDROID_SHARED_ANDROID_INFO_H_
#endif // STARBOARD_ANDROID_SHARED_PLATFORM_INFO_H_
8 changes: 4 additions & 4 deletions starboard/android/shared/system_get_extensions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@

#include "starboard/system.h"

#include "starboard/android/shared/android_info.h"
#include "starboard/android/shared/android_media_session_client.h"
#include "starboard/android/shared/configuration.h"
#include "starboard/android/shared/graphics.h"
#include "starboard/android/shared/platform_info.h"
#include "starboard/android/shared/platform_service.h"
#include "starboard/common/log.h"
#include "starboard/common/string.h"
Expand All @@ -27,11 +27,11 @@
#else
#include "starboard/android/shared/crash_handler.h"
#endif
#include "starboard/extension/android_info.h"
#include "starboard/extension/configuration.h"
#include "starboard/extension/crash_handler.h"
#include "starboard/extension/graphics.h"
#include "starboard/extension/media_session.h"
#include "starboard/extension/platform_info.h"
#include "starboard/extension/platform_service.h"

const void* SbSystemGetExtension(const char* name) {
Expand Down Expand Up @@ -65,8 +65,8 @@ const void* SbSystemGetExtension(const char* name) {
return starboard::android::shared::GetCrashHandlerApi();
#endif
}
if (strcmp(name, kCobaltExtensionAndroidInfoName) == 0) {
return starboard::android::shared::GetAndroidInfoApi();
if (strcmp(name, kCobaltExtensionPlatformInfoName) == 0) {
return starboard::android::shared::GetPlatformInfoApi();
}
return NULL;
}
Loading

0 comments on commit ba6b0d1

Please sign in to comment.