+++ /dev/null
-/*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
- *
- * 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.
- */
-
-#define _GNU_SOURCE
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdbool.h>
-#include <linux/limits.h>
-#include <ctype.h>
-#include <sqlite3.h>
-#include <glib.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <vconf.h>
-
-#include "aul_comp_info.h"
-#include "aul_util.h"
-#include "aul_sock.h"
-#include "aul_error.h"
-#include "aul_sock.h"
-#include "aul_api.h"
-#include "aul.h"
-
-#define ROOT_UID 0
-#define DEFAULT_LOCALE "No Locale"
-#define BUSY_WAITING_USEC 50000
-#define BUSY_WAITING_MAX 40
-
-#define AUL_COMP_LOCALIZED_INFO_START 0
-#define AUL_COMP_INFO_START 0
-
-enum aul_comp_info_e {
- AUL_COMP_INFO_APP_ID = AUL_COMP_INFO_START,
- AUL_COMP_INFO_COMP_ID,
- AUL_COMP_INFO_TYPE,
- AUL_COMP_INFO_LAUNCH_MODE,
- AUL_COMP_INFO_MAIN_COMP,
- AUL_COMP_INFO_ICON_DISPLAY,
- AUL_COMP_INFO_TASKMANAGE,
- AUL_COMP_INFO_LOCALIZED_INFO,
- AUL_COMP_INFO_MAX,
-};
-
-struct aul_comp_info_s {
- char *value[AUL_COMP_INFO_MAX];
-};
-
-enum aul_comp_localized_info_e {
- AUL_COMP_LOCALIZED_INFO_LOCALE = AUL_COMP_LOCALIZED_INFO_START,
- AUL_COMP_LOCALIZED_INFO_ICON,
- AUL_COMP_LOCALIZED_INFO_LABEL,
- AUL_COMP_LOCALIZED_INFO_MAX,
-};
-
-struct aul_comp_localized_info_s {
- char *value[AUL_COMP_LOCALIZED_INFO_MAX];
-};
-
-typedef int (*aul_comp_info_add_cb)(bundle *b,
- struct aul_comp_info_s *info,
- void *data);
-typedef void (*aul_comp_info_remove_cb)(void *data);
-typedef int (*aul_comp_info_clone_cb)(struct aul_comp_info_s *info,
- struct aul_comp_info_s *clone,
- void *data);
-
-typedef struct _aul_comp_info_vft {
- aul_comp_info_add_cb ctor;
- aul_comp_info_remove_cb dtor;
- aul_comp_info_clone_cb clnr;
-} aul_comp_info_vft;
-
-typedef int (*aul_comp_localized_info_add_cb)(bundle *b,
- struct aul_comp_localized_info_s *info,
- void *data);
-typedef void (*aul_comp_localized_info_remove_cb)(void *data);
-typedef int (*aul_comp_localized_info_clone_cb)(
- struct aul_comp_localized_info_s *info,
- struct aul_comp_localized_info_s *clone,
- void *data);
-
-typedef struct _aul_comp_localized_info_vft {
- aul_comp_localized_info_add_cb ctor;
- aul_comp_localized_info_remove_cb dtor;
- aul_comp_localized_info_clone_cb clnr;
-} aul_comp_localized_info_vft;
-
-static int __comp_localized_info_add_locale(bundle *b,
- struct aul_comp_localized_info_s *info,
- void *data)
-{
- const char *locale;
-
- locale = bundle_get_val(b, AUL_K_LOCALE);
- if (!locale) {
- _E("Failed to get locale");
- return -1;
- }
-
- info->value[AUL_COMP_LOCALIZED_INFO_LOCALE] = strdup(locale);
- if (!info->value[AUL_COMP_LOCALIZED_INFO_LOCALE]) {
- _E("Failed to duplicate locale");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_localized_info_add_icon(bundle *b,
- struct aul_comp_localized_info_s *info,
- void *data)
-{
- const char *icon;
-
- icon = bundle_get_val(b, AUL_K_ICON);
- if (!icon) {
- _W("Failed to get icon");
- return 0;
- }
-
- info->value[AUL_COMP_LOCALIZED_INFO_ICON] = strdup(icon);
- if (!info->value[AUL_COMP_LOCALIZED_INFO_ICON]) {
- _E("Failed to duplicate icon");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_localized_info_add_label(bundle *b,
- struct aul_comp_localized_info_s *info,
- void *data)
-{
- const char *label;
-
- label = bundle_get_val(b, AUL_K_LABEL);
- if (!label) {
- _W("Failed to get label");
- return 0;
- }
-
- info->value[AUL_COMP_LOCALIZED_INFO_LABEL] = strdup(label);
- if (!info->value[AUL_COMP_LOCALIZED_INFO_LABEL]) {
- _E("Failed to duplicate icon");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_localized_info_clone_locale(
- struct aul_comp_localized_info_s *info,
- struct aul_comp_localized_info_s *clone,
- void *data)
-{
- char *locale;
-
- if (!info->value[AUL_COMP_LOCALIZED_INFO_LOCALE]) {
- _E("Invalid parameter");
- return -1;
- }
-
- locale = strdup(info->value[AUL_COMP_LOCALIZED_INFO_LOCALE]);
- if (!locale) {
- _E("Failed to duplicate locale");
- return -1;
- }
-
- clone->value[AUL_COMP_LOCALIZED_INFO_LOCALE] = locale;
-
- return 0;
-}
-
-static int __comp_localized_info_clone_icon(
- struct aul_comp_localized_info_s *info,
- struct aul_comp_localized_info_s *clone,
- void *data)
-{
- char *icon;
-
- if (!info->value[AUL_COMP_LOCALIZED_INFO_ICON])
- return 0;
-
- icon = strdup(info->value[AUL_COMP_LOCALIZED_INFO_ICON]);
- if (!icon) {
- _E("Failed to duplicate icon");
- return -1;
- }
-
- clone->value[AUL_COMP_LOCALIZED_INFO_ICON] = icon;
-
- return 0;
-}
-
-static int __comp_localized_info_clone_label(
- struct aul_comp_localized_info_s *info,
- struct aul_comp_localized_info_s *clone,
- void *data)
-{
- char *label;
-
- if (!info->value[AUL_COMP_LOCALIZED_INFO_LABEL])
- return 0;
-
- label = strdup(info->value[AUL_COMP_LOCALIZED_INFO_LABEL]);
- if (!label) {
- _E("Failed to duplicate label");
- return -1;
- }
-
- clone->value[AUL_COMP_LOCALIZED_INFO_LABEL] = label;
-
- return 0;
-}
-
-static aul_comp_localized_info_vft __localized_info_table[] = {
- {
- .ctor = __comp_localized_info_add_locale,
- .dtor = free,
- .clnr = __comp_localized_info_clone_locale
- },
- {
- .ctor = __comp_localized_info_add_icon,
- .dtor = free,
- .clnr = __comp_localized_info_clone_icon
- },
- {
- .ctor = __comp_localized_info_add_label,
- .dtor = free,
- .clnr = __comp_localized_info_clone_label
- },
-};
-
-static void __destroy_comp_localized_info(gpointer data)
-{
- struct aul_comp_localized_info_s *info;
- int i;
-
- info = (struct aul_comp_localized_info_s *)data;
- if (!info)
- return;
-
- for (i = AUL_COMP_LOCALIZED_INFO_START;
- i < AUL_COMP_LOCALIZED_INFO_MAX;
- i++) {
- if (__localized_info_table[i].dtor && info->value[i])
- __localized_info_table[i].dtor(info->value[i]);
- }
-
- free(info);
-}
-
-static struct aul_comp_localized_info_s *__create_comp_localized_info(bundle *b)
-{
- struct aul_comp_localized_info_s *info;
- int ret;
- int i;
-
- info = calloc(1, sizeof(struct aul_comp_localized_info_s));
- if (!info) {
- _E("Out of memory");
- return NULL;
- }
-
- for (i = AUL_COMP_LOCALIZED_INFO_START;
- i < AUL_COMP_LOCALIZED_INFO_MAX;
- i++) {
- if (__localized_info_table[i].ctor) {
- ret = __localized_info_table[i].ctor(b, info, NULL);
- if (ret < 0) {
- _E("Failed to add localized info[%d]", i);
- __destroy_comp_localized_info(info);
- return NULL;
- }
- }
- }
-
- return info;
-}
-
-static struct aul_comp_localized_info_s *__clone_comp_localized_info(
- struct aul_comp_localized_info_s *info)
-{
- struct aul_comp_localized_info_s *clone;
- int ret;
- int i;
-
- clone = calloc(1, sizeof(struct aul_comp_localized_info_s));
- if (!clone) {
- _E("Out of memory");
- return NULL;
- }
-
- for (i = AUL_COMP_LOCALIZED_INFO_START;
- i < AUL_COMP_LOCALIZED_INFO_MAX;
- i++) {
- if (__localized_info_table[i].clnr) {
- ret = __localized_info_table[i].clnr(info, clone, NULL);
- if (ret < 0) {
- _E("Failed to clone localized info[%d]", i);
- __destroy_comp_localized_info(info);
- return NULL;
- }
- }
- }
-
- return clone;
-}
-
-static char *__get_system_locale(void)
-{
- char *lang;
- char *locale;
-
- lang = vconf_get_str(VCONFKEY_LANGSET);
- if (lang == NULL) {
- locale = strdup(DEFAULT_LOCALE);
- if (locale == NULL) {
- LOGE("out of memory");
- return NULL;
- }
- return locale;
- }
-
- locale = malloc(sizeof(char) * 6);
- if (locale == NULL) {
- LOGE("out of memory");
- free(lang);
- return NULL;
- }
-
- strncpy(locale, lang, 2);
- locale[2] = '-';
- locale[3] = tolower(lang[3]);
- locale[4] = tolower(lang[4]);
- locale[5] = '\0';
-
- free(lang);
-
- return locale;
-}
-
-static bool __get_boolean_value(const char *str)
-{
- if (str && !strcmp(str, "true"))
- return true;
-
- return false;
-}
-
-static void __comp_info_remove_localized_info(void *data)
-{
- GList *list = (GList *)data;
-
- if (!list)
- return;
-
- g_list_free_full(list, __destroy_comp_localized_info);
-}
-
-static int __comp_info_add_app_id(bundle *b, struct aul_comp_info_s *info,
- void *data)
-{
- const char *app_id;
-
- app_id = bundle_get_val(b, AUL_K_APPID);
- if (!app_id) {
- _E("Failed to get application ID");
- return -1;
- }
-
- info->value[AUL_COMP_INFO_APP_ID] = strdup(app_id);
- if (!info->value[AUL_COMP_INFO_APP_ID]) {
- _E("Failed to duplicate application ID");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_add_comp_id(bundle *b, struct aul_comp_info_s *info,
- void *data)
-{
- const char *comp_id;
-
- comp_id = bundle_get_val(b, AUL_K_COMPONENT_ID);
- if (!comp_id) {
- _E("Failed to get component ID");
- return -1;
- }
-
- info->value[AUL_COMP_INFO_COMP_ID] = strdup(comp_id);
- if (!info->value[AUL_COMP_INFO_COMP_ID]) {
- _E("Failed to duplicate component ID");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_add_type(bundle *b, struct aul_comp_info_s *info,
- void *data)
-{
- const char *type;
-
- type = bundle_get_val(b, AUL_K_COMPONENT_TYPE);
- if (!type) {
- _E("Failed to get component type");
- return -1;
- }
-
- info->value[AUL_COMP_INFO_TYPE] = strdup(type);
- if (!info->value[AUL_COMP_INFO_TYPE]) {
- _E("Failed to duplicate component type");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_add_launch_mode(bundle *b, struct aul_comp_info_s *info,
- void *data)
-{
- const char *launch_mode;
-
- launch_mode = bundle_get_val(b, AUL_K_LAUNCH_MODE);
- if (!launch_mode) {
- _E("Failed to get launch mode");
- return -1;
- }
-
- info->value[AUL_COMP_INFO_LAUNCH_MODE] = strdup(launch_mode);
- if (!info->value[AUL_COMP_INFO_LAUNCH_MODE]) {
- _E("Failed to duplicate launch mode");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_add_main_comp(bundle *b, struct aul_comp_info_s *info,
- void *data)
-{
- const char *main_comp;
-
- main_comp = bundle_get_val(b, AUL_K_MAIN_COMP);
- if (!main_comp) {
- _E("Failed to get main comp");
- return -1;
- }
-
- info->value[AUL_COMP_INFO_MAIN_COMP] = strdup(main_comp);
- if (!info->value[AUL_COMP_INFO_MAIN_COMP]) {
- _E("Failed to duplicate main comp");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_add_icon_display(bundle *b, struct aul_comp_info_s *info,
- void *data)
-{
- const char *icon_display;
-
- icon_display = bundle_get_val(b, AUL_K_ICON_DISPLAY);
- if (!icon_display) {
- _E("Failed to get icon display");
- return -1;
- }
-
- info->value[AUL_COMP_INFO_ICON_DISPLAY] = strdup(icon_display);
- if (!info->value[AUL_COMP_INFO_ICON_DISPLAY]) {
- _E("Failed to duplicate icon display");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_add_taskmanage(bundle *b, struct aul_comp_info_s *info,
- void *data)
-{
- const char *taskmanage;
-
- taskmanage = bundle_get_val(b, AUL_K_TASK_MANAGE);
- if (!taskmanage) {
- _E("Failed to get taskmanage");
- return -1;
- }
-
- info->value[AUL_COMP_INFO_TASKMANAGE] = strdup(taskmanage);
- if (!info->value[AUL_COMP_INFO_TASKMANAGE]) {
- _E("Failed to duplicate taskmanage");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_add_localized_info(bundle *b,
- struct aul_comp_info_s *info, void *data)
-{
- struct aul_comp_localized_info_s *localized_info;
- const char **localized_info_arr;
- const char **localized_info_size_arr;
- GList *list = NULL;
- bundle *decoded_b;
- int len = 0;
- int size_len = 0;
- int size;
- int i;
-
- localized_info_arr = bundle_get_str_array(b,
- AUL_K_LOCALIZED_INFO, &len);
- if (!localized_info_arr || len <= 0) {
- _W("Failed to get localized info");
- return 0;
- }
-
- localized_info_size_arr = bundle_get_str_array(b,
- AUL_K_LOCALIZED_INFO_SIZE, &size_len);
- if (!localized_info_size_arr || size_len <= 0) {
- _E("Failed to get localized info size");
- return -1;
- }
-
- if (len != size_len) {
- _E("Invalid size");
- return -1;
- }
-
- for (i = 0; i < len; ++i) {
- size = atoi(localized_info_size_arr[i]);
- decoded_b = bundle_decode((bundle_raw *)localized_info_arr[i],
- size);
- if (!decoded_b) {
- _E("Failed to decode bundle");
- __comp_info_remove_localized_info(list);
- return -1;
- }
-
- localized_info = __create_comp_localized_info(decoded_b);
- bundle_free(decoded_b);
- if (!localized_info) {
- __comp_info_remove_localized_info(list);
- return -1;
- }
-
- list = g_list_append(list, localized_info);
- }
-
- info->value[AUL_COMP_INFO_LOCALIZED_INFO] = (char *)list;
-
- return 0;
-}
-
-static int __comp_info_clone_app_id(struct aul_comp_info_s *info,
- struct aul_comp_info_s *clone, void *data)
-{
- const char *app_id;
-
- app_id = info->value[AUL_COMP_INFO_APP_ID];
- if (!app_id) {
- _E("Invalid parameter");
- return -1;
- }
-
- clone->value[AUL_COMP_INFO_APP_ID] = strdup(app_id);
- if (!clone->value[AUL_COMP_INFO_APP_ID]) {
- _E("Failed to duplicate application ID");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_clone_comp_id(struct aul_comp_info_s *info,
- struct aul_comp_info_s *clone, void *data)
-{
- const char *comp_id;
-
- comp_id = info->value[AUL_COMP_INFO_COMP_ID];
- if (!comp_id) {
- _E("Invalid parameter");
- return -1;
- }
-
- clone->value[AUL_COMP_INFO_COMP_ID] = strdup(comp_id);
- if (!clone->value[AUL_COMP_INFO_COMP_ID]) {
- _E("Failed to duplicate component ID");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_clone_type(struct aul_comp_info_s *info,
- struct aul_comp_info_s *clone, void *data)
-{
- const char *type;
-
- type = info->value[AUL_COMP_INFO_TYPE];
- if (!type) {
- _E("Invalid parameter");
- return -1;
- }
-
- clone->value[AUL_COMP_INFO_TYPE] = strdup(type);
- if (!clone->value[AUL_COMP_INFO_TYPE]) {
- _E("Failed to duplicate component type");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_clone_launch_mode(struct aul_comp_info_s *info,
- struct aul_comp_info_s *clone, void *data)
-{
- const char *launch_mode;
-
- launch_mode = info->value[AUL_COMP_INFO_LAUNCH_MODE];
- if (!launch_mode) {
- _E("Invalid parameter");
- return -1;
- }
-
- clone->value[AUL_COMP_INFO_LAUNCH_MODE] = strdup(launch_mode);
- if (!clone->value[AUL_COMP_INFO_LAUNCH_MODE]) {
- _E("Failed to duplicate launch mode");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_clone_main_comp(struct aul_comp_info_s *info,
- struct aul_comp_info_s *clone, void *data)
-{
- const char *main_comp;
-
- main_comp = info->value[AUL_COMP_INFO_MAIN_COMP];
- if (!main_comp) {
- _E("Invalid parameter");
- return -1;
- }
-
- clone->value[AUL_COMP_INFO_MAIN_COMP] = strdup(main_comp);
- if (!clone->value[AUL_COMP_INFO_MAIN_COMP]) {
- _E("Failed to duplicate main comp");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_clone_icon_display(struct aul_comp_info_s *info,
- struct aul_comp_info_s *clone, void *data)
-{
- const char *icon_display;
-
- icon_display = info->value[AUL_COMP_INFO_ICON_DISPLAY];
- if (!icon_display) {
- _E("Invalid parameter");
- return -1;
- }
-
- clone->value[AUL_COMP_INFO_ICON_DISPLAY] = strdup(icon_display);
- if (!clone->value[AUL_COMP_INFO_ICON_DISPLAY]) {
- _E("Failed to duplicate icon display");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_clone_taskmanage(struct aul_comp_info_s *info,
- struct aul_comp_info_s *clone, void *data)
-{
- const char *taskmanage;
-
- taskmanage = info->value[AUL_COMP_INFO_TASKMANAGE];
- if (!taskmanage) {
- _E("Invalid parameter");
- return -1;
- }
-
- clone->value[AUL_COMP_INFO_TASKMANAGE] = strdup(taskmanage);
- if (!clone->value[AUL_COMP_INFO_TASKMANAGE]) {
- _E("Failed to duplicate taskmanage");
- return -1;
- }
-
- return 0;
-}
-
-static int __comp_info_clone_localized_info(struct aul_comp_info_s *info,
- struct aul_comp_info_s *clone, void *data)
-{
- struct aul_comp_localized_info_s *localized_info;
- struct aul_comp_localized_info_s *clone_info;
- GList *localized_info_list;
- GList *list = NULL;
- GList *iter;
-
- localized_info_list =
- (GList *)info->value[AUL_COMP_INFO_LOCALIZED_INFO];
- if (!localized_info_list)
- return 0;
-
- iter = localized_info_list;
- while (iter) {
- localized_info = (struct aul_comp_localized_info_s *)iter->data;
- if (!localized_info) {
- _E("Critical error!");
- __comp_info_remove_localized_info(list);
- return -1;
- }
-
- clone_info = __clone_comp_localized_info(localized_info);
- if (!clone_info) {
- __comp_info_remove_localized_info(list);
- return -1;
- }
-
- list = g_list_append(list, clone_info);
- iter = g_list_next(iter);
- }
-
- clone->value[AUL_COMP_INFO_LOCALIZED_INFO] = (char *)list;
-
- return 0;
-}
-
-static aul_comp_info_vft __comp_info_table[] = {
- {
- .ctor = __comp_info_add_app_id,
- .dtor = free,
- .clnr = __comp_info_clone_app_id
- },
- {
- .ctor = __comp_info_add_comp_id,
- .dtor = free,
- .clnr = __comp_info_clone_comp_id
- },
- {
- .ctor = __comp_info_add_type,
- .dtor = free,
- .clnr = __comp_info_clone_type
- },
- {
- .ctor = __comp_info_add_launch_mode,
- .dtor = free,
- .clnr = __comp_info_clone_launch_mode
- },
- {
- .ctor = __comp_info_add_main_comp,
- .dtor = free,
- .clnr = __comp_info_clone_main_comp
- },
- {
- .ctor = __comp_info_add_icon_display,
- .dtor = free,
- .clnr = __comp_info_clone_icon_display
- },
- {
- .ctor = __comp_info_add_taskmanage,
- .dtor = free,
- .clnr = __comp_info_clone_taskmanage
- },
- {
- .ctor = __comp_info_add_localized_info,
- .dtor = __comp_info_remove_localized_info,
- .clnr = __comp_info_clone_localized_info
- }
-};
-
-static void __destroy_comp_info(gpointer data)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)data;
- int i;
-
- if (!info)
- return;
-
- for (i = AUL_COMP_INFO_START; i < AUL_COMP_INFO_MAX; ++i) {
- if (__comp_info_table[i].dtor && info->value[i])
- __comp_info_table[i].dtor(info->value[i]);
- }
-
- free(info);
-}
-
-static struct aul_comp_info_s *__create_comp_info(bundle *b)
-{
- struct aul_comp_info_s *info;
- int ret;
- int i;
-
- info = calloc(1, sizeof(struct aul_comp_info_s));
- if (!info) {
- _E("Out of memory");
- return NULL;
- }
-
- for (i = AUL_COMP_INFO_START; i < AUL_COMP_INFO_MAX; ++i) {
- if (__comp_info_table[i].ctor) {
- ret = __comp_info_table[i].ctor(b, info, NULL);
- if (ret < 0) {
- _E("Failed to add component info[%d]", i);
- __destroy_comp_info(info);
- return NULL;
- }
- }
- }
-
- return info;
-}
-
-static struct aul_comp_info_s *__clone_comp_info(struct aul_comp_info_s *info)
-{
- struct aul_comp_info_s *comp_info;
- int ret;
- int i;
-
- comp_info = calloc(1, sizeof(struct aul_comp_info_s));
- if (!comp_info) {
- _E("Out of memory");
- return NULL;
- }
-
- for (i = AUL_COMP_INFO_START; i < AUL_COMP_INFO_MAX; ++i) {
- if (__comp_info_table[i].clnr) {
- ret = __comp_info_table[i].clnr(info, comp_info, NULL);
- if (ret < 0) {
- _E("Failed to clone component info[%d]", i);
- __destroy_comp_info(comp_info);
- return NULL;
- }
- }
- }
-
- return comp_info;
-}
-
-API int aul_comp_info_create(const char *comp_id, aul_comp_info_h *handle)
-{
- return aul_comp_info_usr_create(comp_id, getuid(), handle);
-}
-
-API int aul_comp_info_usr_create(const char *comp_id, uid_t uid,
- aul_comp_info_h *handle) {
- struct aul_comp_info_s *info;
- app_pkt_t *pkt = NULL;
- char buf[32];
- bundle *b;
- int ret;
- int fd;
-
- if (!comp_id || !handle) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- b = bundle_create();
- if (!b) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- snprintf(buf, sizeof(buf), "%d", uid);
- bundle_add(b, AUL_K_TARGET_UID, buf);
- bundle_add(b, AUL_K_COMPONENT_ID, comp_id);
-
- fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, COMP_INFO_GET,
- b, AUL_SOCK_ASYNC);
- bundle_free(b);
- if (fd < 0) {
- _E("Failed to send request. error(%d)", fd);
- return aul_error_convert(fd);
- }
-
- ret = aul_sock_recv_reply_pkt(fd, &pkt);
- if (ret < 0) {
- _E("Failed to receive packet. error(%d)", ret);
- return aul_error_convert(ret);
- }
-
- if (pkt->cmd != APP_GET_INFO_OK) {
- _E("Failed to get component info. error(%d)", pkt->cmd);
- ret = pkt->cmd;
- free(pkt);
- return aul_error_convert(ret);
- }
-
- b = NULL;
- if (pkt->opt & AUL_SOCK_BUNDLE) {
- b = bundle_decode(pkt->data, pkt->len);
- if (!b) {
- _E("Failed to decode bundle");
- free(pkt);
- return AUL_R_ENOMEM;
- }
- }
- free(pkt);
-
- if (!b) {
- _E("Invalid packet");
- return AUL_R_ERROR;
- }
-
- info = __create_comp_info(b);
- if (!info) {
- bundle_free(b);
- return AUL_R_ENOMEM;
- }
- bundle_free(b);
-
- *handle = (aul_comp_info_h)info;
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_destroy(aul_comp_info_h handle)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
-
- if (!handle) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- __destroy_comp_info(info);
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_clone(aul_comp_info_h handle, aul_comp_info_h *clone)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
- struct aul_comp_info_s *new_info;
-
- if (!handle || !clone) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- new_info = __clone_comp_info(info);
- if (!new_info) {
- _E("Failed to clone comp info");
- return AUL_R_ENOMEM;
- }
-
- *clone = (aul_comp_info_h)new_info;
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_get_app_id(aul_comp_info_h handle, const char **app_id)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
-
- if (!handle || !app_id) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *app_id = info->value[AUL_COMP_INFO_APP_ID];
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_get_comp_id(aul_comp_info_h handle, const char **comp_id)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
-
- if (!handle || !comp_id) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *comp_id = info->value[AUL_COMP_INFO_COMP_ID];
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_get_type(aul_comp_info_h handle, const char **type)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
-
- if (!handle || !type) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *type = info->value[AUL_COMP_INFO_TYPE];
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_get_launch_mode(aul_comp_info_h handle,
- const char **launch_mode)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
-
- if (!handle || !launch_mode) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *launch_mode = info->value[AUL_COMP_INFO_LAUNCH_MODE];
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_is_main_comp(aul_comp_info_h handle, bool *main_comp)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
-
- if (!handle || !main_comp) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *main_comp = __get_boolean_value(info->value[AUL_COMP_INFO_MAIN_COMP]);
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_is_icon_display(aul_comp_info_h handle,
- bool *icon_display)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
-
- if (!handle || !icon_display) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *icon_display =
- __get_boolean_value(info->value[AUL_COMP_INFO_ICON_DISPLAY]);
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_is_taskmanage(aul_comp_info_h handle, bool *taskmanage)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
-
- if (!handle || !taskmanage) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- *taskmanage =
- __get_boolean_value(info->value[AUL_COMP_INFO_TASKMANAGE]);
-
- return AUL_R_OK;
-}
-
-static gint __compare_locale(gconstpointer a, gconstpointer b)
-{
- struct aul_comp_localized_info_s *info;
- const char *locale;
-
- info = (struct aul_comp_localized_info_s *)a;
- locale = (const char *)b;
-
- if (!info || !info->value[AUL_COMP_LOCALIZED_INFO_LOCALE] || !locale)
- return -1;
-
- return strcmp(info->value[AUL_COMP_LOCALIZED_INFO_LOCALE], locale);
-}
-
-static struct aul_comp_localized_info_s *__find_comp_localized_info(
- struct aul_comp_info_s *info, const char *locale)
-{
- GList *found;
- GList *list;
-
- list = (GList *)info->value[AUL_COMP_INFO_LOCALIZED_INFO];
- if (!list) {
- _E("Localized info is empty");
- return NULL;
- }
-
- found = g_list_find_custom(list, locale, __compare_locale);
- if (!found) {
- found = g_list_find_custom(list, DEFAULT_LOCALE,
- __compare_locale);
- }
-
- if (!found) {
- _E("Failed to find localized info");
- return NULL;
- }
-
- return (struct aul_comp_localized_info_s *)found->data;
-}
-
-API int aul_comp_info_get_icon(aul_comp_info_h handle, const char **icon)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
- struct aul_comp_localized_info_s *localized_info;
- char *locale;
-
- if (!handle || !icon) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- locale = __get_system_locale();
- if (!locale) {
- _E("Failed to get system locale");
- return AUL_R_ENOMEM;
- }
-
- localized_info = __find_comp_localized_info(info, locale);
- if (!localized_info) {
- free(locale);
- return AUL_R_ENOENT;
- }
- free(locale);
-
- *icon = localized_info->value[AUL_COMP_LOCALIZED_INFO_ICON];
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_get_label(aul_comp_info_h handle, const char **label)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
- struct aul_comp_localized_info_s *localized_info;
- char *locale;
-
- if (!handle || !label) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- locale = __get_system_locale();
- if (!locale) {
- _E("Failed to get system locale");
- return AUL_R_ENOMEM;
- }
-
- localized_info = __find_comp_localized_info(info, locale);
- if (!localized_info) {
- free(locale);
- return AUL_R_ENOENT;
- }
- free(locale);
-
- *label = localized_info->value[AUL_COMP_LOCALIZED_INFO_LABEL];
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_get_localed_label(aul_comp_info_h handle,
- const char *locale, const char **label)
-{
- struct aul_comp_info_s *info = (struct aul_comp_info_s *)handle;
- struct aul_comp_localized_info_s *localized_info;
-
- if (!handle || !locale || !label) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- localized_info = __find_comp_localized_info(info, locale);
- if (!localized_info)
- return AUL_R_ENOENT;
-
- *label = localized_info->value[AUL_COMP_LOCALIZED_INFO_LABEL];
-
- return AUL_R_OK;
-}
-
-static void __comp_info_foreach_cb(app_pkt_t *pkt, void *user_data)
-{
- GList **list = (GList **)user_data;
- struct aul_comp_info_s *info;
- bundle *b = NULL;
-
- if (!pkt) {
- _E("Invalid parameter");
- return;
- }
-
- if (pkt->cmd == APP_GET_INFO_ERROR) {
- _E("Failed to get component info");
- return;
- }
-
- if (pkt->opt & AUL_SOCK_BUNDLE)
- b = bundle_decode(pkt->data, pkt->len);
-
- if (!b)
- return;
-
- info = __create_comp_info(b);
- if (!info) {
- bundle_free(b);
- return;
- }
- bundle_free(b);
-
- *list = g_list_append(*list, info);
-}
-
-static int __get_comp_info_list(uid_t uid, GList **info_list)
-{
- GList *list = NULL;
- char buf[32];
- bundle *b;
- int ret;
- int fd;
-
- b = bundle_create();
- if (!b) {
- _E("Out of memory");
- return AUL_R_ENOMEM;
- }
-
- snprintf(buf, sizeof(buf), "%d", uid);
- bundle_add(b, AUL_K_TARGET_UID, buf);
-
- fd = aul_sock_send_bundle(AUL_UTIL_PID, uid, COMP_INFO_FOREACH,
- b, AUL_SOCK_ASYNC);
- bundle_free(b);
- if (fd < 0)
- return aul_error_convert(fd);
-
- ret = aul_sock_recv_pkt_with_cb(fd, __comp_info_foreach_cb,
- &list);
- if (ret < 0) {
- g_list_free_full(list, __destroy_comp_info);
- return aul_error_convert(ret);
- }
-
- *info_list = list;
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_foreach_comp_info_from_app(const char *app_id,
- aul_comp_info_cb callback, void *user_data)
-{
- return aul_comp_info_usr_foreach_comp_info_from_app(app_id, getuid(),
- callback, user_data);
-}
-
-API int aul_comp_info_usr_foreach_comp_info_from_app(const char *app_id,
- uid_t uid, aul_comp_info_cb callback, void *user_data)
-{
- struct aul_comp_info_s *info;
- GList *list = NULL;
- GList *iter;
- int ret;
-
- if (!app_id || !callback) {
- LOGE("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- ret = __get_comp_info_list(uid, &list);
- if (ret < 0)
- return ret;
-
- iter = list;
- while (iter) {
- info = (struct aul_comp_info_s *)iter->data;
- iter = g_list_next(iter);
- if (strcmp(info->value[AUL_COMP_INFO_APP_ID], app_id) != 0)
- continue;
-
- if (!callback(info, user_data))
- break;
- }
-
- g_list_free_full(list, __destroy_comp_info);
-
- return AUL_R_OK;
-}
-
-API int aul_comp_info_foreach_comp_info(aul_comp_info_cb callback,
- void *user_data)
-{
- return aul_comp_info_usr_foreach_comp_info(getuid(), callback,
- user_data);
-}
-
-API int aul_comp_info_usr_foreach_comp_info(uid_t uid,
- aul_comp_info_cb callback, void *user_data)
-{
- struct aul_comp_info_s *info;
- GList *list = NULL;
- GList *iter;
- int ret;
-
- if (!callback) {
- LOGE("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- ret = __get_comp_info_list(uid, &list);
- if (ret < 0)
- return ret;
-
- iter = list;
- while (iter) {
- info = (struct aul_comp_info_s *)iter->data;
- if (!callback(info, user_data))
- break;
-
- iter = g_list_next(iter);
- }
-
- g_list_free_full(list, __destroy_comp_info);
-
- return AUL_R_OK;
-}
--- /dev/null
+/*
+ * Copyright (c) 2019 - 2022 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * 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 "include/aul_comp_info.h"
+
+#include <vconf.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+
+#include "app_request.h"
+#include "aul_api.h"
+#include "aul_util.h"
+#include "include/aul.h"
+#include "include/aul_error.h"
+#include "include/aul_sock.h"
+
+#include "aul/common/exception.hh"
+#include "aul/component/component_info.hh"
+
+using namespace aul;
+
+namespace {
+using namespace aul::internal;
+
+constexpr const char kDefaultLocale[] = "No Locale";
+
+std::string GetSystemLocale() {
+ char* lang = vconf_get_str(VCONFKEY_LANGSET);
+ if (lang == nullptr) {
+ lang = strdup(kDefaultLocale);
+ if (lang == nullptr) {
+ _E("strdup() is failed");
+ THROW(AUL_R_ENOMEM);
+ }
+ }
+
+ auto lang_auto = std::unique_ptr<char, decltype(std::free)*>(lang, std::free);
+
+ return std::string({
+ lang[0],
+ lang[1],
+ '-',
+ std::tolower(lang[3]),
+ std::tolower(lang[4])
+ });
+}
+
+ComponentInfo* CreateComponentInfoFromAppPacket(
+ app_pkt_t* pkt) {
+ if (pkt->cmd != APP_GET_INFO_OK)
+ THROW(pkt->cmd);
+
+ bundle* kb = nullptr;
+ if (pkt->opt & AUL_SOCK_BUNDLE) {
+ kb = bundle_decode(pkt->data, pkt->len);
+ if (kb == nullptr)
+ THROW(AUL_R_ENOMEM);
+ } else {
+ THROW(AUL_R_ERROR);
+ }
+
+ tizen_base::Bundle b(kb, false, true);
+ return ComponentInfo::Builder()
+ .SetAppId(b)
+ .SetComponentId(b)
+ .SetType(b)
+ .SetLaunchMode(b)
+ .SetMainComponent(b)
+ .SetIconDisplay(b)
+ .SetTaskmanage(b)
+ .SetLocalizedInfo(b);
+}
+
+ComponentInfo* GetComponentInfo(const char* comp_id,
+ uid_t uid) {
+ tizen_base::Bundle b { { AUL_K_COMPONENT_ID, comp_id } };
+ int fd = AppRequest(COMP_INFO_GET, uid)
+ .With(std::move(b))
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ THROW(fd);
+
+ app_pkt_t* pkt = nullptr;
+ int ret = aul_sock_recv_reply_pkt(fd, &pkt);
+ if (ret < 0)
+ THROW(ret);
+
+ auto pkt_auto = std::unique_ptr<app_pkt_t, decltype(std::free)*>(
+ pkt, std::free);
+ return CreateComponentInfoFromAppPacket(pkt);
+}
+
+std::vector<std::shared_ptr<ComponentInfo>> GetComponentInfos(uid_t uid) {
+ int fd = AppRequest(COMP_INFO_FOREACH, uid)
+ .SendSimply(AUL_SOCK_ASYNC);
+ if (fd < 0)
+ THROW(fd);
+
+ std::vector<std::shared_ptr<ComponentInfo>> component_infos;
+ int ret = aul_sock_recv_pkt_with_cb(fd,
+ [](app_pkt_t* pkt, void* user_data) {
+ if (pkt == nullptr)
+ return;
+
+ try {
+ auto* infos =
+ static_cast<std::vector<std::shared_ptr<ComponentInfo>>*>(
+ user_data);
+ infos->emplace_back(CreateComponentInfoFromAppPacket(pkt));
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ }
+ }, &component_infos);
+ if (ret < 0)
+ THROW(ret);
+
+ return component_infos;
+}
+
+} // namespace
+
+extern "C" API int aul_comp_info_create(const char* comp_id,
+ aul_comp_info_h* handle) {
+ return aul_comp_info_usr_create(comp_id, getuid(), handle);
+}
+
+extern "C" API int aul_comp_info_usr_create(const char* comp_id, uid_t uid,
+ aul_comp_info_h* handle) {
+ if(comp_id == nullptr || handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ auto* info = GetComponentInfo(comp_id, uid);
+ *handle = static_cast<aul_comp_info_h>(info);
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_destroy(aul_comp_info_h handle) {
+ if (handle == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ delete info;
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_clone(aul_comp_info_h handle,
+ aul_comp_info_h* clone) {
+ if (handle == nullptr || clone == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ auto* cloned_info = new (std::nothrow) ComponentInfo(*info);
+ if (cloned_info == nullptr) {
+ _E("Out of memory");
+ return AUL_R_ENOMEM;
+ }
+
+ *clone = static_cast<aul_comp_info_h>(cloned_info);
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_app_id(aul_comp_info_h handle,
+ const char** app_id) {
+ if (handle == nullptr || app_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *app_id = info->GetAppId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_comp_id(aul_comp_info_h handle,
+ const char** comp_id) {
+ if (handle == nullptr || comp_id == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *comp_id = info->GetComponentId().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_type(aul_comp_info_h handle,
+ const char** type) {
+ if (handle == nullptr || type == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *type = info->GetType().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_launch_mode(aul_comp_info_h handle,
+ const char** launch_mode) {
+ if (handle == nullptr || launch_mode == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *launch_mode = info->GetLaunchMode().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_is_main_comp(aul_comp_info_h handle,
+ bool* main_comp) {
+ if (handle == nullptr || main_comp == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *main_comp = info->IsMainComponent();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_is_icon_display(aul_comp_info_h handle,
+ bool* icon_display) {
+ if (handle == nullptr || icon_display == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *icon_display = info->IsIconDisplay();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_is_taskmanage(aul_comp_info_h handle,
+ bool* taskmanage) {
+ if (handle == nullptr || taskmanage == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ *taskmanage = info->IsTaskmanage();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_icon(aul_comp_info_h handle,
+ const char** icon) {
+ if (handle == nullptr || icon == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ try {
+ auto* localized_info = info->GetLocalizedInfo(GetSystemLocale());
+ if (localized_info == nullptr)
+ return AUL_R_ENOENT;
+
+ *icon = localized_info->GetIcon().c_str();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_label(aul_comp_info_h handle,
+ const char** label) {
+ if (handle == nullptr || label == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ try {
+ auto* localized_info = info->GetLocalizedInfo(GetSystemLocale());
+ if (localized_info == nullptr)
+ return AUL_R_ENOENT;
+
+ *label = localized_info->GetLabel().c_str();
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_get_localed_label(aul_comp_info_h handle,
+ const char* locale, const char** label) {
+ if (handle == nullptr || locale == nullptr || label == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ auto* info = static_cast<ComponentInfo*>(handle);
+ auto* localized_info = info->GetLocalizedInfo(locale);
+ if (localized_info == nullptr)
+ return AUL_R_ENOENT;
+
+ *label = localized_info->GetLabel().c_str();
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_foreach_comp_info_from_app(const char* app_id,
+ aul_comp_info_cb callback, void* user_data) {
+ return aul_comp_info_usr_foreach_comp_info_from_app(app_id, getuid(),
+ callback, user_data);
+}
+
+extern "C" API int aul_comp_info_usr_foreach_comp_info_from_app(
+ const char* app_id, uid_t uid, aul_comp_info_cb callback, void* user_data) {
+ if (app_id == nullptr || callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ for (auto const& info : GetComponentInfos(uid)) {
+ if (info->GetAppId().compare(app_id) != 0)
+ continue;
+
+ if (!callback(info.get(), user_data))
+ break;
+ }
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}
+
+extern "C" API int aul_comp_info_foreach_comp_info(aul_comp_info_cb callback,
+ void* user_data) {
+ return aul_comp_info_usr_foreach_comp_info(getuid(), callback, user_data);
+}
+
+extern "C" API int aul_comp_info_usr_foreach_comp_info(uid_t uid,
+ aul_comp_info_cb callback, void* user_data) {
+ if (callback == nullptr) {
+ _E("Invalid parameter");
+ return AUL_R_EINVAL;
+ }
+
+ try {
+ for (auto const& info : GetComponentInfos(uid)) {
+ if (!callback(info.get(), user_data))
+ break;
+ }
+ } catch (const Exception& e) {
+ _E("Exception occurs. error(%s)", e.what());
+ return e.GetErrorCode();
+ }
+
+ return AUL_R_OK;
+}