support FA by environment check

Signed-off-by: chyyy0213 <chenhaiying3@huawei.com>
Change-Id: I11b30f3b6efbf1297cd4256298edb0ca7f20c661
Signed-off-by: chyyy0213 <chenhaiying3@huawei.com>
This commit is contained in:
chyyy0213
2022-05-05 10:24:01 +08:00
parent f428851edd
commit 04af8a38bc
3 changed files with 31 additions and 20 deletions
@@ -88,8 +88,14 @@ NativeValue* JsWindowManager::SetWindowLayoutMode(NativeEngine* engine, NativeCa
return (me != nullptr) ? me->OnSetWindowLayoutMode(*engine, *info) : nullptr;
}
static void GetNativeContext(NativeValue* nativeContext, void*& contextPtr, WMError& errCode)
static void GetNativeContext(NativeEngine& engine, NativeValue* nativeContext, void*& contextPtr, WMError& errCode)
{
AppExecFwk::Ability* ability = nullptr;
bool isOldApi = GetAPI7Ability(engine, ability);
WLOGFI("[NAPI]FA mode:%{public}u", isOldApi);
if (isOldApi) {
return;
}
if (nativeContext != nullptr) {
auto objContext = AbilityRuntime::ConvertNativeValueTo<NativeObject>(nativeContext);
if (objContext == nullptr) {
@@ -241,7 +247,7 @@ NativeValue* JsWindowManager::OnCreateWindow(NativeEngine& engine, NativeCallbac
errCode = WMError::WM_ERROR_INVALID_PARAM;
}
void* contextPtr = nullptr;
GetNativeContext(nativeContext, contextPtr, errCode);
GetNativeContext(engine, nativeContext, contextPtr, errCode);
WLOGFI("[NAPI]Window name = %{public}s, type = %{public}u, err = %{public}d", windowName.c_str(), winType, errCode);
AsyncTask::CompleteCallback complete =
@@ -395,13 +401,14 @@ NativeValue* JsWindowManager::OnUnregisterWindowManagerCallback(NativeEngine& en
return engine.CreateUndefined();
}
static void GetTopWindowTask(void* contextPtr, bool isOldApi, NativeEngine& engine, AsyncTask& task)
static void GetTopWindowTask(void* contextPtr, NativeEngine& engine, AsyncTask& task)
{
std::string windowName;
sptr<Window> window = nullptr;
AppExecFwk::Ability* ability = nullptr;
bool isOldApi = GetAPI7Ability(engine, ability);
if (isOldApi) {
AppExecFwk::Ability* ability = nullptr;
if (!GetAPI7Ability(engine, ability) || ability->GetWindow() == nullptr) {
if (ability->GetWindow() == nullptr) {
task.Reject(engine, CreateJsError(engine,
static_cast<int32_t>(WMError::WM_ERROR_NULLPTR), "FA mode can not get ability window"));
WLOGE("[NAPI]FA mode can not get ability window");
@@ -442,32 +449,29 @@ NativeValue* JsWindowManager::OnGetTopWindow(NativeEngine& engine, NativeCallbac
NativeValue* nativeContext = nullptr;
NativeValue* nativeCallback = nullptr;
void* contextPtr = nullptr;
bool isOldApi = false;
if (info.argc > 2) { // 2: maximum params num
WLOGFE("[NAPI]Argc is invalid: %{public}zu", info.argc);
errCode = WMError::WM_ERROR_INVALID_PARAM;
} else {
if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_OBJECT) { // (context, callback?)
isOldApi = false;
nativeContext = info.argv[0];
nativeCallback = (info.argc == 1) ? nullptr :
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
} else { // (callback?)
isOldApi = true;
nativeCallback = (info.argc == 0) ? nullptr :
(info.argv[0]->TypeOf() == NATIVE_FUNCTION ? info.argv[0] : nullptr);
}
GetNativeContext(nativeContext, contextPtr, errCode);
GetNativeContext(engine, nativeContext, contextPtr, errCode);
}
WLOGFI("[NAPI]Context %{public}p, FA mode %{public}u, err %{public}u", contextPtr, isOldApi, errCode);
WLOGFI("[NAPI]Context %{public}p, err %{public}u", contextPtr, errCode);
AsyncTask::CompleteCallback complete =
[=](NativeEngine& engine, AsyncTask& task, int32_t status) {
if (errCode != WMError::WM_OK) {
task.Reject(engine, CreateJsError(engine, static_cast<int32_t>(errCode), "Invalidate params"));
return;
}
return GetTopWindowTask(contextPtr, isOldApi, engine, task);
return GetTopWindowTask(contextPtr, engine, task);
};
NativeValue* result = nullptr;
AsyncTask::Schedule(
@@ -814,7 +814,7 @@ NativeValue* JsWindow::OnSetLayoutFullScreen(NativeEngine& engine, NativeCallbac
NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallbackInfo& info)
{
WMError errCode = WMError::WM_OK;
if (info.argc < 1 || info.argc > 2 || windowToken_ == nullptr) { // 2: maximum params num
if (info.argc > 2 || windowToken_ == nullptr) { // 2: maximum params num
WLOGFE("[NAPI]Window is nullptr or argc is invalid: %{public}zu", info.argc);
errCode = WMError::WM_ERROR_INVALID_PARAM;
}
@@ -842,9 +842,12 @@ NativeValue* JsWindow::OnSetSystemBarEnable(NativeEngine& engine, NativeCallback
WLOGFI("[NAPI]Window [%{public}u, %{public}s] set system bar enable end, ret = %{public}d",
windowToken_->GetWindowId(), windowToken_->GetWindowName().c_str(), ret);
};
NativeValue* lastParam = (info.argc <= 1) ? nullptr :
(info.argv[1]->TypeOf() == NATIVE_FUNCTION ? info.argv[1] : nullptr);
NativeValue* lastParam = nullptr;
if (info.argc > 0 && info.argv[0]->TypeOf() == NATIVE_FUNCTION) {
lastParam = info.argv[0];
} else if (info.argc > 1 && info.argv[1]->TypeOf() == NATIVE_FUNCTION) {
lastParam = info.argv[1];
}
NativeValue* result = nullptr;
AsyncTask::Schedule(
engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
@@ -275,12 +275,16 @@ NativeValue* CreateJsSystemBarRegionTintArrayObject(NativeEngine& engine, const
bool GetSystemBarStatus(std::map<WindowType, SystemBarProperty>& systemBarProperties,
NativeEngine& engine, NativeCallbackInfo& info, sptr<Window>& window)
{
NativeArray* nativeArray = ConvertNativeValueTo<NativeArray>(info.argv[0]);
if (nativeArray == nullptr) {
WLOGFE("[NAPI]Failed to convert parameter to SystemBarArray");
return false;
NativeArray* nativeArray = nullptr;
uint32_t size = 0;
if (info.argc > 0 && info.argv[0]->TypeOf() != NATIVE_FUNCTION) {
nativeArray = ConvertNativeValueTo<NativeArray>(info.argv[0]);
if (nativeArray == nullptr) {
WLOGFE("[NAPI]Failed to convert parameter to SystemBarArray");
return false;
}
size = nativeArray->GetLength();
}
uint32_t size = nativeArray->GetLength();
auto statusProperty = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_STATUS_BAR);
auto navProperty = window->GetSystemBarPropertyByType(WindowType::WINDOW_TYPE_NAVIGATION_BAR);
statusProperty.enable_ = false;