diff --git a/api/@ohos.application.DataShareExtensionAbility.d.ts b/api/@ohos.application.DataShareExtensionAbility.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..dce6c206a8ff9926c35894233dfb8fa8da70de1d --- /dev/null +++ b/api/@ohos.application.DataShareExtensionAbility.d.ts @@ -0,0 +1,173 @@ +/* + * 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. + */ + +import { AsyncCallback } from "./basic"; +import { ResultSet } from './data/rdb/resultSet'; +import ExtensionContext from "./application/ExtensionContext"; +import Want from './@ohos.application.Want'; +import dataAbility from './@ohos.data.dataAbility'; +import rdb from './@ohos.data.rdb'; + +/** + * class of datashare extension ability. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi Hide this for inner system use. + */ +export default class DataShareExtensionAbility { + /** + * Indicates datashare extension ability context. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @systemapi Hide this for inner system use. + */ + context?: ExtensionContext; + + /** + * Called back when a datashare extension ability is started for initialization. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @param want Indicates connection information about the datashare extension ability. + * @systemapi Hide this for inner system use. + * @return - + */ + onCreate?(want: Want): void; + + /** + * Obtains the MIME type of files. This method should be implemented by a data share. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @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}. + *

1. "*/*": Obtains all types supported by a data share. + *

2. "image/*": Obtains files whose main type is image of any subtype. + *

3. "*/jpg": Obtains files whose subtype is JPG of any main type. + * @systemapi Hide this for inner system use. + * @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; + + /** + * Inserts a data record into the database. This method should be implemented by a data share. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @param uri Indicates the position where the data is to insert. + * @param valueBucket Indicates the data to insert. + * @systemapi Hide this for inner system use. + * @return Returns the index of the newly inserted data record. + */ + insert?(uri: string, valueBucket: rdb.ValuesBucket): number; + + /** + * Updates one or more data records in the database. This method should be implemented by a data share. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @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 + * default. + * @systemapi Hide this for inner system use. + * @return Returns the number of data records updated. + */ + update?(uri: string, valueBucket: rdb.ValuesBucket, predicates: dataAbility.DataAbilityPredicates): number; + + /** + * Deletes one or more data records. This method should be implemented by a data share. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @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. + * @systemapi Hide this for inner system use. + * @return Returns the number of data records deleted. + */ + delete?(uri: string, predicates: dataAbility.DataAbilityPredicates): number; + + /** + * Queries one or more data records in the database. This method should be implemented by a data share. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @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. + * @param predicates Indicates filter criteria. If this parameter is null, all data records will be queried by + * default. + * @systemapi Hide this for inner system use. + * @return Returns the queried data. + */ + query?(uri: string, columns: Array, predicates: dataAbility.DataAbilityPredicates): ResultSet; + + /** + * 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.DistributedDataManager.DataShare.Provider + * @param uri Indicates the uri of the data. + * @systemapi Hide this for inner system use. + * @return Returns the MIME type that matches the data specified by {@code uri}. + */ + getType?(uri: string): string; + + /** + * Inserts multiple data records into the database. This method should be implemented by a data share. + * + * @since 9 + * @syscap SystemCapability.DistributedDataManager.DataShare.Provider + * @param uri Indicates the position where the data is to insert. + * @param valueBuckets Indicates the data to insert. + * @systemapi Hide this for inner system use. + * @return Returns the number of data records inserted. + */ + batchInsert?(uri: string, valueBuckets: Array): number; + + /** + * 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.DistributedDataManager.DataShare.Provider + * @param uri Indicates the uri to normalize. + * @systemapi Hide this for inner system use. + * @return Returns the normalized uri if the data share supports URI normalization; + */ + normalizeUri?(uri: string): string; + + /** + * 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.DistributedDataManager.DataShare.Provider + * @param uri Indicates the uri to denormalize. + * @systemapi Hide this for inner system use. + * @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; +} \ No newline at end of file diff --git a/api/@ohos.data.dataShare.d.ts b/api/@ohos.data.dataShare.d.ts new file mode 100644 index 0000000000000000000000000000000000000000..75fe6877d821114146c6e6ab7d17f537271e0b3e --- /dev/null +++ b/api/@ohos.data.dataShare.d.ts @@ -0,0 +1,198 @@ +/* +* 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. +*/ + +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.DistributedDataManager.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.DistributedDataManager.DataShare.Consumer + * @systemapi Hide this for inner system use. + */ + interface DataShareHelper { + /** + * Registers an observer to observe data specified by the given uri. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.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.DistributedDataManager.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.DistributedDataManager.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, value: ValuesBucket, callback: AsyncCallback): void; + insert(URI: string, value: ValuesBucket): Promise; + + /** + * Deletes one or more data records from the database. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.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.DistributedDataManager.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.DistributedDataManager.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, value: ValuesBucket, predicates: DataSharePredicates, callback: AsyncCallback): void; + update(URI: string, value: ValuesBucket, predicates: DataSharePredicates): Promise; + + /** + * Inserts multiple data records into the database. + * @since 9 + * @syscap SystemCapability.DistributedDataManager.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.DistributedDataManager.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.DistributedDataManager.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.DistributedDataManager.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.DistributedDataManager.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.DistributedDataManager.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;