回退 'Pull Request !6843 : 提供NDK接口查询应用入口的MainElement信息-挑单5.0'

This commit is contained in:
wanghang 2024-09-09 04:04:35 +00:00 committed by Gitee
parent fae5a643aa
commit 969cf2efb7
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 0 additions and 134 deletions

View File

@ -61,21 +61,6 @@ struct OH_NativeBundle_ApplicationInfo {
char* fingerprint;
};
/**
* @brief Indicates information of elementName.
*
* @syscap SystemCapability.BundleManager.BundleFramework.Core
* @since 13
*/
struct OH_NativeBundle_ElementName {
/** Indicates the name of application. */
char* bundleName;
/** Indicates the name of module. */
char* moduleName;
/** Indicates the name of ability. */
char* abilityName;
};
/**
* @brief Indicates information of application
*
@ -84,14 +69,6 @@ struct OH_NativeBundle_ElementName {
*/
typedef struct OH_NativeBundle_ApplicationInfo OH_NativeBundle_ApplicationInfo;
/**
* @brief Indicates information of elementName
*
* @since 13
* @version 1.0
*/
typedef struct OH_NativeBundle_ElementName OH_NativeBundle_ElementName;
/**
* @brief Obtains the application info based on the The current bundle.
*
@ -132,20 +109,6 @@ char* OH_NativeBundle_GetAppId();
* @version 1.0
*/
char* OH_NativeBundle_GetAppIdentifier();
/**
* @brief Obtains information of the entry mainElement based on the current application, including bundle name,
* module name, and ability name.
* After utilizing this interface, to prevent memory leaks,
* it is necessary to manually release the pointer returned by the interface.
*
* @return Returns the newly created OH_NativeBundle_ElementName object, if the returned object is NULL,
* it indicates creation failure. The possible cause of failure could be that the application address space is full,
* leading to space allocation failure.
* @since 13
* @version 1.0
*/
OH_NativeBundle_ElementName OH_NativeBundle_GetMainElementName();
#ifdef __cplusplus
};
#endif

View File

@ -10,9 +10,5 @@
{
"first_introduced": "11",
"name": "OH_NativeBundle_GetAppIdentifier"
},
{
"first_introduced": "13",
"name": "OH_NativeBundle_GetMainElementName"
}
]

View File

@ -43,59 +43,6 @@ void ReleaseStrings(Args... args)
(ReleaseMemory(args), ...);
}
bool CopyStringToChar(char* &name, const std::string &value)
{
size_t length = value.size();
if ((length == 0) || (length + 1) > CHAR_MAX_LENGTH) {
APP_LOGE("failed due to the length of value is empty or too long");
return false;
}
name = static_cast<char*>(malloc(length + 1));
if (name == nullptr) {
APP_LOGE("failed due to malloc error");
return false;
}
if (strcpy_s(name, length + 1, value.c_str()) != EOK) {
APP_LOGE("failed due to strcpy_s error");
ReleaseStrings(name);
return false;
}
return true;
}
bool GetElementNameByAbilityInfo(
const OHOS::AppExecFwk::AbilityInfo &abilityInfo, OH_NativeBundle_ElementName &elementName)
{
if (!CopyStringToChar(elementName.bundleName, abilityInfo.bundleName)) {
APP_LOGE("failed to obtains bundleName");
return false;
}
if (!CopyStringToChar(elementName.moduleName, abilityInfo.moduleName)) {
APP_LOGE("failed to obtains moduleName");
ReleaseStrings(elementName.bundleName);
return false;
}
if (!CopyStringToChar(elementName.abilityName, abilityInfo.name)) {
APP_LOGE("failed to obtains abilityName");
ReleaseStrings(elementName.bundleName, elementName.moduleName);
return false;
}
return true;
}
bool GetElementNameByModuleInfo(
const OHOS::AppExecFwk::HapModuleInfo &hapModuleInfo, OH_NativeBundle_ElementName &elementName)
{
for (const auto &abilityInfo : hapModuleInfo.abilityInfos) {
if (abilityInfo.name.compare(hapModuleInfo.mainElementName) == 0) {
return GetElementNameByAbilityInfo(abilityInfo, elementName);
}
}
return false;
}
OH_NativeBundle_ApplicationInfo OH_NativeBundle_GetCurrentApplicationInfo()
{
OH_NativeBundle_ApplicationInfo nativeApplicationInfo;
@ -208,43 +155,3 @@ char* OH_NativeBundle_GetAppIdentifier()
APP_LOGI("OH_NativeBundle_GetAppIdentifier success");
return appIdentifier;
}
OH_NativeBundle_ElementName OH_NativeBundle_GetMainElementName()
{
OH_NativeBundle_ElementName elementName;
OHOS::AppExecFwk::BundleMgrProxyNative bundleMgrProxyNative;
OHOS::AppExecFwk::BundleInfo bundleInfo;
auto bundleInfoFlag = static_cast<int32_t>(OHOS::AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_HAP_MODULE) |
static_cast<int32_t>(OHOS::AppExecFwk::GetBundleInfoFlag::GET_BUNDLE_INFO_WITH_ABILITY);
if (!bundleMgrProxyNative.GetBundleInfoForSelf(bundleInfoFlag, bundleInfo)) {
APP_LOGE("can not get bundleInfo for self");
return elementName;
};
for (const auto &hapModuleInfo : bundleInfo.hapModuleInfos) {
if (hapModuleInfo.moduleType != OHOS::AppExecFwk::ModuleType::ENTRY) {
continue;
}
if (GetElementNameByModuleInfo(hapModuleInfo, elementName)) {
return elementName;
}
}
for (const auto &hapModuleInfo : bundleInfo.hapModuleInfos) {
if (hapModuleInfo.moduleType != OHOS::AppExecFwk::ModuleType::FEATURE) {
continue;
}
if (GetElementNameByModuleInfo(hapModuleInfo, elementName)) {
return elementName;
}
}
for (const auto &hapModuleInfo : bundleInfo.hapModuleInfos) {
for (const auto &abilityInfo : hapModuleInfo.abilityInfos) {
GetElementNameByAbilityInfo(abilityInfo, elementName);
return elementName;
}
}
return elementName;
}