diff --git a/interfaces/kits/ani/BUILD.gn b/interfaces/kits/ani/BUILD.gn index e5994fca066e39d555c49c7848f05eb307ce94bd..1a8ef92099c99d387411b2ba082de828af6b06b0 100755 --- a/interfaces/kits/ani/BUILD.gn +++ b/interfaces/kits/ani/BUILD.gn @@ -29,6 +29,10 @@ group("ani_bms_packages") { "bundle_manager:hap_module_info_etc", "bundle_manager:metadata_etc", "bundle_manager:skill_etc", + "launcher_bundle_manager:ani_launcher_bundle_manager", + "launcher_bundle_manager:element_name_etc", + "launcher_bundle_manager:launcher_ability_info_etc", + "launcher_bundle_manager:launcher_bundle_manager_etc", "resource_manager:ani_bundle_res_manager", "resource_manager:bundle_resource_info_etc", "resource_manager:bundle_resource_manager_etc", diff --git a/interfaces/kits/ani/common/common_fun_ani.cpp b/interfaces/kits/ani/common/common_fun_ani.cpp index 473f0bf110c9fe4420fff69fb271fd09aff3e06e..5e0eb116761ed4a6124ae1d3991d02291c521706 100644 --- a/interfaces/kits/ani/common/common_fun_ani.cpp +++ b/interfaces/kits/ani/common/common_fun_ani.cpp @@ -49,6 +49,7 @@ constexpr const char* CLASSNAME_BUNDLERESINFO = "LbundleManager/BundleResourceIn constexpr const char* CLASSNAME_SHORTCUTINFO = "LbundleManager/ShortcutInfo/ShortcutInfoInner;"; constexpr const char* CLASSNAME_SHORTCUTWANT = "LbundleManager/ShortcutInfo/ShortcutWantInner;"; constexpr const char* CLASSNAME_SHORTCUT_PARAMETERITEM = "LbundleManager/ShortcutInfo/ParameterItemInner;"; +constexpr const char* CLASSNAME_LAUNCHERABILITY = "LbundleManager/LauncherAbilityInfoInner/LauncherAbilityInfoInner;"; constexpr const char* PROPERTYNAME_NAME = "name"; constexpr const char* PROPERTYNAME_VENDOR = "vendor"; @@ -170,6 +171,8 @@ constexpr const char* PROPERTYNAME_TARGETBUNDLE = "targetBundle"; constexpr const char* PROPERTYNAME_TARGETMODULE = "targetModule"; constexpr const char* PROPERTYNAME_TARGETABILITY = "targetAbility"; constexpr const char* PROPERTYNAME_PARAMETERS = "parameters"; +constexpr const char* PROPERTYNAME_ELEMENTNAME = "elementName"; +constexpr const char* PROPERTYNAME_USERID = "userId"; constexpr const char* PATH_PREFIX = "/data/app/el1/bundle/public"; constexpr const char* CODE_PATH_PREFIX = "/data/storage/el1/bundle/"; @@ -1425,6 +1428,42 @@ inline ani_object CommonFunAni::ConvertShortcutIntentParameter( return ConvertKeyValuePair(env, item, CLASSNAME_SHORTCUT_PARAMETERITEM); } + +ani_object CommonFunAni::ConvertLauncherAbilityInfo(ani_env* env, const LauncherAbilityInfo &launcherAbility) +{ + RETURN_NULL_IF_NULL(env); + + ani_class cls = CreateClassByName(env, CLASSNAME_LAUNCHERABILITY); + RETURN_NULL_IF_NULL(cls); + + ani_object object = CreateNewObjectByClass(env, cls); + RETURN_NULL_IF_NULL(object); + + // applicationInfo: ApplicationInfo; + ani_object aObject = ConvertApplicationInfo(env, launcherAbility.applicationInfo); + RETURN_NULL_IF_NULL(aObject); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_APPLICATIONINFO, aObject)); + + // elementName: ElementName; + ani_object aElementNameObject = ConvertElementName(env, launcherAbility.elementName); + RETURN_NULL_IF_NULL(aElementNameObject); + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ELEMENTNAME, aElementNameObject)); + + // labelId: number; + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_LABELID, launcherAbility.labelId)); + + // iconId: number; + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_ICONID, launcherAbility.iconId)); + + // userId: number; + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_USERID, launcherAbility.userId)); + + // installTime: number; + RETURN_NULL_IF_FALSE(CallSetter(env, cls, object, PROPERTYNAME_INSTALLTIME, launcherAbility.installTime)); + + return object; +} + bool CommonFunAni::ParseShortcutInfo(ani_env* env, ani_object object, ShortcutInfo& shortcutInfo) { RETURN_FALSE_IF_NULL(env); diff --git a/interfaces/kits/ani/common/common_fun_ani.h b/interfaces/kits/ani/common/common_fun_ani.h index 27356fa1296f9300a7225d78037691ebeb92eafb..cbf0a1a100225af779345033a99119abe8a81c4a 100644 --- a/interfaces/kits/ani/common/common_fun_ani.h +++ b/interfaces/kits/ani/common/common_fun_ani.h @@ -26,6 +26,7 @@ #include "app_log_wrapper.h" #include "bundle_mgr_interface.h" #include "bundle_resource_info.h" +#include "launcher_ability_info.h" namespace OHOS { namespace AppExecFwk { @@ -140,6 +141,8 @@ public: static ani_object ConvertShortcutIntent(ani_env* env, const ShortcutIntent& shortcutIntent); static ani_object ConvertShortcutIntentParameter(ani_env* env, const std::pair& item); + static ani_object ConvertLauncherAbilityInfo(ani_env* env, const LauncherAbilityInfo &launcherAbility); + // Parse from ets to native static bool ParseShortcutInfo(ani_env* env, ani_object object, ShortcutInfo& shortcutInfo); static bool ParseShortcutIntent(ani_env* env, ani_object object, ShortcutIntent& shortcutIntent); diff --git a/interfaces/kits/ani/launcher_bundle_manager/BUILD.gn b/interfaces/kits/ani/launcher_bundle_manager/BUILD.gn index 597186e709b049cb5655e46cbb51ab07f1530ff4..2f377a0e8e66d058b6b6c2ccf9142b4c74cd1031 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/BUILD.gn +++ b/interfaces/kits/ani/launcher_bundle_manager/BUILD.gn @@ -26,7 +26,11 @@ ohos_shared_library("ani_launcher_bundle_manager") { "${kits_path}/ani/launcher_bundle_manager", "${kits_path}/js/launcher_bundle_manager", ] - sources = [ "ani_launcher_bundle_manager.cpp" ] + if (bundle_framework_launcher) { + sources = [ "ani_launcher_bundle_manager.cpp" ] + } else { + sources = [ "ani_launcher_bundle_manager_unsupported.cpp" ] + } defines = [ "APP_LOG_TAG = \"BMS\"", @@ -71,3 +75,40 @@ ohos_prebuilt_etc("launcher_bundle_manager_etc") { part_name = "bundle_framework" deps = [ ":launcher_bundle_manager" ] } + +generate_static_abc("element_name") { + base_url = "./ets" + files = [ + "./ets/bundleManager/ElementName.ets", + "./ets/bundleManager/ElementNameInner.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/element_name.abc" +} + +ohos_prebuilt_etc("element_name_etc") { + source = "$target_out_dir/element_name.abc" + module_install_dir = "framework" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" + deps = [ ":element_name" ] +} + +generate_static_abc("launcher_ability_info") { + base_url = "./ets" + files = [ + "./ets/bundleManager/LauncherAbilityInfo.ets", + "./ets/bundleManager/LauncherAbilityInfoInner.ets", + ] + is_boot_abc = "True" + device_dst_file = "/system/framework/launcher_ability_info.abc" + external_dependencies = [ "bundle_framework:copy_bundleManager_ets" ] +} + +ohos_prebuilt_etc("launcher_ability_info_etc") { + source = "$target_out_dir/launcher_ability_info.abc" + module_install_dir = "framework" + subsystem_name = "bundlemanager" + part_name = "bundle_framework" + deps = [ ":launcher_ability_info" ] +} \ No newline at end of file diff --git a/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager.cpp b/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager.cpp index 220d0d188379edcf28df39320eb987f6c1ea5d25..0a40d6c674e99576f90f01ef22a15c9d3331e9ef 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager.cpp +++ b/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager.cpp @@ -40,6 +40,8 @@ const std::map START_SHORTCUT_RES_MAP = { { ERR_OK, ERR_OK }, { ERR_NOT_SYSTEM_APP, ERR_BUNDLE_MANAGER_SYSTEM_API_DENIED } }; constexpr const char* GET_SHORTCUT_INFO_SYNC = "GetShortcutInfoSync"; +constexpr const char* GET_LAUNCHER_ABILITY_INFO_SYNC = "GetLauncherAbilityInfoSync"; +constexpr const char* GET_ALL_LAUNCHER_ABILITY_INFO = "GetAllLauncherAbilityInfo"; constexpr const char* PERMISSION_GET_BUNDLE_INFO_PRIVILEGED = "ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"; constexpr const char* ERROR_EMPTY_WANT = "want in ShortcutInfo cannot be empty"; constexpr const char* ERROR_EMPTY_BUNDLE_NAME = "bundle name is empty"; @@ -127,6 +129,91 @@ static ani_object GetShortcutInfoSync([[maybe_unused]] ani_env *env, ani_string return arrayShortcutInfos; } +static ani_ref GetLauncherAbilityInfoSync([[maybe_unused]] ani_env *env, + ani_string aniBundleName, ani_double aniUserId) +{ + std::string bundleName = CommonFunAni::AniStrToString(env, aniBundleName); + if (bundleName.empty()) { + APP_LOGE("BundleName is empty"); + BusinessErrorAni::ThrowError(env, ERROR_PARAM_CHECK_ERROR, ERROR_EMPTY_BUNDLE_NAME); + return nullptr; + } + int32_t userId = 0; + if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + APP_LOGE("try cast userId failed"); + BusinessErrorAni::ThrowParameterTypeError( + env, ERROR_PARAM_CHECK_ERROR, Constants::USER_ID, CommonFunAniNS::TYPE_INT); + return nullptr; + } + + auto launcherService = JSLauncherService::GetLauncherService(); + if (launcherService == nullptr) { + APP_LOGE("launcherService is nullptr"); + BusinessErrorAni::ThrowParameterTypeError( + env, ERROR_BUNDLE_SERVICE_EXCEPTION, + GET_LAUNCHER_ABILITY_INFO_SYNC, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + std::vector launcherAbilityInfos; + ErrCode ret = CommonFunc::ConvertErrCode(launcherService-> + GetLauncherAbilityByBundleName(bundleName, userId, launcherAbilityInfos)); + if (ret != ERR_OK) { + APP_LOGE( + "GetLauncherAbilityByBundleName failed ret:%{public}d,bundleName:%{public}s,userId:%{public}d", + ret, bundleName.c_str(), userId); + BusinessErrorAni::ThrowParameterTypeError( + env, ret, GET_LAUNCHER_ABILITY_INFO_SYNC, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + ani_ref launcherAbilityInfosRef = CommonFunAni::ConvertAniArray( + env, launcherAbilityInfos, CommonFunAni::ConvertLauncherAbilityInfo); + if (launcherAbilityInfosRef == nullptr) { + APP_LOGE("nullptr launcherAbilityInfosRef"); + } + + return launcherAbilityInfosRef; +} + +static ani_ref GetAllLauncherAbilityInfo([[maybe_unused]] ani_env *env, ani_double aniUserId) +{ + int32_t userId = 0; + if (!CommonFunAni::TryCastDoubleTo(aniUserId, &userId)) { + APP_LOGE("try cast userId failed"); + BusinessErrorAni::ThrowParameterTypeError( + env, ERROR_PARAM_CHECK_ERROR, Constants::USER_ID, CommonFunAniNS::TYPE_INT); + return nullptr; + } + + auto launcherService = JSLauncherService::GetLauncherService(); + if (launcherService == nullptr) { + APP_LOGE("launcherService is nullptr"); + BusinessErrorAni::CreateCommonError( + env, CommonFunc::ConvertErrCode(ERROR_BUNDLE_SERVICE_EXCEPTION), + GET_ALL_LAUNCHER_ABILITY_INFO, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + std::vector launcherAbilityInfos; + ErrCode ret = launcherService->GetAllLauncherAbility(userId, launcherAbilityInfos); + if (ret != ERR_OK) { + APP_LOGE("GetAllLauncherAbility failed ret:%{public}d,userId:%{public}d", ret, userId); + BusinessErrorAni::CreateCommonError( + env, CommonFunc::ConvertErrCode(ret), + GET_ALL_LAUNCHER_ABILITY_INFO, Constants::PERMISSION_GET_BUNDLE_INFO_PRIVILEGED); + return nullptr; + } + + ani_ref launcherAbilityInfosRef = CommonFunAni::ConvertAniArray( + env, launcherAbilityInfos, CommonFunAni::ConvertLauncherAbilityInfo); + if (launcherAbilityInfosRef == nullptr) { + APP_LOGE("nullptr launcherAbilityInfosRef"); + } + + return launcherAbilityInfosRef; +} + extern "C" { ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) { @@ -162,6 +249,16 @@ ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) "Lstd/core/String;D:Lescompat/Array;", reinterpret_cast(GetShortcutInfoSync) }, + ani_native_function { + "GetLauncherAbilityInfoSync", + "Lstd/core/String;D:Lescompat/Array;", + reinterpret_cast(GetLauncherAbilityInfoSync) + }, + ani_native_function { + "GetAllLauncherAbilityInfo", + "D:Lescompat/Array;", + reinterpret_cast(GetAllLauncherAbilityInfo) + }, }; if (env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()) != ANI_OK) { diff --git a/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager_unsupported.cpp b/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager_unsupported.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dbb33596edc137a566381a76f275e69248933381 --- /dev/null +++ b/interfaces/kits/ani/launcher_bundle_manager/ani_launcher_bundle_manager_unsupported.cpp @@ -0,0 +1,116 @@ +/* + * 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. + */ +#include "app_log_wrapper.h" +#include "bundle_errors.h" +#include "business_error_ani.h" +#include "common_func.h" + +namespace OHOS { +namespace AppExecFwk { +namespace { +constexpr const char* START_SHORTCUT = "StartShortcut"; +constexpr const char* GET_SHORTCUT_INFO_SYNC = "GetShortcutInfoSync"; +constexpr const char* GET_LAUNCHER_ABILITY_INFO_SYNC = "GetLauncherAbilityInfoSync"; +constexpr const char* GET_ALL_LAUNCHER_ABILITY_INFO = "GetAllLauncherAbilityInfo"; +} + +static void StartShortcut([[maybe_unused]] ani_env *env, ani_object aniShortcutInfo) +{ + APP_LOGE("SystemCapability.BundleManager.BundleFramework.Launcher not supported"); + BusinessErrorAni::ThrowParameterTypeError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, START_SHORTCUT, ""); + return nullptr; +} + +static ani_object GetShortcutInfoSync([[maybe_unused]] ani_env *env, ani_string aniBundleName, ani_double aniUserId) +{ + APP_LOGE("SystemCapability.BundleManager.BundleFramework.Launcher not supported"); + BusinessErrorAni::ThrowParameterTypeError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_SHORTCUT_INFO_SYNC, ""); + return nullptr; +} + +static ani_object GetLauncherAbilityInfoSync([[maybe_unused]] ani_env *env, + ani_string aniBundleName, ani_double aniUserId) +{ + APP_LOGE("SystemCapability.BundleManager.BundleFramework.Launcher not supported"); + BusinessErrorAni::ThrowParameterTypeError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_LAUNCHER_ABILITY_INFO_SYNC, ""); + return nullptr; +} + +static ani_object GetAllLauncherAbilityInfo([[maybe_unused]] ani_env *env, ani_double aniUserId) +{ + APP_LOGE("SystemCapability.BundleManager.BundleFramework.Launcher not supported"); + BusinessErrorAni::ThrowParameterTypeError(env, ERROR_SYSTEM_ABILITY_NOT_FOUND, GET_ALL_LAUNCHER_ABILITY_INFO, ""); + return nullptr; +} + +extern "C" { +ANI_EXPORT ani_status ANI_Constructor(ani_vm *vm, uint32_t *result) +{ + APP_LOGI("ANI_Constructor called"); + ani_env* env; + if (vm == nullptr) { + APP_LOGE("ANI_Constructor vm is nullptr"); + return static_cast(ANI_CONSTRUCTOR_ENV_ERR); + } + if (vm->GetEnv(ANI_VERSION_1, &env) != ANI_OK) { + APP_LOGE("Unsupported ANI_VERSION_1"); + return static_cast(ANI_CONSTRUCTOR_ENV_ERR); + } + if (env == nullptr) { + APP_LOGE("ANI_Constructor env is nullptr"); + return static_cast(ANI_CONSTRUCTOR_ENV_ERR); + } + static const char* nsName = "L@ohos/bundle/launcherBundleManager/launcherBundleManager;"; + ani_namespace kitNs; + if (env->FindNamespace(nsName, &kitNs) != ANI_OK) { + APP_LOGE("Not found nameSpace name: %{public}s", nsName); + return static_cast(ANI_CONSTRUCTOR_FIND_NAMESPACE_ERR); + } + + std::array methods = { + ani_native_function { + "StartShortcutSync", + "LbundleManager/ShortcutInfo/ShortcutInfo;:V", + reinterpret_cast(StartShortcutSync) + }, + ani_native_function { + "GetShortcutInfoSync", + "Lstd/core/String;D:Lescompat/Array;", + reinterpret_cast(GetShortcutInfoSync) + }, + ani_native_function { + "GetLauncherAbilityInfoSync", + "Lstd/core/String;D:Lescompat/Array;", + reinterpret_cast(GetLauncherAbilityInfoSync) + }, + ani_native_function { + "GetAllLauncherAbilityInfo", + "D:Lescompat/Array;", + reinterpret_cast(GetAllLauncherAbilityInfo) + }, + }; + + if (env->Namespace_BindNativeFunctions(kitNs, methods.data(), methods.size()) != ANI_OK) { + APP_LOGE("Cannot bind native methods to %{public}s", nsName); + return static_cast(ANI_CONSTRUCTOR_BIND_NATIVE_FUNC_ERR); + }; + + *result = ANI_VERSION_1; + APP_LOGI("ANI_Constructor finished"); + return ANI_OK; +} +} // extern "C" +} // AppExecFwk +} // OHOS \ No newline at end of file diff --git a/interfaces/kits/ani/launcher_bundle_manager/ets/@ohos.bundle.launcherBundleManager.ets b/interfaces/kits/ani/launcher_bundle_manager/ets/@ohos.bundle.launcherBundleManager.ets index dd6c277796b261eac4c0a6f22133d28f2cc13924..f0a7affce3d574a08064a4b3fc2352cfddded716 100644 --- a/interfaces/kits/ani/launcher_bundle_manager/ets/@ohos.bundle.launcherBundleManager.ets +++ b/interfaces/kits/ani/launcher_bundle_manager/ets/@ohos.bundle.launcherBundleManager.ets @@ -13,36 +13,135 @@ * limitations under the License. */ -import { BusinessError } from '@ohos.base'; +import { BusinessError, AsyncCallback } from '@ohos.base'; import { ShortcutInfo as _ShortcutInfo, ShortcutWant as _ShortcutWant, ParameterItem as _ParameterItem } from 'bundleManager.ShortcutInfo'; +import { LauncherAbilityInfo } from 'bundleManager.LauncherAbilityInfo'; export default namespace launcherBundleManager { - loadLibrary("ani_launcher_bundle_manager.z"); - - export native function StartShortcutSync(shortcutInfo: ShortcutInfo): void; - export native function GetShortcutInfoSync(bundleName: string, userId: number) : Array; - - function startShortcut(shortcutInfo: ShortcutInfo): Promise { - let p:Promise = new Promise((resolve:(v:undefined) =>void, reject: (error: Object) => void):void=> { - let cb = ():NullishType=>{ launcherBundleManager.StartShortcutSync(shortcutInfo); } - let p1 = taskpool.execute(cb); - p1.then(():void => { - resolve(undefined); - }, (err: Object): void => { - let br = err as BusinessError; - reject(br); - }); - }); - return p; - } - - function getShortcutInfoSync(bundleName: string): Array{ + loadLibrary("ani_launcher_bundle_manager.z"); + + export native function StartShortcutSync(shortcutInfo: ShortcutInfo): void; + export native function GetShortcutInfoSync(bundleName: string, userId: number): Array; + export native function GetLauncherAbilityInfoSync(bundleName: string, userId: number): Array; + export native function GetAllLauncherAbilityInfo(userId: number): Array; + + function startShortcut(shortcutInfo: ShortcutInfo): Promise { + let p = new Promise((resolve: (v:undefined) => void, reject: (error: Object) => void): void => { + let cb = (): NullishType => { + launcherBundleManager.StartShortcutSync(shortcutInfo); + } + let p1 = taskpool.execute(cb); + p1.then((): void => { + resolve(undefined); + }, (err: Object): void => { + let br = err as BusinessError; + reject(br); + }); + }); + return p; + } + + function getShortcutInfoSync(bundleName: string): Array { + return launcherBundleManager.GetShortcutInfoSync(bundleName, -500); + } + + function getShortcutInfoSync(bundleName: string, userId: number): Array { + return launcherBundleManager.GetShortcutInfoSync(bundleName, userId); + } + + function getShortcutInfo(bundleName: string, callback: AsyncCallback>): void { + let cb = (): (Array) => { return launcherBundleManager.GetShortcutInfoSync(bundleName, -500); - } + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let resultShortcutInfo: Array = e as Array; + let br: BusinessError = { code: 0, name: "error", message: "error", data: undefined }; + callback(br, resultShortcutInfo); + }, (err: Object): void => { + }); + } + + function getShortcutInfo(bundleName: string): Promise> { + let p = new Promise>((resolve: (arrShortcutInfo: Array) => void, reject: (error: Object) => void) => { + let cb = (): (Array) => { + return launcherBundleManager.GetShortcutInfoSync(bundleName, -500); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let resultShortcutInfo: Array = e as Array; + resolve(resultShortcutInfo); + }, (err: Object): void => { + let br = err as BusinessError; + reject(br); + }); + }); + return p; + } + + function getLauncherAbilityInfo(bundleName: string, userId: number, callback: AsyncCallback, void>): void { + let cb = (): (Array) => { + return launcherBundleManager.GetLauncherAbilityInfoSync(bundleName, userId); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let resultArray: Array = e as Array; + let br: BusinessError = { code: 0, name: "error", message: "error", data: undefined }; + callback(br, resultArray); + }, (err: Object): void => { + }); + } + + function getLauncherAbilityInfo(bundleName: string, userId: number): Promise> { + let p = new Promise>((resolve: (arrLauncherAbilityInfo: Array) => void, reject: (error: Object) => void) => { + let cb = (): (Array) => { + return launcherBundleManager.GetLauncherAbilityInfoSync(bundleName, userId); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let resultArray: Array = e as Array; + resolve(resultArray); + }, (err: Object): void => { + let br = err as BusinessError; + reject(br); + }); + }); + return p; + } + + function getLauncherAbilityInfoSync(bundleName: string, userId: number): Array { + return launcherBundleManager.GetLauncherAbilityInfoSync(bundleName, userId); + } + + function getAllLauncherAbilityInfo(userId: number, callback: AsyncCallback, void>): void { + let cb = (): (Array) => { + return launcherBundleManager.GetAllLauncherAbilityInfo(userId); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let resultArray: Array = e as Array; + let br: BusinessError = { code: 0, name: "error", message: "error", data: undefined }; + callback(br, resultArray); + }, (err: Object): void => { + }); + } - function getShortcutInfoSync(bundleName: string, userId: number) : Array { - return launcherBundleManager.GetShortcutInfoSync(bundleName, userId); - } + function getAllLauncherAbilityInfo(userId: number): Promise>{ + let p = new Promise>((resolve: (arrLauncherAbilityInfo: Array) => void, reject: (error: Object) => void) => { + let cb = (): (Array) => { + return launcherBundleManager.GetAllLauncherAbilityInfo(userId); + }; + let p1 = taskpool.execute(cb); + p1.then((e: NullishType) => { + let resultArray: Array = e as Array; + resolve(resultArray); + }, (err: Object): void => { + let br = err as BusinessError; + reject(br); + }); + }); + return p; + } export type ShortcutInfo = _ShortcutInfo; export type ShortcutWant = _ShortcutWant; diff --git a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementName.ets b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementName.ets new file mode 100644 index 0000000000000000000000000000000000000000..d4804394dd2634063037342efd744d39a9bb37e9 --- /dev/null +++ b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementName.ets @@ -0,0 +1,23 @@ +/* + * 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. + */ + +export interface ElementName { + deviceId?: string; + bundleName: string; + moduleName?: string; + abilityName: string; + uri?: string; + shortName?: string; +} \ No newline at end of file diff --git a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementNameInner.ets b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementNameInner.ets new file mode 100644 index 0000000000000000000000000000000000000000..872af46f7bbc0c5e3eb86dd7a51d6183061ca9b6 --- /dev/null +++ b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/ElementNameInner.ets @@ -0,0 +1,25 @@ +/* + * 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 { ElementName } from 'bundleManager.ElementName'; + +export class ElementNameInner implements ElementName { + deviceId?: string | undefined = ""; + bundleName: string = ""; + moduleName?: string | undefined = ""; + abilityName: string = ""; + uri?: string | undefined = ""; + shortName?: string | undefined = ""; +} \ No newline at end of file diff --git a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfo.ets b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfo.ets new file mode 100644 index 0000000000000000000000000000000000000000..ebfd76b8c82a2f498283f3f009d6be69b622254b --- /dev/null +++ b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfo.ets @@ -0,0 +1,26 @@ +/* + * 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 { ApplicationInfo } from 'bundleManager.ApplicationInfo'; +import { ElementName } from 'bundleManager.ElementName'; + +export interface LauncherAbilityInfo { + readonly applicationInfo: ApplicationInfo; + readonly elementName: ElementName; + readonly labelId: number; + readonly iconId: number; + readonly userId: number; + readonly installTime: number; +} \ No newline at end of file diff --git a/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfoInner.ets b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfoInner.ets new file mode 100644 index 0000000000000000000000000000000000000000..04382de4fed9ebb76dbafd9af97fb2c4de25e0c2 --- /dev/null +++ b/interfaces/kits/ani/launcher_bundle_manager/ets/bundleManager/LauncherAbilityInfoInner.ets @@ -0,0 +1,28 @@ +/* + * 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 { ApplicationInfo } from 'bundleManager.ApplicationInfo'; +import { ApplicationInfoInner } from 'bundleManager.ApplicationInfoInner'; +import { ElementName } from 'bundleManager.ElementName'; +import { ElementNameInner } from './ElementNameInner'; +import { LauncherAbilityInfo } from 'bundleManager.LauncherAbilityInfo'; + +export class LauncherAbilityInfoInner implements LauncherAbilityInfo { + readonly applicationInfo: ApplicationInfo = new ApplicationInfoInner; + readonly elementName: ElementName = new ElementNameInner; + readonly labelId: number; + readonly iconId: number; + readonly userId: number; + readonly installTime: number; +} \ No newline at end of file