;
}
export default particleAbility;
\ No newline at end of file
diff --git a/interfaces/kits/js/@ohos.application.DataShareExtAbility.d.ts b/interfaces/kits/js/@ohos.application.DataShareExtAbility.d.ts
index 47018ace74d282568866da0a7f48a71c8f2d7eaf..4e9c950410bf29f6b5a263a2799e4e08ce27ab9d 100644
--- a/interfaces/kits/js/@ohos.application.DataShareExtAbility.d.ts
+++ b/interfaces/kits/js/@ohos.application.DataShareExtAbility.d.ts
@@ -22,16 +22,17 @@ import rdb from './@ohos.data.rdb';
/**
* class of datashare extension ability.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @since 8
+ * @sysCap AAFwk
+ * @devices phone, tablet, tv, wearable, car
* @systemapi hide for inner use.
*/
export default class DataShareExtAbility {
/**
* Indicates datashare extension ability context.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @since 8
+ * @sysCap AAFwk
* @systemapi hide for inner use.
*/
context?: ExtensionContext;
@@ -39,8 +40,9 @@ export default class DataShareExtAbility {
/**
* Called back when a datashare extension ability is started for initialization.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param want Indicates connection information about the datashare extension ability.
* @systemapi hide for inner use.
* @return -
@@ -50,8 +52,9 @@ export default class DataShareExtAbility {
/**
* Obtains the MIME type of files. This method should be implemented by a data share.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the path of the files to obtain.
* @param mimeTypeFilter Indicates the MIME type of the files to obtain. This parameter cannot be set to {@code
* null}.
@@ -60,13 +63,14 @@ export default class DataShareExtAbility {
* 3. "*/jpg": Obtains files whose subtype is JPG of any main type.
* @return Returns the MIME type of the matched files; returns null if there is no type that matches the Data
*/
- getFileTypes?(uri: string, mimeTypeFilter: string): Array;
+ getFileTypes?(uri: string, mimeTypeFilter:string, callback: AsyncCallback>): void;
/**
* Opens a file. This method should be implemented by a data share.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the path of the file to open.
* @param mode Indicates the open mode, which can be "r" for read-only access, "w" for write-only access (erasing
* whatever data is currently in the file), "wt" for write access that truncates any existing file,
@@ -74,24 +78,26 @@ export default class DataShareExtAbility {
* existing data, or "rwt" for read and write access that truncates any existing file.
* @return Returns the file descriptor.
*/
- openFile?(uri: string, mode: string): number;
+ openFile?(uri: string, mode: string, callback: AsyncCallback): void;
/**
* Inserts a data record into the database. This method should be implemented by a data share.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the position where the data is to insert.
* @param valueBucket Indicates the data to insert.
* @return Returns the index of the newly inserted data record.
*/
- insert?(uri: string, valueBucket: rdb.ValuesBucket): number;
+ insert?(uri: string, values: rdb.ValuesBucket, callback: AsyncCallback): void;
/**
* Updates one or more data records in the database. This method should be implemented by a data share.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the database table storing the data to update.
* @param valueBucket Indicates the data to update. This parameter can be null.
* @param predicates Indicates filter criteria. If this parameter is null, all data records will be updated by
@@ -99,25 +105,28 @@ export default class DataShareExtAbility {
* @return Returns the number of data records updated.
* @return -
*/
- update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates): number;
+ update?(uri: string, values: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates,
+ callback: AsyncCallback): void;
/**
* Deletes one or more data records. This method should be implemented by a data share.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the database table storing the data to delete.
* @param predicates Indicates filter criteria. If this parameter is null, all data records will be deleted by
* default.
* @return Returns the number of data records deleted.
*/
- delete?(uri: string, predicates: dataAbility.DataAbilityPredicates): number;
+ delete?(uri: string, predicates: dataAbility.DataAbilityPredicates, callback: AsyncCallback): void;
/**
* Queries one or more data records in the database. This method should be implemented by a data share.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the database table storing the data to query.
* @param columns Indicates the columns to be queried, in array, for example, {"name","age"}. You should define
* the processing logic when this parameter is null.
@@ -125,54 +134,59 @@ export default class DataShareExtAbility {
* default.
* @return Returns the queried data.
*/
- query?(uri: string, columns: Array, predicates: dataAbility.DataAbilityPredicates): ResultSet;
+ query?(uri: string, columns: Array, predicates: dataAbility.DataAbilityPredicates,
+ callback: AsyncCallback): void;
/**
- * Obtains the MIME type matching the data specified by the URI of the data share. This method should be
+ * Obtains the MIME type matching the data specified by the uri of the data share. This method should be
* implemented by a data share.
*
* Data abilities supports general data types, including text, HTML, and JPEG.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the uri of the data.
* @return Returns the MIME type that matches the data specified by {@code uri}.
*/
- getType?(uri: string): string;
+ getType?(uri: string, callback: AsyncCallback): void;
/**
* Inserts multiple data records into the database. This method should be implemented by a data share.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the position where the data is to insert.
* @param valueBuckets Indicates the data to insert.
* @return Returns the number of data records inserted.
*/
- batchInsert?(uri: string, valueBuckets: Array): number;
+ batchInsert?(uri: string, values: Array, callback: AsyncCallback): void;
/**
- * Converts the given {@code uri} that refer to the data share into a normalized URI. A normalized URI can be
+ * Converts the given {@code uri} that refer to the data share into a normalized uri. A normalized uri can be
* used across devices, persisted, backed up, and restored. It can refer to the same item in the data share
* even if the context has changed.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the uri to normalize.
- * @return Returns the normalized uri if the data share supports URI normalization;
+ * @return Returns the normalized uri if the data share supports uri normalization;
*/
- normalizeUri?(uri: string): string;
+ normalizeUri?(uri: string, callback: AsyncCallback): void;
/**
* Converts the given normalized {@code uri} generated by {@link #normalizeUri(uri)} into a denormalized one.
* The default implementation of this method returns the original uri passed to it.
*
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Provider
+ * @devices phone, tablet, tv, wearable, car
+ * @since 8
+ * @sysCap AAFwk
* @param uri Indicates the uri to denormalize.
* @return Returns the denormalized {@code uri} object if the denormalization is successful; returns the original
* {@code uri} passed to this method if there is nothing to do; returns {@code null} if the data identified by
* the original {@code uri} cannot be found in the current environment.
*/
- denormalizeUri?(uri: string): string;
+ denormalizeUri?(uri: string, callback: AsyncCallback): void;
}
\ No newline at end of file
diff --git a/interfaces/kits/js/@ohos.data.dataShare.d.ts b/interfaces/kits/js/@ohos.data.dataShare.d.ts
deleted file mode 100644
index 20cf3eb02d747bf9dbfe97e34a945064e86af9f2..0000000000000000000000000000000000000000
--- a/interfaces/kits/js/@ohos.data.dataShare.d.ts
+++ /dev/null
@@ -1,213 +0,0 @@
-/*
-* 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 { AsyncCallback, Callback } from './basic';
-import { Want } from './ability/want';
-import Context from './application/Context';
-import { ValuesBucket, ResultSet, DataSharePredicates } from './@ohos.data.rdb';
-
-declare namespace dataShare {
- /**
- * Obtains the dataShareHelper.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param context Indicates the application context.
- * @param want Indicates The element parameter of the service ability.
- * @param uri Indicates the path of the file to open.
- * @return Returns the dataShareHelper.
- * @systemapi Hide this for inner system use
- */
- function createDataShareHelper(context: Context, want: Want, uri: string): DataShareHelper;
-
- /**
- * DataShareHelper
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @systemapi Hide this for inner system use
- */
- interface DataShareHelper {
- /**
- * Opens a file in a specified remote path.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the path of the file to open.
- * @param mode Indicates the file open mode, which can be "r" for read-only access, "w" for write-only access
- * (erasing whatever data is currently in the file), "wt" for write access that truncates any existing
- * file, "wa" for write-only access to append to any existing data, "rw" for read and write access on
- * any existing data, or "rwt" for read and write access that truncates any existing file.
- * @param callback Indicates the callback when openfile success
- * @systemapi Hide this for inner system use
- */
- openFile(uri: string, mode: string, callback: AsyncCallback): void;
- openFile(uri: string, mode: string): Promise;
-
- /**
- * Registers an observer to observe data specified by the given uri.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param type dataChange.
- * @param uri Indicates the path of the data to operate.
- * @param callback Indicates the callback when dataChange.
- * @systemapi Hide this for inner system use
- */
- on(type: 'dataChange', uri: string, callback: AsyncCallback): void;
-
- /**
- * Deregisters an observer used for monitoring data specified by the given uri.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param type dataChange.
- * @param uri Indicates the path of the data to operate.
- * @param callback Indicates the registered callback.
- * @systemapi Hide this for inner system use
- */
- off(type: 'dataChange', uri: string, callback?: AsyncCallback): void;
-
- /**
- * Inserts a single data record into the database.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the path of the data to operate.
- * @param value Indicates the data record to insert. If this parameter is null, a blank row will be inserted.
- * @return Returns the index of the inserted data record.
- * @systemapi Hide this for inner system use
- */
- insert(URI: string, values: ValuesBucket, callback: AsyncCallback): void;
- insert(URI: string, values: ValuesBucket): Promise;
-
- /**
- * Deletes one or more data records from the database.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the path of the data to operate.
- * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
- * @return Returns the number of data records deleted.
- * @systemapi Hide this for inner system use
- */
- delete(URI: string, predicates: DataSharePredicates, callback: AsyncCallback): void;
- delete(URI: string, predicates: DataSharePredicates): Promise;
-
- /**
- * Queries data in the database.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the path of data to query.
- * @param columns Indicates the columns to query. If this parameter is null, all columns are queried.
- * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
- * @return Returns the query result.
- * @systemapi Hide this for inner system use
- */
- query(URI: string, columns: Array, predicates: DataSharePredicates, callback: AsyncCallback): void;
- query(URI: string, columns: Array, predicates: DataSharePredicates): Promise;
-
- /**
- * Updates data records in the database.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the path of data to update.
- * @param value Indicates the data to update. This parameter can be null.
- * @param predicates Indicates filter criteria. You should define the processing logic when this parameter is null.
- * @return Returns the number of data records updated.
- * @systemapi Hide this for inner system use
- */
- update(URI: string, values: ValuesBucket, predicates: DataSharePredicates, callback: AsyncCallback): void;
- update(URI: string, values: ValuesBucket, predicates: DataSharePredicates): Promise;
-
- /**
- * Inserts multiple data records into the database.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the path of the data to operate.
- * @param values Indicates the data records to insert.
- * @return Returns the number of data records inserted.
- * @systemapi Hide this for inner system use
- */
- batchInsert(URI: string, values: Array, callback: AsyncCallback): void;
- batchInsert(URI: string, values: Array): Promise;
-
- /**
- * Obtains the MIME type of the date specified by the given URI.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the path of the data to operate.
- * @return Returns the MIME type that matches the data specified by uri.
- * @systemapi Hide this for inner system use
- */
- getType(URI: string, callback: AsyncCallback): void;
- getType(URI: string): Promise;
-
- /**
- * Obtains the MIME types of files supported.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the path of the files to obtain.
- * @param mimeTypeFilter Indicates the MIME types of the files to obtain. This parameter cannot be null.
- * 1. "*/*": Obtains all types supported by Data abilities.
- *
2. "image/*": Obtains files whose main type is image of any subtype.
- *
3. "*/jpg": Obtains files whose subtype is JPG of any main type.
- * @return Returns the matched MIME types. If there is no match, {@code null} is returned.
- * @systemapi Hide this for inner system use
- */
- getFileTypes(uri: string, mimeTypeFilter:string, callback: AsyncCallback>): void;
- getFileTypes(uri: string, mimeTypeFilter): Promise>;
-
- /**
- * Converts the given {@code uri} that refers to the Data ability into a normalized {@link ohos.utils.net.Uri}.
- * A normalized URI can be used across devices, persisted, backed up, and restored.
- * To transfer a normalized URI from another environment to the current environment, you should call this
- * method again to re-normalize the URI for the current environment or call {@link #denormalizeUri(Uri)}
- * to convert it to a denormalized URI that can be used only in the current environment.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the {@link ohos.utils.net.Uri} object to normalize.
- * @return Returns the normalized {@code Uri} object if the Data ability supports URI normalization;
- * returns {@code null} otherwise.
- * @throws DataShareRemoteException Throws this exception if the remote process exits.
- * @throws NullPointerException Throws this exception if {@code uri} is null.
- * @see #denormalizeUri
- * @systemapi Hide this for inner system use
- */
- normalizeUri(uri: string, callback: AsyncCallback): void;
- normalizeUri(uri: string): Promise;
-
- /**
- * Converts the given normalized {@code uri} generated by {@link #normalizeUri(Uri)} into a denormalized one.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the {@link ohos.utils.net.Uri} object to denormalize.
- * @return Returns the denormalized {@code Uri} object if the denormalization is successful; returns the
- * original {@code Uri} passed to this method if there is nothing to do; returns {@code null} if the data
- * identified by the normalized {@code Uri} cannot be found in the current environment.
- * @throws DataShareRemoteException Throws this exception if the remote process exits.
- * @throws NullPointerException Throws this exception if {@code uri} is null.
- * @see #normalizeUri
- * @systemapi Hide this for inner system use
- */
- denormalizeUri(uri: string, callback: AsyncCallback): void;
- denormalizeUri(uri: string): Promise;
-
- /**
- * Notifies the registered observers of a change to the data resource specified by Uri.
- * @since 9
- * @sysCap SystemCapability.DistributedDataMgr.DataShare.Consumer
- * @param uri Indicates the {@link ohos.utils.net.Uri} object to notifyChange.
- * @systemapi Hide this for inner system use
- */
- notifyChange(URI: string, callback: AsyncCallback): void;
- notifyChange(URI: string): Promise;
- }
-}
-
-export default dataShare;
diff --git a/interfaces/kits/napi/BUILD.gn b/interfaces/kits/napi/BUILD.gn
index 355186047787ae6d13201d93436b33a1429c53b8..aff640ffd0f3bc5e2e014181a14f2b1a81491baf 100644
--- a/interfaces/kits/napi/BUILD.gn
+++ b/interfaces/kits/napi/BUILD.gn
@@ -29,7 +29,6 @@ group("napi_packages") {
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/app/test_runner:testrunner_napi",
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/callee:callee_napi",
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/caller:caller_napi",
- "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/dataShare:datashare",
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/dataUriUtils:datauriutils",
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/datashare_ext_ability:datashareextability_napi",
"//foundation/aafwk/standard/interfaces/kits/napi/aafwk/datashare_ext_ability_context:datashareextabilitycontext_napi",
diff --git a/interfaces/kits/napi/aafwk/abilityManager/napi_ability_manager.cpp b/interfaces/kits/napi/aafwk/abilityManager/napi_ability_manager.cpp
index 6f33960308b7ba5413c6b261cca5cb529a65f775..6517c51b2c4444b7d23d188988b7fdd3f16d1e3a 100644
--- a/interfaces/kits/napi/aafwk/abilityManager/napi_ability_manager.cpp
+++ b/interfaces/kits/napi/aafwk/abilityManager/napi_ability_manager.cpp
@@ -50,9 +50,6 @@ OHOS::sptr GetAppManagerInstance()
napi_value ParseBundleName(napi_env env, std::string &bundleName, napi_value args)
{
- napi_valuetype valuetype = napi_valuetype::napi_null;
- NAPI_CALL(env, napi_typeof(env, args, &valuetype));
- NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected.");
char buf[NapiAbilityMgr::BUFFER_LENGTH_MAX] = {0};
size_t len = 0;
napi_get_value_string_utf8(env, args, buf, NapiAbilityMgr::BUFFER_LENGTH_MAX, &len);
@@ -1692,6 +1689,9 @@ napi_value NAPI_KillProcessesByBundleName(napi_env env, napi_callback_info info)
HILOG_INFO("argc = [%{public}zu]", argc);
std::string bundleName = "";
+ napi_valuetype valuetype = napi_valuetype::napi_null;
+ NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
+ NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected.");
ParseBundleName(env, bundleName, argv[0]);
bool callBackMode = false;
@@ -1813,6 +1813,9 @@ napi_value NAPI_ClearUpApplicationData(napi_env env, napi_callback_info info)
HILOG_INFO("argc = [%{public}zu]", argc);
std::string bundleName = "";
+ napi_valuetype valuetype = napi_valuetype::napi_null;
+ NAPI_CALL(env, napi_typeof(env, argv[0], &valuetype));
+ NAPI_ASSERT(env, valuetype == napi_string, "Wrong argument type. String expected.");
ParseBundleName(env, bundleName, argv[0]);
bool callBackMode = false;
diff --git a/interfaces/kits/napi/aafwk/ability_context/ability_context.js b/interfaces/kits/napi/aafwk/ability_context/ability_context.js
index 0be12bee92f9d4b43a49938fa4fe3919594be7a0..c053519cd7c01bddf99987417eef145dd577b4dd 100755
--- a/interfaces/kits/napi/aafwk/ability_context/ability_context.js
+++ b/interfaces/kits/napi/aafwk/ability_context/ability_context.js
@@ -52,12 +52,12 @@ class AbilityContext extends Context {
}
}
- startAbilityForResult(want, options, callback) {
- return this.__context_impl__.startAbilityForResult(want, options, callback)
+ startAbilityForResult(want, callback) {
+ return this.__context_impl__.startAbilityForResult(want, callback)
}
- startAbilityForResultWithAccount(want, accountId, options, callback) {
- return this.__context_impl__.startAbilityForResultWithAccount(want, accountId, options, callback)
+ startAbilityForResultWithAccount(want, accountId, callback) {
+ return this.__context_impl__.startAbilityForResultWithAccount(want, accountId, callback)
}
connectAbility(want, options) {
diff --git a/interfaces/kits/napi/aafwk/app/app_manager/js_app_manager.cpp b/interfaces/kits/napi/aafwk/app/app_manager/js_app_manager.cpp
index 9e864b0619ab41f277fc84869a28be429438f894..66029a291d6d02e7b4b5eceb707e8939deab09f9 100644
--- a/interfaces/kits/napi/aafwk/app/app_manager/js_app_manager.cpp
+++ b/interfaces/kits/napi/aafwk/app/app_manager/js_app_manager.cpp
@@ -89,6 +89,18 @@ public:
return (me != nullptr) ? me->OnKillProcessWithAccount(*engine, *info) : nullptr;
}
+ static NativeValue* KillProcessesByBundleName(NativeEngine* engine, NativeCallbackInfo* info)
+ {
+ JsAppManager* me = CheckParamsAndGetThis(engine, info);
+ return (me != nullptr) ? me->OnkillProcess(*engine, *info) : nullptr;
+ }
+
+ static NativeValue* ClearUpApplicationData(NativeEngine* engine, NativeCallbackInfo* info)
+ {
+ JsAppManager* me = CheckParamsAndGetThis(engine, info);
+ return (me != nullptr) ? me->OnClearUpApplicationData(*engine, *info) : nullptr;
+ }
+
private:
sptr appManager_ = nullptr;
sptr abilityManager_ = nullptr;
@@ -270,6 +282,80 @@ private:
return result;
}
+ NativeValue* OnkillProcess(NativeEngine &engine, NativeCallbackInfo &info)
+ {
+ HILOG_INFO("%{public}s is called", __FUNCTION__);
+ if (info.argc == 0) {
+ HILOG_ERROR("Not enough params");
+ return engine.CreateUndefined();
+ }
+
+ std::string bundleName;
+ if (!ConvertFromJsValue(engine, info.argv[0], bundleName)) {
+ HILOG_ERROR("get bundelName failed!");
+ return engine.CreateUndefined();
+ }
+
+ HILOG_INFO("kill process [%{public}s]", bundleName.c_str());
+ AsyncTask::CompleteCallback complete = [bundleName, abilityManager = abilityManager_](NativeEngine& engine,
+ AsyncTask& task, int32_t status) {
+ if (abilityManager == nullptr) {
+ HILOG_WARN("abilityManager nullptr");
+ task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "abilityManager nullptr"));
+ return;
+ }
+ auto errcode = abilityManager->KillProcess(bundleName);
+ if (errcode == 0) {
+ task.Resolve(engine, engine.CreateUndefined());
+ } else {
+ task.Reject(engine, CreateJsError(engine, errcode, "kill process failed."));
+ }
+ };
+
+ NativeValue* lastParam = (info.argc == 1) ? nullptr : info.argv[1];
+ NativeValue* result = nullptr;
+ AsyncTask::Schedule(
+ engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
+ return result;
+ }
+
+ NativeValue* OnClearUpApplicationData(NativeEngine &engine, NativeCallbackInfo &info)
+ {
+ HILOG_INFO("%{public}s is called", __FUNCTION__);
+ if (info.argc == 0) {
+ HILOG_ERROR("Not enough params");
+ return engine.CreateUndefined();
+ }
+
+ std::string bundleName;
+ if (!ConvertFromJsValue(engine, info.argv[0], bundleName)) {
+ HILOG_ERROR("get bundelName failed!");
+ return engine.CreateUndefined();
+ }
+
+ HILOG_INFO("kill process [%{public}s]", bundleName.c_str());
+ AsyncTask::CompleteCallback complete = [bundleName, abilityManager = abilityManager_](NativeEngine& engine,
+ AsyncTask& task, int32_t status) {
+ if (abilityManager == nullptr) {
+ HILOG_WARN("abilityManager nullptr");
+ task.Reject(engine, CreateJsError(engine, ERROR_CODE_ONE, "abilityManager nullptr"));
+ return;
+ }
+ auto errcode = abilityManager->ClearUpApplicationData(bundleName);
+ if (errcode == 0) {
+ task.Resolve(engine, engine.CreateUndefined());
+ } else {
+ task.Reject(engine, CreateJsError(engine, errcode, "clear up application failed."));
+ }
+ };
+
+ NativeValue* lastParam = (info.argc == 1) ? nullptr : info.argv[1];
+ NativeValue* result = nullptr;
+ AsyncTask::Schedule(
+ engine, CreateAsyncTaskWithLastParam(engine, lastParam, nullptr, std::move(complete), &result));
+ return result;
+ }
+
NativeValue* OnKillProcessWithAccount(NativeEngine &engine, NativeCallbackInfo &info)
{
HILOG_INFO("%{public}s is called", __FUNCTION__);
@@ -359,6 +445,10 @@ NativeValue* JsAppManagerInit(NativeEngine* engine, NativeValue* exportObj)
JsAppManager::IsRunningInStabilityTest);
BindNativeFunction(*engine, *object, "killProcessWithAccount",
JsAppManager::KillProcessWithAccount);
+ BindNativeFunction(*engine, *object, "killProcessesByBundleName",
+ JsAppManager::KillProcessesByBundleName);
+ BindNativeFunction(*engine, *object, "clearUpApplicationData",
+ JsAppManager::ClearUpApplicationData);
HILOG_INFO("JsAppManagerInit end");
return engine->CreateUndefined();
}
diff --git a/interfaces/kits/napi/aafwk/dataShare/BUILD.gn b/interfaces/kits/napi/aafwk/dataShare/BUILD.gn
deleted file mode 100644
index 2248e600e88809dd8374be7bd7b028e973e65eaf..0000000000000000000000000000000000000000
--- a/interfaces/kits/napi/aafwk/dataShare/BUILD.gn
+++ /dev/null
@@ -1,69 +0,0 @@
-# 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("//build/ohos.gni")
-
-ohos_shared_library("datashare") {
- include_dirs = [
- "//foundation/ace/napi/interfaces/kits",
- "//third_party/node/src",
- "//third_party/libuv/include",
- "//foundation/aafwk/standard/frameworks/kits/ability/native/include",
- "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/dataShare",
- "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common",
- "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_rdb/include",
- "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/include",
- "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/include",
- "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_resultset/include",
- ]
-
- sources = [
- "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/common/src/js_utils.cpp",
- "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_dataability/src/napi_data_ability_predicates.cpp",
- "//foundation/distributeddatamgr/appdatamgr/frameworks/jskitsimpl/napi_resultset/src/napi_result_set.cpp",
- "napi_datashare_helper.cpp",
- "native_datashare_module.cpp",
- ]
-
- deps = [
- "//foundation/aafwk/standard/frameworks/kits/ability/native:abilitykit_native",
- "//foundation/aafwk/standard/frameworks/kits/appkit:appkit_native",
- "//foundation/aafwk/standard/interfaces/innerkits/base:base",
- "//foundation/aafwk/standard/interfaces/innerkits/dataobs_manager:dataobs_manager",
- "//foundation/aafwk/standard/interfaces/kits/napi/aafwk/inner/napi_common:napi_common",
- "//foundation/ace/napi:ace_napi",
- "//foundation/distributedschedule/dmsfwk/interfaces/innerkits/uri:zuri",
- "//third_party/libuv:uv_static",
- "//utils/native/base:utils",
- ]
-
- external_deps = [
- "ability_base:want",
- "ability_runtime:ability_manager",
- "ability_runtime:app_manager",
- "ability_runtime:napi_base_context",
- "bundle_framework:appexecfwk_base",
- "bundle_framework:appexecfwk_core",
- "eventhandler:libeventhandler",
- "hiviewdfx_hilog_native:libhilog",
- "ipc:ipc_core",
- "native_appdatamgr:native_appdatafwk",
- "native_appdatamgr:native_dataability",
- "native_appdatamgr:native_rdb",
- ]
-
- relative_install_dir = "module/data"
-
- subsystem_name = "aafwk"
- part_name = "ability_runtime"
-}
diff --git a/interfaces/kits/napi/aafwk/dataShare/data_share_common.h b/interfaces/kits/napi/aafwk/dataShare/data_share_common.h
deleted file mode 100644
index b462002faa4063d97b4cdce433f89a989e8dca4f..0000000000000000000000000000000000000000
--- a/interfaces/kits/napi/aafwk/dataShare/data_share_common.h
+++ /dev/null
@@ -1,360 +0,0 @@
-/*
- * Copyright (c) 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.
- */
-
-#ifndef OHOS_APPEXECFWK_DATASHARE_COMMON_H
-#define OHOS_APPEXECFWK_DATASHARE_COMMON_H
-#include "ability.h"
-#include "abs_shared_result_set.h"
-#include "data_ability_predicates.h"
-#include "napi/native_api.h"
-#include "napi/native_common.h"
-#include "napi/native_node_api.h"
-#include "napi_common.h"
-#include "napi_common_util.h"
-#include "values_bucket.h"
-#include "want.h"
-
-using Want = OHOS::AAFwk::Want;
-using Ability = OHOS::AppExecFwk::Ability;
-using AbilityStartSetting = OHOS::AppExecFwk::AbilityStartSetting;
-
-namespace OHOS {
-namespace AppExecFwk {
-struct CallAbilityParam {
- Want want;
- int requestCode = 0;
- bool forResultOption = false;
- std::shared_ptr setting = nullptr;
-};
-
-struct OnAbilityCallback {
- int requestCode = 0;
- int resultCode = 0;
- Want resultData;
- CallbackInfo cb;
-};
-
-struct ContinueAbilityOptionsInfo {
- bool reversible = false;
- std::string deviceId;
-};
-
-struct AsyncCallbackInfo {
- CallbackInfo cbInfo;
- napi_async_work asyncWork = nullptr;
- napi_deferred deferred = nullptr;
- Ability *ability = nullptr;
- CallAbilityParam param;
- CallbackInfo aceCallback;
- bool native_result;
- AbilityType abilityType = AbilityType::UNKNOWN;
- int errCode = 0;
- ContinueAbilityOptionsInfo optionInfo;
-};
-
-struct CBBase {
- CallbackInfo cbInfo;
- napi_async_work asyncWork;
- napi_deferred deferred;
- Ability *ability = nullptr;
- AbilityType abilityType = AbilityType::UNKNOWN;
- int errCode = 0;
-};
-
-struct AppInfo_ {
- std::string name;
- std::string description;
- int32_t descriptionId = 0;
- bool systemApp = false;
- bool enabled = true; // no data
- std::string label;
- std::string labelId;
- std::string icon;
- std::string iconId;
- std::string process;
- int32_t supportedModes = 0;
- std::vector moduleSourceDirs;
- std::vector permissions;
- std::vector moduleInfos;
- std::string entryDir;
-};
-
-struct AppInfoCB {
- CBBase cbBase;
- AppInfo_ appInfo;
-};
-
-struct AppTypeCB {
- CBBase cbBase;
- std::string name;
-};
-
-struct AbilityInfo_ {
- std::string bundleName;
- std::string name;
- std::string label;
- std::string description;
- std::string icon;
- int32_t labelId;
- int32_t descriptionId;
- int32_t iconId;
- std::string moduleName;
- std::string process;
- std::string targetAbility; // no data
- int32_t backgroundModes; // no data
- bool isVisible = true;
- bool formEnabled = false; // no data
- int32_t type = 0;
- int32_t subType = 0; // no data
- int32_t orientation = 0;
- int32_t launchMode = 0;
- std::vector permissions;
- std::vector deviceTypes;
- std::vector deviceCapabilities;
- std::string readPermission; // no data
- std::string writePermission; // no data
- AppInfo_ appInfo;
- int32_t formEntity; // no data
- int32_t minFormHeight; // no data
- int32_t defaultFormHeight; // no data
- int32_t minFormWidth; // no data
- int32_t defaultFormWidth; // no data
- std::string uri;
-};
-struct AbilityInfoCB {
- CBBase cbBase;
- AbilityInfo_ abilityInfo;
-};
-
-struct AbilityNameCB {
- CBBase cbBase;
- std::string name;
-};
-
-struct ProcessInfoCB {
- CBBase cbBase;
- pid_t pid = 0;
- std::string processName;
-};
-
-struct ProcessNameCB {
- CBBase cbBase;
- std::string processName;
-};
-
-struct CallingBundleCB {
- CBBase cbBase;
- std::string callingBundleName;
-};
-
-struct GetOrCreateLocalDirCB {
- CBBase cbBase;
- std::string rootDir;
-};
-
-struct DatabaseDirCB {
- CBBase cbBase;
- std::string dataBaseDir;
-};
-
-struct PreferencesDirCB {
- CBBase cbBase;
- std::string preferencesDir;
-};
-
-struct ElementNameCB {
- CBBase cbBase;
- std::string deviceId;
- std::string bundleName;
- std::string abilityName;
- std::string uri;
- std::string shortName;
-};
-
-struct HapModuleInfo_ {
- std::string name;
- std::string description;
- int32_t descriptionId = 0; // no data
- std::string icon;
- std::string label;
- int32_t labelId = 0; // no data
- int32_t iconId = 0; // no data
- std::string backgroundImg;
- int32_t supportedModes = 0;
- std::vector reqCapabilities;
- std::vector deviceTypes;
- std::vector abilityInfos;
- std::string moduleName;
- std::string mainAbilityName; // no data
- bool installationFree; // no data
-};
-
-struct HapModuleInfoCB {
- CBBase cbBase;
- HapModuleInfo_ hapModuleInfo;
-};
-
-struct DataShareHelperCB {
- CBBase cbBase;
- napi_ref uri = nullptr;
- napi_value result = nullptr;
-};
-
-struct DSHelperInsertCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- NativeRdb::ValuesBucket valueBucket;
- int result = 0;
- int execResult;
-};
-
-class NAPIAbilityConnection;
-struct AbilityConnectionCB {
- napi_env env;
- napi_ref callback[3] = {0}; // onConnect/onDisconnect/onFailed
- int resultCode = 0;
- ElementName elementName;
- sptr connection;
-};
-struct ConnectAbilityCB {
- CBBase cbBase;
- Want want;
- sptr abilityConnection;
- AbilityConnectionCB abilityConnectionCB;
- int64_t id;
- bool result;
- int errCode = 0;
-};
-
-struct DSHelperNotifyChangeCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- int execResult;
-};
-
-class NAPIDataShareObserver;
-struct DSHelperOnOffCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- sptr observer;
- std::string uri;
- int result = 0;
- std::vector NotifyList;
- std::vector DestoryList;
-};
-
-struct ShowOnLockScreenCB {
- CBBase cbBase;
- bool isShow;
-};
-
-struct DSHelperGetTypeCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- std::string result = "";
- int execResult;
-};
-
-struct DSHelperGetFileTypesCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- std::string mimeTypeFilter;
- std::vector result;
- int execResult;
-};
-
-struct DSHelperNormalizeUriCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- std::string result = "";
- int execResult;
-};
-
-struct DSHelperDenormalizeUriCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- std::string result = "";
- int execResult;
-};
-
-struct DSHelperDeleteCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- NativeRdb::DataAbilityPredicates predicates;
- int result = 0;
- int execResult;
-};
-
-struct DSHelperQueryCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- std::vector columns;
- NativeRdb::DataAbilityPredicates predicates;
- std::shared_ptr result;
- int execResult;
-};
-
-struct DSHelperUpdateCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- NativeRdb::ValuesBucket valueBucket;
- NativeRdb::DataAbilityPredicates predicates;
- int result = 0;
- int execResult;
-};
-
-struct DSHelperBatchInsertCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- std::vector values;
- int result = 0;
- int execResult;
-};
-
-struct DSHelperOpenFileCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- std::string uri;
- std::string mode;
- int result = 0;
- int execResult;
-};
-
-struct DSHelperReleaseCB {
- CBBase cbBase;
- DataShareHelper *dataShareHelper = nullptr;
- bool result = false;
-};
-
-struct DSHelperExecuteBatchCB {
- CBBase cbBase;
- std::string uri;
- std::vector> operations;
- DataShareHelper *dataShareHelper = nullptr;
- std::vector> result;
-};
-} // namespace AppExecFwk
-} // namespace OHOS
-#endif /* OHOS_APPEXECFWK_DATASHARE_COMMON_H */
diff --git a/interfaces/kits/napi/aafwk/dataShare/napi_datashare_helper.cpp b/interfaces/kits/napi/aafwk/dataShare/napi_datashare_helper.cpp
deleted file mode 100644
index 98c264fbbfa049baa115f9168ef468fd1891ff9a..0000000000000000000000000000000000000000
--- a/interfaces/kits/napi/aafwk/dataShare/napi_datashare_helper.cpp
+++ /dev/null
@@ -1,3322 +0,0 @@
-/*
- * Copyright (c) 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_datashare_helper.h"
-
-#include
-#include
-#include
-
-#include "datashare_helper.h"
-#include "data_ability_observer_interface.h"
-#include "uri.h"
-
-#include "data_ability_result.h"
-#include "hilog_wrapper.h"
-#include "message_parcel.h"
-#include "napi_base_context.h"
-#include "napi_data_ability_predicates.h"
-#include "napi_rdb_predicates.h"
-#include "napi_result_set.h"
-#include "securec.h"
-
-using namespace OHOS::AAFwk;
-using namespace OHOS::AppExecFwk;
-
-namespace OHOS {
-namespace AppExecFwk {
-namespace {
-const std::string DATASHARE_CLASS_NAME = "DataShareHelper";
-constexpr int NO_ERROR = 0;
-constexpr int INVALID_PARAMETER = -1;
-
-std::string NapiValueToStringUtf8(napi_env env, napi_value value)
-{
- std::string result = "";
- return UnwrapStringFromJS(env, value, result);
-}
-
-bool NapiValueToArrayStringUtf8(napi_env env, napi_value param, std::vector &result)
-{
- return UnwrapArrayStringFromJS(env, param, result);
-}
-}
-
-std::list> g_dataShareHelperList;
-static napi_ref g_constructorRef = nullptr;
-
-/**
- * @brief acquireDataAbilityHelper processing function.
- *
- * @param env The environment that the Node-API call is invoked under.
- * @param dataShareHelperCB Process data asynchronously.
- *
- * @return Return JS data successfully, otherwise return nullptr.
- */
-napi_value AcquireDataShareHelperWrap(napi_env env, napi_callback_info info, DataShareHelperCB *dataShareHelperCB)
-{
- HILOG_INFO("%{public}s,called", __func__);
- if (dataShareHelperCB == nullptr) {
- HILOG_ERROR("%{public}s,dataShareHelperCB == nullptr", __func__);
- return nullptr;
- }
-
- size_t requireArgc = ARGS_THREE;
- size_t argc = ARGS_THREE;
- napi_value args[ARGS_THREE] = {nullptr};
- NAPI_CALL(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr));
- if (argc > requireArgc) {
- HILOG_ERROR("%{public}s, Wrong argument count %{public}zu.", __func__, argc);
- return nullptr;
- }
-
- napi_value result = nullptr;
- napi_value cons = nullptr;
- if (napi_get_reference_value(env, g_constructorRef, &cons) != napi_ok) {
- return nullptr;
- }
- NAPI_CALL(env, napi_new_instance(env, cons, ARGS_THREE, args, &result));
-
- if (!IsTypeForNapiValue(env, result, napi_object)) {
- HILOG_ERROR("%{public}s, IsTypeForNapiValue isn`t object", __func__);
- return nullptr;
- }
-
- if (IsTypeForNapiValue(env, result, napi_null)) {
- HILOG_ERROR("%{public}s, IsTypeForNapiValue is null", __func__);
- return nullptr;
- }
-
- if (IsTypeForNapiValue(env, result, napi_undefined)) {
- HILOG_ERROR("%{public}s, IsTypeForNapiValue is undefined", __func__);
- return nullptr;
- }
-
- delete dataShareHelperCB;
- dataShareHelperCB = nullptr;
- HILOG_INFO("%{public}s,end", __func__);
- return result;
-}
-
-/**
- * @brief AcquireDataAbilityHelper.
- *
- * @param env The environment that the Node-API call is invoked under.
- * @param info The callback info passed into the callback function.
- *
- * @return The return value from NAPI C++ to JS for the module.
- */
-napi_value NAPI_AcquireDataShareHelperCommon(napi_env env, napi_callback_info info, AbilityType abilityType)
-{
- HILOG_INFO("%{public}s,called", __func__);
- DataShareHelperCB *dataShareHelperCB = new (std::nothrow) DataShareHelperCB;
- if (dataShareHelperCB == nullptr) {
- HILOG_ERROR("%{public}s, dataShareHelperCB == nullptr", __func__);
- return WrapVoidToJS(env);
- }
-
- dataShareHelperCB->cbBase.cbInfo.env = env;
- dataShareHelperCB->cbBase.errCode = NAPI_ERR_NO_ERROR;
- dataShareHelperCB->cbBase.abilityType = abilityType;
- napi_value ret = AcquireDataShareHelperWrap(env, info, dataShareHelperCB);
- if (ret == nullptr) {
- HILOG_ERROR("%{public}s, ret == nullptr", __func__);
- if (dataShareHelperCB != nullptr) {
- delete dataShareHelperCB;
- dataShareHelperCB = nullptr;
- }
- ret = WrapVoidToJS(env);
- }
- HILOG_INFO("%{public}s,end", __func__);
- return ret;
-}
-
-/**
- * @brief DataShareHelper NAPI method : CreateDataShareHelper.
- *
- * @param env The environment that the Node-API call is invoked under.
- * @param info The callback info passed into the callback function.
- *
- * @return The return value from NAPI C++ to JS for the module.
- */
-napi_value NAPI_CreateDataShareHelper(napi_env env, napi_callback_info info)
-{
- HILOG_INFO("%{public}s, called", __func__);
- return NAPI_AcquireDataShareHelperCommon(env, info, AbilityType::EXTENSION);
-}
-
-/**
- * @brief DataShareHelper NAPI module registration.
- *
- * @param env The environment that the Node-API call is invoked under.
- * @param exports An empty object via the exports parameter as a convenience.
- *
- * @return The return value from Init is treated as the exports object for the module.
- */
-napi_value DataShareHelperInit(napi_env env, napi_value exports)
-{
- HILOG_INFO("%{public}s,called", __func__);
- napi_property_descriptor properties[] = {
- DECLARE_NAPI_FUNCTION("insert", NAPI_Insert),
- DECLARE_NAPI_FUNCTION("notifyChange", NAPI_NotifyChange),
- DECLARE_NAPI_FUNCTION("on", NAPI_Register),
- DECLARE_NAPI_FUNCTION("off", NAPI_UnRegister),
- DECLARE_NAPI_FUNCTION("delete", NAPI_Delete),
- DECLARE_NAPI_FUNCTION("query", NAPI_Query),
- DECLARE_NAPI_FUNCTION("update", NAPI_Update),
- DECLARE_NAPI_FUNCTION("batchInsert", NAPI_BatchInsert),
- DECLARE_NAPI_FUNCTION("openFile", NAPI_OpenFile),
- DECLARE_NAPI_FUNCTION("getType", NAPI_GetType),
- DECLARE_NAPI_FUNCTION("getFileTypes", NAPI_GetFileTypes),
- DECLARE_NAPI_FUNCTION("normalizeUri", NAPI_NormalizeUri),
- DECLARE_NAPI_FUNCTION("denormalizeUri", NAPI_DenormalizeUri),
- DECLARE_NAPI_FUNCTION("release", NAPI_Release),
- };
-
- napi_value cons = nullptr;
- NAPI_CALL(env,
- napi_define_class(env,
- DATASHARE_CLASS_NAME.c_str(),
- NAPI_AUTO_LENGTH,
- DataShareHelperConstructor,
- nullptr,
- sizeof(properties) / sizeof(*properties),
- properties,
- &cons));
- g_dataShareHelperList.clear();
- NAPI_CALL(env, napi_create_reference(env, cons, 1, &g_constructorRef));
- NAPI_CALL(env, napi_set_named_property(env, exports, DATASHARE_CLASS_NAME.c_str(), cons));
-
- napi_property_descriptor export_properties[] = {
- DECLARE_NAPI_FUNCTION("createDataShareHelper", NAPI_CreateDataShareHelper),
- };
- NAPI_CALL(env, napi_define_properties(env, exports, sizeof(export_properties) / sizeof(export_properties[0]),
- export_properties));
- return exports;
-}
-
-napi_value DataShareHelperConstructor(napi_env env, napi_callback_info info)
-{
- HILOG_INFO("%{public}s, called", __func__);
- size_t argc = ARGS_THREE;
- napi_value argv[ARGS_THREE] = {nullptr};
- napi_value thisVar = nullptr;
- NAPI_CALL(env, napi_get_cb_info(env, info, &argc, argv, &thisVar, nullptr));
- NAPI_ASSERT(env, argc > 0, "Wrong number of arguments");
- AAFwk::Want want;
- OHOS::AppExecFwk::UnwrapWant(env, argv[PARAM1], want);
- std::string strUri = NapiValueToStringUtf8(env, argv[PARAM2]);
- std::shared_ptr dataShareHelper = nullptr;
- bool isStageMode = false;
- napi_status status = AbilityRuntime::IsStageContext(env, argv[PARAM0], isStageMode);
- if (status != napi_ok || !isStageMode) {
- auto ability = OHOS::AbilityRuntime::GetCurrentAbility(env);
- NAPI_ASSERT(env, ability != nullptr, "DataShareHelperConstructor: failed to get native ability");
- HILOG_INFO("FA Model: ability = %{public}p strUri = %{public}s", ability, strUri.c_str());
- dataShareHelper = DataShareHelper::Creator(ability->GetContext(), want, std::make_shared(strUri));
- } else {
- auto context = OHOS::AbilityRuntime::GetStageModeContext(env, argv[PARAM0]);
- NAPI_ASSERT(env, context != nullptr, "DataShareHelperConstructor: failed to get native context");
- HILOG_INFO("Stage Model: context = %{public}p strUri = %{public}s", context.get(), strUri.c_str());
- dataShareHelper = DataShareHelper::Creator(context, want, std::make_shared(strUri));
- }
- NAPI_ASSERT(env, dataShareHelper != nullptr, "DataShareHelperConstructor: dataShareHelper is nullptr");
- g_dataShareHelperList.emplace_back(dataShareHelper);
- napi_wrap(env, thisVar, dataShareHelper.get(), [](napi_env env, void *data, void *hint) {
- DataShareHelper *objectInfo = static_cast(data);
- auto helper = std::find_if(registerInstances_.begin(), registerInstances_.end(),
- [&objectInfo](const DSHelperOnOffCB *helper) { return helper->dataShareHelper == objectInfo; });
- if (helper != registerInstances_.end()) {
- HILOG_INFO("DataShareHelper finalize_cb find helper");
- (*helper)->dataShareHelper->Release();
- delete *helper;
- registerInstances_.erase(helper);
- }
- g_dataShareHelperList.remove_if([objectInfo](const std::shared_ptr &dataShareHelper) {
- return objectInfo == dataShareHelper.get();
- });
- }, nullptr, nullptr);
- HILOG_INFO("%{public}s,called end", __func__);
- return thisVar;
-}
-
-/**
- * @brief DataShareHelper NAPI method : insert.
- *
- * @param env The environment that the Node-API call is invoked under.
- * @param info The callback info passed into the callback function.
- *
- * @return The return value from NAPI C++ to JS for the module.
- */
-napi_value NAPI_Insert(napi_env env, napi_callback_info info)
-{
- HILOG_INFO("%{public}s, called", __func__);
- DSHelperInsertCB *insertCB = new (std::nothrow) DSHelperInsertCB;
- if (insertCB == nullptr) {
- HILOG_ERROR("%{public}s, insertCB == nullptr.", __func__);
- return WrapVoidToJS(env);
- }
- insertCB->cbBase.cbInfo.env = env;
- insertCB->cbBase.asyncWork = nullptr;
- insertCB->cbBase.deferred = nullptr;
- insertCB->cbBase.ability = nullptr;
-
- napi_value ret = InsertWrap(env, info, insertCB);
- if (ret == nullptr) {
- HILOG_ERROR("%{public}s, ret == nullptr.", __func__);
- if (insertCB != nullptr) {
- delete insertCB;
- insertCB = nullptr;
- }
- ret = WrapVoidToJS(env);
- }
- HILOG_INFO("%{public}s,called end", __func__);
- return ret;
-}
-
-/**
- * @brief Insert processing function.
- *
- * @param env The environment that the Node-API call is invoked under.
- * @param insertCB Process data asynchronously.
- *
- * @return Return JS data successfully, otherwise return nullptr.
- */
-napi_value InsertWrap(napi_env env, napi_callback_info info, DSHelperInsertCB *insertCB)
-{
- HILOG_INFO("%{public}s,called", __func__);
- size_t argcAsync = ARGS_THREE;
- const size_t argcPromise = ARGS_TWO;
- const size_t argCountWithAsync = argcPromise + ARGS_ASYNC_COUNT;
- napi_value args[ARGS_MAX_COUNT] = {nullptr};
- napi_value ret = 0;
- napi_value thisVar = nullptr;
-
- NAPI_CALL(env, napi_get_cb_info(env, info, &argcAsync, args, &thisVar, nullptr));
- if (argcAsync > argCountWithAsync || argcAsync > ARGS_MAX_COUNT) {
- HILOG_ERROR("%{public}s, Wrong argument count.", __func__);
- return nullptr;
- }
-
- napi_valuetype valuetype = napi_undefined;
- NAPI_CALL(env, napi_typeof(env, args[PARAM0], &valuetype));
- if (valuetype == napi_string) {
- insertCB->uri = NapiValueToStringUtf8(env, args[PARAM0]);
- HILOG_INFO("%{public}s,uri=%{public}s", __func__, insertCB->uri.c_str());
- } else {
- HILOG_ERROR("%{public}s, Wrong argument type.", __func__);
- }
-
- insertCB->valueBucket.Clear();
- AnalysisValuesBucket(insertCB->valueBucket, env, args[PARAM1]);
-
- DataShareHelper *objectInfo = nullptr;
- napi_unwrap(env, thisVar, (void **)&objectInfo);
- HILOG_INFO("%{public}s,DataShareHelper objectInfo = %{public}p", __func__, objectInfo);
- insertCB->dataShareHelper = objectInfo;
-
- if (argcAsync > argcPromise) {
- ret = InsertAsync(env, args, ARGS_TWO, insertCB);
- } else {
- ret = InsertPromise(env, insertCB);
- }
- HILOG_INFO("%{public}s,end", __func__);
- return ret;
-}
-
-void AnalysisValuesBucket(NativeRdb::ValuesBucket &valuesBucket, const napi_env &env, const napi_value &arg)
-{
- napi_value keys = 0;
- napi_get_property_names(env, arg, &keys);
- uint32_t arrLen = 0;
- napi_status status = napi_get_array_length(env, keys, &arrLen);
- if (status != napi_ok) {
- HILOG_ERROR("ValuesBucket errr");
- return;
- }
- HILOG_INFO("ValuesBucket num:%{public}d ", arrLen);
- for (size_t i = 0; i < arrLen; ++i) {
- napi_value key = 0;
- status = napi_get_element(env, keys, i, &key);
- std::string keyStr = UnwrapStringFromJS(env, key);
- napi_value value = 0;
- napi_get_property(env, arg, key, &value);
-
- SetValuesBucketObject(valuesBucket, env, keyStr, value);
- }
-}
-
-void SetValuesBucketObject(
- NativeRdb::ValuesBucket &valuesBucket, const napi_env &env, std::string keyStr, napi_value value)
-{
- napi_valuetype valueType = napi_undefined;
- napi_typeof(env, value, &valueType);
- if (valueType == napi_string) {
- std::string valueString = UnwrapStringFromJS(env, value);
- HILOG_INFO("ValueObject type:%{public}d, key:%{public}s, value:%{public}s",
- valueType,
- keyStr.c_str(),
- valueString.c_str());
- valuesBucket.PutString(keyStr, valueString);
- } else if (valueType == napi_number) {
- double valueNumber = 0;
- napi_get_value_double(env, value, &valueNumber);
- valuesBucket.PutDouble(keyStr, valueNumber);
- HILOG_INFO(
- "ValueObject type:%{public}d, key:%{public}s, value:%{public}lf", valueType, keyStr.c_str(), valueNumber);
- } else if (valueType == napi_boolean) {
- bool valueBool = false;
- napi_get_value_bool(env, value, &valueBool);
- HILOG_INFO(
- "ValueObject type:%{public}d, key:%{public}s, value:%{public}d", valueType, keyStr.c_str(), valueBool);
- valuesBucket.PutBool(keyStr, valueBool);
- } else if (valueType == napi_null) {
- valuesBucket.PutNull(keyStr);
- HILOG_INFO("ValueObject type:%{public}d, key:%{public}s, value:null", valueType, keyStr.c_str());
- } else if (valueType == napi_object) {
- HILOG_INFO("ValueObject type:%{public}d, key:%{public}s, value:Uint8Array", valueType, keyStr.c_str());
- valuesBucket.PutBlob(keyStr, ConvertU8Vector(env, value));
- } else {
- HILOG_ERROR("valuesBucket error");
- }
-}
-napi_value InsertAsync(napi_env env, napi_value *args, const size_t argCallback, DSHelperInsertCB *insertCB)
-{
- HILOG_INFO("%{public}s, asyncCallback.", __func__);
- if (args == nullptr || insertCB == nullptr) {
- HILOG_ERROR("%{public}s, param == nullptr.", __func__);
- return nullptr;
- }
- napi_value resourceName = 0;
- NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
-
- napi_valuetype valuetype = napi_undefined;
- NAPI_CALL(env, napi_typeof(env, args[argCallback], &valuetype));
- if (valuetype == napi_function) {
- NAPI_CALL(env, napi_create_reference(env, args[argCallback], 1, &insertCB->cbBase.cbInfo.callback));
- }
-
- NAPI_CALL(env,
- napi_create_async_work(env,
- nullptr,
- resourceName,
- InsertExecuteCB,
- InsertAsyncCompleteCB,
- (void *)insertCB,
- &insertCB->cbBase.asyncWork));
- NAPI_CALL(env, napi_queue_async_work(env, insertCB->cbBase.asyncWork));
- napi_value result = 0;
- NAPI_CALL(env, napi_get_null(env, &result));
- HILOG_INFO("%{public}s, asyncCallback end", __func__);
- return result;
-}
-
-napi_value InsertPromise(napi_env env, DSHelperInsertCB *insertCB)
-{
- HILOG_INFO("%{public}s, promise.", __func__);
- if (insertCB == nullptr) {
- HILOG_ERROR("%{public}s, param == nullptr.", __func__);
- return nullptr;
- }
- napi_value resourceName;
- NAPI_CALL(env, napi_create_string_latin1(env, __func__, NAPI_AUTO_LENGTH, &resourceName));
- napi_deferred deferred;
- napi_value promise = 0;
- NAPI_CALL(env, napi_create_promise(env, &deferred, &promise));
- insertCB->cbBase.deferred = deferred;
-
- NAPI_CALL(env,
- napi_create_async_work(env,
- nullptr,
- resourceName,
- InsertExecuteCB,
- InsertPromiseCompleteCB,
- (void *)insertCB,
- &insertCB->cbBase.asyncWork));
- NAPI_CALL(env, napi_queue_async_work(env, insertCB->cbBase.asyncWork));
- HILOG_INFO("%{public}s, promise end", __func__);
- return promise;
-}
-
-void InsertExecuteCB(napi_env env, void *data)
-{
- HILOG_INFO("NAPI_Insert, worker pool thread execute.");
- DSHelperInsertCB *insertCB = static_cast(data);
- if (insertCB->dataShareHelper != nullptr) {
- insertCB->execResult = INVALID_PARAMETER;
- if (!insertCB->uri.empty()) {
- OHOS::Uri uri(insertCB->uri);
- insertCB->result = insertCB->dataShareHelper->Insert(uri, insertCB->valueBucket);
- insertCB->execResult = NO_ERROR;
- }
- } else {
- HILOG_ERROR("NAPI_Insert, dataShareHelper == nullptr.");
- }
- HILOG_INFO("NAPI_Insert, worker pool thread execute end.");
-}
-
-void InsertAsyncCompleteCB(napi_env env, napi_status status, void *data)
-{
- HILOG_INFO("NAPI_Insert, main event thread complete.");
- DSHelperInsertCB *insertCB = static_cast