modify codex

Signed-off-by: zhaoyuan <zhaoyuan17@huawei.com>
This commit is contained in:
zhaoyuan 2021-09-22 20:27:00 +00:00
parent c0f9f0fb38
commit af5da7507f
32 changed files with 333 additions and 97 deletions

View File

@ -330,7 +330,7 @@ public:
*/
std::shared_ptr<AbilityPostEventTimeout> CreatePostEventTimeouter(std::string taskstr);
std::vector<std::shared_ptr<DataAbilityResult>> ExecuteBatch(const std::vector<std::shared_ptr<DataAbilityOperation>> &operations);
virtual std::vector<std::shared_ptr<DataAbilityResult>> ExecuteBatch(const std::vector<std::shared_ptr<DataAbilityOperation>> &operations);
protected:
/**

View File

@ -1151,7 +1151,9 @@ std::vector<std::shared_ptr<DataAbilityResult>> AbilityThread::ExecuteBatch(
results.clear();
return results;
}
APP_LOGI("AbilityThread::ExecuteBatch before abilityImpl_->ExecuteBatch");
results = abilityImpl_->ExecuteBatch(operations);
APP_LOGI("AbilityThread::ExecuteBatch after abilityImpl_->ExecuteBatch");
APP_LOGI("AbilityThread::ExecuteBatch end");
return results;
}

View File

@ -216,17 +216,18 @@ bool ExtraParams::Marshalling(Parcel &parcel) const
{
bool ret = true;
// devType
ret = parcel.WriteStringVector(devType_);
bool ret1 = parcel.WriteStringVector(devType_);
// targetBundleName
ret &= parcel.WriteString16(Str8ToStr16(targetBundleName_));
bool ret2 = parcel.WriteString16(Str8ToStr16(targetBundleName_));
// description
ret &= parcel.WriteString16(Str8ToStr16(description_));
bool ret3 = parcel.WriteString16(Str8ToStr16(description_));
// jsonParams
ret &= parcel.WriteString16(Str8ToStr16(jsonParams_));
bool ret4 = parcel.WriteString16(Str8ToStr16(jsonParams_));
ret = (ret1 && ret2 && ret3 && ret4) ? true : false;
return ret;
}
@ -254,6 +255,9 @@ ExtraParams *ExtraParams::Unmarshalling(Parcel &parcel)
ExtraParams *extraParams = new (std::nothrow) ExtraParams(devtype, targetBundleName, description, jsonParams);
if (extraParams == nullptr) {
return nullptr;
}
return extraParams;
}
} // namespace AppExecFwk

View File

@ -1226,7 +1226,7 @@ bool PacMap::ToJson(const PacMapList &mapList, Json::Value &dataObject) const
template <typename RawType>
static std::string RawTypeToString(const RawType value, unsigned int precisionAfterPoint)
{
std::ostringstream out(' ');
std::ostringstream out("RawTypeToString");
out.precision(std::numeric_limits<double>::digits10);
out << value;
@ -1465,12 +1465,10 @@ bool PacMap::StringToMapList(const std::string &str, PacMapList &mapList)
const int rawJsonLength = static_cast<int>(str.length());
Json::CharReaderBuilder builder;
Json::CharReader *reader(builder.newCharReader());
if (!reader->parse(str.c_str(), str.c_str() + rawJsonLength, &root, &err)) {
std::unique_ptr<Json::CharReader> const jsonReader(builder.newCharReader());
if (!jsonReader->parse(str.c_str(), str.c_str() + rawJsonLength, &root, &err)) {
return false;
}
delete reader;
reader = nullptr;
if (!root.isMember("pacmap")) {
return false;

View File

@ -1184,6 +1184,9 @@ Want *Want::ParseUri(const std::string &uri)
content = uri.substr(begin, pos - begin);
if (content.compare("PICK") == 0) {
want = new (std::nothrow) Want();
if (want == nullptr) {
return nullptr;
}
inPicker = true;
continue;
}

View File

@ -53,12 +53,20 @@ public:
int fd;
GTEST_LOG_(INFO) << "MockAbilityTest::OpenFile called";
FILE *fd1 = fopen("/dataability_openfile_test.txt", "w+");
if(fd1 == nullptr) {
GTEST_LOG_(INFO) << "MockAbilityTest::OpenFile fd1 == nullptr";
return -1;
}
fputs("123456",fd1);
fclose(fd1);
FILE *fd2 = fopen("/dataability_openfile_test.txt", "r");
if(fd2 == nullptr) {
GTEST_LOG_(INFO) << "MockAbilityTest::OpenFile fd2 == nullptr";
return -1;
}
fd = fileno(fd2);
return fd;
}

View File

@ -238,6 +238,8 @@ HWTEST_F(DataAbilityHelperTest, AaFwk_DataAbilityHelper_OpenFile_Test_0100, Func
Uri urivalue("dataability://device_id/com.domainname.dataability.persondata/person/10?test/te.txt");
std::string mode("r");
int fd = dataAbilityHelper->OpenFile(urivalue, mode);
EXPECT_NE(fd, -1);
std::string result = "123456";
FILE *file = fdopen(fd, "r");
EXPECT_NE(file, nullptr);
@ -274,6 +276,7 @@ HWTEST_F(DataAbilityHelperTest, AaFwk_DataAbilityHelper_OpenFile_Test_0200, Func
Uri urivalue("dataability://device_id/com.domainname.dataability.persondata/person/10?test/te.txt");
std::string mode("r");
int fd = dataAbilityHelper->OpenFile(urivalue, mode);
EXPECT_NE(fd, -1);
std::string result = "123456";
FILE *file = fdopen(fd, "r");

View File

@ -18,6 +18,7 @@ import { StartAbilityParameter } from './ability/startAbilityParameter';
import { AbilityResult } from './ability/abilityResult';
import { Context } from './app/context';
import { DataAbilityHelper } from './ability/dataAbilityHelper';
import { ConnectOptions } from './ability/connectOptions';
/**
* A Feature Ability represents an ability with a UI and is designed to interact with users.
@ -109,6 +110,29 @@ declare namespace featureAbility {
function hasWindowFocus(callback: AsyncCallback<boolean>): void;
function hasWindowFocus(): Promise<boolean>;
/**
* Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template.
* @default -
* @devices phone, tablet
* @since 7
* @SysCap aafwk
* @param request The element name of the service ability
* @param options The remote object instance
* @return Returns the number of the ability connected
*/
function connectAbility(request: Want, options:ConnectOptions ): number;
/**
* The callback interface was connect successfully.
* @default -
* @devices phone, tablet
* @since 7
* @SysCap aafwk
* @param connection The number of the ability connected
*/
function disconnectAbility(connection: number, callback:AsyncCallback<void>): void;
function disconnectAbility(connection: number): Promise<void>;
export enum AbilityWindowConfiguration {
WINDOW_MODE_UNDEFINED = 0,
WINDOW_MODE_FULLSCREEN = 1,

View File

@ -14,6 +14,8 @@
*/
import { AsyncCallback } from './basic';
import { StartAbilityParameter } from './ability/startAbilityParameter';
import { Want } from './ability/want';
import { ConnectOptions } from './ability/connectOptions';
/**
* A Particle Ability represents an ability with service.
@ -35,5 +37,28 @@ declare namespace particleAbility {
*/
function startAbility(parameter: StartAbilityParameter, callback: AsyncCallback<void>): void;
function startAbility(parameter: StartAbilityParameter): Promise<void>;
/**
* Connects the current ability to an ability using the AbilityInfo.AbilityType.SERVICE template.
* @default -
* @devices phone, tablet
* @since 7
* @SysCap aafwk
* @param request The element name of the service ability
* @param options The remote object instance
* @return Returns the number of the ability connected
*/
function connectAbility(request: Want, options:ConnectOptions ): number;
/**
* The callback interface was connect successfully.
* @default -
* @devices phone, tablet
* @since 7
* @SysCap aafwk
* @param connection The number of the ability connected
*/
function disconnectAbility(connection: number, callback:AsyncCallback<void>): void;
function disconnectAbility(connection: number): Promise<void>;
}
export default particleAbility;

View File

@ -0,0 +1,52 @@
/*
* Copyright (c) 2021 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.
*/
import { ElementName } from '../bundle/elementName';
import rpc from './../@ohos.rpc';
export interface ConnectOptions {
/**
* The callback interface was connect successfully.
*
* @default -
* @devices phone, tablet
* @since 7
* @SysCap aafwk
* @param elementName The element name of the service ability
* @param remoteObject The remote object instance
*/
onConnect: (elementName: ElementName, remoteObject: RemoteObject) => void;
/**
* The callback interface was disconnect successfully.
*
* @default -
* @devices phone, tablet
* @since 7
* @SysCap aafwk
* @param elementName The element name of the service ability
*/
onDisconnect: (elementName: ElementName) => void;
/**
* The callback interface was connect failed.
*
* @default -
* @devices phone, tablet
* @since 7
* @SysCap aafwk
* @param code The error code of the failed.
*/
onFailed: (code: number) => void;
}

View File

@ -61,20 +61,6 @@ export interface DataAbilityHelper {
*/
off(type: 'dataChange', uri: string, callback?: AsyncCallback<void>): void;
/**
* Calls the method defined by the Data ability.
* @devices phone, tablet
* @since 7
* @SysCap AAFwk
* @param uri Indicates the Data ability to process.
* @param method Indicates the method name.
* @param arg Indicates the parameter of the String type.
* @param extras Indicates the parameter of the object type.
* @return callback Indicates the value returned by the called method.
*/
call(uri: string, method: string, arg: string, extras: object, callback: AsyncCallback<object>): void;
call(uri: string, method: string, arg: string, extras: object): Promise<object>;
/**
* Inserts a single data record into the database.
* @devices phone, tablet
@ -109,8 +95,8 @@ export interface DataAbilityHelper {
* @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
* @return Returns the query result.
*/
query(URI: string, columns: Array<String>, predicates: DataAbilityPredicates, callback: AsyncCallback<NativeRdb::AbsSharedResultSet>): void;
query(URI: string, columns: Array<String>, predicates: DataAbilityPredicates): Promise<NativeRdb::AbsSharedResultSet>;
query(URI: string, columns: Array<String>, predicates: DataAbilityPredicates, callback: AsyncCallback<ResultSet>): void;
query(URI: string, columns: Array<String>, predicates: DataAbilityPredicates): Promise<ResultSet>;
/**
* Updates data records in the database.
@ -134,8 +120,8 @@ export interface DataAbilityHelper {
* @param values Indicates the data records to insert.
* @return Returns the number of data records inserted.
*/
batchInsert(URI: string, values: Array<NativeRdb::ValuesBucket>, callback: AsyncCallback<number>): void;
batchInsert(URI: string, values: Array<NativeRdb::ValuesBucket>): Promise<number>;
batchInsert(URI: string, values: Array<ValuesBucket>, callback: AsyncCallback<number>): void;
batchInsert(URI: string, values: Array<ValuesBucket>): Promise<number>;
/**
* Performs batch operations on the database.
@ -220,6 +206,16 @@ export interface DataAbilityHelper {
*/
release(callback: AsyncCallback<boolean>): void;
release(): Promise<boolean>;
/**
* Notifies the registered observers of a change to the data resource specified by Uri.
* @devices phone, tablet
* @since 7
* @SysCap AAFwk
* @param uri Indicates the {@link ohos.utils.net.Uri} object to notifyChange.
*/
notifyChange(URI: string, callback: AsyncCallback<void>): void;
notifyChange(URI: string): Promise<void>;
}
export interface DataAbilityResult {

View File

@ -14,19 +14,19 @@
* limitations under the License.
-->
<configuration ver="2.0">
<target name="ability_command_dump_system_test">
<target name="aa_command_dump_system_test">
<depend resource="aa/." pushpath="/data/test/resource/aa/" findpath="res" presetcmd="" />
<preparer>
<option name="push" value="aa/. -> /data/test/resource/aa/" src="res" />
</preparer>
</target>
<target name="ability_command_start_system_test">
<target name="aa_command_start_system_test">
<depend resource="aa/." pushpath="/data/test/resource/aa/" findpath="res" presetcmd="" />
<preparer>
<option name="push" value="aa/. -> /data/test/resource/aa/" src="res" />
</preparer>
</target>
<target name="ability_command_stop_service_system_test">
<target name="aa_command_stop_service_system_test">
<depend resource="aa/." pushpath="/data/test/resource/aa/" findpath="res" presetcmd="" />
<preparer>
<option name="push" value="aa/. -> /data/test/resource/aa/" src="res" />

View File

@ -214,6 +214,90 @@ ErrCode AbilityManagerShellCommand::CreateMessageMap()
POWER_ON_FAILED,
"error: power on failed.",
},
{
NO_FIRST_IN_MISSION,
"error: no first in mission.",
},
{
LOCK_MISSION_DENY_FAILED,
"error: lock mission deny failed.",
},
{
UNLOCK_MISSION_DENY_FAILED,
"error: unlock mission deny failed.",
},
{
SET_MISSION_INFO_FAILED,
"error: set mission info failed.",
},
{
LOCK_MISSION_STATE_DENY_REQUEST,
"error: lock mission state deny request.",
},
{
MOVE_MISSION_TO_STACK_OUT_OF_SIZE,
"error: move mission to stack out of size.",
},
{
MOVE_MISSION_TO_STACK_NOT_SAME_WIN_MODE,
"error: move mission to stack not same win mode.",
},
{
MOVE_MISSION_TO_STACK_NOT_EXIST_MISSION,
"error: move mission to stack not exist mission.",
},
{
MOVE_MISSION_TO_STACK_NOT_SUPPORT_MULTI_WIN,
"error: move mission to stack not support multi win.",
},
{
MOVE_MISSION_TO_STACK_TARGET_STACK_OVERFLOW,
"error: move mission to stack target stack overflow.",
},
{
MOVE_MISSION_TO_STACK_MOVING_DENIED,
"error: move mission to stack moving denied.",
},
{
MINIMIZE_MULTI_WINDOW_FAILED,
"error: minimize multi window failed.",
},
{
MAXIMIZE_MULTIWINDOW_NOT_EXIST,
"error: maximize multiwindow not exist.",
},
{
MAXIMIZE_MULTIWINDOW_FAILED,
"error: maximize multiwindow failed.",
},
{
CHANGE_FOCUS_ABILITY_FAILED,
"error: change focus ability failed.",
},
{
GET_FLOATING_STACK_FAILED,
"error: get floating stack failed.",
},
{
CLOSE_MULTI_WINDOW_FAILED,
"error: close multi window failed.",
},
{
START_ABILITY_SETTING_FAILED,
"error: start ability setting failed.",
},
{
START_ABILITY_SETTING_NOT_SUPPORT_MULTI_WIN,
"error: start ability setting not support multi win.",
},
{
NO_FOUND_ABILITY_BY_CALLER,
"error: no found ability by caller.",
},
{
ABILITY_VISIBLE_FALSE_DENY_REQUEST,
"error: ability visible false deny request.",
},
};
return OHOS::ERR_OK;

View File

@ -26,10 +26,10 @@ config("tools_aa_config_mock") {
tools_aa_mock_sources =
[ "${aafwk_path}/tools/test/mock/mock_ability_manager_stub.cpp" ]
ohos_moduletest("ability_command_start_module_test") {
ohos_moduletest("aa_command_start_module_test") {
module_out_path = module_output_path
sources = [ "ability_command_start_module_test.cpp" ]
sources = [ "aa_command_start_module_test.cpp" ]
sources += tools_aa_mock_sources
configs = [ ":tools_aa_config_mock" ]
@ -52,10 +52,10 @@ ohos_moduletest("ability_command_start_module_test") {
]
}
ohos_moduletest("ability_command_stop_service_module_test") {
ohos_moduletest("aa_command_stop_service_module_test") {
module_out_path = module_output_path
sources = [ "ability_command_stop_service_module_test.cpp" ]
sources = [ "aa_command_stop_service_module_test.cpp" ]
sources += tools_aa_mock_sources
configs = [ ":tools_aa_config_mock" ]
@ -78,10 +78,10 @@ ohos_moduletest("ability_command_stop_service_module_test") {
]
}
ohos_moduletest("ability_command_dump_module_test") {
ohos_moduletest("aa_command_dump_module_test") {
module_out_path = module_output_path
sources = [ "ability_command_dump_module_test.cpp" ]
sources = [ "aa_command_dump_module_test.cpp" ]
sources += tools_aa_mock_sources
configs = [ ":tools_aa_config_mock" ]
@ -108,8 +108,8 @@ group("moduletest") {
testonly = true
deps = [
":ability_command_dump_module_test",
":ability_command_start_module_test",
":ability_command_stop_service_module_test",
":aa_command_dump_module_test",
":aa_command_start_module_test",
":aa_command_stop_service_module_test",
]
}

View File

@ -16,13 +16,13 @@ import("//foundation/aafwk/standard/aafwk.gni")
module_output_path = "aafwk_standard/tools"
ohos_systemtest("ability_command_start_system_test") {
ohos_systemtest("aa_command_start_system_test") {
module_out_path = module_output_path
include_dirs = [ "//third_party/jsoncpp/include" ]
sources = [
"ability_command_start_system_test.cpp",
"aa_command_start_system_test.cpp",
"tool_system_test.cpp",
]
@ -46,11 +46,11 @@ ohos_systemtest("ability_command_start_system_test") {
]
}
ohos_systemtest("ability_command_stop_service_system_test") {
ohos_systemtest("aa_command_stop_service_system_test") {
module_out_path = module_output_path
sources = [
"ability_command_stop_service_system_test.cpp",
"aa_command_stop_service_system_test.cpp",
"tool_system_test.cpp",
]
@ -74,13 +74,13 @@ ohos_systemtest("ability_command_stop_service_system_test") {
]
}
ohos_systemtest("ability_command_dump_system_test") {
ohos_systemtest("aa_command_dump_system_test") {
module_out_path = module_output_path
include_dirs = [ "//third_party/jsoncpp/include" ]
sources = [
"ability_command_dump_system_test.cpp",
"aa_command_dump_system_test.cpp",
"tool_system_test.cpp",
]
@ -108,8 +108,8 @@ group("systemtest") {
testonly = true
deps = [
":ability_command_dump_system_test",
":ability_command_start_system_test",
":ability_command_stop_service_system_test",
":aa_command_dump_system_test",
":aa_command_start_system_test",
":aa_command_stop_service_system_test",
]
}

View File

@ -26,10 +26,10 @@ config("tools_aa_config_mock") {
tools_aa_mock_sources =
[ "${aafwk_path}/tools/test/mock/mock_ability_manager_stub.cpp" ]
ohos_unittest("ability_command_test") {
ohos_unittest("aa_command_test") {
module_out_path = module_output_path
sources = [ "ability_command_test.cpp" ]
sources = [ "aa_command_test.cpp" ]
sources += tools_aa_mock_sources
configs = [ ":tools_aa_config_mock" ]
@ -52,10 +52,10 @@ ohos_unittest("ability_command_test") {
]
}
ohos_unittest("ability_command_start_test") {
ohos_unittest("aa_command_start_test") {
module_out_path = module_output_path
sources = [ "ability_command_start_test.cpp" ]
sources = [ "aa_command_start_test.cpp" ]
sources += tools_aa_mock_sources
configs = [ ":tools_aa_config_mock" ]
@ -78,10 +78,10 @@ ohos_unittest("ability_command_start_test") {
]
}
ohos_unittest("ability_command_stop_service_test") {
ohos_unittest("aa_command_stop_service_test") {
module_out_path = module_output_path
sources = [ "ability_command_stop_service_test.cpp" ]
sources = [ "aa_command_stop_service_test.cpp" ]
sources += tools_aa_mock_sources
configs = [ ":tools_aa_config_mock" ]
@ -104,10 +104,10 @@ ohos_unittest("ability_command_stop_service_test") {
]
}
ohos_unittest("ability_command_dump_test") {
ohos_unittest("aa_command_dump_test") {
module_out_path = module_output_path
sources = [ "ability_command_dump_test.cpp" ]
sources = [ "aa_command_dump_test.cpp" ]
sources += tools_aa_mock_sources
configs = [ ":tools_aa_config_mock" ]
@ -130,10 +130,10 @@ ohos_unittest("ability_command_dump_test") {
]
}
ohos_unittest("ability_command_screen_test") {
ohos_unittest("aa_command_screen_test") {
module_out_path = module_output_path
sources = [ "ability_command_screen_test.cpp" ]
sources = [ "aa_command_screen_test.cpp" ]
sources += tools_aa_mock_sources
configs = [ ":tools_aa_config_mock" ]
@ -154,18 +154,16 @@ ohos_unittest("ability_command_screen_test") {
"hiviewdfx_hilog_native:libhilog",
"ipc:ipc_core",
]
install_enable = true
}
group("unittest") {
testonly = true
deps = [
":ability_command_dump_test",
":ability_command_screen_test",
":ability_command_start_test",
":ability_command_stop_service_test",
":ability_command_test",
":aa_command_dump_test",
":aa_command_screen_test",
":aa_command_start_test",
":aa_command_stop_service_test",
":aa_command_test",
]
}

View File

@ -26,7 +26,9 @@
namespace OHOS {
namespace AAFwk {
namespace LIBZIP {
namespace {
const int E_OK = 0;
}
#define NO_ERROR 0
#define COMPRESS_LEVE_CHECK(level, ret) \
@ -51,8 +53,8 @@ std::shared_ptr<ZlibCallbackInfo> g_zipAceCallbackInfo = nullptr;
std::shared_ptr<ZlibCallbackInfo> g_unzipAceCallbackInfo = nullptr;
void ZipFileAsyncCallBack(int result);
void UnzipFileAsyncCallBack(int result);
napi_value UnwrapZipParam(CallZipUnzipParam &param, napi_env env, napi_value *args);
napi_value UnwrapUnZipParam(CallZipUnzipParam &param, napi_env env, napi_value args[ARGS_MAX_COUNT]);
napi_value UnwrapZipParam(CallZipUnzipParam &param, napi_env env, napi_value *args, size_t argc);
napi_value UnwrapUnZipParam(CallZipUnzipParam &param, napi_env env, napi_value *args, size_t argc);
napi_value ZipFileWrap(napi_env env, napi_callback_info info, AsyncZipCallbackInfo *asyncZipCallbackInfo);
napi_value UnwrapStringParam(std::string &str, napi_env env, napi_value args);
bool UnwrapOptionsParams(OPTIONS &options, napi_env env, napi_value arg);
@ -91,6 +93,10 @@ AsyncZipCallbackInfo *CreateZipAsyncCallbackInfo(napi_env env)
ret = napi_get_global(env, &global);
if (ret != napi_ok) {
napi_get_last_error_info(env, &errorInfo);
if (errorInfo == nullptr) {
HILOG_ERROR("%{public}s errorInfo is null", __func__);
return nullptr;
}
HILOG_ERROR("%{public}s get_global=%{public}d err:%{public}s", __func__, ret, errorInfo->error_message);
}
@ -100,7 +106,8 @@ AsyncZipCallbackInfo *CreateZipAsyncCallbackInfo(napi_env env)
.aceCallback = nullptr,
};
if (asyncCallbackInfo == nullptr) {
HILOG_ERROR("%{public}s asyncCallbackInfo == nullptr", __func__);
HILOG_ERROR("%{public}s asyncCallbackInfo is null", __func__);
return nullptr;
}
HILOG_INFO("%{public}s end.", __func__);
return asyncCallbackInfo;
@ -126,12 +133,6 @@ napi_value NAPI_ZipFile(napi_env env, napi_callback_info info)
HILOG_ERROR("%{public}s, Wrong argument count.", __func__);
return nullptr;
}
// parse param
CallZipUnzipParam param;
if (UnwrapZipParam(param, env, args) == nullptr) {
HILOG_ERROR("%{public}s, call unwrap param failed.", __func__);
return nullptr;
}
AsyncZipCallbackInfo *asyncZipCallbackInfo = CreateZipAsyncCallbackInfo(env);
if (asyncZipCallbackInfo == nullptr) {
@ -163,7 +164,7 @@ napi_value ZipFileWrap(napi_env env, napi_callback_info info, AsyncZipCallbackIn
}
CallZipUnzipParam param;
if (UnwrapZipParam(param, env, args) == nullptr) {
if (UnwrapZipParam(param, env, args, argcAsync) == nullptr) {
HILOG_ERROR("%{public}s, call unwrapWant failed.", __func__);
return nullptr;
}
@ -179,6 +180,14 @@ napi_value ZipFileWrap(napi_env env, napi_callback_info info, AsyncZipCallbackIn
if (argcAsync > PARAM3) {
ret = ZipFileAsync(env, args, argcAsync, asyncZipCallbackInfo);
} else {
if (asyncZipCallbackInfo != nullptr) {
delete asyncZipCallbackInfo;
asyncZipCallbackInfo = nullptr;
}
if (g_zipAceCallbackInfo != nullptr) {
g_zipAceCallbackInfo.reset();
g_zipAceCallbackInfo = nullptr;
}
HILOG_INFO("%{public}s called, wrong number of parameters", __func__);
return nullptr;
}
@ -276,10 +285,15 @@ bool UnwrapOptionsParams(OPTIONS &options, napi_env env, napi_value arg)
return true;
}
napi_value UnwrapZipParam(CallZipUnzipParam &param, napi_env env, napi_value *args)
napi_value UnwrapZipParam(CallZipUnzipParam &param, napi_env env, napi_value *args, size_t argc)
{
HILOG_INFO("%{public}s,called", __func__);
if (argc < 4) {
HILOG_INFO("%{public}s called, param count is wrong", __func__);
return nullptr;
}
// unwrap the param[0]
if (UnwrapStringParam(param.src, env, args[0]) == nullptr) {
HILOG_INFO("%{public}s called, args[0] error", __func__);
@ -303,10 +317,13 @@ napi_value UnwrapZipParam(CallZipUnzipParam &param, napi_env env, napi_value *ar
return ret;
}
napi_value UnwrapUnZipParam(CallZipUnzipParam &param, napi_env env, napi_value args[ARGS_MAX_COUNT])
napi_value UnwrapUnZipParam(CallZipUnzipParam &param, napi_env env, napi_value *args, size_t argc)
{
HILOG_INFO("%{public}s,called", __func__);
if (argc < 4) {
return nullptr;
}
// unwrap the param[0]
if (UnwrapStringParam(param.src, env, args[0]) == nullptr) {
return nullptr;
@ -406,7 +423,7 @@ napi_value NAPI_UnzipFile(napi_env env, napi_callback_info info)
}
// parse param
CallZipUnzipParam param;
if (UnwrapUnZipParam(param, env, args) == nullptr) {
if (UnwrapUnZipParam(param, env, args, argcAsync) == nullptr) {
HILOG_ERROR("%{public}s, call unwrap param failed.", __func__);
return nullptr;
}
@ -425,6 +442,14 @@ napi_value NAPI_UnzipFile(napi_env env, napi_callback_info info)
ret = UnzipFileAsync(env, args, argcAsync, asyncZipCallbackInfo);
} else {
HILOG_INFO("%{public}s called, wrong number of parameters", __func__);
if (asyncZipCallbackInfo != nullptr) {
delete asyncZipCallbackInfo;
asyncZipCallbackInfo = nullptr;
}
if (g_unzipAceCallbackInfo != nullptr) {
g_unzipAceCallbackInfo.reset();
g_unzipAceCallbackInfo = nullptr;
}
return nullptr;
}
@ -497,10 +522,12 @@ void ZipAndUnzipFileAsyncCallBack(std::shared_ptr<ZlibCallbackInfo> &zipAceCallb
}
HILOG_INFO("%{public}s,called env=%{public}p", __func__, zipAceCallbackInfo->env);
uv_loop_s *loop = nullptr;
#if NAPI_VERSION >= 2
napi_get_uv_event_loop(zipAceCallbackInfo->env, &loop);
#endif // NAPI_VERSION >= 2
if (loop == nullptr) {
HILOG_ERROR("%{public}s, work == nullptr.", __func__);
return;
}
uv_work_t *work = new (std::nothrow) uv_work_t;
if (work == nullptr) {
HILOG_ERROR("%{public}s, work == nullptr.", __func__);
@ -516,7 +543,7 @@ void ZipAndUnzipFileAsyncCallBack(std::shared_ptr<ZlibCallbackInfo> &zipAceCallb
zipAceCallbackInfo = nullptr;
work->data = (void *)asyncCallbackInfo;
uv_queue_work(
int rev = uv_queue_work(
loop,
work,
[](uv_work_t *work) {},
@ -531,9 +558,6 @@ void ZipAndUnzipFileAsyncCallBack(std::shared_ptr<ZlibCallbackInfo> &zipAceCallb
napi_value callback = 0;
napi_value undefined = 0;
napi_value result[ARGS_TWO] = {0};
// get napi last error
const napi_extended_error_info *errorInfo = nullptr;
napi_get_last_error_info(asyncCallbackInfo->env, &errorInfo);
// callback(err, data) errorInfo->error_code;
result[PARAM0] = GetCallbackErrorValue(asyncCallbackInfo->env, NO_ERROR);
// callback result
@ -548,12 +572,29 @@ void ZipAndUnzipFileAsyncCallBack(std::shared_ptr<ZlibCallbackInfo> &zipAceCallb
if (asyncCallbackInfo->callback != nullptr) {
napi_delete_reference(asyncCallbackInfo->env, asyncCallbackInfo->callback);
}
if (asyncCallbackInfo != nullptr) {
delete asyncCallbackInfo;
asyncCallbackInfo = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
}
});
if (rev != E_OK) {
// free data
if (asyncCallbackInfo->callback != nullptr) {
napi_delete_reference(asyncCallbackInfo->env, asyncCallbackInfo->callback);
}
if (asyncCallbackInfo != nullptr) {
delete asyncCallbackInfo;
asyncCallbackInfo = nullptr;
}
if (work != nullptr) {
delete work;
work = nullptr;
asyncCallbackInfo = nullptr;
});
}
}
return;
}

View File

@ -50,7 +50,7 @@ std::string UnwrapStringFromJS(napi_env env, napi_value param, const std::string
if (buf == nullptr) {
return value;
}
if (memset_s(buf, sizeof(buf), 0, sizeof(buf)) != E_OK) {
if (memset_s(buf, size + 1, 0, size + 1) != E_OK) {
delete[] buf;
buf = nullptr;
return nullptr;

View File

@ -74,10 +74,9 @@ std::vector<FileAccessor::DirectoryContentEntry> ListDirectoryContent(const File
std::vector<FileAccessor::DirectoryContentEntry> fileDirectoryVector;
std::vector<std::string> filelist;
GetDirFiles(curPath.Value(), filelist);
// HILOG_INFO("filelist ========filelist.size=%{public}d", filelist.size());
HILOG_INFO("filelist ========filelist.size=%{public}zu", filelist.size());
for (size_t i = 0; i < filelist.size(); i++) {
std::string str(filelist[i]);
HILOG_INFO("filelist %{public}s ===8888==", str.c_str());
if (!str.empty()) {
fileDirectoryVector.push_back(
FileAccessor::DirectoryContentEntry(FilePath(str), FilePath::DirectoryExists(FilePath(str))));

View File

@ -26,7 +26,7 @@ namespace AAFwk {
namespace LIBZIP {
namespace {
const std::string SEPARATOR = "/";
const std::regex FILE_PATH_REGEX("[a-zA-Z0-9]|/|");
const std::regex FILE_PATH_REGEX("([0-9A-Za-z/+_=\\-,.])+");
} // namespace
using namespace OHOS::AppExecFwk;
@ -93,8 +93,7 @@ bool IsASCIIChar(const char *pszStr)
}
bool FilePathCheckValid(const std::string &str)
{
return true;
// return std::regex_match(str, FILE_PATH_REGEX);
return std::regex_match(str, FILE_PATH_REGEX);
}
} // namespace LIBZIP