diff --git a/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp b/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp index 2ebcca46e717289c6bf2ef4b1de676a8e457ccab..123ed09550c2377e7c69e0d12c88fc68a87887fc 100644 --- a/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp +++ b/interfaces/kits/ani/shortcut_manager/ani_shortcut_manager.cpp @@ -31,6 +31,30 @@ constexpr const char* PARSE_SHORTCUT_INFO = "ParseShortCutInfo"; constexpr const char* NS_NAME_SHORTCUTMANAGER = "@ohos.bundle.shortcutManager.shortcutManager"; } +static void AniSetShortcutVisibleForSelf(ani_env* env, ani_object info, ani_string aniShortcutId, ani_boolean aniVisible) +{ + APP_LOGD("ani SetShortcutVisibleForSelf called"); + std::string shortcutId; + if (!CommonFunAni::ParseString(env, aniShortcutId, shortcutId)) { + APP_LOGE("shortcutId %{public}s invalid", shortcutId.c_str()); + BusinessErrorAni::ThrowCommonError(env, ERROR_PARAM_CHECK_ERROR, SHORT_CUT_ID, TYPE_STRING); + return nullptr; + } + bool visible = CommonFunAni::AniBooleanToBool(aniVisible); + auto iBundleMgr = CommonFunc::GetBundleMgr(); + if (iBundleMgr == nullptr) { + BusinessErrorAni::ThrowError(env, ERR_APPEXECFWK_SERVICE_NOT_READY, SET_SHORTCUT_VISIBLE_FOR_SELF); + return; + } + ErrCode ret = iBundleMgr->SetShortcutVisibleForSelf(shortcutId, visible); + if (ret != ERR_OK) { + APP_LOGE("SetShortcutVisibleForSelf failed ret:%{public}d, shortcutId:%{public}s, visible:%{public}d", + ret, shortcutId.c_str(), visible); + BusinessErrorAni::ThrowCommonError( + env, CommonFunc::ConvertErrCode(ret), SET_SHORTCUT_VISIBLE_FOR_SELF, Constants::PERMISSION_MANAGER_SHORTCUT); + } +} + static void AniAddDesktopShortcutInfo(ani_env* env, ani_object info, ani_double aniUserId) { APP_LOGD("ani AddDesktopShortcutInfo called"); @@ -155,6 +179,8 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm* vm, uint32_t* result) reinterpret_cast(AniDeleteDesktopShortcutInfo) }, ani_native_function { "getAllDesktopShortcutInfoNative", nullptr, reinterpret_cast(AniGetAllDesktopShortcutInfo) }, + ani_native_function { "setShortcutVisibleForSelfNative", nullptr, + reinterpret_cast(AniSetShortcutVisibleForSelf) }, }; status = env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()); diff --git a/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets b/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets index d5c64e1e7136f1f1fbb35cb07d685ff43b5fc258..70a68eaa0ea013ec90b758f022240bd1f084c384 100644 --- a/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets +++ b/interfaces/kits/ani/shortcut_manager/ets/@ohos.bundle.shortcutManager.ets @@ -23,6 +23,7 @@ namespace shortcutManager { export native function addDesktopShortcutInfoNative(shortcutInfo: ShortcutInfo, userId: number): void; export native function deleteDesktopShortcutInfoNative(shortcutInfo: ShortcutInfo, userId: number): void; export native function getAllDesktopShortcutInfoNative(userId: number): Array; + export native function setShortcutVisibleForSelfNative(shortcutId: string, visible: boolean): void; function addDesktopShortcutInfo(shortcutInfo: ShortcutInfo, userId: number): Promise { let p = new Promise((resolve: (v: undefined) => void, reject: (error: BusinessError) => void): void => { @@ -70,6 +71,21 @@ namespace shortcutManager { return p; } + function setShortcutVisibleForSelf(shortcutId: string, visible: boolean): Promise { + let p = new Promise((resolve: (v: undefined) => void, reject: (error: BusinessError) => void): void => { + let cb = (): NullishType => { + return shortcutManager.setShortcutVisibleForSelfNative(shortcutId, visible); + } + let p1 = taskpool.execute(cb); + p1.then((): void => { + resolve(undefined); + }, (err: Error): void => { + reject(err as BusinessError); + }); + }); + return p; + } + export type ShortcutInfo = _ShortcutInfo; export type ShortcutWant = _ShortcutWant; export type ParameterItem = _ParameterItem; diff --git a/interfaces/kits/js/common/napi_constants.h b/interfaces/kits/js/common/napi_constants.h index 87ec27297619a7e08eef0af702ddde942005844e..59f3b87abb224866cf9e1edb348761cf29439428 100644 --- a/interfaces/kits/js/common/napi_constants.h +++ b/interfaces/kits/js/common/napi_constants.h @@ -43,6 +43,7 @@ constexpr const char* TYPE_ARRAY = "array"; constexpr const char* UID = "uid"; constexpr const char* USER_ID = "userId"; +constexpr const char* SHORT_CUT_ID = "shortCutId"; constexpr const char* BUNDLE_NAME = "bundleName"; constexpr const char* MODULE_NAME = "moduleName"; constexpr const char* ABILITY_NAME = "abilityName"; @@ -74,6 +75,7 @@ constexpr const char* RESOURCE_FLAGS = "resourceFlags"; constexpr const char* ADD_DESKTOP_SHORTCUT_INFO = "AddDesktopShortcutInfo"; constexpr const char* DELETE_DESKTOP_SHORTCUT_INFO = "DeleteDesktopShortcutInfo"; constexpr const char* GET_ALL_DESKTOP_SHORTCUT_INFO = "GetAllDesktopShortcutInfo"; +constexpr const char* SET_SHORTCUT_VISIBLE_FOR_SELF = "SetShortcutVisibleForSelf"; } } }