diff --git a/interfaces/innerkits/dm/dm_common.h b/interfaces/innerkits/dm/dm_common.h index 212334dc..cb9dce04 100644 --- a/interfaces/innerkits/dm/dm_common.h +++ b/interfaces/innerkits/dm/dm_common.h @@ -70,7 +70,7 @@ enum class DMError : int32_t { DM_ERROR_WRITE_DATA_FAILED = 170, DM_ERROR_RENDER_SERVICE_FAILED = 180, DM_ERROR_UNREGISTER_AGENT_FAILED = 190, - DM_ERROR_UNKNOWN, + DM_ERROR_UNKNOWN = -1, }; using DisplayStateCallback = std::function; diff --git a/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts b/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts index 1d892d8f..301ac4c4 100644 --- a/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts +++ b/interfaces/kits/napi/screen_runtime/api/@ohos.screen.d.ts @@ -27,11 +27,6 @@ declare namespace screen { * @since 9 */ function getAllScreens(callback: AsyncCallback>): void; - - /** - * get all screen - * @since 9 - */ function getAllScreens(): Promise>; /** @@ -52,24 +47,14 @@ declare namespace screen { * make screens as expand-screen * @since 9 */ - function makeExpand(options:Array, callback: AsyncCallback): void; - - /** - * make screens as expand-screen - * @since 9 - */ + function makeExpand(options:Array, callback: AsyncCallback): void; function makeExpand(options:Array): Promise; /** * make screens as mirror-screen * @since 9 */ - function makeMirror(mainScreen:number, mirrorScreen:Array, callback: AsyncCallback): void; - - /** - * make screens as mirror-screen - * @since 9 - */ + function makeMirror(mainScreen:number, mirrorScreen:Array, callback: AsyncCallback): void; function makeMirror(mainScreen:number, mirrorScreen:Array): Promise; /** @@ -129,27 +114,17 @@ declare namespace screen { * set the orientation of the screen * @since 9 */ - setOrientation(orientation: Orientation, callback: AsyncCallback): void; - - /** - * set the orientation of the screen - * @since 9 - */ - setOrientation(orientation: Orientation): Promise; + setOrientation(orientation: Orientation, callback: AsyncCallback): void; + setOrientation(orientation: Orientation): Promise; /** * active the mode */ - setScreenActiveMode(modeIndex: number, callback: AsyncCallback): void; + setScreenActiveMode(modeIndex: number, callback: AsyncCallback): void; + setScreenActiveMode(modeIndex: number): Promise; - /** - * active the mode - */ - setScreenActiveMode(modeIndex: number): Promise; - - setDensityDpi(densityDpi: number, callback: AsyncCallback): void; - - setDensityDpi(densityDpi: number): Promise; + setDensityDpi(densityDpi: number, callback: AsyncCallback): void; + setDensityDpi(densityDpi: number): Promise; } /** diff --git a/interfaces/kits/napi/screen_runtime/napi/js_screen.cpp b/interfaces/kits/napi/screen_runtime/napi/js_screen.cpp index a294eca1..75515ed2 100644 --- a/interfaces/kits/napi/screen_runtime/napi/js_screen.cpp +++ b/interfaces/kits/napi/screen_runtime/napi/js_screen.cpp @@ -70,10 +70,10 @@ NativeValue* JsScreen::SetOrientation(NativeEngine* engine, NativeCallbackInfo* NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsScreen::OnSetOrientation is called"); + WLOGFI("OnSetOrientation is called"); bool paramValidFlag = true; Orientation orientation = Orientation::UNSPECIFIED; - if (info.argc != ARGC_ONE) { + if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) { WLOGFE("OnSetOrientation Params not match, info argc: %{public}zu", info.argc); paramValidFlag = false; } else { @@ -86,7 +86,7 @@ NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (!paramValidFlag) { - WLOGE("JsScreen::OnSetOrientation paramValidFlag error"); + WLOGE("OnSetOrientation paramValidFlag error"); task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_INVALID_PARAM), "JsScreen::OnSetOrientation failed.")); return; @@ -100,11 +100,12 @@ NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo bool res = screen_->SetOrientation(orientation); if (res) { - task.Resolve(engine, CreateJsValue(engine, true)); - WLOGFI("JsScreen::OnSetOrientation success"); + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("OnSetOrientation success"); } else { - task.Resolve(engine, CreateJsError(engine, false, "JsScreen::OnSetOrientation failed.")); - WLOGFE("JsScreen::OnSetOrientation failed"); + task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_UNKNOWN), + "JsScreen::OnSetOrientation failed.")); + WLOGFE("OnSetOrientation failed"); } }; NativeValue* lastParam = nullptr; @@ -120,17 +121,17 @@ NativeValue* JsScreen::OnSetOrientation(NativeEngine& engine, NativeCallbackInfo NativeValue* JsScreen::SetScreenActiveMode(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsScreen::SetScreenActiveMode is called"); + WLOGFI("SetScreenActiveMode is called"); JsScreen* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetScreenActiveMode(*engine, *info) : nullptr; } NativeValue* JsScreen::OnSetScreenActiveMode(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsScreen::OnSetScreenActiveMode is called"); + WLOGFI("OnSetScreenActiveMode is called"); bool paramValidFlag = true; uint32_t modeId = 0; - if (info.argc != ARGC_ONE) { + if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) { WLOGFE("OnSetScreenActiveMode Params not match %{public}zu", info.argc); paramValidFlag = false; } else { @@ -143,18 +144,19 @@ NativeValue* JsScreen::OnSetScreenActiveMode(NativeEngine& engine, NativeCallbac AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (!paramValidFlag) { - WLOGFE("JsScreen::OnSetScreenActiveMode paramValidFlag error"); + WLOGFE("OnSetScreenActiveMode paramValidFlag error"); task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_INVALID_PARAM), "JsScreen::OnSetScreenActiveMode failed.")); return; } bool res = screen_->SetScreenActiveMode(modeId); if (res) { - task.Resolve(engine, CreateJsValue(engine, true)); - WLOGFI("JsScreen::OnSetScreenActiveMode success"); + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("OnSetScreenActiveMode success"); } else { - task.Reject(engine, CreateJsError(engine, false, "JsScreen::OnSetScreenActiveMode failed.")); - WLOGFE("JsScreen::OnSetScreenActiveMode failed"); + task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_UNKNOWN), + "JsScreen::OnSetScreenActiveMode failed.")); + WLOGFE("OnSetScreenActiveMode failed"); } }; NativeValue* lastParam = nullptr; @@ -169,17 +171,17 @@ NativeValue* JsScreen::OnSetScreenActiveMode(NativeEngine& engine, NativeCallbac NativeValue* JsScreen::SetDensityDpi(NativeEngine* engine, NativeCallbackInfo* info) { - WLOGFI("JsScreen::SetDensityDpi is called"); + WLOGFI("SetDensityDpi is called"); JsScreen* me = CheckParamsAndGetThis(engine, info); return (me != nullptr) ? me->OnSetDensityDpi(*engine, *info) : nullptr; } NativeValue* JsScreen::OnSetDensityDpi(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsScreen::OnSetDensityDpi is called"); + WLOGFI("OnSetDensityDpi is called"); bool paramValidFlag = true; uint32_t densityDpi = 0; - if (info.argc != ARGC_ONE) { + if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) { WLOGFE("OnSetDensityDpi Params not match %{public}zu", info.argc); paramValidFlag = false; } else { @@ -192,18 +194,19 @@ NativeValue* JsScreen::OnSetDensityDpi(NativeEngine& engine, NativeCallbackInfo& AsyncTask::CompleteCallback complete = [=](NativeEngine& engine, AsyncTask& task, int32_t status) { if (!paramValidFlag) { - WLOGFE("JsScreen::OnSetDensityDpi paramValidFlag error"); + WLOGFE("OnSetDensityDpi paramValidFlag error"); task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_INVALID_PARAM), "JsScreen::OnSetDensityDpi failed.")); return; } bool res = screen_->SetDensityDpi(densityDpi); if (res) { - task.Resolve(engine, CreateJsValue(engine, true)); - WLOGFI("JsScreen::OnSetDensityDpi success"); + task.Resolve(engine, engine.CreateUndefined()); + WLOGFI("OnSetDensityDpi success"); } else { - task.Reject(engine, CreateJsError(engine, false, "JsScreen::OnSetDensityDpi failed.")); - WLOGFE("JsScreen::OnSetDensityDpi failed"); + task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_UNKNOWN), + "JsScreen::OnSetDensityDpi failed.")); + WLOGFE("OnSetDensityDpi failed"); } }; NativeValue* lastParam = nullptr; diff --git a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp index f93064a3..d179664b 100644 --- a/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp +++ b/interfaces/kits/napi/screen_runtime/napi/js_screen_manager.cpp @@ -86,7 +86,7 @@ std::mutex mtx_; NativeValue* OnGetAllScreens(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsScreenManager::OnGetAllScreens is called"); + WLOGFI("OnGetAllScreens is called"); AsyncTask::CompleteCallback complete = [this](NativeEngine& engine, AsyncTask& task, int32_t status) { std::vector> screens = SingletonContainer::Get().GetAllScreens(); @@ -271,8 +271,8 @@ NativeValue* OnUnregisterScreenManagerCallback(NativeEngine& engine, NativeCallb NativeValue* OnMakeMirror(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsScreenManager::OnMakeMirror is called"); - if (info.argc != ARGC_TWO) { + WLOGFI("OnMakeMirror is called"); + if (info.argc != ARGC_TWO && info.argc != ARGC_THREE) { WLOGFE("Params not match"); return engine.CreateUndefined(); } @@ -304,11 +304,11 @@ NativeValue* OnMakeMirror(NativeEngine& engine, NativeCallbackInfo& info) ScreenId id = SingletonContainer::Get().MakeMirror(mainScreenId, screenIds); if (id != SCREEN_ID_INVALID) { task.Resolve(engine, CreateJsValue(engine, static_cast(id))); - WLOGFI("JsScreenManager::MakeMirror success"); + WLOGFI("MakeMirror success"); } else { task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_NULLPTR), "JsScreenManager::OnMakeMirror failed.")); - WLOGFE("JsScreenManager::MakeMirror failed"); + WLOGFE("MakeMirror failed"); } }; NativeValue* lastParam = nullptr; @@ -323,8 +323,8 @@ NativeValue* OnMakeMirror(NativeEngine& engine, NativeCallbackInfo& info) NativeValue* OnMakeExpand(NativeEngine& engine, NativeCallbackInfo& info) { - WLOGFI("JsScreenManager::OnMakeExpand is called"); - if (info.argc != ARGC_ONE) { + WLOGFI("OnMakeExpand is called"); + if (info.argc != ARGC_ONE && info.argc != ARGC_TWO) { WLOGFE("Params not match"); return engine.CreateUndefined(); } @@ -352,11 +352,11 @@ NativeValue* OnMakeExpand(NativeEngine& engine, NativeCallbackInfo& info) ScreenId id = SingletonContainer::Get().MakeExpand(options); if (id != SCREEN_ID_INVALID) { task.Resolve(engine, CreateJsValue(engine, static_cast(id))); - WLOGFI("JsScreenManager::MakeExpand success"); + WLOGFI("MakeExpand success"); } else { task.Reject(engine, CreateJsError(engine, static_cast(DMError::DM_ERROR_NULLPTR), "JsScreenManager::OnMakeExpand failed.")); - WLOGFE("JsScreenManager::MakeExpand failed"); + WLOGFE("MakeExpand failed"); } }; NativeValue* lastParam = nullptr;