2 * Copyright (c) 2011 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the License);
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an AS IS BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include <app_internal.h>
31 #define LOG_TAG "CAPI_APPFW_APPLICATION"
33 int app_get_package_app_name(const char *appid, char **name)
35 char *name_token = NULL;
39 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
42 // com.vendor.name -> name
43 name_token = strrchr(appid, '.');
45 if (name_token == NULL)
47 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
52 *name = strdup(name_token);
56 return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
59 return APP_ERROR_NONE;
62 int app_get_package(char **package)
64 return app_get_id(package);
67 int app_get_id(char **id)
69 static char id_buf[TIZEN_PATH_MAX] = {0, };
74 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
77 if (id_buf[0] == '\0')
79 ret = aul_app_get_appid_bypid(getpid(), id_buf, sizeof(id_buf));
81 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
85 if (id_buf[0] == '\0')
87 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
94 return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
97 return APP_ERROR_NONE;
100 static int app_get_appinfo(const char *package, const char *property, char **value)
102 ail_appinfo_h appinfo;
104 char *appinfo_value_dup;
106 if (ail_get_appinfo(package, &appinfo) != 0)
108 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-info");
111 if (ail_appinfo_get_str(appinfo, property, &appinfo_value) != 0)
113 ail_destroy_appinfo(appinfo);
114 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-property");
117 appinfo_value_dup = strdup(appinfo_value);
119 ail_destroy_appinfo(appinfo);
121 if (appinfo_value_dup == NULL)
123 return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
126 *value = appinfo_value_dup;
128 return APP_ERROR_NONE;
131 int app_get_name(char **name)
133 char *package = NULL;
138 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
141 if (app_get_id(&package) != 0)
143 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
146 retval = app_get_appinfo(package, AIL_PROP_NAME_STR, name);
156 int app_get_version(char **version)
163 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
166 if (app_get_id(&package) != 0)
168 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
171 retval = app_get_appinfo(package, AIL_PROP_VERSION_STR, version);