使用相机状态判断功能

Change-Id: I8a21d25b43756a43b013ce6ce8b3c141fff7f2fc
Signed-off-by: jintong <jintong2@huawei.com>
This commit is contained in:
guofanfeng 2024-11-12 16:05:19 +08:00 committed by jintong
parent 28aa98690e
commit 307b52d861
13 changed files with 164 additions and 40 deletions

View File

@ -137,6 +137,7 @@ enum class DisplayManagerMessage : unsigned int {
TRANS_ID_GET_DISPLAY_CAPTURE,
TRANS_ID_GET_PRIMARY_DISPLAY_INFO,
TRANS_ID_GET_DISPLAY_SNAPSHOT_WITH_OPTION,
TRANS_ID_SET_CAMERA_STATUS,
};
}
#endif // FOUNDATION_DMSERVER_DISPLAY_MANAGER_INTERFACE_CODE_H

View File

@ -40,6 +40,7 @@ const std::string ON_SCREEN_EXTEND_CHANGE = "screenExtendChange";
const std::string ON_HOVER_STATUS_CHANGE_CALLBACK = "hoverStatusChange";
const std::string ON_SCREEN_CAPTURE_NOTIFY = "screenCaptureNotify";
const std::string ON_SUPER_FOLD_STATUS_CHANGE_CALLBACK = "superFoldStatusChange";
const std::string ON_CAMERA_FOLD_STATUS_CHANGE_CALLBACK = "cameraStatusChange";
constexpr size_t ARGC_ONE = 1;
} // namespace

View File

@ -92,12 +92,12 @@ napi_value JsScreenSessionManager::Init(napi_env env, napi_value exportObj)
JsScreenSessionManager::SetScreenOffDelayTime);
BindNativeFunction(env, exportObj, "notifyFoldToExpandCompletion", moduleName,
JsScreenSessionManager::NotifyFoldToExpandCompletion);
BindNativeFunction(env, exportObj, "getFoldStatus", moduleName,
JsScreenSessionManager::GetFoldStatus);
BindNativeFunction(env, exportObj, "getFoldStatus", moduleName, JsScreenSessionManager::GetFoldStatus);
BindNativeFunction(env, exportObj, "getScreenSnapshot", moduleName,
JsScreenSessionManager::GetScreenSnapshot);
BindNativeFunction(env, exportObj, "getDeviceScreenConfig", moduleName,
JsScreenSessionManager::GetDeviceScreenConfig);
BindNativeFunction(env, exportObj, "setCameraStatus", moduleName, JsScreenSessionManager::SetCameraStatus);
return NapiGetUndefined(env);
}
@ -247,6 +247,13 @@ void JsScreenSessionManager::OnScreenConnected(const sptr<ScreenSession>& screen
}
}
napi_value JsScreenSessionManager::SetCameraStatus(napi_env env, napi_callback_info info)
{
TLOGD(WmsLogTag::DMS, "[NAPI]SetCameraStatus");
JsScreenSessionManager* me = CheckParamsAndGetThis<JsScreenSessionManager>(env, info);
return (me != nullptr) ? me->OnSetCameraStatus(env, info) : nullptr;
}
void JsScreenSessionManager::OnScreenDisconnected(const sptr<ScreenSession>& screenSession)
{
if (screenConnectionCallback_ == nullptr) {
@ -674,4 +681,41 @@ napi_value JsScreenSessionManager::OnGetDeviceScreenConfig(napi_env env, const n
}
return jsDeviceScreenConfigObj;
}
napi_value JsScreenSessionManager::OnSetCameraStatus(napi_env env, const napi_callback_info info)
{
WLOGFD("[NAPI]OnSetCameraStatus");
size_t argc = 2;
napi_handle_scope scope = nullptr;
napi_open_handle_scope(env, &scope);
napi_value argv[2] = {nullptr, nullptr};
napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr);
if (argc < 2) { // 2: params num
TLOGE(WmsLogTag::DMS, "[NAPI]Argc is invalid: %{public}zu", argc);
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
napi_close_handle_scope(env, scope);
return NapiGetUndefined(env);
}
int32_t cameraStatus;
int32_t cameraPosition;
if (!ConvertFromJsValue(env, argv[0], cameraStatus)) {
TLOGE(WmsLogTag::DMS, "[NAPI]Failed to convert parameter to cameraStatus");
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
napi_close_handle_scope(env, scope);
return NapiGetUndefined(env);
}
if (!ConvertFromJsValue(env, argv[1], cameraPosition)) {
TLOGE(WmsLogTag::DMS, "[NAPI]Failed to convert parameter to cameraPosition");
napi_throw(env, CreateJsError(env, static_cast<int32_t>(WSErrorCode::WS_ERROR_INVALID_PARAM),
"Input parameter is missing or invalid"));
napi_close_handle_scope(env, scope);
return NapiGetUndefined(env);
}
ScreenSessionManagerClient::GetInstance().SetCameraStatus(cameraStatus, cameraPosition);
napi_close_handle_scope(env, scope);
return NapiGetUndefined(env);
}
} // namespace OHOS::Rosen

View File

@ -51,6 +51,7 @@ private:
static napi_value UpdateAvailableArea(napi_env env, napi_callback_info info);
static napi_value SetScreenOffDelayTime(napi_env env, napi_callback_info info);
static napi_value NotifyFoldToExpandCompletion(napi_env env, napi_callback_info info);
static napi_value SetCameraStatus(napi_env env, napi_callback_info info);
static napi_value GetFoldStatus(napi_env env, napi_callback_info info);
static napi_value GetScreenSnapshot(napi_env env, napi_callback_info info);
static napi_value GetDeviceScreenConfig(napi_env env, napi_callback_info info);
@ -64,6 +65,7 @@ private:
napi_value OnNotifyScreenLockEvent(napi_env env, const napi_callback_info info);
napi_value OnUpdateAvailableArea(napi_env env, const napi_callback_info info);
napi_value OnSetScreenOffDelayTime(napi_env env, const napi_callback_info info);
napi_value OnSetCameraStatus(napi_env env, napi_callback_info info);
napi_value OnNotifyFoldToExpandCompletion(napi_env env, const napi_callback_info info);
napi_value OnGetFoldStatus(napi_env env, const napi_callback_info info);
napi_value OnGetScreenSnapshot(napi_env env, const napi_callback_info info);

View File

@ -65,10 +65,10 @@ private:
FoldStatus GetNextFoldState(float angle, int hall);
void UpdateSwitchScreenBoundaryForLargeFoldDevice(float, int);
void SetCameraFoldStrategy(float angle);
void SetCameraStatusChange(float angle, int hall);
void SetCameraRotationStatusChange(float angle, int hall);
sptr<ApplicationStatePocketObserver> applicationStateObserver_;
bool isInCameraFoldStrategy_ = false;
bool isCameraStatus_ = false;
bool isCameraRotationStrategy_ = false;
std::vector<std::string> hallSwitchPackageNameList_;
int allowUserSensorForLargeFoldDevice = 0;
bool TriggerTentExit(float angle, int hall);

View File

@ -282,7 +282,10 @@ public:
DMError GetAvailableArea(DisplayId displayId, DMRect& area) override;
void NotifyAvailableAreaChanged(DMRect area);
void NotifyFoldToExpandCompletion(bool foldToExpand) override;
void SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition) override;
bool GetSnapshotArea(Media::Rect &rect, DmErrorCode* errorCode, ScreenId &screenId);
int32_t GetCameraStatus();
int32_t GetCameraPosition();
VirtualScreenFlag GetVirtualScreenFlag(ScreenId screenId) override;
DMError SetVirtualScreenFlag(ScreenId screenId, VirtualScreenFlag screenFlag) override;
@ -512,6 +515,8 @@ private:
std::atomic<bool> isScreenLockSuspend_ = false;
std::atomic<bool> gotScreenlockFingerprint_ = false;
std::atomic<bool> isPhyScreenConnected_ = false;
int32_t cameraStatus_ = {0};
int32_t cameraPosition_ = {0};
// Fold Screen
std::map<ScreenId, ScreenProperty> phyScreenPropMap_;

View File

@ -166,6 +166,7 @@ public:
ScreenPropertyChangeType screenPropertyChangeType) {}
virtual void UpdateAvailableArea(ScreenId screenId, DMRect area) {}
virtual int32_t SetScreenOffDelayTime(int32_t delay) { return 0; }
virtual void SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition) {}
virtual uint32_t GetCurvedCompressionArea() { return 0; }
virtual ScreenProperty GetPhyScreenProperty(ScreenId screenId) { return ScreenProperty(); }
virtual void NotifyDisplayChangeInfoChanged(const sptr<DisplayChangeInfo>& info) {}

View File

@ -148,6 +148,8 @@ public:
sptr<FoldCreaseRegion> GetCurrentFoldCreaseRegion() override;
void SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition) override;
// unique screen
DMError MakeUniqueScreen(const std::vector<ScreenId>& screenIds) override;

View File

@ -25,6 +25,7 @@
#include "window_manager_hilog.h"
#include "app_mgr_client.h"
#include "screen_session_manager/include/screen_rotation_property.h"
#include "screen_session_manager.h"
#ifdef POWER_MANAGER_ENABLE
#include <power_mgr_client.h>
@ -34,7 +35,6 @@ namespace OHOS::Rosen {
using OHOS::AppExecFwk::AppStateData;
using OHOS::AppExecFwk::ApplicationState;
namespace {
const std::string CAMERA_NAME = "camera";
constexpr HiviewDFX::HiLogLabel LABEL = {LOG_CORE, HILOG_DOMAIN_DISPLAY, "SingleDisplaySensorPocketFoldStateManager"};
constexpr float ANGLE_MIN_VAL = 0.0F;
constexpr float ALTA_HALF_FOLDED_MAX_THRESHOLD = 140.0F;
@ -51,6 +51,8 @@ constexpr float TENT_MODE_EXIT_MIN_THRESHOLD = 5.0F;
constexpr float TENT_MODE_EXIT_MAX_THRESHOLD = 175.0F;
constexpr float HOVER_STATUS_EXIT_MIN_THRESHOLD = 5.0F;
constexpr float HOVER_STATUS_EXIT_MAX_THRESHOLD = 175.0F;
constexpr int32_t CAMERA_STATUS_UNAVAILABLE = 3;
constexpr int32_t CAMERA_POSITION_FRONT = 2;
} // namespace
SingleDisplaySensorPocketFoldStateManager::SingleDisplaySensorPocketFoldStateManager()
@ -68,10 +70,10 @@ void SingleDisplaySensorPocketFoldStateManager::HandleAngleChange(float angle, i
SetCameraFoldStrategy(angle);
if (isInCameraFoldStrategy_) {
HandleSensorChange(FoldStatus::FOLDED, angle, foldScreenPolicy);
SetCameraStatusChange(angle, hall);
SetCameraRotationStatusChange(angle, hall);
return;
}
SetCameraStatusChange(angle, hall);
SetCameraRotationStatusChange(angle, hall);
if (IsTentMode()) {
return TentModeHandleSensorChange(angle, hall, foldScreenPolicy);
}
@ -85,10 +87,10 @@ void SingleDisplaySensorPocketFoldStateManager::HandleHallChange(float angle, in
SetCameraFoldStrategy(angle);
if (isInCameraFoldStrategy_) {
HandleSensorChange(FoldStatus::FOLDED, angle, foldScreenPolicy);
SetCameraStatusChange(angle, hall);
SetCameraRotationStatusChange(angle, hall);
return;
}
SetCameraStatusChange(angle, hall);
SetCameraRotationStatusChange(angle, hall);
if (IsTentMode()) {
return TentModeHandleSensorChange(angle, hall, foldScreenPolicy);
}
@ -108,66 +110,70 @@ void SingleDisplaySensorPocketFoldStateManager::UpdateSwitchScreenBoundaryForLar
void SingleDisplaySensorPocketFoldStateManager::SetCameraFoldStrategy(float angle)
{
FoldStatus currentState = GetCurrentState();
int32_t cameraStatus = ScreenSessionManager::GetInstance().GetCameraStatus();
int32_t cameraPosition = ScreenSessionManager::GetInstance().GetCameraPosition();
if (angle >= CAMERA_MAX_VAL) {
if (isInCameraFoldStrategy_ != false) {
isInCameraFoldStrategy_ = false;
TLOGI(WmsLogTag::DMS, "Disable CameraFoldStrategy.");
TLOGI(WmsLogTag::DMS, "Disable CameraFoldStrategy, angle: %{public}f, currentFoldState: %{public}d, "
"cameraStatus: %{public}d, cameraPosition: %{public}d. ",
angle, currentState, cameraStatus, cameraPosition);
}
return;
}
if (applicationStateObserver_ == nullptr) {
return;
}
if (applicationStateObserver_->GetForegroundApp().empty()) {
return;
}
if (applicationStateObserver_->GetForegroundApp().find(CAMERA_NAME) != std::string::npos &&
currentState == FoldStatus::FOLDED) {
if ((cameraStatus == CAMERA_STATUS_UNAVAILABLE) && (cameraPosition == CAMERA_POSITION_FRONT) &&
(currentState == FoldStatus::FOLDED)) {
if (isInCameraFoldStrategy_ != true) {
isInCameraFoldStrategy_ = true;
TLOGI(WmsLogTag::DMS, "Enable CameraFoldStrategy.");
TLOGI(WmsLogTag::DMS, "Enable CameraFoldStrategy, angle: %{public}f, currentFoldState: %{public}d, "
"cameraStatus: %{public}d, cameraPosition: %{public}d. ",
angle, currentState, cameraStatus, cameraPosition);
}
}
}
void SingleDisplaySensorPocketFoldStateManager::SetCameraStatusChange(float angle, int hall)
void SingleDisplaySensorPocketFoldStateManager::SetCameraRotationStatusChange(float angle, int hall)
{
FoldStatus currentState = GetCurrentState();
int32_t cameraStatus = ScreenSessionManager::GetInstance().GetCameraStatus();
int32_t cameraPosition = ScreenSessionManager::GetInstance().GetCameraPosition();
if (hall == HALL_FOLDED_THRESHOLD) {
if (isCameraStatus_) {
if (isCameraRotationStrategy_) {
TLOGI(WmsLogTag::DMS, "hall is %{public}d, exit cemera status", hall);
ScreenRotationProperty::HandleHoverStatusEventInput(DeviceHoverStatus::CAMERA_STATUS_CANCEL);
isCameraStatus_ = false;
isCameraRotationStrategy_ = false;
}
return;
}
if ((std::isless(angle, HOVER_STATUS_EXIT_MIN_THRESHOLD)) ||
(std::isgreater(angle, HOVER_STATUS_EXIT_MAX_THRESHOLD))) {
if (isCameraStatus_) {
if (isCameraRotationStrategy_) {
TLOGI(WmsLogTag::DMS, "angle is:%{public}f, exit camera status", angle);
ScreenRotationProperty::HandleHoverStatusEventInput(DeviceHoverStatus::CAMERA_STATUS_CANCEL);
isCameraStatus_ = false;
isCameraRotationStrategy_ = false;
}
return;
}
if (applicationStateObserver_ == nullptr) {
return;
}
if ((angle > ANGLE_MIN_VAL) && (angle < CAMERA_MAX_VAL) &&
(applicationStateObserver_->GetForegroundApp().find(CAMERA_NAME) != std::string::npos)) {
if (!isCameraStatus_) {
TLOGI(WmsLogTag::DMS, "angle is:%{public}f and is camera app, into camera status", angle);
if ((angle > ANGLE_MIN_VAL) && (cameraStatus == CAMERA_STATUS_UNAVAILABLE) &&
(cameraPosition == CAMERA_POSITION_FRONT) && (currentState == FoldStatus::FOLDED)) {
if (!isCameraRotationStrategy_) {
TLOGI(WmsLogTag::DMS, "angle is:%{public}f , currentFoldState is:%{public}d, "
"cameraStatus is:%{public}d, cameraPosition is:%{public}d, enter camera rotation status.",
angle, static_cast<int32_t>(currentState), cameraStatus, cameraPosition);
ScreenRotationProperty::HandleHoverStatusEventInput(DeviceHoverStatus::CAMERA_STATUS);
isCameraStatus_ = true;
isCameraRotationStrategy_ = true;
}
} else {
if (isCameraStatus_) {
TLOGI(WmsLogTag::DMS, "angle is:%{public}f or is not camera app, exit camera status", angle);
if (isCameraRotationStrategy_) {
TLOGI(WmsLogTag::DMS, "angle is:%{public}f , currentFoldState is:%{public}d, "
"cameraStatus is:%{public}d, cameraPosition is:%{public}d, exit camera rotation status.",
angle, static_cast<int32_t>(currentState), cameraStatus, cameraPosition);
ScreenRotationProperty::HandleHoverStatusEventInput(DeviceHoverStatus::CAMERA_STATUS_CANCEL);
isCameraStatus_ = false;
isCameraRotationStrategy_ = false;
}
}
}

View File

@ -2086,6 +2086,17 @@ int32_t ScreenSessionManager::SetScreenOffDelayTime(int32_t delay)
return screenOffDelay_;
}
void ScreenSessionManager::SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition)
{
if ((cameraStatus_ == cameraStatus) && (cameraPosition_ = cameraPosition)) {
return; // no need to update
}
cameraStatus_ = cameraStatus;
cameraPosition_ = cameraPosition;
TLOGI(WmsLogTag::DMS, "SetCameraStatus, cameraStatus:%{public}d, cameraPosition:%{public}d",
cameraStatus, cameraPosition);
}
bool ScreenSessionManager::IsScreenLockSuspend(void)
{
return isScreenLockSuspend_;
@ -6424,4 +6435,14 @@ void ScreenSessionManager::OnSuperFoldStatusChange(ScreenId screenId, SuperFoldS
}
clientProxy_->OnSuperFoldStatusChanged(screenId, superFoldStatus);
}
int32_t ScreenSessionManager::GetCameraStatus()
{
return cameraStatus_;
}
int32_t ScreenSessionManager::GetCameraPosition()
{
return cameraPosition_;
}
} // namespace OHOS::Rosen

View File

@ -2758,6 +2758,37 @@ int32_t ScreenSessionManagerProxy::SetScreenOffDelayTime(int32_t delay)
return reply.ReadInt32();
}
void ScreenSessionManagerProxy::SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition)
{
sptr<IRemoteObject> remote = Remote();
if (remote == nullptr) {
WLOGFE("SetCameraStatus: remote is null");
return;
}
MessageOption option(MessageOption::TF_SYNC);
MessageParcel reply;
MessageParcel data;
if (!data.WriteInterfaceToken(GetDescriptor())) {
WLOGFE("WriteInterfaceToken failed");
return;
}
if (!data.WriteInt32(cameraStatus)) {
WLOGFE("Write cameraStatus failed");
return;
}
if (!data.WriteInt32(cameraPosition)) {
WLOGFE("Write cameraPosition failed");
return;
}
if (remote->SendRequest(static_cast<uint32_t>(DisplayManagerMessage::TRANS_ID_SET_CAMERA_STATUS),
data, reply, option) != ERR_NONE) {
WLOGFE("SendRequest failed");
return;
}
}
DMError ScreenSessionManagerProxy::GetAvailableArea(DisplayId displayId, DMRect& area)
{
sptr<IRemoteObject> remote = Remote();

View File

@ -67,6 +67,7 @@ public:
void OnUpdateFoldDisplayMode(FoldDisplayMode displayMode) override;
void UpdateAvailableArea(ScreenId screenId, DMRect area);
int32_t SetScreenOffDelayTime(int32_t delay);
void SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition);
void NotifyFoldToExpandCompletion(bool foldToExpand);
FoldStatus GetFoldStatus();
std::shared_ptr<Media::PixelMap> GetScreenSnapshot(ScreenId screenId, float scaleX, float scaleY);

View File

@ -415,6 +415,15 @@ int32_t ScreenSessionManagerClient::SetScreenOffDelayTime(int32_t delay)
return screenSessionManager_->SetScreenOffDelayTime(delay);
}
void ScreenSessionManagerClient::SetCameraStatus(int32_t cameraStatus, int32_t cameraPosition)
{
if (!screenSessionManager_) {
WLOGFE("screenSessionManager_ is null");
return;
}
return screenSessionManager_->SetCameraStatus(cameraStatus, cameraPosition);
}
void ScreenSessionManagerClient::NotifyFoldToExpandCompletion(bool foldToExpand)
{
if (!screenSessionManager_) {