fix issue

Signed-off-by: wangbing <wangbing175@huawei-partners.com>
This commit is contained in:
wangbing
2025-06-06 20:43:41 +08:00
parent ac029d135a
commit eb89048a50
21 changed files with 49 additions and 121 deletions
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2025 Huawei Device Co., Ltd.
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -68,11 +68,11 @@ napi_value JsKioskManager::CreateJsKioskStatus(napi_env env,
napi_value objValue = nullptr;
napi_create_object(env, &objValue);
if (objValue == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "null ObjValue");
TAG_LOGE(AAFwkTag::APPKIT, "null ObjValue");
return nullptr;
}
if (kioskStatus == nullptr) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "null kioskStatus");
TAG_LOGE(AAFwkTag::APPKIT, "null kioskStatus");
return nullptr;
}
napi_set_named_property(env, objValue, "isKioskMode",
@@ -100,8 +100,8 @@ napi_value JsKioskManager::OnUpdateKioskApplicationList(napi_env env, NapiCallba
std::vector<std::string> appList;
if (!OHOS::AppExecFwk::UnwrapArrayStringFromJS(env, info.argv[ARGC_ZERO], appList)) {
TAG_LOGE(AAFwkTag::QUICKFIX, "app list is invalid");
ThrowInvalidParamError(env, "Parameter error: app list is invalid, must be a Array<string>.");
TAG_LOGE(AAFwkTag::APPKIT, "app list is invalid");
ThrowInvalidParamError(env, "Failed to parse application list. Application list must be an Array<string>.");
return CreateJsUndefined(env);
}
NapiAsyncTask::ExecuteCallback execute = [innerErrCode, appList]() {
@@ -146,13 +146,13 @@ napi_value JsKioskManager::OnEnterKioskMode(napi_env env, NapiCallbackInfo &info
auto context = OHOS::AbilityRuntime::GetStageModeContext(env, info.argv[INDEX_ZERO]);
if (context == nullptr) {
TAG_LOGE(AAFwkTag::APPKIT, "null context");
ThrowInvalidParamError(env, "Parse param context failed, must not be nullptr.");
ThrowInvalidParamError(env, "Failed to get context. Context must not be nullptr.");
return CreateJsUndefined(env);
}
auto uiAbilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context);
if (uiAbilityContext == nullptr) {
TAG_LOGE(AAFwkTag::APPKIT, "null UIAbilityContext");
ThrowInvalidParamError(env, "Parse param context failed, must be UIAbilityContext.");
ThrowInvalidParamError(env, "Failed to get uiAbilityContext, uiAbilityContext must not be nullptr.");
return CreateJsUndefined(env);
}
auto token = uiAbilityContext->GetToken();
@@ -202,13 +202,13 @@ napi_value JsKioskManager::OnExitKioskMode(napi_env env, NapiCallbackInfo &info)
auto context = OHOS::AbilityRuntime::GetStageModeContext(env, info.argv[INDEX_ZERO]);
if (context == nullptr) {
TAG_LOGE(AAFwkTag::APPKIT, "null context");
ThrowInvalidParamError(env, "Parse param context failed, must not be nullptr.");
ThrowInvalidParamError(env, "Failed to get context. Context must not be nullptr.");
return CreateJsUndefined(env);
}
auto uiAbilityContext = AbilityRuntime::Context::ConvertTo<AbilityRuntime::AbilityContext>(context);
if (uiAbilityContext == nullptr) {
TAG_LOGE(AAFwkTag::APPKIT, "null UIAbilityContext");
ThrowInvalidParamError(env, "Parse param context failed, must be UIAbilityContext.");
ThrowInvalidParamError(env, "Failed to get uIAbilityContext. Context must be uIAbilityContext.");
return CreateJsUndefined(env);
}
auto token = uiAbilityContext->GetToken();
@@ -277,15 +277,13 @@ napi_value JsKioskManager::OnGetKioskStatus(napi_env env, NapiCallbackInfo &info
napi_value JsKioskManagerInit(napi_env env, napi_value exportObj)
{
TAG_LOGD(AAFwkTag::APPKIT, "called");
std::unique_ptr<JsKioskManager> jsKioskManager = std::make_unique<JsKioskManager>();
napi_wrap(env, exportObj, jsKioskManager.release(), JsKioskManager::Finalizer, nullptr,
nullptr);
const char *moduleName = "JsKioskManager";
BindNativeFunction(env, exportObj, "updateKioskApplicationList", moduleName,
BindNativeFunction(env, exportObj, "updateKioskAppList", moduleName,
JsKioskManager::UpdateKioskApplicationList);
BindNativeFunction(env, exportObj, "enterKioskMode", moduleName, JsKioskManager::EnterKioskMode);
BindNativeFunction(env, exportObj, "exitKioskMode", moduleName, JsKioskManager::ExitKioskMode);
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -16,35 +16,15 @@
#include "native_engine/native_engine.h"
#include "js_kiosk_manager.h"
#ifdef ENABLE_ERRCODE
/*
* The module definition.
*/
static napi_module _module = {
.nm_version = 0,
.nm_filename = "app/ability/kioskmanager_napi.so/kiosk_manager.js",
.nm_register_func = OHOS::AbilityRuntime::JsKioskManagerInit,
.nm_modname = "app.ability.kioskManager",
};
/*
* The module registration.
*/
extern "C" __attribute__((constructor)) void NAPI_application_KioskManager_AutoRegister(void)
{
napi_module_register(&_module);
}
#else
/*
* The module definition.
*/
static napi_module _module = {
.nm_version = 0,
.nm_filename = "application/kioskmanager_napi.so/kiosk_manager.js",
.nm_register_func = OHOS::AbilityRuntime::JsKioskManagerInit,
.nm_modname = "application.kioskManager",
};
/*
* The module registration.
*/
@@ -52,4 +32,3 @@ extern "C" __attribute__((constructor)) void NapiApplicationKioskManagerAutoRegi
{
napi_module_register(&_module);
}
#endif
@@ -1,4 +1,4 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Copyright (c) 2023-2025 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -847,6 +847,10 @@ enum {
*/
ERR_APP_NOT_IN_FOCUS = 2097354,
ERR_WRITE_KIOSK_UPDATE_APP_LIST_FAILED = 2097355,
ERR_WRITE_KIOSK_STATUS_FAILED = 2097356,
/**
* Native error(3000000) for target bundle not exist.
*/
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2025 Huawei Device Co., Ltd.
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -12,8 +12,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_ABILITY_RUNTIME_KIOSK_INFO_H
#define OHOS_ABILITY_RUNTIME_KIOSK_INFO_H
#ifndef OHOS_ABILITY_RUNTIME_KIOSK_STATUS_H
#define OHOS_ABILITY_RUNTIME_KIOSK_STATUS_H
#include <string>
@@ -37,4 +37,4 @@ struct KioskStatus : public Parcelable {
};
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_KIOSK_INFO_H
#endif // OHOS_ABILITY_RUNTIME_KIOSK_STATUS_H
+1 -1
View File
@@ -1,4 +1,4 @@
# Copyright (c) 2021-2024 Huawei Device Co., Ltd.
# Copyright (c) 2021-2025 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
@@ -1735,30 +1735,12 @@ public:
const std::string &intentName,
InsightIntentInfoForQuery &info) override;
/**
* Update the list of applications allowed in Kiosk mode.
* @param appList, the vector of bundle names for applications allowed in Kiosk mode.
* @return Returns ERR_OK on success, others on failure.
*/
int32_t UpdateKioskApplicationList(const std::vector<std::string> &appList) override;
/**
* Enter Kiosk mode
* @return Returns ERR_OK on success, others on failure.
*/
int32_t EnterKioskMode(sptr<IRemoteObject> callerToken) override;
/**
* Exit Kiosk mode
* @return Returns ERR_OK on success, others on failure.
*/
int32_t ExitKioskMode(sptr<IRemoteObject> callerToken) override;
/**
* Get current Kiosk mode information.
* @param kioskStatus, the structure to store Kiosk mode details.
* @return Returns ERR_OK on success, others on failure.
*/
int32_t GetKioskStatus(AAFwk::KioskStatus &kioskStatus) override;
private:
@@ -2075,30 +2075,12 @@ public:
const std::string &intentName,
InsightIntentInfoForQuery &info) override;
/**
* Update the list of applications allowed in kiosk mode.
* @param appList, the list of application bundle names that are allowed in kiosk mode.
* @return Returns ERR_OK on success, others on failure.
*/
int32_t UpdateKioskApplicationList(const std::vector<std::string> &appList) override;
/**
* Enter kiosk mode
* @return Returns ERR_OK on success, others on failure.
*/
int32_t EnterKioskMode(sptr<IRemoteObject> callerToken) override;
/**
* Exit kiosk mode
* @return Returns ERR_OK on success, others on failure.
*/
int32_t ExitKioskMode(sptr<IRemoteObject> callerToken) override;
/**
* Retrieve the current kiosk mode configuration and status.
* @param kioskStatus, the structure to store kiosk configuration and status information.
* @return Returns ERR_OK on success, others on failure.
*/
int32_t GetKioskStatus(AAFwk::KioskStatus &kioskStatus) override;
std::shared_ptr<AbilityInterceptorExecuter> GetAbilityInterceptorExecuter();
@@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef OHOS_KIOSK_INTERCEPTOR_INTERCEPTOR
#define OHOS_KIOSK_INTERCEPTOR_INTERCEPTOR
#ifndef OHOS_KIOSK_INTERCEPTOR_H
#define OHOS_KIOSK_INTERCEPTOR_H
#include "ability_interceptor_interface.h"
namespace OHOS {
@@ -26,4 +26,4 @@ public:
} // namespace AAFwk
} // namespace OHOS
#endif // OHOS_KIOSK_INTERCEPTOR_INTERCEPTOR
#endif // OHOS_KIOSK_INTERCEPTOR_H
+2 -2
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -44,7 +44,7 @@ private:
DISALLOW_COPY_AND_MOVE(KioskManager);
int32_t ExitKioskModeInner(const std::string &bundleName);
bool IsInKioskModeInner();
void notifyKioskModeChanged(bool isInKioskMode);
void NotifyKioskModeChanged(bool isInKioskMode);
bool IsInWhiteListInner(const std::string &bundleName);
std::function<void()> GetEnterKioskModeCallback();
std::function<void()> GetExitKioskModeCallback();
@@ -6612,7 +6612,7 @@ int32_t AbilityManagerProxy::UpdateKioskApplicationList(const std::vector<std::s
if (!data.WriteStringVector(appList)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "appList write fail");
return ERR_IPC_PROXY_WRITE_FAILED;
return ERR_WRITE_KIOSK_UPDATE_APP_LIST_FAILED;
}
auto error =
@@ -6705,7 +6705,7 @@ int32_t AbilityManagerProxy::GetKioskStatus(KioskStatus &kioskStatus)
std::unique_ptr<KioskStatus> info(reply.ReadParcelable<KioskStatus>());
if (!info) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "read KioskStatus fail");
return ERR_UNKNOWN_OBJECT;
return ERR_READ_RESULT_PARCEL_FAILED;
}
kioskStatus = *info;
return reply.ReadInt32();
@@ -4658,7 +4658,7 @@ int32_t AbilityManagerStub::UpdateKioskApplicationListInner(MessageParcel &data,
auto result = UpdateKioskApplicationList(appList);
if (!reply.WriteInt32(result)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "write result fail");
return ERR_INVALID_VALUE;
return ERR_WRITE_RESULT_CODE_FAILED;
}
return NO_ERROR;
}
@@ -4669,7 +4669,7 @@ int32_t AbilityManagerStub::EnterKioskModeInner(MessageParcel &data, MessageParc
auto result = EnterKioskMode(token);
if (!reply.WriteInt32(result)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "write result fail");
return ERR_INVALID_VALUE;
return ERR_WRITE_RESULT_CODE_FAILED;
}
return NO_ERROR;
}
@@ -4680,7 +4680,7 @@ int32_t AbilityManagerStub::ExitKioskModeInner(MessageParcel &data, MessageParce
auto result = ExitKioskMode(token);
if (!reply.WriteInt32(result)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "write result fail");
return ERR_INVALID_VALUE;
return ERR_WRITE_RESULT_CODE_FAILED;
}
return NO_ERROR;
}
@@ -4690,13 +4690,13 @@ int32_t AbilityManagerStub::GetKioskStatusInner(MessageParcel &data, MessageParc
KioskStatus kioskStatus;
int result = GetKioskStatus(kioskStatus);
if (!reply.WriteParcelable(&kioskStatus)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "write kiosk info fail");
return ERR_INVALID_VALUE;
TAG_LOGE(AAFwkTag::ABILITYMGR, "write kiosk status fail");
return ERR_WRITE_KIOSK_STATUS_FAILED;
}
if (!reply.WriteInt32(result)) {
TAG_LOGE(AAFwkTag::ABILITYMGR, "write result fail");
return ERR_INVALID_VALUE;
return ERR_WRITE_RESULT_CODE_FAILED;
}
return NO_ERROR;
}
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2024 Huawei Device Co., Ltd.
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -21,10 +21,11 @@ namespace AAFwk {
int KioskInterceptor::DoProcess(AbilityInterceptorParam param)
{
auto bundleName = param.want.GetElement().GetBundleName();
if (!KioskManager::GetInstance().IsInKioskMode()) {
auto& kioskManager = KioskManager::GetInstance();
if (!kioskManager.IsInKioskMode()) {
return ERR_OK;
}
if (!KioskManager::GetInstance().IsInWhiteList(bundleName)) {
if (!kioskManager.IsInWhiteList(bundleName)) {
return ERR_KIOSK_MODE_NOT_IN_WHITELIST;
}
return ERR_OK;
+5 -5
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -104,7 +104,7 @@ int32_t KioskManager::EnterKioskMode(sptr<IRemoteObject> callerToken)
kioskStatus_.kioskBundleName_ = bundleName;
kioskStatus_.kioskBundleUid_ = IPCSkeleton::GetCallingUid();
GetEnterKioskModeCallback()();
notifyKioskModeChanged(true);
NotifyKioskModeChanged(true);
return ERR_OK;
}
@@ -130,7 +130,7 @@ int32_t KioskManager::ExitKioskModeInner(const std::string & bundleName)
return ERR_NOT_IN_KIOSK_MODE;
}
GetExitKioskModeCallback()();
notifyKioskModeChanged(false);
NotifyKioskModeChanged(false);
kioskStatus_.Clear();
return ERR_OK;
}
@@ -164,7 +164,7 @@ bool KioskManager::IsInKioskModeInner()
return kioskStatus_.isKioskMode_;
}
void KioskManager::notifyKioskModeChanged(bool isInKioskMode)
void KioskManager::NotifyKioskModeChanged(bool isInKioskMode)
{
std::string eventData = isInKioskMode
? EventFwk::CommonEventSupport::COMMON_EVENT_KIOSK_MODE_ON
@@ -195,7 +195,7 @@ std::function<void()> KioskManager::GetEnterKioskModeCallback()
std::function<void()> KioskManager::GetExitKioskModeCallback()
{
auto exitKioskModeCallback = []() {
TAG_LOGI(AAFwkTag::ABILITYMGR, "EnterKioskMode");
TAG_LOGI(AAFwkTag::ABILITYMGR, "ExitKioskMode");
KioskManager::GetInstance().RemoveKioskInterceptor();
};
return exitKioskModeCallback;
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2022-2023 Huawei Device Co., Ltd.
* Copyright (c) 2022-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -1131,24 +1131,6 @@ HWTEST_F(AbilityManagerServiceTwelfthTest, KioskManager_ExitKioskMode_Fail_01, T
ASSERT_EQ(result, ERR_KIOSK_MODE_NOT_IN_WHITELIST);
}
/*
* Feature: KioskManager
* Function: ExitKioskMode
* SubFunction: NA
* FunctionPoints: KioskManager ExitKioskMode
*/
HWTEST_F(AbilityManagerServiceTwelfthTest, KioskManager_ExitKioskMode_Fail_02, TestSize.Level1) {
std::vector<std::string> bundleNames;
bundleNames.emplace_back("com.test.demo");
bundleNames.emplace_back("com.test.demo2");
bundleNames.emplace_back("com.test.demo3");
auto result = KioskManager::GetInstance().UpdateKioskApplicationList(bundleNames);
ASSERT_EQ(result, ERR_OK);
auto callerToken = MockToken(AbilityType::PAGE);
result = KioskManager::GetInstance().ExitKioskMode(callerToken);
ASSERT_EQ(result, ERR_NOT_IN_KIOSK_MODE);
}
/*
* Feature: KioskManager
* Function: GetKioskStatus
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 Huawei Device Co., Ltd.
* Copyright (c) 2021-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2024 Huawei Device Co., Ltd.
* Copyright (c) 2021-2025 Huawei Device Co., Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at