From 954724646283e3bd9d626bb10d73775be76c10a8 Mon Sep 17 00:00:00 2001 From: igorlegalov Date: Tue, 15 Jul 2025 18:54:48 +0300 Subject: [PATCH] Remove NullishType alias Issue: https://gitee.com/open_harmony/dashboard?issue_id=ICW8Y8 Testing: all pre-merge tests passed Signed-off-by: igorlegalov --- .../ani/file_share/ets/@ohos.fileshare.ets | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 interfaces/kits/ani/file_share/ets/@ohos.fileshare.ets diff --git a/interfaces/kits/ani/file_share/ets/@ohos.fileshare.ets b/interfaces/kits/ani/file_share/ets/@ohos.fileshare.ets new file mode 100644 index 000000000..edfa94547 --- /dev/null +++ b/interfaces/kits/ani/file_share/ets/@ohos.fileshare.ets @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2025 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 type { AsyncCallback } from '@ohos.base'; +import { BusinessError } from '@ohos.base'; +import type wantConstant from '@ohos.app.ability.wantConstant'; +import hilog from '@ohos.hilog' + +export namespace fileShare { + loadLibrary("fileshare_ani") + + export enum OperationMode { + READ_MODE = 0b1, + WRITE_MODE = 0b10 + } + export interface PolicyInfo { + uri: string; + operationMode: int; + } + + class PolicyInfo_inner implements PolicyInfo { + uri: string; + operationMode: int; + } + + export function grantUriPermission(uri: string, bundleName: string, flag: wantConstant.Flags, + callback: AsyncCallback): void { + hilog.info(0x0000, 'grantUriPermission', "Start grantUriPermission in callback main thread."); + let p1 = taskpool.execute(grantUriPermissionSync, uri, bundleName, flag); + p1.then((data: Any) => { + let ret = data as int; + hilog.info(0x0000, 'grantUriPermission', "grantUriPermission ret = " + ret); + let error: BusinessError; + callback(error, undefined); + }); + p1.catch((err: Any) => { + hilog.info(0x0000, 'grantUriPermission', "grantUriPermission catch in callback thread."); + let error = err as BusinessError; + callback(error, undefined); + }); + } + + export function grantUriPermission(uri: string, bundleName: string, flag: wantConstant.Flags): Promise { + hilog.info(0x0000, 'grantUriPermission', "Start grantUriPermission in promise main thread"); + let p = new Promise((resolve: (value: PromiseLike) => void, reject: (error: Error) => void): void => { + let p1 = taskpool.execute(grantUriPermissionSync, uri, bundleName, flag); + p1.then((e: Any): void => { + resolve(Promise.resolve()); + }); + p1.catch((e: Error): void => { + hilog.info(0x0000, 'grantUriPermission', "grantUriPermission catch in promise thread."); + reject(e); + }); + }); + return p; + } + + export function grantUriPermissionSync(uri: string, bundleName: string, flag: wantConstant.Flags): int { + try { + grantUriPermissionInner(uri, bundleName, flag); + } catch (error) { + hilog.info(0x0000, 'grantUriPermission', "grantUriPermissionInner catch error"); + return -1; + } + return 0; + } + native function grantUriPermissionInner(uri: string, bundleName: string, flag: wantConstant.Flags):void; +} -- Gitee