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.
22 #include <sys/types.h>
27 #include <appcore-common.h>
32 #include <app_private.h>
33 #include <app_service_private.h>
39 #define LOG_TAG "TIZEN_N_APPLICATION"
41 int app_get_package_app_name(const char *package, char **name)
43 char *name_token = NULL;
47 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
50 // com.vendor.name -> name
51 name_token = strrchr(package, '.');
53 if (name_token == NULL)
55 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
60 *name = strdup(name_token);
64 return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
67 return APP_ERROR_NONE;
70 int app_get_package(char **package)
72 return app_get_id(package);
75 int app_get_id(char **id)
77 static char id_buf[TIZEN_PATH_MAX] = {0, };
81 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
84 if (id_buf[0] == '\0')
86 aul_app_get_pkgname_bypid(getpid(), id_buf, sizeof(id_buf));
89 if (id_buf[0] == '\0')
91 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
98 return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
101 return APP_ERROR_NONE;
104 static int app_get_appinfo(const char *package, const char *property, char **value)
106 ail_appinfo_h appinfo;
108 char *appinfo_value_dup;
110 if (ail_package_get_appinfo(package, &appinfo) != 0)
112 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-info");
115 if (ail_appinfo_get_str(appinfo, property, &appinfo_value) != 0)
117 ail_package_destroy_appinfo(appinfo);
118 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-property");
121 appinfo_value_dup = strdup(appinfo_value);
123 ail_package_destroy_appinfo(appinfo);
125 if (appinfo_value_dup == NULL)
127 return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
130 *value = appinfo_value_dup;
132 return APP_ERROR_NONE;
135 int app_get_name(char **name)
137 char *package = NULL;
142 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
145 if (app_get_package(&package) != 0)
147 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
150 retval = app_get_appinfo(package, AIL_PROP_NAME_STR, name);
160 int app_get_version(char **version)
167 return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
170 if (app_get_package(&package) != 0)
172 return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
175 retval = app_get_appinfo(package, AIL_PROP_VERSION_STR, version);