add target

Signed-off-by: libuyan <libuyan1@huawei.com>
This commit is contained in:
libuyan 2024-04-25 21:49:01 +08:00
parent 3d0549a62f
commit 2bd1d7ceae
11 changed files with 17 additions and 224 deletions

View File

@ -14,8 +14,6 @@
import("//build/ohos.gni")
import("//build/ohos/ace/ace.gni")
import("../../../../../../arkcompiler/ets_frontend/es2panda/es2abc_config.gni")
import(
"../../../../../../foundation/ability/ability_runtime/ability_runtime.gni")
import("../../../../../../foundation/arkui/ace_engine/ace_config.gni")
import("../../../filemanagement_aafwk.gni")
@ -64,7 +62,6 @@ ohos_shared_library("picker") {
sources = [
"native_module_ohos_picker.cpp",
"src/modal_ui_callback.cpp",
"src/napi_error.cpp",
"src/picker_n_exporter.cpp",
"src/picker_napi_utils.cpp",
]

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Copyright (C) 2024 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

View File

@ -1,38 +0,0 @@
/*
* Copyright (C) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef INTERFACES_KITS_JS_PICKER_INCLUDE_NAPI_ERROR_H
#define INTERFACES_KITS_JS_PICKER_INCLUDE_NAPI_ERROR_H
#include <string>
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "picker_napi_utils.h"
namespace OHOS {
namespace Picker {
#define EXPORT __attribute__ ((visibility ("default")))
struct NapiError {
int32_t error = 0;
std::string apiName;
void SetApiName(const std::string &Name);
void HandleError(napi_env env, napi_value &errorObj);
EXPORT static void ThrowError(napi_env env, int32_t err, const std::string &errMsg = "");
EXPORT static void ThrowError(napi_env env, int32_t err, const char *func, int32_t line,
const std::string &errMsg = "");
};
} // namespace Picker
} // namespace OHOS
#endif // INTERFACES_KITS_JS_PICKER_INCLUDE_NAPI_ERROR_H

View File

@ -1,83 +0,0 @@
/*
* Copyright (C) 2024 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef OHOS_PICKER_CLIENT_ERRNO_H
#define OHOS_PICKER_CLIENT_ERRNO_H
#include <errno.h>
#include <unordered_map>
namespace OHOS {
namespace Picker {
constexpr int32_t FILEIO_MODULE_CODE = 139;
constexpr int32_t UFM_MODULE_CODE = 140;
constexpr int32_t UFM_SYSCAP_BASE = 202;
constexpr int32_t OHOS_PERMISSION_DENIED_CODE = 201;
constexpr int32_t OHOS_INVALID_PARAM_CODE = 401;
#define MODULE_OFFSET 100000
#define MODULE_CODE(code) (((code) * MODULE_OFFSET))
#define UFM_JS_ERR(moduleCode, errCode) ((MODULE_CODE(moduleCode)) + (errCode))
//JS_INNER_FAIL JS_ERR_PARAMETER_INVALID
// file io common error code
constexpr int32_t JS_ERR_NO_SUCH_FILE = UFM_JS_ERR(FILEIO_MODULE_CODE, 2); // no such file
constexpr int32_t JS_ERR_NO_MEM = UFM_JS_ERR(FILEIO_MODULE_CODE, 11); // cannot allocate memory
constexpr int32_t JS_ERR_PERMISSION_DENIED = UFM_JS_ERR(FILEIO_MODULE_CODE, 12); // permission deny
constexpr int32_t JS_ERR_FILE_EXIST = UFM_JS_ERR(FILEIO_MODULE_CODE, 15); // file has exist
constexpr int32_t JS_ERR_PARAMETER_INVALID = UFM_JS_ERR(FILEIO_MODULE_CODE, 20); // input parameter invalid
// userfileMananger error code
constexpr int32_t JS_E_DISPLAYNAME = UFM_JS_ERR(UFM_MODULE_CODE, 1);
constexpr int32_t JS_E_URI = UFM_JS_ERR(UFM_MODULE_CODE, 2);
constexpr int32_t JS_E_FILE_EXTENSION = UFM_JS_ERR(UFM_MODULE_CODE, 3);
constexpr int32_t JS_E_TRASHED = UFM_JS_ERR(UFM_MODULE_CODE, 4);
constexpr int32_t JS_E_OPEN_MODE = UFM_JS_ERR(UFM_MODULE_CODE, 5);
constexpr int32_t JS_E_NOT_ALBUM = UFM_JS_ERR(UFM_MODULE_CODE, 6);
constexpr int32_t JS_E_ROOT_DIR = UFM_JS_ERR(UFM_MODULE_CODE, 7);
constexpr int32_t JS_E_MOVE_DENIED = UFM_JS_ERR(UFM_MODULE_CODE, 8);
constexpr int32_t JS_E_RENAME_DENIED = UFM_JS_ERR(UFM_MODULE_CODE, 9);
constexpr int32_t JS_E_RELATIVEPATH = UFM_JS_ERR(UFM_MODULE_CODE, 10);
constexpr int32_t JS_INNER_FAIL = UFM_JS_ERR(UFM_MODULE_CODE, 11);
// file type is not allow in the directory
constexpr int32_t JS_E_FILE_TYPE = UFM_JS_ERR(UFM_MODULE_CODE, 12);
constexpr int32_t JS_E_NO_MEMORY = UFM_JS_ERR(UFM_MODULE_CODE, 13); // no memory left
constexpr int32_t JS_E_FILE_KEY = UFM_JS_ERR(UFM_MODULE_CODE, 14); // wrong member name
constexpr int32_t JS_E_INPUT = UFM_JS_ERR(UFM_MODULE_CODE, 15);
// media change request error
constexpr int32_t JS_E_OPERATION_NOT_SUPPORT = UFM_JS_ERR(UFM_MODULE_CODE, 16);
constexpr int32_t JS_E_NAMETOOLONG = UFM_JS_ERR(UFM_SYSCAP_BASE, 36);
const std::unordered_map<int, std::string> jsErrMap = {
{ JS_ERR_PERMISSION_DENIED, "without permission" },
{ JS_INNER_FAIL, "modal picker inner fail" },
{ JS_ERR_PARAMETER_INVALID, "invalid parameter" },
{ JS_E_DISPLAYNAME, "display name invalid" },
{ JS_ERR_NO_SUCH_FILE, "no such file" },
{ JS_ERR_FILE_EXIST, "file has existed" },
{ JS_E_FILE_TYPE, "file type is not allow in the directory" },
{ JS_E_FILE_KEY, "member not exist" },
{ JS_ERR_NO_MEM, "cannot allocate memory" },
{ JS_E_NAMETOOLONG, "file name is too long" },
{ OHOS_PERMISSION_DENIED_CODE, "Permission denied" },
{ OHOS_INVALID_PARAM_CODE, "invalid parameter" },
};
} // namespace Picker
} // namespace OHOS
#endif // OHOS_PICKER_CLIENT_ERRNO_H

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2024 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
@ -22,10 +22,8 @@
#include "data_ability_predicates.h"
#include "filemgmt_libn.h"
#include "picker_napi_utils.h"
#include "napi_error.h"
#include "napi_base_context.h"
#include "napi_common_want.h"
#include "picker_client_errno.h"
namespace OHOS {
@ -45,7 +43,7 @@ struct PickerCallBack {
string uri;
};
struct PickerAsyncContext : public NapiError {
struct PickerAsyncContext {
napi_async_work work;
napi_deferred deferred;
napi_ref callbackRef;

View File

@ -21,7 +21,6 @@
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "hilog_wrapper.h"
#include "picker_client_errno.h"
namespace OHOS {
namespace Picker {
@ -65,7 +64,6 @@ struct NapiClassInfo {
/* Util class used by napi asynchronous methods for making call to js callback function */
class PickerNapiUtils {
public:
static void HandleError(napi_env env, int error, napi_value &errorObj, const std::string &Name);
static void CreateNapiErrorObject(napi_env env, napi_value &errorObj, const int32_t errCode,
const std::string errMsg);
static void InvokeJSAsyncMethod(napi_env env, napi_deferred deferred, napi_ref callbackRef, napi_async_work work,

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Copyright (C) 2023-2024 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

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Huawei Device Co., Ltd.
* Copyright (C) 2024 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

View File

@ -1,62 +0,0 @@
/*
* Copyright (C) 2021-2022 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "napi_error.h"
using namespace std;
namespace OHOS {
namespace Picker {
void NapiError::SetApiName(const std::string &Name)
{
apiName = Name;
}
void NapiError::HandleError(napi_env env, napi_value &errorObj)
{
PickerNapiUtils::HandleError(env, error, errorObj, apiName);
}
void NapiError::ThrowError(napi_env env, int32_t err, const std::string &errMsg)
{
string message = errMsg;
if (message.empty()) {
message = "operation not support";
if (jsErrMap.count(err) > 0) {
message = jsErrMap.at(err);
}
}
HILOG_ERROR("ThrowError errCode:%{public}d errMsg:%{public}s", err, message.c_str());
NAPI_CALL_RETURN_VOID(env, napi_throw_error(env, to_string(err).c_str(), message.c_str()));
}
void NapiError::ThrowError(napi_env env, int32_t err, const char *funcName, int32_t line, const std::string &errMsg)
{
string message = errMsg;
if (message.empty()) {
message = "operation not support";
if (jsErrMap.count(err) > 0) {
message = jsErrMap.at(err);
}
}
HILOG_ERROR("{%{public}s:%d} ThrowError errCode:%{public}d errMsg:%{public}s", funcName, line,
err, message.c_str());
NAPI_CALL_RETURN_VOID(env, napi_throw_error(env, to_string(err).c_str(), message.c_str()));
}
} // namespace Picker
} // namespace OHOS

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Huawei Device Co., Ltd.
* Copyright (c) 2024 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
@ -153,13 +153,14 @@ static napi_value StartPickerExtension(napi_env env, napi_callback_info info,
.onRelease = std::bind(&ModalUICallback::OnRelease, callback, std::placeholders::_1),
.onResult = std::bind(&ModalUICallback::OnResultForModal, callback, std::placeholders::_1,
std::placeholders::_2),
.onReceive = std::bind(&ModalUICallback::OnReceive, callback, std::placeholders::_1),
.onReceive = std::bind(&ModalUICallback::OnReceive, callback, std::placeholders::_1),
.onError = std::bind(&ModalUICallback::OnError, callback, std::placeholders::_1, std::placeholders::_2,
std::placeholders::_3),
.onDestroy = std::bind(&ModalUICallback::OnDestroy, callback),
};
Ace::ModalUIExtensionConfig config;
HILOG_INFO("modal picker: will CreateModalUIExtension by extType: %{public}s, pickerType: %{public}s", targetType.c_str(), pickerType.c_str());
HILOG_INFO("modal picker: will CreateModalUIExtension by extType: %{public}s, pickerType: %{public}s",
targetType.c_str(), pickerType.c_str());
int sessionId = uiContent->CreateModalUIExtension(request, extensionCallback, config);
if (sessionId == 0) {
HILOG_ERROR("modal picker: create modalUIExtension failed");
@ -178,17 +179,18 @@ static napi_status AsyncContextSetStaticObjectInfo(napi_env env, napi_callback_i
HILOG_INFO("modal picker: AsyncContextSetStaticObjectInfo begin.");
napi_value thisVar = nullptr;
asyncContext->argc = maxArgs;
napi_status ret = napi_get_cb_info(env, info, &asyncContext->argc, &(asyncContext->argv[ARGS_ZERO]), &thisVar, nullptr);
napi_status ret = napi_get_cb_info(env, info, &asyncContext->argc, &(asyncContext->argv[ARGS_ZERO]),
&thisVar, nullptr);
if (ret != napi_ok) {
HILOG_ERROR("modal picker: Failed to get cb info");
return ret;
}
if (!((asyncContext->argc >= minArgs) && (asyncContext->argc <= maxArgs))) {
}
if (!((asyncContext->argc >= minArgs) && (asyncContext->argc <= maxArgs))) {
HILOG_ERROR("modal picker: Number of args is invalid");
return napi_invalid_arg;
}
if (minArgs > 0) {
if (asyncContext->argv[ARGS_ZERO] == nullptr) {
if (asyncContext->argv[ARGS_ZERO] == nullptr) {
HILOG_ERROR("modal picker: Argument list is empty");
return napi_invalid_arg;
}
@ -207,9 +209,9 @@ static napi_value ParseArgsStartModalPicker(napi_env env, napi_callback_info inf
HILOG_ERROR("modal picker: AsyncContextSetStaticObjectInfo faild");
}
napi_value ret = StartPickerExtension(env, info, context);
if ((ret) == nullptr) {
if (ret == nullptr) {
return nullptr;
}
}
napi_value result = nullptr;
napi_get_boolean(env, true, &result);
return result;

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2022 Huawei Device Co., Ltd.
* Copyright (C) 2024 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
@ -42,24 +42,6 @@ void PickerNapiUtils::CreateNapiErrorObject(napi_env env, napi_value &errorObj,
}
}
void PickerNapiUtils::HandleError(napi_env env, int error, napi_value &errorObj, const string &Name)
{
if (error == ERR_DEFAULT) {
return;
}
string errMsg = "System inner fail";
int originalError = error;
if (jsErrMap.count(error) > 0) {
errMsg = jsErrMap.at(error);
} else {
error = JS_INNER_FAIL;
}
CreateNapiErrorObject(env, errorObj, error, errMsg);
errMsg = Name + " " + errMsg;
HILOG_ERROR("Error: %{public}s, js errcode:%{public}d ", errMsg.c_str(), originalError);
}
void PickerNapiUtils::InvokeJSAsyncMethod(napi_env env, napi_deferred deferred, napi_ref callbackRef,
napi_async_work work, const JSAsyncContextOutput &asyncContext)
{
@ -92,7 +74,6 @@ napi_value PickerNapiUtils::NapiCreateAsyncWork(napi_env env, unique_ptr<AsyncCo
napi_value resource = nullptr;
napi_create_promise(env, &(asyncContext->deferred), &(result));
napi_create_string_utf8(env, resourceName.c_str(), NAPI_AUTO_LENGTH, &(resource));
asyncContext->SetApiName(resourceName.c_str());
NAPI_CALL(env, napi_create_async_work(env, nullptr, resource, execute, complete,
static_cast<void *>(asyncContext.get()), &asyncContext->work));
NAPI_CALL(env, napi_queue_async_work(env, asyncContext->work));