* 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.
+ * limitations under the License.
*/
-#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <bundle.h>
-#include <appcore-common.h>
#include <aul.h>
-#include <ail.h>
+#include <pkgmgr-info.h>
#include <dlog.h>
#include <app_private.h>
char *name_token = NULL;
if (appid == NULL)
- {
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
// com.vendor.name -> name
name_token = strrchr(appid, '.');
if (name_token == NULL)
- {
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, NULL);
- }
name_token++;
*name = strdup(name_token);
if (*name == NULL)
- {
return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- }
return APP_ERROR_NONE;
}
int ret = -1;
if (id == NULL)
- {
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (id_buf[0] == '\0')
- {
+ if (id_buf[0] == '\0') {
ret = aul_app_get_appid_bypid(getpid(), id_buf, sizeof(id_buf));
- if (ret < 0) {
+ if (ret < 0)
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
- }
}
if (id_buf[0] == '\0')
- {
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the application ID");
- }
*id = strdup(id_buf);
if (*id == NULL)
- {
return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- }
return APP_ERROR_NONE;
}
-static int app_get_appinfo(const char *package, const char *property, char **value)
+int app_get_name(char **name)
{
- ail_appinfo_h appinfo;
- char *appinfo_value;
- char *appinfo_value_dup;
+ int retval = 0;
+ char *appid = NULL;
+ char *label = NULL;
+ pkgmgrinfo_appinfo_h appinfo = NULL;
- if (ail_get_appinfo(package, &appinfo) != 0)
- {
- return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-info");
- }
-
- if (ail_appinfo_get_str(appinfo, property, &appinfo_value) != 0)
- {
- ail_destroy_appinfo(appinfo);
- return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get app-property");
+ if(name == NULL)
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+
+ if (app_get_id(&appid) != 0)
+ return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
+
+ retval = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &appinfo);
+ if (retval != 0) {
+ free(appid);
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
- appinfo_value_dup = strdup(appinfo_value);
+ retval = pkgmgrinfo_appinfo_get_label(appinfo, &label);
+ if (retval != 0) {
+ free(appid);
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+ }
- ail_destroy_appinfo(appinfo);
+ *name = strdup(label);
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
+ free(appid);
- if (appinfo_value_dup == NULL)
- {
+ if (*name == NULL)
return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- }
- *value = appinfo_value_dup;
-
return APP_ERROR_NONE;
}
-int app_get_name(char **name)
+int app_get_version(char **version)
{
- char *package = NULL;
- int retval;
+ int retval = 0;
+ char *appid = NULL;
+ char *pkgid = NULL;
+ char *pkg_version = NULL;
+ pkgmgrinfo_pkginfo_h pkginfo = NULL;
+ pkgmgrinfo_appinfo_h appinfo = NULL;
- if(name == NULL)
- {
+ if(version == NULL)
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- }
- if (app_get_id(&package) != 0)
- {
+ if (app_get_id(&appid) != 0)
return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
- }
- retval = app_get_appinfo(package, AIL_PROP_NAME_STR, name);
-
- if (package != NULL)
- {
- free(package);
+ retval = pkgmgrinfo_appinfo_get_usr_appinfo(appid, getuid(), &appinfo);
+ if (retval != 0) {
+ free(appid);
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
- return retval;
-}
-
-int app_get_version(char **version)
-{
- char *package;
- int retval;
+ retval = pkgmgrinfo_appinfo_get_pkgid(appinfo, &pkgid);
+ if (retval != 0) {
+ free(appid);
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
+ }
- if(version == NULL)
- {
+ retval = pkgmgrinfo_pkginfo_get_pkginfo(pkgid, &pkginfo);
+ if (retval != 0) {
+ free(appid);
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
- if (app_get_id(&package) != 0)
- {
- return app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
+ retval = pkgmgrinfo_pkginfo_get_version(pkginfo, &pkg_version);
+ if (retval != 0) {
+ free(appid);
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ return app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
}
- retval = app_get_appinfo(package, AIL_PROP_VERSION_STR, version);
+ *version = strdup(pkg_version);
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
+ free(appid);
- if (package != NULL)
- {
- free(package);
- }
+ if (*version == NULL)
+ return app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- return retval;
+ return APP_ERROR_NONE;
}
+
* 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.
+ * limitations under the License.
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-
-#include <bundle.h>
#include <appcore-common.h>
#include <appcore-efl.h>
-#include <aul.h>
-#include <dlog.h>
-#include <ail.h>
-
-#include <app_private.h>
-#include <app_service_private.h>
-
-#include <tzplatform_config.h>
#ifdef LOG_TAG
#undef LOG_TAG
#define LOG_TAG "CAPI_APPFW_APPLICATION"
-#define INSTALLED_PATH tzplatform_getenv(TZ_USER_APP)
-#define RO_INSTALLED_PATH tzplatform_getenv(TZ_SYS_RO_APP)
-
-static const char *RES_DIRECTORY_NAME = "res";
-static const char *DATA_DIRECTORY_NAME = "data";
-
-static char * app_get_root_directory(char *buffer, int size)
-{
- char *appid = NULL;
- char root_directory[TIZEN_PATH_MAX] = {0, };
- char bin_directory[TIZEN_PATH_MAX] = {0, };
- ail_appinfo_h ail_app_info;
- char *pkgid;
-
- if (app_get_id(&appid) != APP_ERROR_NONE)
- {
- app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the appid");
- return NULL;
- }
-
- if (ail_get_appinfo(appid, &ail_app_info) != AIL_ERROR_OK)
- {
- app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the appinfo");
- free(appid);
- return NULL;
- }
-
- if (ail_appinfo_get_str(ail_app_info, AIL_PROP_X_SLP_PKGID_STR, &pkgid) != AIL_ERROR_OK)
- {
- app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the pkgid");
- free(appid);
- ail_destroy_appinfo(ail_app_info);
- return NULL;
- }
-
- if(pkgid)
- {
- free(appid);
- appid = strdup(pkgid);
- }
-
- ail_destroy_appinfo(ail_app_info);
-
- snprintf(root_directory, sizeof(root_directory), "%s/%s", INSTALLED_PATH, appid);
- snprintf(bin_directory, sizeof(bin_directory), "%s/bin", root_directory);
-
- if (access(bin_directory, R_OK) != 0) {
- snprintf(root_directory, sizeof(root_directory), "%s/%s", RO_INSTALLED_PATH, appid);
- }
-
- free(appid);
-
- if (size < strlen(root_directory)+1)
- {
- app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
- return NULL;
- }
-
- snprintf(buffer, size, "%s", root_directory);
-
- return buffer;
-}
-
-static char* app_get_resource_directory(char *buffer, int size)
-{
- char root_directory[TIZEN_PATH_MAX] = {0, };
- char resource_directory[TIZEN_PATH_MAX] = {0, };
-
- if (app_get_root_directory(root_directory, sizeof(root_directory)) == NULL)
- {
- app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the root directory of the application");
- return NULL;
- }
-
- snprintf(resource_directory, sizeof(resource_directory), "%s/%s", root_directory, RES_DIRECTORY_NAME);
-
- if (size < strlen(resource_directory) +1)
- {
- app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
- return NULL;
- }
-
- snprintf(buffer, size, "%s", resource_directory);
-
- return buffer;
-}
-
-char* app_get_data_directory(char *buffer, int size)
-{
- static char data_directory[TIZEN_PATH_MAX] = {0, };
- static int data_directory_length = 0;
- ail_appinfo_h ail_app_info;
- char *pkgid;
-
- if (data_directory[0] == '\0')
- {
- char *root_directory = NULL;
- char *appid = NULL;
-
- root_directory = calloc(1, TIZEN_PATH_MAX);
-
- if (root_directory == NULL)
- {
- app_error(APP_ERROR_OUT_OF_MEMORY, __FUNCTION__, NULL);
- return NULL;
- }
-
- if (app_get_id(&appid) != APP_ERROR_NONE)
- {
- app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
- free(root_directory);
- return NULL;
- }
-
- if (ail_get_appinfo(appid, &ail_app_info) != AIL_ERROR_OK)
- {
- app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
- free(root_directory);
- free(appid);
- return NULL;
- }
-
- if (ail_appinfo_get_str(ail_app_info, AIL_PROP_X_SLP_PKGID_STR, &pkgid) != AIL_ERROR_OK)
- {
- app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the package");
- free(root_directory);
- free(appid);
- ail_destroy_appinfo(ail_app_info);
- return NULL;
- }
-
- if(pkgid)
- {
- free(appid);
- appid = strdup(pkgid);
- }
-
- ail_destroy_appinfo(ail_app_info);
-
- snprintf(root_directory, TIZEN_PATH_MAX, "%s/%s", INSTALLED_PATH, appid);
-
- free(appid);
-
- snprintf(data_directory, sizeof(data_directory), "%s/%s", root_directory, DATA_DIRECTORY_NAME);
-
- data_directory_length = strlen(data_directory);
-
- free(root_directory);
- }
-
- if (size < data_directory_length+1)
- {
- app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
- return NULL;
- }
-
- snprintf(buffer, size, "%s", data_directory);
-
- return buffer;
-}
-
-char* app_get_resource(const char *resource, char *buffer, int size)
-{
- static char resource_directory[TIZEN_PATH_MAX] = {0, };
- static int resource_directory_length = 0;
-
- int resource_path_length = 0;
-
- if (resource == NULL)
- {
- app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- return NULL;
- }
-
- if (buffer == NULL || size <= 0)
- {
- app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, NULL);
- return NULL;
- }
-
- if (resource_directory[0] == '\0')
- {
- if (app_get_resource_directory(resource_directory, sizeof(resource_directory)) == NULL)
- {
- app_error(APP_ERROR_INVALID_CONTEXT, __FUNCTION__, "failed to get the path to the resource directory");
- return NULL;
- }
-
- resource_directory_length = strlen(resource_directory);
- }
-
- resource_path_length = resource_directory_length + strlen("/") + strlen(resource);
-
- if (size < resource_path_length+1)
- {
- app_error(APP_ERROR_INVALID_PARAMETER, __FUNCTION__, "the buffer is not big enough");
- return NULL;
- }
-
- snprintf(buffer, size, "%s/%s", resource_directory, resource);
-
- return buffer;
-}
-
-
void app_set_reclaiming_system_cache_on_pause(bool enable)
{
appcore_set_system_resource_reclaiming(enable);