diff --git a/frameworks/kits/ability/native/include/ability_impl.h b/frameworks/kits/ability/native/include/ability_impl.h index 7e63eb4ef948cd8fe3923dd9d4e42d736e9978d2..eb3a50955aeec7da5f5d1c793a6cdb2e9d6331ad 100644 --- a/frameworks/kits/ability/native/include/ability_impl.h +++ b/frameworks/kits/ability/native/include/ability_impl.h @@ -330,7 +330,7 @@ public: */ std::shared_ptr CreatePostEventTimeouter(std::string taskstr); - std::vector> ExecuteBatch(const std::vector> &operations); + virtual std::vector> ExecuteBatch(const std::vector> &operations); protected: /** diff --git a/frameworks/kits/ability/native/src/ability_thread.cpp b/frameworks/kits/ability/native/src/ability_thread.cpp index 79555f75afc9a0373ebbdf3d70cdbc28292421f7..b2032c5637492e731fcaae4b2e1242514b1fd3df 100644 --- a/frameworks/kits/ability/native/src/ability_thread.cpp +++ b/frameworks/kits/ability/native/src/ability_thread.cpp @@ -1151,7 +1151,9 @@ std::vector> 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; } diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/extra_params.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/extra_params.cpp old mode 100644 new mode 100755 index b86cb4f4dc3eaf68bef02f3087108b4b0cabb8eb..94099396a684ca8d081d9091dfe5c90d8f192ea6 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/extra_params.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/extra_params.cpp @@ -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 diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/pac_map.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/pac_map.cpp index df50cec5c3bc03282122e782d054e4b2bd4a6a6d..c1527c7bb78291ee6cfaee52902d322763071c77 100755 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/pac_map.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/pac_map.cpp @@ -1226,7 +1226,7 @@ bool PacMap::ToJson(const PacMapList &mapList, Json::Value &dataObject) const template static std::string RawTypeToString(const RawType value, unsigned int precisionAfterPoint) { - std::ostringstream out(' '); + std::ostringstream out("RawTypeToString"); out.precision(std::numeric_limits::digits10); out << value; @@ -1465,12 +1465,10 @@ bool PacMap::StringToMapList(const std::string &str, PacMapList &mapList) const int rawJsonLength = static_cast(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 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; diff --git a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp index 249bb066a8e0ac796072e24f380abb02a3343fe4..9ffc20e7d38eaf5f855c6e92072ff957843f97db 100755 --- a/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp +++ b/frameworks/kits/content/cpp/src/ohos/aafwk/content/want.cpp @@ -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; } diff --git a/frameworks/kits/test/mock/DemoAbility/mock_ability_test.h b/frameworks/kits/test/mock/DemoAbility/mock_ability_test.h index 9aa908b3542fda221d57b00ab35a124874316015..02b976a1a680b6d64d3ab6f0f0088c25adfd1169 100644 --- a/frameworks/kits/test/mock/DemoAbility/mock_ability_test.h +++ b/frameworks/kits/test/mock/DemoAbility/mock_ability_test.h @@ -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; } diff --git a/frameworks/kits/test/moduletest/cpp/abilitytest/data_ability_helper_module_test.cpp b/frameworks/kits/test/moduletest/cpp/abilitytest/data_ability_helper_module_test.cpp index 4bb39e3e3dc5b3884ceb6ae6926758c778ad3a91..fd2bd3c3c86fa514efb75ce7e446bea1e768b9d6 100644 --- a/frameworks/kits/test/moduletest/cpp/abilitytest/data_ability_helper_module_test.cpp +++ b/frameworks/kits/test/moduletest/cpp/abilitytest/data_ability_helper_module_test.cpp @@ -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"); diff --git a/interfaces/kits/js/@ohos.ability.featureAbility.d.ts b/interfaces/kits/js/@ohos.ability.featureAbility.d.ts index 043a7951ec26c87ac37515bcfb19f2eabf9f2af2..d92e73b84042761f75587e8d617bd57bcd14b4f5 100644 --- a/interfaces/kits/js/@ohos.ability.featureAbility.d.ts +++ b/interfaces/kits/js/@ohos.ability.featureAbility.d.ts @@ -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): void; function hasWindowFocus(): Promise; + /** + * 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; + function disconnectAbility(connection: number): Promise; + export enum AbilityWindowConfiguration { WINDOW_MODE_UNDEFINED = 0, WINDOW_MODE_FULLSCREEN = 1, diff --git a/interfaces/kits/js/@ohos.ability.particleAbility.d.ts b/interfaces/kits/js/@ohos.ability.particleAbility.d.ts index e6388be022987f338939f969412f731c7180e8f3..44e794c32b5e290c2508cdc4bd16cbaa51bc3ace 100644 --- a/interfaces/kits/js/@ohos.ability.particleAbility.d.ts +++ b/interfaces/kits/js/@ohos.ability.particleAbility.d.ts @@ -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; function startAbility(parameter: StartAbilityParameter): Promise; + + /** + * 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; + function disconnectAbility(connection: number): Promise; } export default particleAbility; \ No newline at end of file diff --git a/interfaces/kits/js/ability/connectOptions.d.ts b/interfaces/kits/js/ability/connectOptions.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..c718f678c3b1a8efde126c16d3378e9e0a91ebf8 --- /dev/null +++ b/interfaces/kits/js/ability/connectOptions.d.ts @@ -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; +} diff --git a/interfaces/kits/js/ability/dataAbilityHelper.d.ts b/interfaces/kits/js/ability/dataAbilityHelper.d.ts index 76a5abc9dfa96e240fcdcdc3bbcb6eccfc1fc8a7..71dd47e5b0ffb35ee89462c8dde7a5307cae20d5 100644 --- a/interfaces/kits/js/ability/dataAbilityHelper.d.ts +++ b/interfaces/kits/js/ability/dataAbilityHelper.d.ts @@ -61,20 +61,6 @@ export interface DataAbilityHelper { */ off(type: 'dataChange', uri: string, callback?: AsyncCallback): 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): void; - call(uri: string, method: string, arg: string, extras: object): Promise; - /** * 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, predicates: DataAbilityPredicates, callback: AsyncCallback): void; - query(URI: string, columns: Array, predicates: DataAbilityPredicates): Promise; + query(URI: string, columns: Array, predicates: DataAbilityPredicates, callback: AsyncCallback): void; + query(URI: string, columns: Array, predicates: DataAbilityPredicates): Promise; /** * 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, callback: AsyncCallback): void; - batchInsert(URI: string, values: Array): Promise; + batchInsert(URI: string, values: Array, callback: AsyncCallback): void; + batchInsert(URI: string, values: Array): Promise; /** * Performs batch operations on the database. @@ -220,6 +206,16 @@ export interface DataAbilityHelper { */ release(callback: AsyncCallback): void; release(): Promise; + + /** + * 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; + notifyChange(URI: string): Promise; } export interface DataAbilityResult { diff --git a/test/resource/tools/aa/pageAbilityBundleForStart.hap b/test/resource/tools/aa/pageAbilityBundleForStart.hap index 0a00c268ba56a202419def130d0213bca4006a6b..9c9537c49190b3c6c3e1ddab2c8277e8c239021c 100644 Binary files a/test/resource/tools/aa/pageAbilityBundleForStart.hap and b/test/resource/tools/aa/pageAbilityBundleForStart.hap differ diff --git a/test/resource/tools/ohos_test.xml b/test/resource/tools/ohos_test.xml index c2ed5e5806a3b3d4524e6c2d6158af04971debe7..d94a2929fc9a28d2730d52594ccb0acd12dd326e 100644 --- a/test/resource/tools/ohos_test.xml +++ b/test/resource/tools/ohos_test.xml @@ -14,19 +14,19 @@ * limitations under the License. --> - + - + - +