1 // Copyright 2022 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include "components/metrics/ui/form_factor_metrics_provider.h" 6 #include "build/config/chromebox_for_meetings/buildflags.h" // PLATFORM_CFM 7 8 #include "build/build_config.h" 9 #include "ui/base/device_form_factor.h" 10 11 #if BUILDFLAG(IS_ANDROID) 12 #include "base/android/build_info.h" 13 #endif 14 15 namespace metrics { 16 ProvideSystemProfileMetrics(SystemProfileProto * system_profile_proto)17void FormFactorMetricsProvider::ProvideSystemProfileMetrics( 18 SystemProfileProto* system_profile_proto) { 19 system_profile_proto->mutable_hardware()->set_form_factor(GetFormFactor()); 20 } 21 22 SystemProfileProto::Hardware::FormFactor GetFormFactor() const23FormFactorMetricsProvider::GetFormFactor() const { 24 // Temporary workaround to report foldable for UMA without affecting 25 // other form factors. This will be removed and replaced with a long-term 26 // solution in DeviceFormFactor::GetDeviceFormFactor() after conducting an 27 // audit of form factor usage or exposing ui_mode. 28 // VariationsServiceClient::GetCurrentFormFactor() also needs to be updated. 29 #if BUILDFLAG(IS_ANDROID) 30 if (base::android::BuildInfo::GetInstance()->is_foldable()) { 31 return SystemProfileProto::Hardware::FORM_FACTOR_FOLDABLE; 32 } 33 #endif 34 35 #if BUILDFLAG(PLATFORM_CFM) 36 return SystemProfileProto::Hardware::FORM_FACTOR_MEET_DEVICE; 37 #else 38 switch (ui::GetDeviceFormFactor()) { 39 case ui::DEVICE_FORM_FACTOR_DESKTOP: 40 return SystemProfileProto::Hardware::FORM_FACTOR_DESKTOP; 41 case ui::DEVICE_FORM_FACTOR_PHONE: 42 return SystemProfileProto::Hardware::FORM_FACTOR_PHONE; 43 case ui::DEVICE_FORM_FACTOR_TABLET: 44 return SystemProfileProto::Hardware::FORM_FACTOR_TABLET; 45 case ui::DEVICE_FORM_FACTOR_TV: 46 return SystemProfileProto::Hardware::FORM_FACTOR_TV; 47 case ui::DEVICE_FORM_FACTOR_AUTOMOTIVE: 48 return SystemProfileProto::Hardware::FORM_FACTOR_AUTOMOTIVE; 49 case ui::DEVICE_FORM_FACTOR_FOLDABLE: 50 return SystemProfileProto::Hardware::FORM_FACTOR_FOLDABLE; 51 default: 52 return SystemProfileProto::Hardware::FORM_FACTOR_UNKNOWN; 53 } 54 #endif // BUILDFLAG(PLATFORM_CFM) 55 } 56 57 } // namespace metrics 58