!2572 元能力codecheck问题修改

Merge pull request !2572 from mingxihua/master
This commit is contained in:
openharmony_ci 2022-07-30 01:30:10 +00:00 committed by Gitee
commit a1e7db04e8
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
8 changed files with 78 additions and 143 deletions

View File

@ -361,10 +361,7 @@ napi_value SetResultAsync(
napi_create_reference(env, args[argCallback], 1, &asyncCallbackInfo->cbInfo.callback);
}
NAPI_CALL(env, napi_create_async_work(
env,
nullptr,
resourceName,
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) {
HILOG_INFO("NAPI_SetResult, worker pool thread execute.");
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);
@ -537,10 +534,7 @@ napi_value TerminateAbilityAsync(
NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &asyncCallbackInfo->cbInfo.callback));
}
NAPI_CALL(env, napi_create_async_work(
env,
nullptr,
resourceName,
NAPI_CALL(env, napi_create_async_work(env, nullptr, resourceName,
[](napi_env env, void *data) {
HILOG_INFO("NAPI_TerminateAbility, worker pool thread execute.");
AsyncCallbackInfo *asyncCallbackInfo = static_cast<AsyncCallbackInfo *>(data);

View File

@ -30,37 +30,18 @@ int32_t JsAbilityLifecycleCallback::serialNumber_ = 0;
void JsAbilityLifecycleCallback::CallJsMethodInner(
const std::string &methodName, const std::shared_ptr<NativeReference> &ability)
{
for (auto &callback : callbacks_) {
if (!callback.second) {
HILOG_ERROR("Invalid jsCallback");
return;
}
auto value = callback.second->Get();
auto obj = ConvertNativeValueTo<NativeObject>(value);
if (obj == nullptr) {
HILOG_ERROR("Failed to get object");
return;
}
auto method = obj->GetProperty(methodName.data());
if (method == nullptr) {
HILOG_ERROR("Failed to get %{public}s from object", methodName.data());
return;
}
auto nativeAbilityObj = engine_->CreateNull();
if (ability != nullptr) {
nativeAbilityObj = ability->Get();
}
NativeValue *argv[] = { nativeAbilityObj };
engine_->CallFunction(value, method, argv, ArraySize(argv));
}
CallJsMethodInnerCommon(methodName, ability, nullptr, false);
}
void JsAbilityLifecycleCallback::CallWindowStageJsMethodInner(const std::string &methodName,
const std::shared_ptr<NativeReference> &ability, const std::shared_ptr<NativeReference> &windowStage)
{
CallJsMethodInnerCommon(methodName, ability, windowStage, true);
}
void JsAbilityLifecycleCallback::CallJsMethodInnerCommon(const std::string &methodName,
const std::shared_ptr<NativeReference> &ability, const std::shared_ptr<NativeReference> &windowStage,
bool isWindowStage)
{
for (auto &callback : callbacks_) {
if (!callback.second) {
@ -91,8 +72,13 @@ void JsAbilityLifecycleCallback::CallWindowStageJsMethodInner(const std::string
nativeWindowStageObj = windowStage->Get();
}
NativeValue *argv[] = { nativeAbilityObj, nativeWindowStageObj };
engine_->CallFunction(value, method, argv, ArraySize(argv));
if (!isWindowStage) {
NativeValue *argv[] = { nativeAbilityObj };
engine_->CallFunction(value, method, argv, ArraySize(argv));
} else {
NativeValue *argv[] = { nativeAbilityObj, nativeWindowStageObj };
engine_->CallFunction(value, method, argv, ArraySize(argv));
}
}
}

View File

@ -40,25 +40,8 @@ NativeValue* CreateJsHapModuleInfo(NativeEngine& engine, AppExecFwk::HapModuleIn
object->SetProperty("mainElementName", CreateJsValue(engine, hapModuleInfo.mainElementName));
object->SetProperty("hashValue", CreateJsValue(engine, hapModuleInfo.hashValue));
NativeValue *capArrayValue = engine.CreateArray(hapModuleInfo.reqCapabilities.size());
NativeArray *capArray = ConvertNativeValueTo<NativeArray>(capArrayValue);
if (capArray != nullptr) {
int index = 0;
for (auto cap : hapModuleInfo.reqCapabilities) {
capArray->SetElement(index++, CreateJsValue(engine, cap));
}
}
object->SetProperty("reqCapabilities", capArrayValue);
NativeValue *deviceArrayValue = engine.CreateArray(hapModuleInfo.deviceTypes.size());
NativeArray *deviceArray = ConvertNativeValueTo<NativeArray>(deviceArrayValue);
if (deviceArray != nullptr) {
int index = 0;
for (auto device : hapModuleInfo.deviceTypes) {
deviceArray->SetElement(index++, CreateJsValue(engine, device));
}
}
object->SetProperty("deviceTypes", deviceArrayValue);
SetProperty(engine, object, hapModuleInfo.reqCapabilities, "reqCapabilities");
SetProperty(engine, object, hapModuleInfo.deviceTypes, "deviceTypes");
NativeValue *abilityArrayValue = engine.CreateArray(hapModuleInfo.abilityInfos.size());
NativeArray *abilityArray = ConvertNativeValueTo<NativeArray>(abilityArrayValue);
@ -92,5 +75,19 @@ NativeValue* CreateJsHapModuleInfo(NativeEngine& engine, AppExecFwk::HapModuleIn
return objValue;
}
void SetProperty(NativeEngine &engine, NativeObject* &object, const std::vector<std::string> properties,
const std::string &proName)
{
NativeValue *arrayValue = engine.CreateArray(properties.size());
NativeArray *array = ConvertNativeValueTo<NativeArray>(arrayValue);
if (array != nullptr) {
int index = 0;
for (auto propertie : properties) {
array->SetElement(index++, CreateJsValue(engine, propertie));
}
}
object->SetProperty(proName.c_str(), arrayValue);
}
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -73,6 +73,7 @@ private:
sptr<IRemoteObject> GetAbilityManager();
void ResetProxy(const wptr<IRemoteObject>& remote);
bool WriteInterfaceToken(MessageParcel &data);
bool CheckSenderAndRecevier(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver);
std::recursive_mutex mutex_;
sptr<IRemoteObject> proxy_;

View File

@ -17,6 +17,7 @@
#include "ability_manager_errors.h"
#include "ability_manager_interface.h"
#include "ability_util.h"
#include "hilog_wrapper.h"
#include "if_system_ability_manager.h"
#include "iservice_registry.h"
@ -38,10 +39,7 @@ sptr<IWantSender> WantAgentClient::GetWantSender(
const WantSenderInfo &wantSenderInfo, const sptr<IRemoteObject> &callerToken)
{
auto abms = GetAbilityManager();
if (!abms) {
HILOG_ERROR("ability proxy is nullptr.");
return nullptr;
}
CHECK_POINTER_AND_RETURN(abms, nullptr);
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -79,10 +77,7 @@ sptr<IWantSender> WantAgentClient::GetWantSender(
ErrCode WantAgentClient::SendWantSender(const sptr<IWantSender> &target, const SenderInfo &senderInfo)
{
auto abms = GetAbilityManager();
if (!abms) {
HILOG_ERROR("ability proxy is nullptr.");
return ABILITY_SERVICE_NOT_CONNECTED;
}
CHECK_POINTER_AND_RETURN(abms, ABILITY_SERVICE_NOT_CONNECTED);
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -132,15 +127,9 @@ void WantAgentClient::CancelWantSender(const sptr<IWantSender> &sender)
ErrCode WantAgentClient::GetPendingWantUid(const sptr<IWantSender> &target, int32_t &uid)
{
if (target == nullptr) {
HILOG_ERROR("target is nullptr.");
return INVALID_PARAMETERS_ERR;
}
CHECK_POINTER_AND_RETURN(target, INVALID_PARAMETERS_ERR);
auto abms = GetAbilityManager();
if (!abms) {
HILOG_ERROR("ability proxy is nullptr.");
return ABILITY_SERVICE_NOT_CONNECTED;
}
CHECK_POINTER_AND_RETURN(abms, ABILITY_SERVICE_NOT_CONNECTED);
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -162,15 +151,9 @@ ErrCode WantAgentClient::GetPendingWantUid(const sptr<IWantSender> &target, int3
ErrCode WantAgentClient::GetPendingWantUserId(const sptr<IWantSender> &target, int32_t &userId)
{
if (target == nullptr) {
HILOG_ERROR("target is nullptr.");
return INVALID_PARAMETERS_ERR;
}
CHECK_POINTER_AND_RETURN(target, INVALID_PARAMETERS_ERR);
auto abms = GetAbilityManager();
if (!abms) {
HILOG_ERROR("ability proxy is nullptr.");
return ABILITY_SERVICE_NOT_CONNECTED;
}
CHECK_POINTER_AND_RETURN(abms, ABILITY_SERVICE_NOT_CONNECTED);
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -192,15 +175,9 @@ ErrCode WantAgentClient::GetPendingWantUserId(const sptr<IWantSender> &target, i
ErrCode WantAgentClient::GetPendingWantBundleName(const sptr<IWantSender> &target, std::string &bundleName)
{
if (target == nullptr) {
HILOG_ERROR("target is nullptr.");
return INVALID_PARAMETERS_ERR;
}
CHECK_POINTER_AND_RETURN(target, INVALID_PARAMETERS_ERR);
auto abms = GetAbilityManager();
if (!abms) {
HILOG_ERROR("ability proxy is nullptr.");
return ABILITY_SERVICE_NOT_CONNECTED;
}
CHECK_POINTER_AND_RETURN(abms, ABILITY_SERVICE_NOT_CONNECTED);
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -222,15 +199,9 @@ ErrCode WantAgentClient::GetPendingWantBundleName(const sptr<IWantSender> &targe
ErrCode WantAgentClient::GetPendingWantCode(const sptr<IWantSender> &target, int32_t &code)
{
if (target == nullptr) {
HILOG_ERROR("target is nullptr.");
return INVALID_PARAMETERS_ERR;
}
CHECK_POINTER_AND_RETURN(target, INVALID_PARAMETERS_ERR);
auto abms = GetAbilityManager();
if (!abms) {
HILOG_ERROR("ability proxy is nullptr.");
return ABILITY_SERVICE_NOT_CONNECTED;
}
CHECK_POINTER_AND_RETURN(abms, ABILITY_SERVICE_NOT_CONNECTED);
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -252,15 +223,9 @@ ErrCode WantAgentClient::GetPendingWantCode(const sptr<IWantSender> &target, int
ErrCode WantAgentClient::GetPendingWantType(const sptr<IWantSender> &target, int32_t &type)
{
if (target == nullptr) {
HILOG_ERROR("target is nullptr.");
return INVALID_PARAMETERS_ERR;
}
CHECK_POINTER_AND_RETURN(target, INVALID_PARAMETERS_ERR);
auto abms = GetAbilityManager();
if (!abms) {
HILOG_ERROR("ability proxy is nullptr.");
return ABILITY_SERVICE_NOT_CONNECTED;
}
CHECK_POINTER_AND_RETURN(abms, ABILITY_SERVICE_NOT_CONNECTED);
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -283,12 +248,7 @@ ErrCode WantAgentClient::GetPendingWantType(const sptr<IWantSender> &target, int
void WantAgentClient::RegisterCancelListener(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver)
{
if (sender == nullptr) {
HILOG_ERROR("sender is nullptr.");
return;
}
if (receiver == nullptr) {
HILOG_ERROR("receiver is nullptr.");
if (!CheckSenderAndRecevier(sender, receiver)) {
return;
}
auto abms = GetAbilityManager();
@ -320,12 +280,7 @@ void WantAgentClient::RegisterCancelListener(const sptr<IWantSender> &sender, co
void WantAgentClient::UnregisterCancelListener(
const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver)
{
if (sender == nullptr) {
HILOG_ERROR("sender is nullptr.");
return;
}
if (receiver == nullptr) {
HILOG_ERROR("receiver is nullptr.");
if (!CheckSenderAndRecevier(sender, receiver)) {
return;
}
auto abms = GetAbilityManager();
@ -356,19 +311,10 @@ void WantAgentClient::UnregisterCancelListener(
ErrCode WantAgentClient::GetPendingRequestWant(const sptr<IWantSender> &target, std::shared_ptr<Want> &want)
{
if (target == nullptr) {
HILOG_ERROR("target is nullptr.");
return INVALID_PARAMETERS_ERR;
}
if (want == nullptr) {
HILOG_ERROR("want is nullptr.");
return INVALID_PARAMETERS_ERR;
}
CHECK_POINTER_AND_RETURN(target, INVALID_PARAMETERS_ERR);
CHECK_POINTER_AND_RETURN(want, INVALID_PARAMETERS_ERR);
auto abms = GetAbilityManager();
if (!abms) {
HILOG_ERROR("ability proxy is nullptr.");
return ABILITY_SERVICE_NOT_CONNECTED;
}
CHECK_POINTER_AND_RETURN(abms, ABILITY_SERVICE_NOT_CONNECTED);
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -400,19 +346,10 @@ ErrCode WantAgentClient::GetPendingRequestWant(const sptr<IWantSender> &target,
ErrCode WantAgentClient::GetWantSenderInfo(const sptr<IWantSender> &target, std::shared_ptr<WantSenderInfo> &info)
{
if (target == nullptr) {
HILOG_ERROR("target is nullptr.");
return INVALID_PARAMETERS_ERR;
}
if (info == nullptr) {
HILOG_ERROR("info is nullptr.");
return INVALID_PARAMETERS_ERR;
}
CHECK_POINTER_AND_RETURN(target, INVALID_PARAMETERS_ERR);
CHECK_POINTER_AND_RETURN(info, INVALID_PARAMETERS_ERR);
auto abms = GetAbilityManager();
if (!abms) {
HILOG_ERROR("ability proxy is nullptr.");
return ABILITY_SERVICE_NOT_CONNECTED;
}
CHECK_POINTER_AND_RETURN(abms, ABILITY_SERVICE_NOT_CONNECTED);
MessageParcel data;
MessageParcel reply;
MessageOption option;
@ -497,5 +434,19 @@ bool WantAgentClient::WriteInterfaceToken(MessageParcel &data)
}
return true;
}
bool WantAgentClient::CheckSenderAndRecevier(const sptr<IWantSender> &sender, const sptr<IWantReceiver> &receiver)
{
if (sender == nullptr) {
HILOG_ERROR("sender is nullptr.");
return false;
}
if (receiver == nullptr) {
HILOG_ERROR("receiver is nullptr.");
return false;
}
return true;
}
} // namespace AAFwk
} // namespace OHOS

View File

@ -158,6 +158,9 @@ private:
const std::shared_ptr<NativeReference> &windowStage);
void CallWindowStageJsMethodInner(const std::string &methodName, const std::shared_ptr<NativeReference> &ability,
const std::shared_ptr<NativeReference> &windowStage);
void CallJsMethodInnerCommon(const std::string &methodName,
const std::shared_ptr<NativeReference> &ability, const std::shared_ptr<NativeReference> &windowStage,
bool isWindowStage);
};
} // namespace AbilityRuntime
} // namespace OHOS

View File

@ -20,12 +20,15 @@
class NativeEngine;
class NativeValue;
class NativeObject;
namespace OHOS {
namespace AbilityRuntime {
class JsRuntime;
NativeValue* CreateJsHapModuleInfo(NativeEngine& engine, AppExecFwk::HapModuleInfo& hapModuleInfo);
void SetProperty(NativeEngine &engine, NativeObject* &object, const std::vector<std::string> properties,
const std::string &proName);
} // namespace AbilityRuntime
} // namespace OHOS
#endif // OHOS_ABILITY_RUNTIME_JS_HAP_MODULE_INFO_UTILS_H

View File

@ -13,8 +13,8 @@
* limitations under the License.
*/
#ifndef RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H_
#define RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H_
#ifndef RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H
#define RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H
#include "ability_info.h"
#include "application_info.h"
#include "process_info.h"
@ -85,4 +85,4 @@ public:
};
} // namespace AppExecFwk
} // namespace OHOS
#endif // RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H_
#endif // RESOURCE_OHOS_ABILITY_RUNTIME_TEST_UTILS_H