0

ash: Add quick setting for toggling autozoom

Add quick setting toggle to toggle autozoom setting. The detailed view
for reframe button will be implemented in the next CL.

Bug: b:221980963
Test: manually
Change-Id: Iec59c0b68bdbda05193c7d198f48a9c275752e62
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3509339
Reviewed-by: Shik Chen <shik@chromium.org>
Auto-Submit: Pi-Hsun Shih <pihsun@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Pi-Hsun Shih <pihsun@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1026664}
This commit is contained in:
Pi-Hsun Shih
2022-07-21 07:45:44 +00:00
committed by Chromium LUCI CQ
parent 818619766e
commit 2ddabea249
29 changed files with 497 additions and 2 deletions

@ -1092,6 +1092,10 @@ component("ash") {
"system/brightness/unified_brightness_view.cc",
"system/brightness/unified_brightness_view.h",
"system/brightness_control_delegate.h",
"system/camera/autozoom_controller_impl.cc",
"system/camera/autozoom_controller_impl.h",
"system/camera/autozoom_feature_pod_controller.cc",
"system/camera/autozoom_feature_pod_controller.h",
"system/caps_lock_notification_controller.cc",
"system/caps_lock_notification_controller.h",
"system/cast/cast_feature_pod_controller.cc",
@ -2320,6 +2324,7 @@ component("ash") {
"//gpu/command_buffer/client",
"//gpu/command_buffer/client:gles2_interface",
"//media",
"//media/capture:capture_lib",
"//net",
"//services/data_decoder/public/cpp",
"//services/metrics/public/cpp:ukm_builders",

@ -29,6 +29,7 @@
#include "ash/shelf/shelf_controller.h"
#include "ash/style/dark_light_mode_controller_impl.h"
#include "ash/system/bluetooth/bluetooth_power_controller.h"
#include "ash/system/camera/autozoom_controller_impl.h"
#include "ash/system/caps_lock_notification_controller.h"
#include "ash/system/gesture_education/gesture_education_notification_controller.h"
#include "ash/system/human_presence/snooping_protection_controller.h"
@ -70,6 +71,7 @@ void RegisterProfilePrefs(PrefRegistrySimple* registry, bool for_test) {
AccessibilityControllerImpl::RegisterProfilePrefs(registry);
AppListControllerImpl::RegisterProfilePrefs(registry);
AssistantControllerImpl::RegisterProfilePrefs(registry);
AutozoomControllerImpl::RegisterProfilePrefs(registry);
AmbientController::RegisterProfilePrefs(registry);
if (!ash::features::IsBluetoothRevampEnabled())
BluetoothPowerController::RegisterProfilePrefs(registry);

@ -314,6 +314,27 @@ This file contains the strings for ash.
<message name="IDS_ASH_QUICK_SETTINGS_BUBBLE_VPN_SETTINGS_ACCESSIBLE_DESCRIPTION" desc="The accessible description for VPN settings accessed through the VPN feature pod.">
VPN Settings
</message>
<message name="IDS_ASH_STATUS_TRAY_AUTOZOOM_BUTTON_LABEL" desc="The shorter label used for the button in the status tray to toggle the Autozoom feature (which controls if camera auto zoom to faces) on or off. [CHAR_LIMIT=14]">
Autozoom
</message>
<message name="IDS_ASH_STATUS_TRAY_AUTOZOOM_TOGGLE_TOOLTIP" desc="The tooltip text used for the button in the status tray to toggle the Autozoom feature (which controls if camera auto zoom to faces) on or off.">
Toggle autozoom. <ph name="STATE_TEXT">$1<ex>Autozoom is on.</ex></ph>
</message>
<message name="IDS_ASH_STATUS_TRAY_AUTOZOOM_TOGGLE_ACCESSIBILITY_DESCRIPTION" desc="The accessible description for the button in the status tray to toggle the Autozoom feature (which controls if camera auto zoom to faces) on or off.">
Adjust camera to put you in the center of the screen.
</message>
<message name="IDS_ASH_STATUS_TRAY_AUTOZOOM_OFF_STATE_TOOLTIP" desc="The tooltip text indicating the Autozoom feature is off.">
Autozoom is off.
</message>
<message name="IDS_ASH_STATUS_TRAY_AUTOZOOM_ON_STATE_TOOLTIP" desc="The tooltip text indicating the Autozoom feature is on.">
Autozoom is on.
</message>
<message name="IDS_ASH_STATUS_TRAY_AUTOZOOM_OFF_STATE" desc="Button label for the Autozoom feature." meaning="Autozoom feature is off. [CHAR_LIMIT=14]">
Off
</message>
<message name="IDS_ASH_STATUS_TRAY_AUTOZOOM_ON_STATE" desc="Button label for the Autozoom feature." meaning="Autozoom feature is on. [CHAR_LIMIT=14]">
On
</message>
<message name="IDS_ASH_STATUS_TRAY_BRAILLE_DISPLAY_CONNECTED" desc="The message shown on a notification when a braille display is connected">
Braille display connected.
</message>

@ -0,0 +1 @@
ac29c0bd3746ffec67b061871d081bcca339c410

@ -0,0 +1 @@
ac29c0bd3746ffec67b061871d081bcca339c410

@ -0,0 +1 @@
9117d29de2fe89fcc33a6dde6bb329a31bceb030

@ -0,0 +1 @@
524d2d5e8b97eedd52d61a48621a384552f7f74b

@ -0,0 +1 @@
ba9e1b31bddc612d6df916ee80f2161e019f90a8

@ -0,0 +1 @@
d0738ee2f959ca74d9816dfb0adfe18243b49f0e

@ -0,0 +1 @@
ba9e1b31bddc612d6df916ee80f2161e019f90a8

@ -1054,6 +1054,10 @@ const char kShowPostRebootNotification[] = "ash.show_post_reboot_notification";
const char kPersonalizationKeyboardBacklightColor[] =
"ash.personalization.keyboard_backlight_color";
// Integer pref corresponding to the autozoom state, the value should be one of
// cros::mojom::CameraAutoFramingState.
const char kAutozoomState[] = "ash.camera.autozoom_state";
// NOTE: New prefs should start with the "ash." prefix. Existing prefs moved
// into this file should not be renamed, since they may be synced.

@ -482,6 +482,9 @@ COMPONENT_EXPORT(ASH_CONSTANTS) extern const char kShowPostRebootNotification[];
COMPONENT_EXPORT(ASH_CONSTANTS)
extern const char kPersonalizationKeyboardBacklightColor[];
COMPONENT_EXPORT(ASH_CONSTANTS) extern const char kAutozoomState[];
} // namespace prefs
} // namespace ash

@ -425,6 +425,7 @@ aggregate_vector_icons("ash_vector_icons") {
"two_files.icon",
"undo.icon",
"unified_menu_accessibility.icon",
"unified_menu_autozoom.icon",
"unified_menu_battery_alert.icon",
"unified_menu_battery_alert_outline.icon",
"unified_menu_battery_alert_outline_mask.icon",

@ -0,0 +1,54 @@
// Copyright 2022 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.
CANVAS_DIMENSIONS, 20,
MOVE_TO, 12, 5,
R_H_LINE_TO, 3,
R_V_LINE_TO, 3,
R_H_LINE_TO, 2,
V_LINE_TO, 5,
R_ARC_TO, 2, 2, 0, 0, 0, -2, -2,
R_H_LINE_TO, -3,
R_V_LINE_TO, 2,
CLOSE,
MOVE_TO, 8, 5,
V_LINE_TO, 3,
H_LINE_TO, 5,
R_ARC_TO, 2, 2, 0, 0, 0, -2, 2,
R_V_LINE_TO, 3,
R_H_LINE_TO, 2,
V_LINE_TO, 5,
R_H_LINE_TO, 3,
CLOSE,
MOVE_TO, 5, 12,
H_LINE_TO, 3,
R_V_LINE_TO, 3,
R_ARC_TO, 2, 2, 0, 0, 0, 2, 2,
R_H_LINE_TO, 3,
R_V_LINE_TO, -2,
H_LINE_TO, 5,
R_V_LINE_TO, -3,
CLOSE,
MOVE_TO, 12, 15,
R_V_LINE_TO, 2,
R_H_LINE_TO, 3,
R_ARC_TO, 2, 2, 0, 0, 0, 2, -2,
R_V_LINE_TO, -3,
R_H_LINE_TO, -2,
R_V_LINE_TO, 3,
R_H_LINE_TO, -3,
CLOSE,
MOVE_TO, 8.25f, 8.25f,
R_CUBIC_TO, 0, -0.96f, 0.79f, -1.75f, 1.75f, -1.75f,
R_CUBIC_TO, 0.96f, 0, 1.75f, 0.79f, 1.75f, 1.75f,
CUBIC_TO_SHORTHAND, 10.96f, 10, 10, 10,
R_CUBIC_TO, -0.96f, 0, -1.75f, -0.79f, -1.75f, -1.75f,
CLOSE,
MOVE_TO, 13, 12.14f,
V_LINE_TO, 13,
H_LINE_TO, 7,
R_V_LINE_TO, -0.86f,
R_CUBIC_TO, 0, -1.03f, 1.84f, -1.56f, 3, -1.56f,
R_CUBIC_TO, 1.16f, 0, 3, 0.52f, 3, 1.56f,
CLOSE

@ -115,6 +115,7 @@
#include "ash/system/bluetooth/tray_bluetooth_helper_legacy.h"
#include "ash/system/brightness/brightness_controller_chromeos.h"
#include "ash/system/brightness_control_delegate.h"
#include "ash/system/camera/autozoom_controller_impl.h"
#include "ash/system/caps_lock_notification_controller.h"
#include "ash/system/diagnostics/diagnostics_log_controller.h"
#include "ash/system/firmware_update/firmware_update_notification_controller.h"
@ -206,6 +207,7 @@
#include "components/prefs/pref_service.h"
#include "components/viz/host/host_frame_sink_manager.h"
#include "dbus/bus.h"
#include "media/capture/video/chromeos/video_capture_features_chromeos.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/layout_manager.h"
@ -865,6 +867,8 @@ Shell::~Shell() {
docked_magnifier_controller_ = nullptr;
// Similarly for PrivacyScreenController.
privacy_screen_controller_ = nullptr;
// Similarly for AutozoomControllerImpl
autozoom_controller_ = nullptr;
geolocation_controller_.reset();
@ -1132,6 +1136,9 @@ void Shell::Init(
// display manager was properly initialized.
privacy_screen_controller_ = std::make_unique<PrivacyScreenController>();
if (media::ShouldEnableAutoFraming())
autozoom_controller_ = std::make_unique<AutozoomControllerImpl>();
// Fast Pair depends on the display manager, so initialize it after
// display manager was properly initialized.
if (base::FeatureList::IsEnabled(features::kFastPair)) {

@ -96,6 +96,7 @@ class AshFocusRules;
class AshTouchTransformController;
class AssistantControllerImpl;
class AutoclickController;
class AutozoomControllerImpl;
class BackGestureEventHandler;
class BacklightsForcedOffSetter;
class BluetoothDeviceStatusUiHandler;
@ -373,6 +374,9 @@ class ASH_EXPORT Shell : public SessionObserver,
AutoclickController* autoclick_controller() {
return autoclick_controller_.get();
}
AutozoomControllerImpl* autozoom_controller() {
return autozoom_controller_.get();
}
BacklightsForcedOffSetter* backlights_forced_off_setter() {
return backlights_forced_off_setter_.get();
}
@ -794,6 +798,7 @@ class ASH_EXPORT Shell : public SessionObserver,
scoped_refptr<dbus::Bus> dbus_bus_;
std::unique_ptr<AshDBusServices> ash_dbus_services_;
std::unique_ptr<AssistantControllerImpl> assistant_controller_;
std::unique_ptr<AutozoomControllerImpl> autozoom_controller_;
std::unique_ptr<BacklightsForcedOffSetter> backlights_forced_off_setter_;
std::unique_ptr<BrightnessControlDelegate> brightness_control_delegate_;
std::unique_ptr<CalendarController> calendar_controller_;

@ -0,0 +1,3 @@
buganizer {
component_id: 167281
}

1
ash/system/camera/OWNERS Normal file

@ -0,0 +1 @@
pihsun@chromium.org

@ -0,0 +1,93 @@
// Copyright 2022 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 "ash/system/camera/autozoom_controller_impl.h"
#include "ash/constants/ash_pref_names.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "base/logging.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
namespace ash {
AutozoomControllerImpl::AutozoomControllerImpl() {
Shell::Get()->session_controller()->AddObserver(this);
}
AutozoomControllerImpl::~AutozoomControllerImpl() {
Shell::Get()->session_controller()->RemoveObserver(this);
}
cros::mojom::CameraAutoFramingState AutozoomControllerImpl::GetState() {
return state_;
}
void AutozoomControllerImpl::SetState(
cros::mojom::CameraAutoFramingState state) {
if (active_user_pref_service_) {
active_user_pref_service_->SetInteger(prefs::kAutozoomState,
static_cast<int32_t>(state));
}
}
void AutozoomControllerImpl::Toggle() {
SetState(state_ == cros::mojom::CameraAutoFramingState::OFF
? cros::mojom::CameraAutoFramingState::ON_SINGLE
: cros::mojom::CameraAutoFramingState::OFF);
}
void AutozoomControllerImpl::OnActiveUserPrefServiceChanged(
PrefService* pref_service) {
if (pref_service == active_user_pref_service_)
return;
// Initial login and user switching in multi profiles.
active_user_pref_service_ = pref_service;
InitFromUserPrefs();
}
void AutozoomControllerImpl::OnStatePrefChanged() {
Refresh();
}
void AutozoomControllerImpl::Refresh() {
if (active_user_pref_service_) {
state_ = static_cast<cros::mojom::CameraAutoFramingState>(
active_user_pref_service_->GetInteger(prefs::kAutozoomState));
} else {
state_ = cros::mojom::CameraAutoFramingState::OFF;
}
auto* camera_hal_dispatcher = media::CameraHalDispatcherImpl::GetInstance();
if (camera_hal_dispatcher) {
camera_hal_dispatcher->SetAutoFramingState(GetState());
}
}
void AutozoomControllerImpl::StartWatchingPrefsChanges() {
DCHECK(active_user_pref_service_);
pref_change_registrar_ = std::make_unique<PrefChangeRegistrar>();
pref_change_registrar_->Init(active_user_pref_service_);
pref_change_registrar_->Add(
prefs::kAutozoomState,
base::BindRepeating(&AutozoomControllerImpl::OnStatePrefChanged,
base::Unretained(this)));
}
void AutozoomControllerImpl::InitFromUserPrefs() {
StartWatchingPrefsChanges();
Refresh();
}
// static
void AutozoomControllerImpl::RegisterProfilePrefs(
PrefRegistrySimple* registry) {
registry->RegisterIntegerPref(
prefs::kAutozoomState,
static_cast<int32_t>(cros::mojom::CameraAutoFramingState::OFF));
}
} // namespace ash

@ -0,0 +1,66 @@
// Copyright 2022 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 ASH_SYSTEM_CAMERA_AUTOZOOM_CONTROLLER_IMPL_H_
#define ASH_SYSTEM_CAMERA_AUTOZOOM_CONTROLLER_IMPL_H_
#include "ash/ash_export.h"
#include "ash/public/cpp/session/session_observer.h"
#include "components/prefs/pref_change_registrar.h"
#include "components/prefs/pref_registry_simple.h"
#include "components/prefs/pref_service.h"
#include "media/capture/video/chromeos/mojom/cros_camera_service.mojom.h"
namespace ash {
// Controls the Autozoom feature that, when enabled, intelligently
// pans/tilts/zooms the camera to frame a set of regions of interest captured
// by the camera.
class ASH_EXPORT AutozoomControllerImpl : public SessionObserver {
public:
AutozoomControllerImpl();
AutozoomControllerImpl(const AutozoomControllerImpl&) = delete;
AutozoomControllerImpl& operator=(const AutozoomControllerImpl&) = delete;
~AutozoomControllerImpl() override;
static void RegisterProfilePrefs(PrefRegistrySimple* registry);
void SetState(cros::mojom::CameraAutoFramingState state);
cros::mojom::CameraAutoFramingState GetState();
void Toggle();
// SessionObserver:
void OnActiveUserPrefServiceChanged(PrefService* pref_service) override;
private:
void InitFromUserPrefs();
void Refresh();
void StartWatchingPrefsChanges();
// Called when the user pref for the enabled status of Autozoom is changed.
void OnStatePrefChanged();
// The pref service of the currently active user. Can be null in
// ash_unittests.
PrefService* active_user_pref_service_ = nullptr;
// The registrar used to watch Autozoom prefs changes in the above
// |active_user_pref_service_| from outside ash.
// NOTE: Prefs are how Chrome communicates changes to the Autozoom settings
// controlled by this class.
std::unique_ptr<PrefChangeRegistrar> pref_change_registrar_;
cros::mojom::CameraAutoFramingState state_;
};
} // namespace ash
#endif // ASH_SYSTEM_CAMERA_AUTOZOOM_CONTROLLER_IMPL_H_

@ -0,0 +1,119 @@
// Copyright 2022 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 "ash/system/camera/autozoom_feature_pod_controller.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/session/session_controller_impl.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/camera/autozoom_controller_impl.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/accessibility/view_accessibility.h"
namespace ash {
AutozoomFeaturePodController::AutozoomFeaturePodController() {
auto* camera_hal_dispatcher = media::CameraHalDispatcherImpl::GetInstance();
if (camera_hal_dispatcher) {
camera_hal_dispatcher->AddActiveClientObserver(this);
}
}
AutozoomFeaturePodController::~AutozoomFeaturePodController() {
auto* camera_hal_dispatcher = media::CameraHalDispatcherImpl::GetInstance();
if (camera_hal_dispatcher) {
camera_hal_dispatcher->RemoveActiveClientObserver(this);
}
}
FeaturePodButton* AutozoomFeaturePodController::CreateButton() {
DCHECK(!button_);
button_ = new FeaturePodButton(this);
button_->SetVectorIcon(kUnifiedMenuAutozoomIcon);
button_->SetLabel(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUTOZOOM_BUTTON_LABEL));
auto description = l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_AUTOZOOM_TOGGLE_ACCESSIBILITY_DESCRIPTION);
button_->icon_button()->GetViewAccessibility().OverrideDescription(
description);
button_->label_button()->GetViewAccessibility().OverrideDescription(
description);
UpdateButton();
return button_;
}
SystemTrayItemUmaType AutozoomFeaturePodController::GetUmaType() const {
return SystemTrayItemUmaType::UMA_AUTOZOOM;
}
void AutozoomFeaturePodController::OnToggled() {
Shell::Get()->autozoom_controller()->Toggle();
UpdateButton();
}
void AutozoomFeaturePodController::OnLabelPressed() {
if (!button_->GetEnabled())
return;
OnToggled();
}
void AutozoomFeaturePodController::OnIconPressed() {
OnToggled();
}
void AutozoomFeaturePodController::UpdateButtonVisibility() {
if (!button_)
return;
button_->SetVisible(
Shell::Get()->session_controller()->ShouldEnableSettings() &&
active_camera_client_count_ > 0);
}
void AutozoomFeaturePodController::UpdateButton() {
auto state = Shell::Get()->autozoom_controller()->GetState();
button_->SetToggled(state != cros::mojom::CameraAutoFramingState::OFF);
UpdateButtonVisibility();
std::u16string tooltip_state;
std::u16string button_label;
switch (state) {
case cros::mojom::CameraAutoFramingState::OFF:
button_label =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUTOZOOM_OFF_STATE);
tooltip_state = l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_AUTOZOOM_OFF_STATE_TOOLTIP);
break;
case cros::mojom::CameraAutoFramingState::ON_SINGLE:
case cros::mojom::CameraAutoFramingState::ON_MULTI:
button_label =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUTOZOOM_ON_STATE);
tooltip_state = l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_AUTOZOOM_ON_STATE_TOOLTIP);
break;
}
button_->SetSubLabel(button_label);
button_->SetIconAndLabelTooltips(l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_AUTOZOOM_TOGGLE_TOOLTIP, tooltip_state));
}
void AutozoomFeaturePodController::OnActiveClientChange(
cros::mojom::CameraClientType type,
bool is_active) {
if (is_active) {
active_camera_client_count_++;
} else {
active_camera_client_count_--;
}
UpdateButtonVisibility();
}
} // namespace ash

@ -0,0 +1,48 @@
// Copyright 2022 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 ASH_SYSTEM_CAMERA_AUTOZOOM_FEATURE_POD_CONTROLLER_H_
#define ASH_SYSTEM_CAMERA_AUTOZOOM_FEATURE_POD_CONTROLLER_H_
#include "ash/system/unified/feature_pod_controller_base.h"
#include "media/capture/video/chromeos/camera_hal_dispatcher_impl.h"
namespace ash {
// Controller of a feature pod button that toggles autozoom.
class AutozoomFeaturePodController : public FeaturePodControllerBase,
public media::CameraActiveClientObserver {
public:
AutozoomFeaturePodController();
AutozoomFeaturePodController(const AutozoomFeaturePodController&) = delete;
AutozoomFeaturePodController& operator=(const AutozoomFeaturePodController&) =
delete;
~AutozoomFeaturePodController() override;
// FeaturePodControllerBase:
FeaturePodButton* CreateButton() override;
void OnIconPressed() override;
void OnLabelPressed() override;
SystemTrayItemUmaType GetUmaType() const override;
private:
void OnToggled();
void UpdateButton();
void UpdateButtonVisibility();
// CameraActiveClientObserver
void OnActiveClientChange(cros::mojom::CameraClientType type,
bool is_active) override;
FeaturePodButton* button_ = nullptr;
int active_camera_client_count_ = 0;
};
} // namespace ash
#endif // ASH_SYSTEM_CAMERA_AUTOZOOM_FEATURE_POD_CONTROLLER_H_

@ -48,7 +48,8 @@ enum class SystemTrayItemUmaType {
UMA_NEARBY_SHARE = 31,
UMA_PROJECTOR = 32,
UMA_SHELF_PARTY = 33,
UMA_COUNT = 34,
UMA_AUTOZOOM = 34,
UMA_COUNT = 35,
};
} // namespace ash

@ -23,6 +23,7 @@
#include "ash/system/bluetooth/bluetooth_feature_pod_controller_legacy.h"
#include "ash/system/bluetooth/unified_bluetooth_detailed_view_controller.h"
#include "ash/system/brightness/unified_brightness_slider_controller.h"
#include "ash/system/camera/autozoom_feature_pod_controller.h"
#include "ash/system/cast/cast_feature_pod_controller.h"
#include "ash/system/cast/unified_cast_detailed_view_controller.h"
#include "ash/system/dark_mode/dark_mode_feature_pod_controller.h"
@ -68,6 +69,7 @@
#include "base/metrics/user_metrics.h"
#include "components/prefs/pref_service.h"
#include "media/base/media_switches.h"
#include "media/capture/video/chromeos/video_capture_features_chromeos.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/compositor/compositor.h"
#include "ui/display/screen.h"
@ -546,6 +548,9 @@ void UnifiedSystemTrayController::InitFeaturePods() {
if (base::FeatureList::IsEnabled(features::kShelfParty))
AddFeaturePodItem(std::make_unique<ShelfPartyFeaturePodController>());
if (media::ShouldEnableAutoFraming())
AddFeaturePodItem(std::make_unique<AutozoomFeaturePodController>());
// If you want to add a new feature pod item, add here.
if (Shell::Get()->tablet_mode_controller()->InTabletMode()) {

@ -460,6 +460,7 @@ void CameraHalDispatcherImpl::RegisterServerWithToken(
camera_hal_server_.set_disconnect_handler(
base::BindOnce(&CameraHalDispatcherImpl::OnCameraHalServerConnectionError,
base::Unretained(this)));
camera_hal_server_->SetAutoFramingState(current_auto_framing_state_);
CAMERA_LOG(EVENT) << "Camera HAL server registered";
std::move(callback).Run(
0, camera_hal_server_callbacks_.BindNewPipeAndPassRemote());
@ -930,6 +931,29 @@ void CameraHalDispatcherImpl::StopOnProxyThread() {
receiver_set_.Clear();
}
void CameraHalDispatcherImpl::SetAutoFramingState(
cros::mojom::CameraAutoFramingState state) {
if (!proxy_thread_.IsRunning()) {
// The camera hal dispatcher is not running, ignore the request.
// TODO(pihsun): Any better way?
return;
}
proxy_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&CameraHalDispatcherImpl::SetAutoFramingStateOnProxyThread,
base::Unretained(this), state));
}
void CameraHalDispatcherImpl::SetAutoFramingStateOnProxyThread(
cros::mojom::CameraAutoFramingState state) {
DCHECK(proxy_task_runner_->BelongsToCurrentThread());
current_auto_framing_state_ = state;
if (camera_hal_server_) {
camera_hal_server_->SetAutoFramingState(state);
}
}
TokenManager* CameraHalDispatcherImpl::GetTokenManagerForTesting() {
return &token_manager_;
}

@ -239,6 +239,8 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final
base::UnguessableToken GetTokenForTrustedClient(
cros::mojom::CameraClientType type);
void SetAutoFramingState(cros::mojom::CameraAutoFramingState state);
private:
friend struct base::DefaultSingletonTraits<CameraHalDispatcherImpl>;
// Allow the test to construct the class directly.
@ -295,6 +297,9 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final
const base::UnguessableToken& auth_token,
RegisterSensorClientWithTokenCallback callback);
void SetAutoFramingStateOnProxyThread(
cros::mojom::CameraAutoFramingState state);
void StopOnProxyThread();
TokenManager* GetTokenManagerForTesting();
@ -341,6 +346,9 @@ class CAPTURE_EXPORT CameraHalDispatcherImpl final
cros::mojom::CameraPrivacySwitchState current_sw_privacy_switch_state_
GUARDED_BY(sw_privacy_switch_lock_);
cros::mojom::CameraAutoFramingState current_auto_framing_state_ =
cros::mojom::CameraAutoFramingState::OFF;
scoped_refptr<base::ObserverListThreadSafe<CameraPrivacySwitchObserver>>
privacy_switch_observers_ GUARDED_BY(privacy_switch_lock_);

@ -46,9 +46,13 @@ enum CameraPrivacySwitchState {
OFF = 2,
};
// CameraAutoZoomState indicates the state of the camera autozoom feature.
// CameraAutoFramingState indicates the state of the camera autozoom feature.
// Note that this enum is saved into user prefs, so enum values should not be
// reordered, deleted or repurposed.
[Stable, Extensible]
enum CameraAutoFramingState {
// Auto framing is disabled.
[Default]
OFF = 0,
// Auto framing is enabled and set to single person mode.

@ -4,6 +4,8 @@
#include "media/capture/video/chromeos/video_capture_features_chromeos.h"
#include "base/command_line.h"
namespace media {
namespace switches {
@ -23,4 +25,14 @@ const base::Feature kDisableCameraFrameRotationAtSource{
} // namespace features
// Check if auto framing should be enabled.
bool ShouldEnableAutoFraming() {
const base::CommandLine* command_line =
base::CommandLine::ForCurrentProcess();
// TODO(pihsun): Migrate the flag to use base::Feature.
std::string value =
command_line->GetSwitchValueASCII(media::switches::kAutoFramingOverride);
return value == media::switches::kAutoFramingForceEnabled;
}
} // namespace media

@ -30,6 +30,8 @@ CAPTURE_EXPORT extern const base::Feature kDisableCameraFrameRotationAtSource;
} // namespace features
CAPTURE_EXPORT bool ShouldEnableAutoFraming();
} // namespace media
#endif // MEDIA_CAPTURE_VIDEO_CHROMEOS_VIDEO_CAPTURE_FEATURES_CHROMEOS_H_