Add aul-server package for daemon 51/254251/10
authorHwankyu Jhun <h.jhun@samsung.com>
Thu, 25 Feb 2021 05:09:24 +0000 (14:09 +0900)
committerHwankyu Jhun <h.jhun@samsung.com>
Tue, 9 Mar 2021 10:32:42 +0000 (19:32 +0900)
The aul-server package is separated from the aul package. The codes
related to sqlite3 are moved to the aul-server package.
Unused functions are deprecated.

Requires:
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/amd/+/254134/
 - https://review.tizen.org/gerrit/#/c/platform/core/appfw/aul-1/+/254251/
 - https://review.tizen.org/gerrit/#/c/platform/core/api/component-manager/+/254796/

Change-Id: Ie4efda89ab105d70dc30e7b0deae5c525bcfb65f
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
38 files changed:
CMakeLists.txt
include/aul_cmd.h
include/aul_svc.h
include/aul_widget.h
packaging/aul-server.manifest [new file with mode: 0644]
packaging/aul.spec [changed mode: 0755->0644]
server/CMakeLists.txt [new file with mode: 0644]
server/api/aul_comp_info_internal.cc [new file with mode: 0644]
server/api/aul_comp_info_internal.h [moved from include/aul_comp_info_internal.h with 98% similarity]
server/api/aul_service.cc [new file with mode: 0644]
server/api/aul_service.h [new file with mode: 0644]
server/api/aul_types.h [new file with mode: 0644]
server/api/aul_widget_service.cc [new file with mode: 0644]
server/api/aul_widget_service.h [new file with mode: 0644]
server/aul-server.pc.in [new file with mode: 0644]
server/common_private.hh [new file with mode: 0644]
server/component_info.cc [new file with mode: 0644]
server/component_info.hh [new file with mode: 0644]
server/database.cc [new file with mode: 0644]
server/database.hh [new file with mode: 0644]
server/exception.hh [new file with mode: 0644]
server/localized_info.cc [new file with mode: 0644]
server/localized_info.hh [new file with mode: 0644]
server/log_private.hh [new file with mode: 0644]
src/aul_cmd.c [changed mode: 0755->0644]
src/aul_comp_info.c
src/aul_comp_info_internal.c [deleted file]
src/aul_complication.c [changed mode: 0755->0644]
src/aul_rsc_mgr.c [changed mode: 0755->0644]
src/launch.c [changed mode: 0755->0644]
src/service.c [changed mode: 0755->0644]
src/service_db.c [deleted file]
src/widget.c
tool/recovery/CMakeLists.txt
tool/recovery/appsvc_db_recovery.c
tool/recovery/component_db_recovery.c
tool/recovery/db_internal.c [moved from src/aul_db.c with 89% similarity]
tool/recovery/db_internal.h [moved from src/aul_db.h with 80% similarity]

index 83a1cbc..12f05a2 100644 (file)
@@ -11,7 +11,7 @@ SET(EXEC_PREFIX "\${prefix}")
 ADD_DEFINITIONS("-DSHARE_PREFIX=\"${SHARE_INSTALL_PREFIX}/aul\"")
 
 ## Compile flags
-SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-zdefs -fvisibility=hidden -g -Wall -Werror -fpic")
+SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wl,-zdefs -fvisibility=hidden -g -Wall -Werror -fpic ")
 SET(CMAKE_C_FLAGS_DEBUG "-O0 -g")
 SET(CMAKE_C_FLAGS_RELEASE "-O2")
 
@@ -98,7 +98,6 @@ APPLY_PKG_CONFIG(${TARGET_AUL} PUBLIC
   LIBTZPLATFORM_CONFIG_DEPS
   LIBXML_DEPS
   PKGMGR_INFO_DEPS
-  SQLITE3_DEPS
   STORAGE_DEPS
   TTRACE_DEPS
   UUID_DEPS
@@ -126,6 +125,7 @@ INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/aul/api/ DESTINATION include/aul/api
 )
 
 ## Sub directories
-ADD_SUBDIRECTORY(tool)
 ADD_SUBDIRECTORY(parser)
+ADD_SUBDIRECTORY(server)
 ADD_SUBDIRECTORY(test)
+ADD_SUBDIRECTORY(tool)
index 089cee1..9346725 100644 (file)
@@ -196,6 +196,8 @@ enum app_cmd {
        APP_LIFECYCLE_UPDATE_STATE = 155,
 
        APP_STATUS_UPDATE_V2 = 156,
+       APP_GET_APP_CONTROL_DEFAULT_APPS = 157,
+       APP_GET_APPID_BY_ALIAS_APPID = 158,
 
        APP_CMD_MAX
 };
index 5def1df..1eaff91 100644 (file)
@@ -23,6 +23,9 @@
 extern "C" {
 #endif
 
+#ifndef AUL_DEPRECATED_API
+#define AUL_DEPRECATED_API __attribute__((__visibility__("default"), deprecated))
+#endif
 
 /** AUL_SVC OPERATION TYPE*/
 #define AUL_SVC_OPERATION_DEFAULT        "http://tizen.org/appcontrol/operation/default"
@@ -885,129 +888,6 @@ int aul_svc_send_result(bundle *b, aul_svc_result_val result);
 
 /**
  * @par Description:
- * This API set the default application(package name) associated with op, uri and mime-type.
- *
- * @param[in] op        operation
- * @param[in] mime_type mime-type
- * @param[in] scheme    scheme of uri
- * @param[in] defapp    default application
- *
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- * @retval AUL_SVC_RET_EINVAL - invalid argument(content)
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
-    aul_svc_set_defapp(AUL_SVC_OPERATION_VIEW, NULL,"http", "org.tizen.mybrowser");
-}
- * @endcode
- *
- */
-int aul_svc_set_defapp(const char *op, const char *mime_type, const char *uri,
-                                               const char *defapp);
-int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type, const char *uri,
-                                               const char *defapp, uid_t uid);
-
-/**
- * @par Description:
- * This API unset the default application(package name) associated with op, uri and mime-type.
- *
- * @param[in] defapp    default application
- *
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
-    aul_svc_unset_defapp("org.tizen.test");
-}
- * @endcode
- *
- */
-int aul_svc_unset_defapp(const char *defapp);
-int aul_svc_unset_defapp_for_uid(const char *defapp, uid_t uid);
-
-/**
- * @par Description:
- * This API unset all of default applications associated with op, uri and mime-type.
- *
- *
- * @retval AUL_SVC_RET_OK - success
- * @retval AUL_SVC_RET_ERROR - general error
- *
- * @pre None.
- * @post None.
- * @see None.
- * @remarks None.
- *
- * @par Sample code:
- * @code
-#include <aul_svc.h>
-
-...
-{
-    aul_svc_unset_all_defapps();
-}
- * @endcode
- *
- */
-int aul_svc_unset_all_defapps();
-int aul_svc_unset_all_defapps_for_uid(uid_t uid);
-
-/**
- * @par Description:
- *  This API ask a application is default application or not.
- *
- * @param[in]   appid   application appid
- * @return  true / false
- * @retval  1   app_name is default application in appsvc.
- * @retval  0   app_name is NOT default application in appsvc.
- *
-  * @pre None.
-  * @post None.
-  * @see None.
-  * @remarks None.
-  *
-  * @par Sample code:
-  * @code
-#include <aul_svc.h>
-
- ...
-
- * int is_defapp_browser_app()
- * {
- *      return aul_svc_is_defapp("org.tizen.browser");
- * }
- *
- * @endcode
- * @remark
- *  None
-*
-*/
-int aul_svc_is_defapp(const char *appid);
-int aul_svc_is_defapp_for_uid(const char *pkg_name, uid_t uid);
-
-
-/**
- * @par Description:
  *  This API ask a extra data is array or not.
  *
  * @param[in] b bundle object
@@ -1144,64 +1024,6 @@ int aul_svc_set_background_launch(bundle *b, int enabled);
 
 /**
  * @par Description:
- * This API set the alias appid.
- *
- * @param[in] alias_appid      an alias application ID
- * @param[in] appid            an application ID
- * @return 0 if success, negative value(<0) if fail
- */
-int aul_svc_set_alias_appid(const char *alias_appid, const char *appid);
-int aul_svc_set_alias_appid_for_uid(const char *alias_appid,
-               const char *appid, uid_t uid);
-
-/**
- * @par Description:
- * This API unset the alias appid.
- *
- * @param[in] alias_appid an alias application ID
- *
- * @return 0 if success, negative value(<0) if fail
- */
-int aul_svc_unset_alias_appid(const char *alias_appid);
-int aul_svc_unset_alias_appid_for_uid(const char *alias_appid, uid_t uid);
-
-/**
- * @par Description:
- * This API retrieves all alias information.
- *
- * @param[in]  callback        The callback function to be invoked
- * @param[in]  user_data       The user data to be passed to the callback function
- *
- * @return     0 if success, negative value(<0) if fail
- */
-int aul_svc_foreach_alias_info(void (*callback)(const char *alias_appid,
-                       const char *appid, void *data), void *user_data);
-int aul_svc_foreach_alias_info_for_uid(void (*callback)(const char *alias_appid,
-                       const char *appid, void *data),
-               uid_t uid, void *user_data);
-
-/**
- * @par Description:
- * This API activates the alias information based on the given appid.
- *
- * @param[in]  appid   an application ID
- * @return     0 if success, negative value(<0) if fail
- */
-int aul_svc_enable_alias_info(const char *appid);
-int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid);
-
-/**
- * @par Description:
- * This API deactivates the alias information based on the given appid.
- *
- * @param[in]  appid   an application ID
- * @return     0 if success, negative value(<0) if fail
- */
-int aul_svc_disable_alias_info(const char *appid);
-int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid);
-
-/**
- * @par Description:
  * This API gets an application ID by an alias application ID.
  *
  * @param[in]   alias_appid   An alias application ID
@@ -1215,56 +1037,6 @@ int aul_svc_get_appid_by_alias_appid_for_uid(const char *alias_appid,
 
 /**
  * @par Description:
- * This API retrieves all alias information based on the given appid.
- *
- * @param[in]   callback        The callback function to be invoked
- * @param[in]   appid           An application ID
- * @param[in]   user_data       The user data to be passed to the callback function
- *
- * @return      0 if success, negative value(<0) if fail
- */
-int aul_svc_foreach_alias_info_by_appid(int (*callback)(
-                       const char *alias_appid, const char *appid, void *data),
-               const char *appid, void *user_data);
-int aul_svc_foreach_alias_info_by_appid_for_uid(int (*callback)(
-                       const char *alias_appid, const char *appid, void *data),
-               const char *appid, uid_t uid, void *user_data);
-
-/**
- * @par Description:
- * This API retrieves all allowed information.
- *
- * @param[in]   callback        The callback function to be invoked
- * @param[in]   user_data       The user data to be passed to the callback function
- *
- * @return      0 if success, negative value(<0) if fail
- */
-int aul_svc_foreach_allowed_info(int (*callback)(const char *appid,
-                       const char *allowed_appid, void *data),
-               void *user_data);
-int aul_svc_foreach_allowed_info_for_uid(int (*callback)(const char *appid,
-                       const char *allowed_appid, void *data),
-               uid_t uid, void *user_data);
-
-/**
- * @par Description:
- * This API retrieves all allowed information based on the given appid.
- *
- * @param[in]   callback        The callback function to be invoked
- * @param[in]   appid           An application ID
- * @param[in]   user_data       The user data to be passed to the callback function
- *
- * @return      0 if success, negative value(<0) if fail
- */
-int aul_svc_foreach_allowed_info_by_appid(int (*callback)(
-                       const char *appid, const char *allowed_appid, void *data),
-               const char *appid, void *user_data);
-int aul_svc_foreach_allowed_info_by_appid_for_uid(int (*callback)(
-                       const char *appid, const char *allowed_appid, void *data),
-               const char *appid, uid_t uid, void *user_data);
-
-/**
- * @par Description:
  *      Gets the instance ID.
  *
  * @param[in]   b               Bundle object
@@ -1407,6 +1179,97 @@ int aul_svc_send_resume_request(bundle *b, int request_code,
 int aul_svc_send_resume_request_for_uid(bundle *b, int request_code,
                aul_svc_err_cb err_cb, void *user_data, uid_t uid);
 
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_set_defapp(const char *op, const char *mime_type,
+               const char *uri, const char *defapp) AUL_DEPRECATED_API;
+int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type,
+               const char *uri, const char *defapp, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_unset_defapp(const char *defapp) AUL_DEPRECATED_API;
+int aul_svc_unset_defapp_for_uid(const char *defapp, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_unset_all_defapps(void) AUL_DEPRECATED_API;
+int aul_svc_unset_all_defapps_for_uid(uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5
+ */
+int aul_svc_is_defapp(const char *appid) AUL_DEPRECATED_API;
+int aul_svc_is_defapp_for_uid(const char *pkg_name, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_set_alias_appid(const char *alias_appid, const char *appid) AUL_DEPRECATED_API;
+int aul_svc_set_alias_appid_for_uid(const char *alias_appid, const char *appid,
+               uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_unset_alias_appid(const char *alias_appid) AUL_DEPRECATED_API;
+int aul_svc_unset_alias_appid_for_uid(const char *alias_appid, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_foreach_alias_info(
+               void (*callback)(const char *, const char *, void *),
+               void *user_data) AUL_DEPRECATED_API;
+int aul_svc_foreach_alias_info_for_uid(
+               void (*callback)(const char *, const char *, void *),
+               uid_t uid, void *user_data) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_enable_alias_info(const char *appid) AUL_DEPRECATED_API;
+int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_disable_alias_info(const char *appid) AUL_DEPRECATED_API;
+int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_foreach_alias_info_by_appid(
+               int (*callback)(const char *, const char *, void *),
+               const char *appid, void *user_data) AUL_DEPRECATED_API;
+int aul_svc_foreach_alias_info_by_appid_for_uid(
+               int (*callback)(const char *, const char *, void *),
+               const char *appid, uid_t uid, void *user_data) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5.
+ */
+int aul_svc_foreach_allowed_info(
+               int (*callback)(const char *, const char *, void *),
+               void *user_data) AUL_DEPRECATED_API;
+int aul_svc_foreach_allowed_info_for_uid(
+               int (*callback)(const char *, const char *, void *),
+               uid_t uid, void *user_data) AUL_DEPRECATED_API;
+
+/**
+ * @deprecated Deprecated since 6.5
+ */
+int aul_svc_foreach_allowed_info_by_appid(
+               int (*callback)(const char *, const char *, void *),
+               const char *appid, void *user_data) AUL_DEPRECATED_API;
+int aul_svc_foreach_allowed_info_by_appid_for_uid(
+               int (*callback)(const char *, const char *, void *),
+               const char *appid, uid_t uid, void *user_data) AUL_DEPRECATED_API;
+
 #ifdef __cplusplus
 }
 #endif
index c15c1d0..2faeda3 100644 (file)
@@ -150,8 +150,6 @@ int aul_widget_write_log(const char *tag, const char *format, ...);
 
 int aul_widget_service_set_disable(const char *widget_id, bool is_disable);
 
-int aul_widget_service_set_disable_db(const char *widget_id, bool is_disable);
-
 /**
  * @brief Called when the widget event is delivered.
  * @since_tizen 5.5
diff --git a/packaging/aul-server.manifest b/packaging/aul-server.manifest
new file mode 100644 (file)
index 0000000..2a0cec5
--- /dev/null
@@ -0,0 +1,5 @@
+<manifest>
+  <request>
+    <domain name="_"/>
+  </request>
+</manifest>
old mode 100755 (executable)
new mode 100644 (file)
index 31e66bf..7984724
@@ -6,6 +6,7 @@ Group:      Application Framework/Libraries
 License:    Apache-2.0
 Source0:    %{name}-%{version}.tar.gz
 Source1001: %{name}.manifest
+Source1002: %{name}-server.manifest
 
 Requires(post):   /sbin/ldconfig
 Requires(post):   /usr/bin/systemctl
@@ -75,6 +76,24 @@ Group:      Application Framework/Testing
 AUL gcov objects
 %endif
 
+#################################################
+# aul-server
+#################################################
+%package server
+Summary:    Application Utility Library (Server)
+Group:      Development/Libraries
+
+%description server
+Application Utility Library (Server)
+
+%package server-devel
+Summary:    Application Utility Library (Server)
+Group:      Development/Libraries
+Requires:   %{name}-server = %{version}-%{release}
+
+%description server-devel
+Application Utility Library (devel)
+
 %if "%{?_prelink_enable}" == "y"
 %define tizen_feature_prelink 1
 %else
@@ -87,6 +106,7 @@ AUL gcov objects
 %setup -q
 sed -i 's|TZ_SYS_DB|%{TZ_SYS_DB}|g' %{SOURCE1001}
 cp %{SOURCE1001} .
+cp %{SOURCE1002} .
 
 %build
 %if 0%{?gcov:1}
@@ -175,6 +195,12 @@ chsmack -a 'User::Home' %{TZ_SYS_DB}/.component.db-journal
 chmod +x %{_aulresdir}/tpk/install.sh
 %{_aulresdir}/tpk/install.sh
 
+%postun server
+/sbin/ldconfig
+
+%post server
+/sbin/ldconfig
+
 %files
 %license LICENSE
 %manifest %{name}.manifest
@@ -210,8 +236,8 @@ chmod +x %{_aulresdir}/tpk/install.sh
 %files devel
 %{_includedir}/aul/*.h
 %{_includedir}/aul/api/*.h
-%{_libdir}/*.so
-%{_libdir}/pkgconfig/*.pc
+%{_libdir}/libaul.so
+%{_libdir}/pkgconfig/aul.pc
 
 #################################################
 # aul-gcov
@@ -220,3 +246,12 @@ chmod +x %{_aulresdir}/tpk/install.sh
 %files gcov
 %{_datadir}/gcov/*
 %endif
+
+%files server
+%manifest %{name}-server.manifest
+%attr(0644,root,root) %{_libdir}/libaul-server.so.*
+
+%files server-devel
+%{_includedir}/aul/server/*.h
+%{_libdir}/libaul-server.so
+%{_libdir}/pkgconfig/aul-server.pc
diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt
new file mode 100644 (file)
index 0000000..59c194c
--- /dev/null
@@ -0,0 +1,36 @@
+SET(TARGET_AUL_SERVER "aul-server")
+
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR} AUL_SERVER_SRCS)
+AUX_SOURCE_DIRECTORY(${CMAKE_CURRENT_SOURCE_DIR}/api AUL_SERVER_API_SRCS)
+
+ADD_LIBRARY(${TARGET_AUL_SERVER} SHARED
+  ${AUL_SERVER_SRCS}
+  ${AUL_SERVER_API_SRCS}
+)
+
+TARGET_INCLUDE_DIRECTORIES(${TARGET_AUL_SERVER} PUBLIC
+  ${CMAKE_CURRENT_SOURCE_DIR}
+  ${CMAKE_CURRENT_SOURCE_DIR}/../
+  ${CMAKE_CURRENT_SOURCE_DIR}/api
+)
+
+SET_TARGET_PROPERTIES(${TARGET_AUL_SERVER} PROPERTIES SOVERSION ${MAJORVER})
+SET_TARGET_PROPERTIES(${TARGET_AUL_SERVER} PROPERTIES VERSION ${FULLVER})
+
+APPLY_PKG_CONFIG(${TARGET_AUL_SERVER} PUBLIC
+  SQLITE3_DEPS
+  DLOG_DEPS
+)
+
+CONFIGURE_FILE(${TARGET_AUL_SERVER}.pc.in ${TARGET_AUL_SERVER}.pc @ONLY)
+INSTALL(FILES ${CMAKE_CURRENT_SOURCE_DIR}/${TARGET_AUL_SERVER}.pc
+  DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
+
+INSTALL(TARGETS ${TARGET_AUL_SERVER} DESTINATION ${LIB_INSTALL_DIR}
+  COMPONENT RuntimeLibraries)
+
+INSTALL(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/api/
+  DESTINATION include/aul/server
+  FILES_MATCHING
+  PATTERN "*.h"
+)
diff --git a/server/api/aul_comp_info_internal.cc b/server/api/aul_comp_info_internal.cc
new file mode 100644 (file)
index 0000000..9c3f8d9
--- /dev/null
@@ -0,0 +1,459 @@
+/*
+ * Copyright (c) 2019 - 2021 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 <errno.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include <memory>
+#include <string>
+#include <vector>
+#include <tuple>
+
+#include "server/api/aul_comp_info_internal.h"
+#include "server/common_private.hh"
+#include "server/component_info.hh"
+#include "server/database.hh"
+#include "server/exception.hh"
+#include "server/localized_info.hh"
+#include "server/log_private.hh"
+
+using namespace aul;
+
+namespace {
+
+const char COMPONENT_DB[] = ".component.db";
+const char QUERY_COMPONENT_INFO[] = "SELECT app_id, component_id, "
+  "component_type, component_launch_mode, component_main, "
+  "component_icon_display, component_taskmanage FROM component_info";
+const char QUERY_LOCALIZED_INFO[] = "SELECT component_locale, "
+  "component_icon, component_label FROM component_localized_info";
+
+ComponentInfo* CreateComponentInfo(sqlite3_stmt* stmt) {
+  int idx = 0;
+  ComponentInfo::Builder builder;
+  builder.SetAppId(Database::ColumnText(stmt, idx++));
+  builder.SetCompId(Database::ColumnText(stmt, idx++));
+  builder.SetType(Database::ColumnText(stmt, idx++));
+  builder.SetLaunchMode(Database::ColumnText(stmt, idx++));
+  builder.SetMainComp(Database::ColumnText(stmt, idx++));
+  builder.SetIconDisplay(Database::ColumnText(stmt, idx++));
+  builder.SetTaskManage(Database::ColumnText(stmt, idx++));
+  return builder.Build();
+}
+
+LocalizedInfo* CreateLocalizedInfo(sqlite3_stmt* stmt) {
+  int idx = 0;
+  LocalizedInfo::Builder builder;
+  builder.SetLocale(Database::ColumnText(stmt, idx++));
+  builder.SetIcon(Database::ColumnText(stmt, idx++));
+  builder.SetLabel(Database::ColumnText(stmt, idx++));
+  return builder.Build();
+}
+
+template <typename T, typename ...ARGS>
+int Step(T cb, std::tuple<ARGS...> args, const std::string& query, uid_t uid) {
+  std::string path = Database::GetPath(COMPONENT_DB, uid);
+  Database db(path);
+  try {
+    db.Open(SQLITE_OPEN_READONLY);
+  } catch (Exception& e) {
+    return e.GetErrorCode();
+  }
+
+  sqlite3_stmt* stmt;
+  __PREPARE_V2(db.GetHandle(), query.c_str(), query.length(), stmt);
+  auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+      stmt, sqlite3_finalize);
+  return cb(db.GetHandle(), stmt, args);
+}
+
+using GetComponentInfoCb =
+    int (*)(sqlite3*, sqlite3_stmt*, std::tuple<const char*, ComponentInfo**>);
+using GetComponentInfosCb =
+    int (*)(sqlite3*, sqlite3_stmt*,
+        std::tuple<const char*, std::vector<std::unique_ptr<ComponentInfo>>&>);
+using GetLocalizedInfosCb =
+    int (*)(sqlite3*, sqlite3_stmt*,
+        std::tuple<const char*, std::vector<std::unique_ptr<LocalizedInfo>>&>);
+
+int GetComponentInfo(const char* comp_id, uid_t uid,
+    ComponentInfo** info) {
+  std::string query = std::string(QUERY_COMPONENT_INFO) +
+      " WHERE component_id=?";
+  std::tuple<const char*, ComponentInfo**> param(comp_id, info);
+  return Step<GetComponentInfoCb, const char*, ComponentInfo**>(
+      [](sqlite3* db, sqlite3_stmt* stmt,
+         std::tuple<const char*, ComponentInfo**> args) -> int {
+        __BIND_TEXT(db, stmt, 1, std::get<0>(args));
+        int ret = sqlite3_step(stmt);
+        if (ret != SQLITE_ROW) {
+          _E("sqlite3_step() is failed");
+          return AUL_ERROR_NO_SUCH_APP;
+        }
+
+        auto** component_info = std::get<1>(args);
+        *component_info = CreateComponentInfo(stmt);
+        if (*component_info == nullptr)
+          return AUL_ERROR_OUT_OF_MEMORY;
+
+        return AUL_ERROR_NONE;
+      }, param, query, uid);
+}
+
+int GetComponentInfos(const char* app_id, uid_t uid,
+    std::vector<std::unique_ptr<ComponentInfo>>& infos) {
+  std::string query = std::string(QUERY_COMPONENT_INFO);
+  if (app_id != nullptr)
+    query += " WHERE app_id=?";
+
+  std::tuple<const char*, std::vector<std::unique_ptr<ComponentInfo>>&> param(
+      app_id, infos);
+  return Step<GetComponentInfosCb, const char*,
+              std::vector<std::unique_ptr<ComponentInfo>>&>(
+      [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*,
+          std::vector<std::unique_ptr<ComponentInfo>>&> args) -> int {
+        auto* id = std::get<0>(args);
+        if (id != nullptr)
+          __BIND_TEXT(db, stmt, 1, id);
+
+        auto& v = std::get<1>(args);
+        while (sqlite3_step(stmt) == SQLITE_ROW)
+          v.emplace_back(CreateComponentInfo(stmt));
+
+        if (v.empty())
+          return AUL_ERROR_NO_SUCH_APP;
+
+        return AUL_ERROR_NONE;
+      }, param, query, uid);
+}
+
+int GetLocalizedInfos(const char* comp_id, uid_t uid,
+    std::vector<std::unique_ptr<LocalizedInfo>>& infos) {
+  std::string query = std::string(QUERY_LOCALIZED_INFO);
+  if (comp_id != nullptr)
+    query += " WHERE component_id=?";
+
+  std::tuple<const char*, std::vector<std::unique_ptr<LocalizedInfo>>&> param(
+      comp_id, infos);
+  return Step<GetLocalizedInfosCb, const char*,
+              std::vector<std::unique_ptr<LocalizedInfo>>&>(
+      [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*,
+          std::vector<std::unique_ptr<LocalizedInfo>>&> args) -> int {
+        auto* id = std::get<0>(args);
+        if (id != nullptr)
+          __BIND_TEXT(db, stmt, 1, id);
+
+        auto& v = std::get<1>(args);
+        while (sqlite3_step(stmt) == SQLITE_ROW)
+          v.emplace_back(CreateLocalizedInfo(stmt));
+
+        if (v.empty())
+          return AUL_ERROR_NO_SUCH_APP;
+
+        return AUL_ERROR_NONE;
+      }, param, query, uid);
+}
+
+}  // namespace
+
+extern "C" API int aul_compinfo_create(const char* comp_id,
+    aul_compinfo_h* handle) {
+  return aul_compinfo_usr_create(comp_id, getuid(), handle);
+}
+
+extern "C" API int aul_compinfo_usr_create(const char* comp_id, uid_t uid,
+    aul_compinfo_h* handle) {
+  if (comp_id == nullptr || handle == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  ComponentInfo* info;
+  int ret = ::GetComponentInfo(comp_id, uid, &info);
+  if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+    ret = ::GetComponentInfo(comp_id, GLOBALAPP_UID, &info);
+
+  if (ret != AUL_ERROR_NONE)
+    return ret;
+
+  *handle = static_cast<aul_compinfo_h>(info);
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_destroy(aul_compinfo_h handle) {
+  if (handle == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<ComponentInfo*>(handle);
+  delete info;
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_clone(aul_compinfo_h handle,
+    aul_compinfo_h* clone) {
+  if (handle == nullptr || clone == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<ComponentInfo*>(handle);
+  ComponentInfo::Builder builder;
+  builder.SetAppId(info->GetAppId());
+  builder.SetCompId(info->GetCompId());
+  builder.SetType(info->GetType());
+  builder.SetLaunchMode(info->GetLaunchMode());
+  builder.SetMainComp(info->GetMainComp());
+  builder.SetIconDisplay(info->GetIconDisplay());
+  builder.SetTaskManage(info->GetTaskManage());
+  auto* cloned_info = builder.Build();
+  if (cloned_info == nullptr) {
+    _E("Out of memory");
+    return AUL_ERROR_OUT_OF_MEMORY;
+  }
+
+  *clone = static_cast<aul_compinfo_h>(cloned_info);
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_get_app_id(aul_compinfo_h handle,
+    const char** app_id) {
+  if (handle == nullptr || app_id == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<ComponentInfo*>(handle);
+  *app_id = info->GetAppId().c_str();
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_get_comp_id(aul_compinfo_h handle,
+    const char** comp_id) {
+  if (handle == nullptr || comp_id == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<ComponentInfo*>(handle);
+  *comp_id = info->GetCompId().c_str();
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_get_type(aul_compinfo_h handle,
+    const char** type) {
+  if (handle == nullptr || type == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<ComponentInfo*>(handle);
+  *type = info->GetType().c_str();
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_get_launch_mode(aul_compinfo_h handle,
+    const char** launch_mode) {
+  if (handle == nullptr || launch_mode == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<ComponentInfo*>(handle);
+  *launch_mode = info->GetLaunchMode().c_str();
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_is_main_comp(aul_compinfo_h handle,
+    bool* main_comp) {
+  if (handle == nullptr || main_comp == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<ComponentInfo*>(handle);
+  if (info->GetMainComp() == "true")
+    *main_comp = true;
+  else
+    *main_comp = false;
+
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_is_icon_display(aul_compinfo_h handle,
+    bool* icon_display) {
+  if (handle == nullptr || icon_display == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<ComponentInfo*>(handle);
+  if (info->GetIconDisplay() == "true")
+    *icon_display = true;
+  else
+    *icon_display = false;
+
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_is_taskmanage(aul_compinfo_h handle,
+    bool* taskmanage) {
+  if (handle == nullptr || taskmanage == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<ComponentInfo*>(handle);
+  if (info->GetTaskManage() == "true")
+    *taskmanage = true;
+  else
+    *taskmanage = false;
+
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_foreach_compinfo_from_app(const char* app_id,
+    aul_compinfo_cb callback, void* user_data) {
+  return aul_compinfo_usr_foreach_compinfo_from_app(app_id, getuid(),
+      callback, user_data);
+}
+
+extern "C" API int aul_compinfo_usr_foreach_compinfo_from_app(
+    const char* app_id, uid_t uid, aul_compinfo_cb callback, void* user_data) {
+  if (app_id == nullptr || callback == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  std::vector<std::unique_ptr<ComponentInfo>> infos;
+  int ret = ::GetComponentInfos(app_id, uid, infos);
+  if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+    ret = ::GetComponentInfos(app_id, GLOBALAPP_UID, infos);
+
+  if (ret != AUL_ERROR_NONE) {
+    _E("Failed to get component infos");
+    return ret;
+  }
+
+  for (auto& info : infos) {
+    aul_compinfo_h handle = static_cast<aul_compinfo_h>(info.get());
+    if (!callback(handle, user_data))
+      break;
+  }
+
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_foreach_compinfo(aul_compinfo_cb callback,
+    void* user_data) {
+  return aul_compinfo_usr_foreach_compinfo(getuid(), callback, user_data);
+}
+
+extern "C" API int aul_compinfo_usr_foreach_compinfo(uid_t uid,
+    aul_compinfo_cb callback, void* user_data) {
+  if (callback == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  std::vector<std::unique_ptr<ComponentInfo>> infos;
+  int ret = ::GetComponentInfos(nullptr, uid, infos);
+  if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+    ret = ::GetComponentInfos(nullptr, GLOBALAPP_UID, infos);
+
+  if (ret != AUL_ERROR_NONE) {
+    _E("Failed to get component infos");
+    return ret;
+  }
+
+  for (auto& info : infos) {
+    aul_compinfo_h handle = static_cast<aul_compinfo_h>(info.get());
+    if (!callback(handle, user_data))
+      break;
+  }
+
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_localized_info_get_locale(
+    aul_compinfo_localized_info_h handle, const char** locale) {
+  if (handle == nullptr || locale == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<LocalizedInfo*>(handle);
+  *locale = info->GetLocale().c_str();
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_localized_info_get_icon(
+    aul_compinfo_localized_info_h handle, const char** icon) {
+  if (handle == nullptr || icon == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<LocalizedInfo*>(handle);
+  *icon = info->GetIcon().c_str();
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_localized_info_get_label(
+    aul_compinfo_localized_info_h handle, const char** label) {
+  if (handle == nullptr || label == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  auto* info = static_cast<LocalizedInfo*>(handle);
+  *label = info->GetLabel().c_str();
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_compinfo_foreach_localized_info(const char* comp_id,
+    aul_compinfo_localized_info_cb callback, void* user_data) {
+  return aul_compinfo_usr_foreach_localized_info(comp_id, getuid(),
+      callback, user_data);
+}
+
+extern "C" API int aul_compinfo_usr_foreach_localized_info(const char* comp_id,
+    uid_t uid, aul_compinfo_localized_info_cb callback, void* user_data) {
+  if (comp_id == nullptr || callback == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  std::vector<std::unique_ptr<LocalizedInfo>> infos;
+  int ret = GetLocalizedInfos(comp_id, uid, infos);
+  if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+    ret = GetLocalizedInfos(comp_id, GLOBALAPP_UID, infos);
+
+  if (ret != AUL_ERROR_NONE) {
+    _E("Failed to get localized infos");
+    return ret;
+  }
+
+  for (auto& info : infos) {
+    auto handle = static_cast<aul_compinfo_localized_info_h>(info.get());
+    if (!callback(handle, user_data))
+      break;
+  }
+
+  return AUL_ERROR_NONE;
+}
similarity index 98%
rename from include/aul_comp_info_internal.h
rename to server/api/aul_comp_info_internal.h
index 294ba87..202bc56 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2019 - 2021 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.
  * limitations under the License.
  */
 
-#pragma once
+#ifndef __AUL_COMP_INFO_INTERNAL_H__
+#define __AUL_COMP_INFO_INTERNAL_H__
 
 #include <unistd.h>
 
+#include <aul_types.h>
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -369,3 +372,5 @@ int aul_compinfo_usr_foreach_localized_info(const char *comp_id, uid_t uid,
 #ifdef __cplusplus
 }
 #endif
+
+#endif /* __AUL_COMP_INFO_INTERNAL_H__ */
diff --git a/server/api/aul_service.cc b/server/api/aul_service.cc
new file mode 100644 (file)
index 0000000..6c240dd
--- /dev/null
@@ -0,0 +1,393 @@
+/*
+ * Copyright (c) 2021 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 <sys/types.h>
+#include <tzplatform_config.h>
+#include <unistd.h>
+
+#include <map>
+#include <memory>
+#include <string>
+#include <tuple>
+#include <utility>
+#include <vector>
+
+#include "server/api/aul_service.h"
+#include "server/common_private.hh"
+#include "server/database.hh"
+#include "server/log_private.hh"
+
+using namespace aul;
+
+namespace {
+
+const char APPSVC_DB[] = ".appsvc.db";
+const char QUERY_INSERT_OR_REPLACE_INTO_APPSVC[] = "INSERT OR REPLACE INTO "
+    "appsvc(operation, mime_type, uri, pkg_name) VALUES(?, ?, ?, ?)";
+const char QUERY_DELETE_FROM_APPSVC[] = "DELETE FROM appsvc";
+const char QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO[] =
+    "INSERT OR REPLACE INTO alias_info(alias_appid, appid) VALUES(?, ?)";
+const char QUERY_DELETE_FROM_ALIAS_INFO[] = "DELETE FROM alias_info";
+const char QUERY_SELECT_FROM_ALIAS_INFO[] = "SELECT alias_appid, appid "
+    "FROM alias_info";
+const char QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO_FOR_UID[] =
+    "INSERT OR REPLACE INTO alias_info_for_uid(appid, uid, is_enabled) "
+    "VALUES((SELECT appid FROM alias_info WHERE appid = ?), ?, ?)";
+const char QUERY_UPDATE_ALIAS_INFO_SET_ENABLE_WHERE_APPID[] =
+    "UPDATE alias_info set enable = ? WHERE appid = ?";
+const char QUERY_SELECT_APPID_FROM_ALIAS_INFO[] =
+    "SELECT appid FROM alias_info WHERE alias_info.alias_appid = ?";
+const char QUERY_SELECT_FROM_ALLOWED_INFO[] =
+    "SELECT appid, allowed_appid FROM allowed_info";
+
+using InsertDefaultAppTupleParam = std::vector<const char*>;
+using InsertDefaultAppCb =
+    int (*)(sqlite3*, sqlite3_stmt*, std::tuple<InsertDefaultAppTupleParam>);
+using DeleteDefaultAppCb =
+    int (*)(sqlite3*, sqlite3_stmt*, std::tuple<const char*>);
+using InsertAliasAppIdParam = std::vector<const char*>;
+using InsertAliasAppIdCb =
+    int (*)(sqlite3*, sqlite3_stmt*, std::tuple<InsertAliasAppIdParam>);
+using DeleteAliasAppIdCb =
+    int (*)(sqlite3*, sqlite3_stmt*, std::tuple<const char*>);
+using SelectAliasInfoCb =
+    int (*)(sqlite3*, sqlite3_stmt*,
+        std::tuple<uid_t, uid_t, std::map<std::string, std::string>&>);
+using EnableOrDisableAliasInfoCb =
+    int (*)(sqlite3*, sqlite3_stmt*,
+        std::tuple<uid_t, uid_t, const char*, bool>);
+using SelectAllowedInfoCb =
+    int (*)(sqlite3*, sqlite3_stmt*,
+        std::tuple<std::vector<std::pair<std::string, std::string>>&>);
+
+template <typename T, typename ...ARGS>
+int Step(T cb, std::tuple<ARGS...> args,
+    bool readonly, const std::string& query, uid_t uid) {
+  std::string path = Database::GetPath(APPSVC_DB, uid);
+  Database db(path);
+  try {
+    db.Open(readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE);
+  } catch (Exception& e) {
+    return AUL_ERROR_IO_ERROR;
+  }
+
+  sqlite3_stmt* stmt;
+  __PREPARE_V2(db.GetHandle(), query.c_str(), query.length(), stmt);
+  auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+      stmt, sqlite3_finalize);
+
+  int ret;
+  if (readonly) {
+    ret = cb(db.GetHandle(), stmt, args);
+  } else {
+    db.BeginTransaction();
+    ret = cb(db.GetHandle(), stmt, args);
+    if (ret < 0)
+      db.Rollback();
+    else
+      db.EndTransaction();
+  }
+
+  return ret;
+}
+
+int GetAliasInfos(uid_t uid, uid_t db_uid,
+    std::map<std::string, std::string>& infos) {
+  std::string query(QUERY_SELECT_FROM_ALIAS_INFO);
+  if (db_uid == GLOBALAPP_UID) {
+    query += " WHERE alias_info.appid NOT IN (SELECT appid FROM";
+    query += " alias_info_for_uid WHERE uid = ?)";
+  } else {
+    query += " WHERE enable = 'true'";
+  }
+
+  std::tuple<uid_t, uid_t, std::map<std::string, std::string>&> param(
+      uid, db_uid, infos);
+  int ret = Step<SelectAliasInfoCb, uid_t, uid_t,
+      std::map<std::string, std::string>&>(
+          [](sqlite3* db, sqlite3_stmt* stmt,
+              std::tuple<uid_t, uid_t,
+                  std::map<std::string, std::string>&> args) -> int {
+            uid_t db_uid = std::get<1>(args);
+            if (db_uid == GLOBALAPP_UID) {
+              uid_t uid = std::get<0>(args);
+              __BIND_INT(db, stmt, 1, uid);
+            }
+
+            auto& infos = std::get<2>(args);
+            while (sqlite3_step(stmt) == SQLITE_ROW) {
+              int idx = 0;
+              std::string alias_appid = Database::ColumnText(stmt, idx++);
+              std::string appid = Database::ColumnText(stmt, idx++);
+              infos[alias_appid] = appid;
+            }
+
+            return AUL_ERROR_NONE;
+          }, param, true, query, db_uid);
+  if (ret != AUL_ERROR_NONE)
+    return AUL_ERROR_IO_ERROR;
+
+  return AUL_ERROR_NONE;
+}
+
+int EnableOrDisableAliasInfo(uid_t uid, uid_t db_uid, const char* appid,
+    bool enable) {
+  std::string query;
+  if (db_uid == GLOBALAPP_UID)
+    query = QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO_FOR_UID;
+  else
+    query = QUERY_UPDATE_ALIAS_INFO_SET_ENABLE_WHERE_APPID;
+
+  std::tuple<uid_t, uid_t, const char*, bool> param(uid, db_uid, appid, enable);
+  int ret = Step<EnableOrDisableAliasInfoCb, uid_t, uid_t, const char*, bool>(
+      [](sqlite3* db, sqlite3_stmt* stmt,
+          std::tuple<uid_t, uid_t, const char*, bool> args) -> int {
+        int idx = 1;
+        uid_t db_uid = std::get<1>(args);
+        if (db_uid == GLOBALAPP_UID) {
+          __BIND_TEXT(db, stmt, idx++, std::get<2>(args));
+          __BIND_INT(db, stmt, idx++, std::get<0>(args));
+          __BIND_TEXT(db, stmt, idx++, std::get<3>(args) ? "true" : "false");
+        } else {
+          __BIND_TEXT(db, stmt, idx++, std::get<3>(args) ? "true" : "false");
+          __BIND_TEXT(db, stmt, idx++, std::get<2>(args));
+        }
+
+        __STEP(db, stmt);
+        return AUL_ERROR_NONE;
+      }, param, false, query, db_uid);
+  if (ret != AUL_ERROR_NONE)
+    return AUL_ERROR_IO_ERROR;
+
+  return AUL_ERROR_NONE;
+}
+
+int GetAllowedInfos(uid_t uid,
+    std::vector<std::pair<std::string, std::string>>& infos) {
+  std::string query(QUERY_SELECT_FROM_ALLOWED_INFO);
+  std::tuple<std::vector<std::pair<std::string, std::string>>&> param(infos);
+  int ret = Step<SelectAllowedInfoCb,
+      std::vector<std::pair<std::string, std::string>>&>(
+          [](sqlite3* db, sqlite3_stmt* stmt,
+             std::tuple<std::vector<std::pair<std::string,
+                std::string>>&> args) -> int {
+            auto& infos = std::get<0>(args);
+            while (sqlite3_step(stmt) == SQLITE_ROW) {
+              int idx = 0;
+              std::string appid = Database::ColumnText(stmt, idx++);
+              std::string allowed_appid = Database::ColumnText(stmt, idx++);
+              infos.emplace_back(appid, allowed_appid);
+            }
+            return AUL_ERROR_NONE;
+          }, param, false, query, uid);
+  if (ret != AUL_ERROR_NONE)
+    return AUL_ERROR_IO_ERROR;
+
+  return AUL_ERROR_NONE;
+}
+
+}  // namespace
+
+extern "C" API int aul_service_insert_usr_default_app(const char* operation,
+    const char* mime_type, const char* uri, const char* appid, uid_t uid) {
+  if (operation == nullptr || appid == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  std::string query(QUERY_INSERT_OR_REPLACE_INTO_APPSVC);
+  std::vector<const char*> argv { operation, mime_type, uri, appid };
+  std::tuple<InsertDefaultAppTupleParam> param(argv);
+  int ret = Step<InsertDefaultAppCb, InsertDefaultAppTupleParam>(
+      [](sqlite3* db, sqlite3_stmt* stmt,
+         std::tuple<InsertDefaultAppTupleParam> args) -> int {
+        int idx = 1;
+        auto argv = std::get<0>(args);
+        __BIND_TEXT(db, stmt, idx++, argv[0]);
+        __BIND_TEXT(db, stmt, idx++, argv[1] ? argv[1] : "NULL");
+        __BIND_TEXT(db, stmt, idx++, argv[2] ? argv[2] : "NULL");
+        __BIND_TEXT(db, stmt, idx++, argv[3]);
+        __STEP(db, stmt);
+        return AUL_ERROR_NONE;
+      }, param, false, query, uid);
+  if (ret != AUL_ERROR_NONE)
+    return AUL_ERROR_IO_ERROR;
+
+  return AUL_ERROR_NONE;
+}
+
+static int __delete_usr_default_app(const char* appid, uid_t uid) {
+  std::string query(QUERY_DELETE_FROM_APPSVC);
+  if (appid != nullptr)
+    query += " WHERE pkg_name = ?";
+
+  std::tuple<const char*> param(appid);
+  int ret = Step<DeleteDefaultAppCb, const char*>(
+      [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*> args) -> int {
+      auto* appid = std::get<0>(args);
+      __BIND_TEXT(db, stmt, 1, appid);
+      __STEP(db, stmt);
+      return AUL_ERROR_NONE;
+      }, param, false, query, uid);
+  if (ret != AUL_ERROR_NONE)
+    return AUL_ERROR_IO_ERROR;
+
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_service_delete_usr_default_app(const char* appid,
+    uid_t uid) {
+  if (appid == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  return __delete_usr_default_app(appid, uid);
+}
+
+extern "C" API int aul_service_delete_usr_all_default_app(uid_t uid) {
+  return __delete_usr_default_app(nullptr, uid);
+}
+
+extern "C" API int aul_service_insert_usr_alias_appid(const char* alias_appid,
+    const char* appid, uid_t uid) {
+  if (alias_appid == nullptr || appid == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  std::string query(QUERY_INSERT_OR_REPLACE_INTO_ALIAS_INFO);
+  std::vector<const char*> argv { alias_appid, appid };
+  std::tuple<InsertAliasAppIdParam> param(argv);
+  int ret = Step<InsertAliasAppIdCb, InsertAliasAppIdParam>(
+      [](sqlite3* db, sqlite3_stmt* stmt,
+         std::tuple<InsertAliasAppIdParam> args) -> int {
+        auto& argv = std::get<0>(args);
+        int idx = 1;
+        __BIND_TEXT(db, stmt, idx++, argv[0]);
+        __BIND_TEXT(db, stmt, idx++, argv[1]);
+        __STEP(db, stmt);
+        return AUL_ERROR_NONE;
+      }, param, false, query, uid);
+  if (ret != AUL_ERROR_NONE)
+    return AUL_ERROR_IO_ERROR;
+
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_service_delete_usr_alias_appid(const char* alias_appid,
+    uid_t uid) {
+  if (alias_appid == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  std::string query = std::string(QUERY_DELETE_FROM_ALIAS_INFO) +
+      " WHERE alias_appid = ?";
+  std::tuple<const char*> param(alias_appid);
+  int ret = Step<DeleteAliasAppIdCb, const char*>(
+      [](sqlite3* db, sqlite3_stmt* stmt, std::tuple<const char*> args) -> int {
+        auto* alias_appid = std::get<0>(args);
+        __BIND_TEXT(db, stmt, 1, alias_appid);
+        __STEP(db, stmt);
+        return AUL_ERROR_NONE;
+      }, param, false, query, uid);
+  if (ret != AUL_ERROR_NONE)
+    return AUL_ERROR_IO_ERROR;
+
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_service_foreach_usr_alias_info(
+    aul_service_alias_info_cb callback, uid_t uid, void* user_data) {
+  if (callback == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+
+  std::map<std::string, std::string> infos;
+  int ret = GetAliasInfos(uid, uid, infos);
+  if (ret == AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+    ret = GetAliasInfos(uid, GLOBALAPP_UID, infos);
+
+  if (ret != AUL_ERROR_NONE) {
+    _E("Failed to get alias infos. error(%d)", ret);
+    return ret;
+  }
+
+  auto iter = infos.begin();
+  while (iter != infos.end()) {
+    if (!callback(iter->first.c_str(), iter->second.c_str(), user_data))
+      break;
+    iter++;
+  }
+
+  return AUL_ERROR_NONE;
+}
+
+extern "C" API int aul_service_enable_usr_alias_info(const char* appid,
+    uid_t uid) {
+  if (appid == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  int ret = EnableOrDisableAliasInfo(uid, uid, appid, true);
+  if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+    ret = EnableOrDisableAliasInfo(uid, GLOBALAPP_UID, appid, true);
+
+  return ret;
+}
+
+extern "C" API int aul_service_disable_usr_alias_info(const char* appid,
+    uid_t uid) {
+  if (appid == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  int ret = EnableOrDisableAliasInfo(uid, uid, appid, false);
+  if (ret != AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+    ret = EnableOrDisableAliasInfo(uid, GLOBALAPP_UID, appid, false);
+
+  return ret;
+}
+
+extern "C" API int aul_service_foreach_usr_allowed_info(
+    aul_service_allowed_info_cb callback, uid_t uid, void* user_data) {
+  if (callback == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  std::vector<std::pair<std::string, std::string>> infos;
+  int ret = GetAllowedInfos(uid, infos);
+  if (ret == AUL_ERROR_NONE && uid != GLOBALAPP_UID)
+    ret = GetAllowedInfos(GLOBALAPP_UID, infos);
+
+  if (ret != AUL_ERROR_NONE) {
+    _E("Failed to get allowed infos. error(%d)", ret);
+    return ret;
+  }
+
+  for (auto& info : infos) {
+    if (!callback(info.first.c_str(), info.second.c_str(), user_data))
+      break;
+  }
+
+  return AUL_ERROR_NONE;
+}
diff --git a/server/api/aul_service.h b/server/api/aul_service.h
new file mode 100644 (file)
index 0000000..5db2a5a
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __AUL_SERVICE_H__
+#define __AUL_SERVICE_H__
+
+#include <stdbool.h>
+
+#include <aul_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef bool (*aul_service_alias_info_cb)(const char *alias_appid, const char *appid, void *user_data);
+
+typedef bool (*aul_service_allowed_info_cb)(const char *appid, const char *allowed_appid, void *user_data);
+
+int aul_service_insert_usr_default_app(const char* operation, const char* mime_type, const char* uri, const char* appid, uid_t uid);
+
+int aul_service_delete_usr_default_app(const char* appid, uid_t uid);
+
+int aul_service_delete_usr_all_default_app(uid_t uid);
+
+int aul_service_insert_usr_alias_appid(const char* alias_appid, const char* appid, uid_t uid);
+
+int aul_service_delete_usr_alias_appid(const char* alias_appid, uid_t uid);
+
+int aul_service_foreach_usr_alias_info(aul_service_alias_info_cb callback, uid_t uid, void* user_data);
+
+int aul_service_enable_usr_alias_info(const char* appid, uid_t uid);
+
+int aul_service_disable_usr_alias_info(const char* appid, uid_t uid);
+
+int aul_service_foreach_usr_allowed_info(aul_service_allowed_info_cb callback, uid_t uid, void* user_data);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_SERVICE_H__ */
diff --git a/server/api/aul_types.h b/server/api/aul_types.h
new file mode 100644 (file)
index 0000000..90293d7
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __AUL_TYPES_H__
+#define __AUL_TYPES_H__
+
+#include <errno.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * @brief Enumeration for errors of AUL.
+ * @since_tizen 6.5
+ */
+typedef enum {
+       AUL_ERROR_NONE = 0, /**< Successful */
+       AUL_ERROR_INVALID_PARAMETER = -EINVAL, /**< Invalid parameter */
+       AUL_ERROR_IO_ERROR = -EIO, /**< I/O error */
+       AUL_ERROR_NO_SUCH_APP = -ENOENT, /**< No such application */
+       AUL_ERROR_NO_DATA = -ENODATA, /**< No data */
+       AUL_ERROR_OUT_OF_MEMORY = -ENOMEM, /**< Out of memory */
+       AUL_ERROR_PERMISSION_DENIED = -EPERM, /**< Permission denied */
+} aul_error_e;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_TYPES_H__ */
diff --git a/server/api/aul_widget_service.cc b/server/api/aul_widget_service.cc
new file mode 100644 (file)
index 0000000..f39abf7
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2021 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 <sys/types.h>
+#include <tzplatform_config.h>
+#include <unistd.h>
+
+#include "server/api/aul_widget_service.h"
+#include "server/common_private.hh"
+#include "server/database.hh"
+#include "server/log_private.hh"
+
+using namespace aul;
+
+namespace {
+
+const char WIDGET_DB[] = ".widget.db";
+const char QUERY_SET_DISABLE[] = "UPDATE widget_class SET is_disable = ? "
+  "WHERE classid = ?";
+
+std::string GetWidgetDBPath(uid_t uid) {
+  std::string path;
+  if (uid == ROOT_UID || uid == GLOBALAPP_UID) {
+    path = tzplatform_mkpath(TZ_SYS_DB, WIDGET_DB);
+  } else {
+    tzplatform_set_user(uid);
+    path = tzplatform_mkpath(TZ_USER_DB, WIDGET_DB);
+    tzplatform_reset_user();
+  }
+
+  return path;
+}
+
+int SetDisable(sqlite3* db, const char* widget_id, bool is_disable) {
+  sqlite3_stmt* stmt;
+  __PREPARE_V2(db, QUERY_SET_DISABLE, strlen(QUERY_SET_DISABLE),
+      stmt);
+  auto stmt_ptr = std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*>(
+      stmt, sqlite3_finalize);
+
+  int idx = 1;
+  __BIND_INT(db, stmt, idx++, is_disable ? 1 : 0);
+  __BIND_TEXT(db, stmt, idx++, widget_id);
+  __STEP(db, stmt);
+  return AUL_ERROR_NONE;
+}
+
+}  // namespace
+
+extern "C" API int aul_widget_service_set_usr_disable_db(const char* widget_id,
+    bool is_disable, uid_t uid) {
+  if (widget_id == nullptr) {
+    _E("Invalid parameter");
+    return AUL_ERROR_INVALID_PARAMETER;
+  }
+
+  std::string path = ::GetWidgetDBPath(uid);
+  aul::Database db(path);
+  try {
+    db.Open();
+    if (!db.IntegrityCheck()) {
+      _E("database is corrupted");
+      return AUL_ERROR_IO_ERROR;
+    }
+  } catch (Exception& e) {
+    return AUL_ERROR_IO_ERROR;
+  }
+
+  db.BeginTransaction();
+  int ret = ::SetDisable(db.GetHandle(), widget_id, is_disable);
+  db.EndTransaction();
+  return ret;
+}
+
+extern "C" API int aul_widget_service_set_disable_db(const char *widget_id,
+    bool is_disable) {
+  return aul_widget_service_set_usr_disable_db(widget_id, is_disable, getuid());
+}
diff --git a/server/api/aul_widget_service.h b/server/api/aul_widget_service.h
new file mode 100644 (file)
index 0000000..2785ddc
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef __AUL_WIDGET_SERVICE_H__
+#define __AUL_WIDGET_SERVICE_H__
+
+#include <aul_types.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+int aul_widget_service_set_usr_disable_db(const char* widget_id, bool is_disable, uid_t uid);
+
+int aul_widget_service_set_disable_db(const char *widget_id, bool is_disable);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __AUL_WIDGET_SERVICE_H__ */
diff --git a/server/aul-server.pc.in b/server/aul-server.pc.in
new file mode 100644 (file)
index 0000000..0e9fa90
--- /dev/null
@@ -0,0 +1,13 @@
+# Package Information for pkg-config
+
+prefix=@PREFIX@
+exec_prefix=@EXEC_PREFIX@
+libdir=@LIB_INSTALL_DIR@
+includedir=@INCLUDE_INSTALL_DIR@
+
+Name: libaul-server
+Description: Application Utility Libarary (Server)
+Version: @VERSION@
+Requires: dlog
+Libs: -L${libdir} -laul-server
+Cflags: -I${includedir} -I${includedir}/aul/server
diff --git a/server/common_private.hh b/server/common_private.hh
new file mode 100644 (file)
index 0000000..ec67485
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef SERVER_COMMON_PRIVATE_HH_
+#define SERVER_COMMON_PRIVATE_HH_
+
+#include <tzplatform_config.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#undef API
+#define API __attribute__ ((visibility("default")))
+
+#undef ROOT_UID
+#define ROOT_UID 0
+
+#undef GLOBALAPP_UID
+#define GLOBALAPP_UID tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
+
+#undef REGULAR_UID_MIN
+#define REGULAR_UID_MIN 5000
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif  // SERVER_COMMON_PRIVATE_HH_
diff --git a/server/component_info.cc b/server/component_info.cc
new file mode 100644 (file)
index 0000000..696ebb9
--- /dev/null
@@ -0,0 +1,109 @@
+/*
+ * Copyright (c) 2021 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 "server/component_info.hh"
+
+namespace aul {
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetAppId(std::string app_id) {
+  app_id_ = std::move(app_id);
+  return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetCompId(std::string comp_id) {
+  comp_id_ = std::move(comp_id);
+  return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetType(std::string type) {
+  type_ = std::move(type);
+  return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetLaunchMode(
+    std::string launch_mode) {
+  launch_mode_ = std::move(launch_mode);
+  return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetMainComp(
+    std::string main_comp) {
+  main_comp_ = std::move(main_comp);
+  return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetIconDisplay(
+    std::string icon_display) {
+  icon_display_ = std::move(icon_display);
+  return *this;
+}
+
+ComponentInfo::Builder& ComponentInfo::Builder::SetTaskManage(
+    std::string taskmanage) {
+  taskmanage_ = std::move(taskmanage);
+  return *this;
+}
+
+ComponentInfo* ComponentInfo::Builder::Build() {
+  return new (std::nothrow) ComponentInfo(app_id_, comp_id_, type_,
+      launch_mode_, main_comp_, icon_display_, taskmanage_);
+}
+
+ComponentInfo::ComponentInfo(std::string app_id,
+    std::string comp_id,
+    std::string type,
+    std::string launch_mode,
+    std::string main_comp,
+    std::string icon_display,
+    std::string taskmanage)
+    : app_id_(std::move(app_id)),
+      comp_id_(std::move(comp_id)),
+      type_(std::move(type)),
+      launch_mode_(std::move(launch_mode)),
+      main_comp_(std::move(main_comp)),
+      icon_display_(std::move(icon_display)),
+      taskmanage_(std::move(taskmanage)) {
+}
+
+const std::string& ComponentInfo::GetAppId() const {
+  return app_id_;
+}
+
+const std::string& ComponentInfo::GetCompId() const {
+  return comp_id_;
+}
+
+const std::string& ComponentInfo::GetType() const {
+  return type_;
+}
+
+const std::string& ComponentInfo::GetLaunchMode() const {
+  return launch_mode_;
+}
+
+const std::string& ComponentInfo::GetMainComp() const {
+  return main_comp_;
+}
+
+const std::string& ComponentInfo::GetIconDisplay() const {
+  return icon_display_;
+}
+
+const std::string& ComponentInfo::GetTaskManage() const {
+  return taskmanage_;
+}
+
+}  // namespace aul
diff --git a/server/component_info.hh b/server/component_info.hh
new file mode 100644 (file)
index 0000000..1940978
--- /dev/null
@@ -0,0 +1,75 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef SERVER_COMPONENT_INFO_HH_
+#define SERVER_COMPONENT_INFO_HH_
+
+#include <string>
+
+namespace aul {
+
+class ComponentInfo {
+ public:
+  class Builder {
+   public:
+    Builder& SetAppId(std::string app_id);
+    Builder& SetCompId(std::string comp_id);
+    Builder& SetType(std::string type);
+    Builder& SetLaunchMode(std::string launch_mode);
+    Builder& SetMainComp(std::string main_comp);
+    Builder& SetIconDisplay(std::string icon_display);
+    Builder& SetTaskManage(std::string taskmanage);
+    ComponentInfo* Build();
+
+   private:
+    std::string app_id_;
+    std::string comp_id_;
+    std::string type_;
+    std::string launch_mode_;
+    std::string main_comp_;
+    std::string icon_display_;
+    std::string taskmanage_;
+  };
+
+  ComponentInfo(std::string app_id,
+      std::string comp_id,
+      std::string type,
+      std::string launch_mode,
+      std::string main_comp,
+      std::string icon_display,
+      std::string taskmanage);
+
+  const std::string& GetAppId() const;
+  const std::string& GetCompId() const;
+  const std::string& GetType() const;
+  const std::string& GetLaunchMode() const;
+  const std::string& GetMainComp() const;
+  const std::string& GetIconDisplay() const;
+  const std::string& GetTaskManage() const;
+
+ private:
+  std::string app_id_;
+  std::string comp_id_;
+  std::string type_;
+  std::string launch_mode_;
+  std::string main_comp_;
+  std::string icon_display_;
+  std::string taskmanage_;
+};
+
+}  // namespace aul
+
+#endif  // SERVER_COMPONENT_INFO_HH_
diff --git a/server/database.cc b/server/database.cc
new file mode 100644 (file)
index 0000000..63104c3
--- /dev/null
@@ -0,0 +1,156 @@
+/*
+ * Copyright (c) 2021 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 <unistd.h>
+
+#include <memory>
+
+#include "server/common_private.hh"
+#include "server/database.hh"
+#include "server/exception.hh"
+#include "server/log_private.hh"
+
+namespace aul {
+namespace {
+
+const int BUSY_WAITING_USEC = 50000;
+const int BUSY_WAITING_MAX = 40;
+
+}  // namespace
+
+Database::Database(std::string path) : path_(std::move(path)) {
+}
+
+Database::~Database() {
+  Close();
+}
+
+void Database::BeginTransaction() {
+  int ret = sqlite3_exec(db_, "BEGIN TRANSACTION", nullptr, nullptr, nullptr);
+  if (ret != SQLITE_OK)
+    _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+}
+
+void Database::EndTransaction() {
+  int ret = sqlite3_exec(db_, "END TRANSACTION", nullptr, nullptr, nullptr);
+  if (ret != SQLITE_OK)
+    _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+}
+
+void Database::Rollback() {
+  int ret = sqlite3_exec(db_, "ROLLBACK", nullptr, nullptr, nullptr);
+  if (ret != SQLITE_OK)
+    _E("sqlite3_exec() is failed. error(%s:%d", sqlite3_errmsg(db_), ret);
+}
+
+void Database::Open(int flags) {
+  sqlite3* db;
+  int ret = sqlite3_open_v2(path_.c_str(), &db, flags, nullptr);
+  if (ret != SQLITE_OK) {
+    _E("sqlite3_open_v2() is failed. path(%s), error(%d)", path_.c_str(), ret);
+    THROW(-ret);
+  }
+
+  ret = sqlite3_busy_handler(db, BusyHandler,
+      static_cast<void*>(const_cast<char*>(path_.c_str())));
+  if (ret != SQLITE_OK) {
+    _E("sqlite3_busy_handler() is failed. error(%s:%d)",
+        sqlite3_errmsg(db), ret);
+    sqlite3_close_v2(db);
+    THROW(-ret);
+  }
+
+  ret = sqlite3_exec(db, "PRAGMA foreign_keys=ON", nullptr, nullptr, nullptr);
+  if (ret != SQLITE_OK) {
+    _E("sqlite3_exec() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);
+    sqlite3_close_v2(db);
+    THROW(-ret);
+  }
+
+  db_ = db;
+}
+
+void Database::Close() {
+  if (db_) {
+    sqlite3_close(db_);
+    db_ = nullptr;
+  }
+}
+
+sqlite3* Database::GetHandle() {
+  return db_;
+}
+
+std::string Database::ColumnText(sqlite3_stmt* stmt, int index) {
+  auto* text = reinterpret_cast<const char*>(sqlite3_column_text(stmt, index));
+  if (text)
+    return std::string(text);
+
+  return {};
+}
+
+bool Database::IntegrityCheck() {
+  static const char query[] = "PRAGMA integrity_check";
+  sqlite3_stmt* stmt;
+  int ret = sqlite3_prepare_v2(db_, query, strlen(query), &stmt, nullptr);
+  if (ret != SQLITE_OK) {
+    _E("sqlite3_prepare_v2() is failed. error(%s:%d)",
+        sqlite3_errmsg(db_), ret);
+    return false;
+  }
+
+  std::unique_ptr<sqlite3_stmt, decltype(sqlite3_finalize)*> stmt_ptr(
+      stmt, sqlite3_finalize);
+
+  ret = sqlite3_step(stmt);
+  if (ret != SQLITE_ROW) {
+    _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db_), ret);
+    return false;
+  }
+
+  auto* res = reinterpret_cast<const char*>(sqlite3_column_text(stmt, 0));
+  if (res == nullptr) {
+    _E("sqlite3_column_text() is failed. error(%s)", sqlite3_errmsg(db_));
+    return false;
+  }
+
+  if (strcmp(res, "ok") != 0)
+    return false;
+
+  return true;
+}
+
+std::string Database::GetPath(const std::string& name, uid_t uid) {
+  std::string path = std::string(tzplatform_getenv(TZ_SYS_DB)) + "/";
+  if (uid >= REGULAR_UID_MIN)
+    path += "user/" + std::to_string(uid) + "/";
+
+  path += name;
+  return path;
+}
+
+int Database::BusyHandler(void* data, int count) {
+  if (count < BUSY_WAITING_MAX) {
+    usleep(BUSY_WAITING_USEC);
+    return 1;
+  }
+
+  auto* path = static_cast<char*>(data);
+  _E("Database(%s) is busy", path);
+  return 0;
+}
+
+}  // namespace aul
diff --git a/server/database.hh b/server/database.hh
new file mode 100644 (file)
index 0000000..d44f2f0
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef SERVER_DATABASE_HH_
+#define SERVER_DATABASE_HH_
+
+#include <sqlite3.h>
+
+#include <memory>
+#include <string>
+
+#include "exception.hh"
+
+#define __PREPARE_V2(db, query, length, stmt) do {                             \
+  int ret = sqlite3_prepare_v2(db, query, length, &stmt, nullptr);             \
+  if (ret != SQLITE_OK) {                                                      \
+    _E("sqlite3_prepare_v2() is failed. error(%s:%d)",                         \
+        sqlite3_errmsg(db), ret);                                              \
+    return -1;                                                                 \
+  }                                                                            \
+} while (0)
+
+#define __BIND_INT(db, stmt, i, val) do {                                      \
+  if (sqlite3_bind_int(stmt, i, val) != SQLITE_OK) {                           \
+    _E("sqlite3_bind_int() is failed. index(%d), error(%s)",                   \
+        i, sqlite3_errmsg(db));                                                \
+    return -1;                                                                 \
+  }                                                                            \
+} while (0)
+
+#define __BIND_TEXT(db, stmt, i, text) do {                                    \
+  int ret = sqlite3_bind_text(stmt, i, text, -1, SQLITE_TRANSIENT);            \
+  if (ret != SQLITE_OK) {                                                      \
+    _E("sqlite3_bind_text() is failed. index(%d), error(%s:%d)",               \
+        i, sqlite3_errmsg(db), ret);                                           \
+    return -1;                                                                 \
+  }                                                                            \
+} while (0)
+
+#define __STEP(db, stmt) do {                                                  \
+  int ret = sqlite3_step(stmt);                                                \
+  if (ret != SQLITE_DONE) {                                                    \
+    _E("sqlite3_step() is failed. error(%s:%d)", sqlite3_errmsg(db), ret);     \
+    return -1;                                                                 \
+  }                                                                            \
+} while (0)
+
+#define JOURNAL_MODE_WAL "WAL"
+
+#define JOURNAL_MODE_PERSIST "PERSIST"
+
+#define JOURNAL_MODE_MEMORY "MEMORY"
+
+namespace aul {
+
+class Database {
+ public:
+  Database(std::string path);
+  virtual ~Database();
+
+  void Open(int flags = SQLITE_OPEN_READWRITE);
+  void Close();
+  bool IntegrityCheck();
+  void BeginTransaction();
+  void EndTransaction();
+  void Rollback();
+  sqlite3* GetHandle();
+
+  static std::string ColumnText(sqlite3_stmt* stmt, int index);
+  static std::string GetPath(const std::string& name, uid_t uid);
+
+ private:
+  static int BusyHandler(void* data, int count);
+
+ private:
+  std::string path_;
+  sqlite3* db_ = nullptr;
+};
+
+}  // namespace aul
+
+#endif  // SERVER_DATABASE_HH_
diff --git a/server/exception.hh b/server/exception.hh
new file mode 100644 (file)
index 0000000..1d9a5bb
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 2021 Samsung Electronics Co., Ltd.
+ *
+ * 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.
+ */
+
+#ifndef SERVER_EXCEPTION_HH_
+#define SERVER_EXCEPTION_HH_
+
+#include <libgen.h>
+
+#include <string>
+#include <exception>
+
+#include "server/log_private.hh"
+
+#define THROW(error_code) throw Exception(error_code, __FILE__, __LINE__)
+
+namespace aul {
+
+class Exception : public std::exception {
+ public:
+  explicit Exception(int error_code, std::string file, int line) {
+    error_code_ = error_code;
+    message_ = std::string(basename(const_cast<char*>(file.c_str()))) + ":" +
+        std::to_string(line) + " code:" + std::to_string(error_code_);
+    _E("%s", message_.c_str());
+  }
+
+  virtual ~Exception() {}
+
+  virtual const char* what() const noexcept {
+    return message_.c_str();
+  }
+
+  int GetErrorCode() {
+    return error_code_;
+  }
+
+ private:
+  int error_code_;
+  std::string message_;
+};
+
+}  // namespace aul
+
+#endif  // SERVER_EXCEPTION_HH_
diff --git a/server/localized_info.cc b/server/localized_info.cc
new file mode 100644 (file)
index 0000000..3c45999
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2021 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 "server/localized_info.hh"
+
+namespace aul {
+
+LocalizedInfo::Builder& LocalizedInfo::Builder::SetLocale(std::string locale) {
+  locale_ = std::move(locale);
+  return *this;
+}
+
+LocalizedInfo::Builder& LocalizedInfo::Builder::SetIcon(std::string icon) {
+  icon_ = std::move(icon);
+  return *this;
+}
+
+LocalizedInfo::Builder& LocalizedInfo::Builder::SetLabel(std::string label) {
+  label_ = std::move(label);
+  return *this;
+}
+
+LocalizedInfo* LocalizedInfo::Builder::Build() {
+  return new (std::nothrow) LocalizedInfo(locale_, icon_, label_);
+}
+
+LocalizedInfo::LocalizedInfo(std::string locale,
+    std::string icon,
+    std::string label)
+    : locale_(std::move(locale)),
+      icon_(std::move(icon)),
+      label_(std::move(label)) {
+}
+
+const std::string& LocalizedInfo::GetLocale() const {
+  return locale_;
+}
+
+const std::string& LocalizedInfo::GetIcon() const {
+  return icon_;
+}
+
+const std::string& LocalizedInfo::GetLabel() const {
+  return label_;
+}
+
+}  // namespace aul
diff --git a/server/localized_info.hh b/server/localized_info.hh
new file mode 100644 (file)
index 0000000..67a70c7
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef SERVER_LOCALIZED_INFO_HH_
+#define SERVER_LOCALIZED_INFO_HH_
+
+#include <string>
+
+namespace aul {
+
+class LocalizedInfo {
+ public:
+  class Builder {
+   public:
+    Builder& SetLocale(std::string locale);
+    Builder& SetIcon(std::string icon);
+    Builder& SetLabel(std::string label);
+    LocalizedInfo* Build();
+
+   private:
+    std::string locale_;
+    std::string icon_;
+    std::string label_;
+  };
+
+  LocalizedInfo(std::string locale, std::string icon, std::string label);
+  const std::string& GetLocale() const;
+  const std::string& GetIcon() const;
+  const std::string& GetLabel() const;
+
+ private:
+  std::string locale_;
+  std::string icon_;
+  std::string label_;
+};
+
+}  // namespace aul
+
+#endif  // SERVER_LOCALIZED_INFO_HH_
diff --git a/server/log_private.hh b/server/log_private.hh
new file mode 100644 (file)
index 0000000..6d210d0
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2021 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.
+ */
+
+#ifndef SERVER_LOG_PRIVATE_HH_
+#define SERVER_LOG_PRIVATE_HH_
+
+#include <dlog.h>
+
+#undef LOG_TAG
+#define LOG_TAG "AUL"
+
+#undef _E
+#define _E LOGE
+
+#undef _W
+#define _W LOGW
+
+#undef _I
+#define _I LOGI
+
+#undef _D
+#define _D LOGD
+
+#endif  // SERVER_LOG_PRIVATE_HH_
old mode 100755 (executable)
new mode 100644 (file)
index 3d80c35..e064840
@@ -198,6 +198,8 @@ API const char *aul_cmd_convert_to_string(int cmd)
                "APP_LIFECYCLE_UPDATE_STATE",
 
                "APP_STATUS_UPDATE_V2",
+               "APP_GET_APP_CONTROL_DEFAULT_APPS",
+               "APP_GET_APPID_BY_ALIAS_APPID",
 
                "CUSTOM_COMMAND"
        };
index a9fc3de..82ac6f0 100644 (file)
@@ -905,7 +905,7 @@ API int aul_comp_info_usr_create(const char *comp_id, uid_t uid,
                _E("Failed to get component info. error(%d)", pkt->cmd);
                ret = pkt->cmd;
                free(pkt);
-               return ret;
+               return aul_error_convert(ret);
        }
 
        b = NULL;
diff --git a/src/aul_comp_info_internal.c b/src/aul_comp_info_internal.c
deleted file mode 100644 (file)
index 5f9f399..0000000
+++ /dev/null
@@ -1,723 +0,0 @@
-/*
- * 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 <ctype.h>
-#include <linux/limits.h>
-#include <stdbool.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <bundle.h>
-#include <bundle_internal.h>
-#include <glib.h>
-#include <sqlite3.h>
-#include <vconf.h>
-
-#include "aul.h"
-#include "aul_api.h"
-#include "aul_comp_info_internal.h"
-#include "aul_db.h"
-#include "aul_sock.h"
-#include "aul_util.h"
-
-#define COMPONENT_DB ".component.db"
-#define DEFAULT_LOCALE "No Locale"
-#define AUL_COMPINFO_LOCALIZED_INFO_START 0
-#define AUL_COMPINFO_START 0
-
-enum aul_compinfo_e {
-       AUL_COMPINFO_APP_ID = AUL_COMPINFO_START,
-       AUL_COMPINFO_COMP_ID,
-       AUL_COMPINFO_TYPE,
-       AUL_COMPINFO_LAUNCH_MODE,
-       AUL_COMPINFO_MAIN_COMP,
-       AUL_COMPINFO_ICON_DISPLAY,
-       AUL_COMPINFO_TASKMANAGE,
-       AUL_COMPINFO_MAX,
-};
-
-struct aul_compinfo_s {
-       char *value[AUL_COMPINFO_MAX];
-};
-
-enum aul_compinfo_localized_info_e {
-       AUL_COMPINFO_LOCALIZED_INFO_LOCALE = AUL_COMPINFO_LOCALIZED_INFO_START,
-       AUL_COMPINFO_LOCALIZED_INFO_ICON,
-       AUL_COMPINFO_LOCALIZED_INFO_LABEL,
-       AUL_COMPINFO_LOCALIZED_INFO_MAX,
-};
-
-struct aul_compinfo_localized_info_s {
-       char *value[AUL_COMPINFO_LOCALIZED_INFO_MAX];
-};
-
-static void __destroy_compinfo_localized_info(gpointer data)
-{
-       struct aul_compinfo_localized_info_s *info;
-       int idx;
-
-       info = (struct aul_compinfo_localized_info_s *)data;
-       if (!info)
-               return;
-
-       for (idx = AUL_COMPINFO_LOCALIZED_INFO_START;
-                       idx < AUL_COMPINFO_LOCALIZED_INFO_MAX; idx++)
-               free(info->value[idx]);
-
-       free(info);
-}
-
-static bool __get_boolean_value(const char *str)
-{
-       if (str && !strcmp(str, "true"))
-               return true;
-
-       return false;
-}
-
-static sqlite3 *__open_component_db(uid_t uid)
-{
-       sqlite3 *db;
-       char *path;
-
-       path = aul_db_get_path(COMPONENT_DB, uid);
-       if (!path) {
-               _E("Failed to get db path");
-               return NULL;
-       }
-
-       db = aul_db_open(path, true);
-       free(path);
-
-       return db;
-}
-
-static void __close_component_db(sqlite3 *db)
-{
-       aul_db_close(db);
-}
-
-static void __destroy_compinfo(gpointer data)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)data;
-       int idx;
-
-       if (!info)
-               return;
-
-       for (idx = AUL_COMPINFO_START; idx < AUL_COMPINFO_MAX; idx++)
-               free(info->value[idx]);
-
-       free(info);
-}
-
-static struct aul_compinfo_s *__clone_compinfo(struct aul_compinfo_s *info)
-{
-       struct aul_compinfo_s *compinfo;
-       int idx;
-
-       compinfo = calloc(1, sizeof(struct aul_compinfo_s));
-       if (!compinfo) {
-               _E("Out of memory");
-               return NULL;
-       }
-
-       for (idx = AUL_COMPINFO_START; idx < AUL_COMPINFO_MAX; idx++) {
-               compinfo->value[idx] = strdup(info->value[idx]);
-               if (!compinfo->value[idx]) {
-                       _E("Out of memory");
-                       __destroy_compinfo(compinfo);
-                       return NULL;
-               }
-       }
-
-       return compinfo;
-}
-
-static int __create_compinfo(const char *comp_id, uid_t uid,
-               struct aul_compinfo_s **compinfo)
-{
-       static const char query_raw[] = "SELECT "
-               "app_id, component_type, component_launch_mode, "
-               "component_main, component_icon_display, component_taskmanage "
-               "FROM component_info WHERE component_id=%Q";
-       sqlite3_stmt *stmt = NULL;
-       sqlite3 *db;
-       char *query;
-       int value_idx;
-       int idx;
-       struct aul_compinfo_s *info;
-       int ret;
-
-       db = __open_component_db(uid);
-       if (!db) {
-               _E("Failed to open component db. uid(%u)", uid);
-               return AUL_R_ERROR;
-       }
-
-       query = sqlite3_mprintf(query_raw, comp_id);
-       if (!query) {
-               _E("Out of memory");
-               ret = AUL_R_ENOMEM;
-               goto end;
-       }
-
-       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               _E("sqlite3_prepare_v2() is failed. error(%s)",
-                               sqlite3_errmsg(db));
-               if (ret == SQLITE_NOMEM)
-                       ret = AUL_R_ENOMEM;
-               else
-                       ret = AUL_R_ERROR;
-               goto end;
-       }
-
-       ret = sqlite3_step(stmt);
-       if (ret != SQLITE_ROW) {
-               _E("sqlite3_step() is failed");
-               ret = AUL_R_ENOENT;
-               goto end;
-       }
-
-       info = calloc(1, sizeof(struct aul_compinfo_s));
-       if (!info) {
-               _E("Out of memory");
-               ret = AUL_R_ENOMEM;
-               goto end;
-       }
-
-       info->value[AUL_COMPINFO_COMP_ID] = strdup(comp_id);
-       if (!info->value[AUL_COMPINFO_COMP_ID]) {
-               _E("Failed to duplicate component ID");
-               __destroy_compinfo(info);
-               ret = AUL_R_ENOMEM;
-               goto end;
-       }
-
-       for (idx = AUL_COMPINFO_START; idx < AUL_COMPINFO_MAX - 1; idx++) {
-               value_idx = (idx < AUL_COMPINFO_COMP_ID) ? idx : idx + 1;
-               ret = aul_db_save_column_str(stmt, idx,
-                               &info->value[value_idx]);
-               if (ret != AUL_R_OK) {
-                       __destroy_compinfo(info);
-                       goto end;
-               }
-       }
-
-       *compinfo = info;
-       ret = AUL_R_OK;
-
-end:
-       sqlite3_finalize(stmt);
-       sqlite3_free(query);
-       __close_component_db(db);
-
-       return ret;
-}
-
-API int aul_compinfo_create(const char *comp_id, aul_compinfo_h *handle)
-{
-       return aul_compinfo_usr_create(comp_id, getuid(), handle);
-}
-
-API int aul_compinfo_usr_create(const char *comp_id, uid_t uid,
-               aul_compinfo_h *handle) {
-       struct aul_compinfo_s *info;
-       int ret;
-
-       if (!comp_id || !handle) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       ret = __create_compinfo(comp_id, uid, &info);
-       if (ret != AUL_R_OK && uid != GLOBAL_USER)
-               ret = __create_compinfo(comp_id, GLOBAL_USER, &info);
-
-       if (ret != AUL_R_OK)
-               return ret;
-
-       *handle = (aul_compinfo_h)info;
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_destroy(aul_compinfo_h handle)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)handle;
-
-       if (!handle) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       __destroy_compinfo(info);
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_clone(aul_compinfo_h handle, aul_compinfo_h *clone)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)handle;
-       struct aul_compinfo_s *new_info;
-
-       if (!handle || !clone) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       new_info = __clone_compinfo(info);
-       if (!new_info) {
-               _E("Failed to clone comp info");
-               return AUL_R_ENOMEM;
-       }
-
-       *clone = (aul_compinfo_h)new_info;
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_get_app_id(aul_compinfo_h handle, const char **app_id)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)handle;
-
-       if (!handle || !app_id) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       *app_id = info->value[AUL_COMPINFO_APP_ID];
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_get_comp_id(aul_compinfo_h handle, const char **comp_id)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)handle;
-
-       if (!handle || !comp_id) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       *comp_id = info->value[AUL_COMPINFO_COMP_ID];
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_get_type(aul_compinfo_h handle, const char **type)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)handle;
-
-       if (!handle || !type) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       *type = info->value[AUL_COMPINFO_TYPE];
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_get_launch_mode(aul_compinfo_h handle,
-               const char **launch_mode)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)handle;
-
-       if (!handle || !launch_mode) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       *launch_mode = info->value[AUL_COMPINFO_LAUNCH_MODE];
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_is_main_comp(aul_compinfo_h handle, bool *main_comp)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)handle;
-
-       if (!handle || !main_comp) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       *main_comp = __get_boolean_value(info->value[AUL_COMPINFO_MAIN_COMP]);
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_is_icon_display(aul_compinfo_h handle,
-               bool *icon_display)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)handle;
-
-       if (!handle || !icon_display) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       *icon_display =
-               __get_boolean_value(info->value[AUL_COMPINFO_ICON_DISPLAY]);
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_is_taskmanage(aul_compinfo_h handle, bool *taskmanage)
-{
-       struct aul_compinfo_s *info = (struct aul_compinfo_s *)handle;
-
-       if (!handle || !taskmanage) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       *taskmanage =
-               __get_boolean_value(info->value[AUL_COMPINFO_TASKMANAGE]);
-
-       return AUL_R_OK;
-}
-
-static int __get_compinfo_list(uid_t uid, GList **list)
-{
-       static const char query[] = "SELECT "
-               "app_id, component_id, component_type, "
-               "component_launch_mode, component_main, "
-               "component_icon_display, component_taskmanage "
-               "FROM component_info";
-       sqlite3_stmt *stmt = NULL;
-       sqlite3 *db;
-       int idx;
-       struct aul_compinfo_s *info;
-       int ret;
-
-       db = __open_component_db(uid);
-       if (!db) {
-               _E("Failed to open component db. uid(%u)", uid);
-               return AUL_R_ERROR;
-       }
-
-       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               _E("sqlite3_prepare_v2() is failed. error(%s)",
-                               sqlite3_errmsg(db));
-               if (ret == SQLITE_NOMEM)
-                       ret = AUL_R_ENOMEM;
-               else
-                       ret = AUL_R_ERROR;
-               goto end;
-       }
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               info = calloc(1, sizeof(struct aul_compinfo_s));
-               if (!info) {
-                       _E("Out of memory");
-                       if (*list) {
-                               g_list_free_full(*list, __destroy_compinfo);
-                               *list = NULL;
-                       }
-                       ret = AUL_R_ENOMEM;
-                       goto end;
-               }
-
-               for (idx = AUL_COMPINFO_START; idx < AUL_COMPINFO_MAX; idx++) {
-                       ret = aul_db_save_column_str(stmt, idx,
-                                       &info->value[idx]);
-                       if (ret != AUL_R_OK) {
-                               __destroy_compinfo(info);
-                               g_list_free_full(*list, __destroy_compinfo);
-                               *list = NULL;
-                               goto end;
-                       }
-               }
-
-               *list = g_list_append(*list, info);
-       }
-
-       if (*list == NULL)
-               ret = AUL_R_ENOENT;
-       else
-               ret = AUL_R_OK;
-
-end:
-       sqlite3_finalize(stmt);
-       __close_component_db(db);
-
-       return ret;
-}
-
-API int aul_compinfo_foreach_compinfo_from_app(const char *app_id,
-               aul_compinfo_cb callback, void *user_data)
-{
-       return aul_compinfo_usr_foreach_compinfo_from_app(app_id, getuid(),
-                       callback, user_data);
-}
-
-API int aul_compinfo_usr_foreach_compinfo_from_app(const char *app_id,
-               uid_t uid, aul_compinfo_cb callback, void *user_data)
-{
-       struct aul_compinfo_s *info;
-       GList *list = NULL;
-       GList *iter;
-       int ret;
-
-       if (!app_id || !callback) {
-               LOGE("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       ret = __get_compinfo_list(uid, &list);
-       if (ret != AUL_R_OK && uid != GLOBAL_USER)
-               ret = __get_compinfo_list(GLOBAL_USER, &list);
-
-       if (ret != AUL_R_OK) {
-               _E("Failed to get comp infos");
-               return ret;
-       }
-
-       iter = list;
-       while (iter) {
-               info = (struct aul_compinfo_s *)iter->data;
-               iter = g_list_next(iter);
-
-               if (strcmp(info->value[AUL_COMPINFO_APP_ID], app_id) != 0)
-                       continue;
-
-               if (!callback((aul_compinfo_h)info, user_data))
-                       break;
-       }
-
-       g_list_free_full(list, __destroy_compinfo);
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_foreach_compinfo(aul_compinfo_cb callback,
-               void *user_data)
-{
-       return aul_compinfo_usr_foreach_compinfo(getuid(), callback, user_data);
-}
-
-API int aul_compinfo_usr_foreach_compinfo(uid_t uid, aul_compinfo_cb callback,
-               void *user_data)
-{
-       struct aul_compinfo_s *info;
-       GList *list = NULL;
-       GList *iter;
-       int ret;
-
-       if (!callback) {
-               LOGE("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       ret = __get_compinfo_list(uid, &list);
-       if (ret != AUL_R_OK && uid != GLOBAL_USER)
-               ret = __get_compinfo_list(GLOBAL_USER, &list);
-
-       if (ret != AUL_R_OK) {
-               _E("Failed to get comp infos");
-               return ret;
-       }
-
-       iter = list;
-       while (iter) {
-               info = (struct aul_compinfo_s *)iter->data;
-               if (!callback((aul_compinfo_h)info, user_data))
-                       break;
-
-               iter = g_list_next(iter);
-       }
-
-       g_list_free_full(list, __destroy_compinfo);
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_localized_info_get_locale(
-               aul_compinfo_localized_info_h handle, const char **locale)
-{
-       struct aul_compinfo_localized_info_s *info;
-
-       if (!handle || !locale) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       info = (struct aul_compinfo_localized_info_s *)handle;
-       *locale = info->value[AUL_COMPINFO_LOCALIZED_INFO_LOCALE];
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_localized_info_get_icon(
-               aul_compinfo_localized_info_h handle, const char **icon)
-{
-       struct aul_compinfo_localized_info_s *info;
-
-       if (!handle || !icon) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       info = (struct aul_compinfo_localized_info_s *)handle;
-       *icon = info->value[AUL_COMPINFO_LOCALIZED_INFO_ICON];
-
-       return AUL_R_OK;
-}
-
-API int aul_compinfo_localized_info_get_label(
-               aul_compinfo_localized_info_h handle, const char **label)
-{
-       struct aul_compinfo_localized_info_s *info;
-
-       if (!handle || !label) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       info = (struct aul_compinfo_localized_info_s *)handle;
-       *label = info->value[AUL_COMPINFO_LOCALIZED_INFO_LABEL];
-
-       return AUL_R_OK;
-}
-
-static int __get_localized_info_list(const char *comp_id, uid_t uid,
-               GList **list)
-{
-       static const char query_raw[] = "SELECT "
-               "component_locale, component_icon, component_label "
-               "FROM component_localized_info WHERE component_id=%Q";
-       sqlite3_stmt *stmt = NULL;
-       sqlite3 *db;
-       char *query;
-       int idx;
-       struct aul_compinfo_localized_info_s *info;
-       int ret;
-
-       db = __open_component_db(uid);
-       if (!db) {
-               _E("Failed to open component db. uid(%u)", uid);
-               return AUL_R_ERROR;
-       }
-
-       query = sqlite3_mprintf(query_raw, comp_id);
-       if (!query) {
-               _E("Out of memory");
-               ret = AUL_R_ENOMEM;
-               goto end;
-       }
-
-       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               _E("sqlite3_prepare_v2() is failed. error(%s)",
-                               sqlite3_errmsg(db));
-               if (ret == SQLITE_NOMEM)
-                       ret = AUL_R_ENOMEM;
-               else
-                       ret = AUL_R_ERROR;
-               goto end;
-       }
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               info = calloc(1, sizeof(struct aul_compinfo_localized_info_s));
-               if (!info) {
-                       _E("Out of memory");
-                       if (*list) {
-                               g_list_free_full(*list,
-                                       __destroy_compinfo_localized_info);
-                               *list = NULL;
-                       }
-                       ret = AUL_R_ENOMEM;
-                       goto end;
-               }
-
-               for (idx = AUL_COMPINFO_LOCALIZED_INFO_START;
-                               idx < AUL_COMPINFO_LOCALIZED_INFO_MAX;
-                               idx++) {
-                       ret = aul_db_save_column_str(stmt, idx,
-                                       &info->value[idx]);
-                       if (ret != AUL_R_OK) {
-                               __destroy_compinfo_localized_info(info);
-                               g_list_free_full(*list,
-                                       __destroy_compinfo_localized_info);
-                               *list = NULL;
-                               goto end;
-                       }
-               }
-
-               *list = g_list_append(*list, info);
-       }
-
-       if (*list == NULL)
-               ret = AUL_R_ENOENT;
-       else
-               ret = AUL_R_OK;
-
-end:
-       sqlite3_finalize(stmt);
-       sqlite3_free(query);
-       __close_component_db(db);
-
-       return ret;
-}
-
-API int aul_compinfo_foreach_localized_info(const char *comp_id,
-               aul_compinfo_localized_info_cb callback, void *user_data)
-{
-       return aul_compinfo_usr_foreach_localized_info(comp_id, getuid(),
-                       callback, user_data);
-}
-
-API int aul_compinfo_usr_foreach_localized_info(const char *comp_id,
-               uid_t uid, aul_compinfo_localized_info_cb callback,
-               void *user_data)
-{
-       struct aul_compinfo_localized_info_s *info;
-       GList *list = NULL;
-       GList *iter;
-       int ret;
-
-       if (!comp_id || !callback) {
-               _E("Invalid parameter");
-               return AUL_R_EINVAL;
-       }
-
-       ret = __get_localized_info_list(comp_id, uid, &list);
-       if (ret != AUL_R_OK && uid != GLOBAL_USER)
-               ret = __get_localized_info_list(comp_id, GLOBAL_USER, &list);
-
-       if (ret != AUL_R_OK) {
-               _E("Failed to get comp infos");
-               return ret;
-       }
-
-       iter = list;
-       while (iter) {
-               info = (struct aul_compinfo_localized_info_s *)iter->data;
-               if (!callback((aul_compinfo_localized_info_h)info, user_data))
-                       break;
-
-               iter = g_list_next(iter);
-       }
-
-       g_list_free_full(list, __destroy_compinfo_localized_info);
-
-       return AUL_R_OK;
-}
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
old mode 100755 (executable)
new mode 100644 (file)
index 87c4844..a19c558
 #include "aul_error.h"
 #include "aul_sock.h"
 #include "aul_svc.h"
-#include "aul_svc_db.h"
 #include "aul_svc_internal.h"
 #include "aul_svc_priv_key.h"
 #include "aul_util.h"
 #include "launch.h"
 
-#define MAX_CHECKSUM_BUF       2048
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
-#define FREE_AND_NULL(x) do {  \
-       if (x) {                \
-               free(x);        \
-               x = NULL;       \
-       }                       \
+#undef MAX_MIME_STR_SIZE
+#define MAX_MIME_STR_SIZE 256
+
+#undef MAX_SCHEME_STR_SIZE
+#define MAX_SCHEME_STR_SIZE 256
+
+#undef MAX_HOST_STR_SIZE
+#define MAX_HOST_STR_SIZE 256
+
+#undef DEPRECATION_WARNING
+#define DEPRECATION_WARNING() do {                                             \
+       dlog_print(DLOG_WARN, LOG_TAG,                                         \
+                       "DEPRECATION WARNING: %s() is deprecated and "         \
+                       "will be removed from next release.", __FUNCTION__);   \
 } while (0)
 
 /* callback handling */
@@ -81,7 +87,6 @@ typedef struct _aul_svc_transient_cb_info_t {
 } aul_svc_transient_cb_info_t;
 
 static pthread_mutex_t iniparser_lock = PTHREAD_MUTEX_INITIALIZER;
-static GSList *tmp_list;
 
 static aul_svc_cb_info_t *__create_rescb(int request_code,
                aul_svc_res_fn cbfunc, aul_svc_err_cb err_cb, void *data);
@@ -585,166 +590,6 @@ static char* __get_alias_appid(char *appid)
        return alias_id;
 }
 
-static char* __make_query(char *query, char *op, char *uri,
-                       char *mime, char *m_type, char *s_type)
-{
-       char tmp[MAX_MIME_STR_SIZE] = { 0, };
-
-       query = _svc_db_query_builder_add(query, op, uri, mime, false);
-       if ((mime && strncmp(mime, "NULL", 4) != 0) &&
-                       (s_type && strncmp(s_type, "%", 1) != 0)) {
-               snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
-               query = _svc_db_query_builder_add(query, op, uri, tmp, false);
-       }
-
-       if ((mime && strncmp(mime, "NULL", 4) != 0) &&
-                       (m_type && strncmp(m_type, "%", 1) != 0)) {
-               snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
-               query = _svc_db_query_builder_add(query, op, uri, tmp, false);
-       }
-
-       return query;
-}
-
-static char* __make_query_with_collation(char *op, char *uri, char *mime, char *m_type, char *s_type)
-{
-       char tmp[MAX_MIME_STR_SIZE];
-       char *query = NULL;
-
-       query = _svc_db_query_builder_add(query, op, uri, mime, true);
-
-       if (mime && (strncmp(mime, "NULL", 4) != 0) &&
-                       s_type && (strncmp(s_type, "%", 1) != 0)) {
-               snprintf(tmp, MAX_MIME_STR_SIZE - 1, "%s/*", m_type);
-               query = _svc_db_query_builder_add(query, op, uri, tmp, true);
-       }
-       if (mime && (strncmp(mime, "NULL", 4) != 0) &&
-                       m_type && (strncmp(m_type, "%", 1) != 0)) {
-               snprintf(tmp, MAX_MIME_STR_SIZE - 1, "*/*");
-               query = _svc_db_query_builder_add(query, op, uri, tmp, true);
-       }
-
-       query = _svc_db_query_builder_in("ac.app_control collate appsvc_collation ", query);
-
-       return query;
-}
-
-
-static int __app_list_cb(pkgmgrinfo_appinfo_h handle, void *user_data)
-{
-       char *appid = NULL;
-       GSList **app_list = (GSList **)user_data;
-       char *str = NULL;
-       GSList *iter = NULL;
-
-       pkgmgrinfo_appinfo_get_appid(handle, &str);
-       _D("Matching application is %s", str);
-
-       for (iter = tmp_list; iter != NULL; iter = g_slist_next(iter)) {
-               if (strncmp(str, (char *)iter->data, MAX_PACKAGE_STR_SIZE - 1) == 0) {
-                       appid = strdup(str);
-                       *app_list = g_slist_append(*app_list, (void *)appid);
-                       _D("%s is added", appid);
-               }
-       }
-
-       return 0;
-}
-
-static int __get_list_with_category(char *category, GSList **pkg_list, uid_t uid)
-{
-       int ret;
-       pkgmgrinfo_appinfo_filter_h handle;
-       GSList *app_list = NULL;
-       GSList *iter = NULL;
-       char *list_item = NULL;
-
-       ret = pkgmgrinfo_appinfo_filter_create(&handle);
-       ret = pkgmgrinfo_appinfo_filter_add_string(handle,
-                               PMINFO_APPINFO_PROP_APP_CATEGORY, category);
-
-       tmp_list = *pkg_list;
-       ret = pkgmgrinfo_appinfo_usr_filter_foreach_appinfo(handle,
-                               __app_list_cb, &app_list, uid);
-       if (ret != PMINFO_R_OK) {
-               pkgmgrinfo_appinfo_filter_destroy(handle);
-               return -1;
-       }
-       pkgmgrinfo_appinfo_filter_destroy(handle);
-
-       for (iter = *pkg_list; iter != NULL; iter = g_slist_next(iter)) {
-               list_item = (char *)iter->data;
-               g_free(list_item);
-       }
-       g_slist_free(*pkg_list);
-
-       *pkg_list = app_list;
-
-       return 0;
-}
-
-static int __check_mainapp_mode(char *operation)
-{
-       return 0;
-}
-
-static int __get_list_with_submode(char *operation, char *win_id,
-                               GSList **pkg_list, uid_t uid)
-{
-       int ret = 0;
-       int mainapp_mode = 0;
-
-       mainapp_mode = __check_mainapp_mode(operation);
-
-       SECURE_LOGD("mainapp_mode : %d", mainapp_mode);
-
-       ret = _svc_db_adjust_list_with_submode(mainapp_mode, win_id, pkg_list, uid);
-
-       if (ret < 0) {
-               _E("error: %d", ret);
-               return -1;
-       }
-
-       return 0;
-}
-
-static void __free_pkg_list(GSList *list)
-{
-       char *list_item;
-       GSList *iter = NULL;
-
-       if (list == NULL)
-               return;
-
-       for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
-               list_item = (char *)iter->data;
-               g_free(list_item);
-       }
-       g_slist_free(list);
-}
-
-static void __invalidate_cache(uid_t uid)
-{
-       int ret;
-       bundle *b;
-       char buf[MAX_PID_STR_BUFSZ];
-
-       b = bundle_create();
-       if (!b) {
-               _E("out of memory");
-               return;
-       }
-
-       snprintf(buf, sizeof(buf), "%d", uid);
-       bundle_add(b, AUL_K_TARGET_UID, buf);
-       ret = app_send_cmd_for_uid(AUL_UTIL_PID, uid, APP_INVALIDATE_CACHE, b);
-
-       if (ret < 0)
-               _E("Failed to invalidate cache : %d", ret);
-
-       bundle_free(b);
-}
-
 API int aul_svc_set_operation(bundle *b, const char *operation)
 {
        if (b == NULL) {
@@ -850,280 +695,10 @@ API int aul_svc_set_launch_mode(bundle *b, const char *mode)
        return __set_bundle(b, AUL_SVC_K_LAUNCH_MODE, mode);
 }
 
-typedef struct resolution_info_s {
-       char *appid;
-       const char *uri_r_info;
-       GSList *list;
-       bundle *b;
-       uid_t uid;
-       aul_svc_resolve_info_t ri;
-       char **appid_array;
-       unsigned int len;
-} resolution_info_t;
-
-typedef int (*resolution_handler)(resolution_info_t *info);
-
-static int __resolution_pre(resolution_info_t *info)
-{
-       aul_svc_resolve_info_t *ri = &info->ri;
-       int ret;
-
-       ret = __get_resolve_info(info->b, ri);
-       if (ret < 0) {
-               __free_resolve_info_data(ri);
-               return ret;
-       }
-
-       SECURE_LOGD("op - %s / mime - %s / scheme - %s",
-                       ri->op, ri->origin_mime, ri->scheme);
-
-       return AUL_SVC_RET_OK;
-}
-
-static int __resolution_uri(resolution_info_t *info)
-{
-       aul_svc_resolve_info_t *ri = &info->ri;
-       char *id;
-       char *query;
-
-       if (info->list)
-               return AUL_SVC_RET_OK;
-
-       id = _svc_db_get_app(ri->op, ri->origin_mime, ri->uri, info->uid);
-       if (id) {
-               info->list = g_slist_append(info->list, strdup(id));
-               return AUL_SVC_RET_OK;
-       }
-
-       query = __make_query_with_collation(ri->op, ri->uri, ri->mime,
-                       ri->m_type, ri->s_type);
-       query = _svc_db_query_builder_build(query);
-       _svc_db_exec_query(query, &info->list, info->uid);
-       FREE_AND_NULL(query);
-
-       if (!info->list)
-               return AUL_SVC_RET_OK;
-
-       __free_pkg_list(info->list);
-       info->list = NULL;
-
-       if (ri->uri_r_info) {
-               query = __make_query(query, ri->op, ri->uri_r_info,
-                               ri->mime, ri->m_type, ri->s_type);
-       }
-
-       query = __make_query(query, ri->op, ri->scheme, ri->mime,
-                       ri->m_type, ri->s_type);
-       query = __make_query(query, ri->op, "*", ri->mime,
-                       ri->m_type, ri->s_type);
-       if ((ri->scheme && strcmp(ri->scheme, "file") == 0) &&
-                       (ri->mime && strcmp(ri->mime, "NULL") != 0)) {
-               query = __make_query(query, ri->op, "NULL", ri->mime,
-                               ri->m_type, ri->s_type);
-       }
-       query = _svc_db_query_builder_build(query);
-       _svc_db_exec_query(query, &info->list, info->uid);
-       FREE_AND_NULL(query);
-
-       if (ri->category)
-               __get_list_with_category(ri->category, &info->list, info->uid);
-       __get_list_with_submode(ri->op, ri->win_id, &info->list, info->uid);
-
-       if (g_slist_length(info->list) > 1) {
-               _E("uri_r_info: %s, uri: %s", info->uri_r_info, ri->uri);
-               info->uri_r_info = ri->uri;
-       }
-
-       return AUL_SVC_RET_OK;
-}
-
-static int __resolution_scheme_and_host(resolution_info_t *info)
-{
-       aul_svc_resolve_info_t *ri = &info->ri;
-       char *id;
-       char *query = NULL;
-
-       if (info->list)
-               return AUL_SVC_RET_OK;
-
-       if (!ri->uri_r_info)
-               return AUL_SVC_RET_OK;
-
-       id = _svc_db_get_app(ri->op, ri->origin_mime, ri->uri_r_info,
-                       info->uid);
-       if (id) {
-               info->list = g_slist_append(info->list, strdup(id));
-               return AUL_SVC_RET_OK;
-       }
-
-       query = __make_query(query, ri->op, ri->uri_r_info, ri->mime,
-                       ri->m_type, ri->s_type);
-       query = _svc_db_query_builder_build(query);
-       _svc_db_exec_query(query, &info->list, info->uid);
-       FREE_AND_NULL(query);
-
-       if (!info->list)
-               return AUL_SVC_RET_OK;
-
-       __free_pkg_list(info->list);
-       info->list = NULL;
-
-       query = __make_query(query, ri->op, "*", ri->mime, ri->m_type,
-                       ri->s_type);
-       if ((ri->scheme && strcmp(ri->scheme, "file") == 0) &&
-                               (ri->mime && strcmp(ri->mime, "NULL") != 0)) {
-               query = __make_query(query, ri->op, "NULL", ri->mime,
-                               ri->m_type, ri->s_type);
-       }
-       query = _svc_db_query_builder_build(query);
-       _svc_db_exec_query(query, &info->list, info->uid);
-       FREE_AND_NULL(query);
-
-       if (ri->category)
-               __get_list_with_category(ri->category, &info->list, info->uid);
-       __get_list_with_submode(ri->op, ri->win_id, &info->list, info->uid);
-
-       if (g_slist_length(info->list) > 1) {
-               _E("uri_r_info: %s, uri_r_info: %s",
-                               info->uri_r_info, info->uri_r_info);
-               info->uri_r_info = ri->uri_r_info;
-       }
-
-       return AUL_SVC_RET_OK;
-}
-
-static int __resolution_scheme(resolution_info_t *info)
-{
-       aul_svc_resolve_info_t *ri = &info->ri;
-       char *id;
-       char *query = NULL;
-
-       if (info->list)
-               return AUL_SVC_RET_OK;
-
-       id = _svc_db_get_app(ri->op, ri->origin_mime, ri->scheme, info->uid);
-       if (id) {
-               info->list = g_slist_append(info->list, strdup(id));
-               return AUL_SVC_RET_OK;
-       }
-
-       query = __make_query(query, ri->op, ri->scheme, ri->mime,
-                       ri->m_type, ri->s_type);
-       query = __make_query(query, ri->op, "*", ri->mime,
-                       ri->m_type, ri->s_type);
-       if ((ri->scheme && strcmp(ri->scheme, "file") == 0) &&
-                       (ri->mime && strcmp(ri->mime, "NULL") != 0)) {
-               query = __make_query(query, ri->op, "NULL", ri->mime,
-                               ri->m_type, ri->s_type);
-       }
-       query = _svc_db_query_builder_build(query);
-       _svc_db_exec_query(query, &info->list, info->uid);
-       FREE_AND_NULL(query);
-
-       if (ri->category)
-               __get_list_with_category(ri->category, &info->list, info->uid);
-       __get_list_with_submode(ri->op, ri->win_id, &info->list, info->uid);
-
-       if (g_slist_length(info->list) > 1) {
-               _E("uri_r_info: %s, scheme: %s", info->uri_r_info, ri->scheme);
-               info->uri_r_info = ri->scheme;
-       }
-
-       return AUL_SVC_RET_OK;
-}
-
-static int __resolution_post(resolution_info_t *info)
-{
-       GSList *iter;
-       int ret = AUL_SVC_RET_OK;
-       int count;
-       int i = 0;
-
-       count = g_slist_length(info->list);
-       _D("count: %d", count);
-       if (count < 1) {
-               ret = AUL_SVC_RET_ENOMATCH;
-       } else {
-               _E("uri_r_info: %s", info->uri_r_info);
-               bundle_add(info->b, AUL_SVC_K_URI_R_INFO, info->uri_r_info);
-               info->appid_array = calloc(count, sizeof(char *));
-               if (!info->appid_array) {
-                       _E("Out of memory");
-                       ret = AUL_SVC_RET_ENOMEM;
-                       goto end;
-               }
-               info->len = count;
-
-               iter = info->list;
-               while (iter) {
-                       info->appid_array[i++] = strdup((char *)iter->data);
-                       iter = g_slist_next(iter);
-               }
-       }
-
-end:
-       __free_pkg_list(info->list);
-       __free_resolve_info_data(&info->ri);
-       return ret;
-}
-
 API int aul_svc_resolve(bundle *b, uid_t uid, char ***appid_array,
                unsigned int *len)
 {
-       static const resolution_handler handlers[] = {
-               __resolution_pre,
-               __resolution_uri,
-               __resolution_scheme_and_host,
-               __resolution_scheme,
-               __resolution_post,
-       };
-       resolution_info_t info = { 0, };
-       char *id;
-       char *op;
-       int ret;
-       int i;
-
-       if (b == NULL || appid_array == NULL || len == NULL) {
-               _E("Invalid parameter");
-               return AUL_SVC_RET_EINVAL;
-       }
-
-       op = (char *)aul_svc_get_operation(b);
-       id = (char *)aul_svc_get_pkgname(b);
-       if (id) {
-               if (!op)
-                       aul_svc_set_operation(b, AUL_SVC_OPERATION_DEFAULT);
-               *appid_array = calloc(1, sizeof(char *));
-               (*appid_array)[0] = strdup(id);
-               *len = 1;
-               return AUL_SVC_RET_OK;
-       }
-
-       if (TIZEN_FEATURE_SHARE_PANEL &&
-                       (op && (!strcmp(op, AUL_SVC_OPERATION_SHARE) ||
-                        !strcmp(op, AUL_SVC_OPERATION_MULTI_SHARE) ||
-                        !strcmp(op, AUL_SVC_OPERATION_SHARE_TEXT)))) {
-               *appid_array = calloc(1, sizeof(char *));
-               (*appid_array)[0] = strdup(SHARE_PANEL);
-               *len = 1;
-               return AUL_SVC_RET_OK;
-       }
-
-       info.b = b;
-       info.uid = uid;
-
-       for (i = 0; i < ARRAY_SIZE(handlers); i++) {
-               if (handlers[i]) {
-                       ret = handlers[i](&info);
-                       if (ret != AUL_SVC_RET_OK)
-                               return ret;
-               }
-       }
-
-       *appid_array = info.appid_array;
-       *len = info.len;
-
-       return AUL_SVC_RET_OK;
+       return aul_svc_get_appid_array(b, uid, appid_array, len);
 }
 
 static int __get_appid(bundle *b, char **appid)
@@ -1204,89 +779,77 @@ API int aul_svc_get_list(bundle *b, aul_svc_info_iter_fn iter_fn,
 API int aul_svc_get_list_for_uid(bundle *b, aul_svc_info_iter_fn iter_fn,
                void *data, uid_t uid)
 {
-       aul_svc_resolve_info_t info;
-       char *pkgname = NULL;
-       int pkg_count;
-       int ret = -1;
-
-       GSList *pkg_list = NULL;
-       GSList *iter = NULL;
-       char *query = NULL;
-       char *query2 = NULL;
+       char **appid_array = NULL;
+       unsigned int len = 0;
+       unsigned int i;
+       int ret;
 
-       if (b == NULL) {
-               _E("bundle is NULL");
+       if (!b || !iter_fn) {
+               _E("Invalid parameter");
                return AUL_SVC_RET_EINVAL;
        }
 
-       if (iter_fn == NULL) {
-               _E("iter_fn is NULL");
-               return AUL_SVC_RET_EINVAL;
+       ret = aul_svc_get_appid_array(b, uid, &appid_array, &len);
+       if (ret != AUL_SVC_RET_OK)
+               return ret;
+
+       if (len == 0) {
+               _E("Failed to find associated application");
+               aul_svc_free_appid_array(appid_array, len);
+               return AUL_SVC_RET_ENOMATCH;
        }
 
 
-       /* parse bundle */
-       memset(&info, 0, sizeof(aul_svc_resolve_info_t));
-       ret = __get_resolve_info(b, &info);
-       if (ret < 0) {
-               __free_resolve_info_data(&info);
-               return ret;
+       for (i = 0; i < len; ++i) {
+               SECURE_LOGD("APPID: %s", appid_array[i]);
+               if (iter_fn(appid_array[i], data) != 0)
+                       break;
        }
 
-       _D("operation - %s / shceme - %s / mime - %s", info.op, info.scheme,
-          info.mime);
+       aul_svc_free_appid_array(appid_array, len);
 
-       query2 = __make_query_with_collation(info.op, info.uri,
-                       info.mime, info.m_type, info.s_type);
-
-       if (info.uri_r_info) {
-               query = __make_query(query, info.op, info.uri_r_info,
-                       info.mime, info.m_type, info.s_type);
-       }
+       return AUL_SVC_RET_OK;
+}
 
-       query = __make_query(query, info.op, info.scheme,
-               info.mime, info.m_type, info.s_type);
+static int __send_and_receive(int cmd, bundle *request, bundle **response)
+{
+       app_pkt_t *pkt = NULL;
+       bundle *b = NULL;
+       int ret;
+       int fd;
 
-       query = __make_query(query, info.op, "*",
-               info.mime, info.m_type, info.s_type);
+       fd = aul_sock_send_bundle(AUL_UTIL_PID, getuid(), cmd,
+                       request, AUL_SOCK_ASYNC);
+       if (fd < 0)
+               return AUL_SVC_RET_ERROR;
 
-       if (info.scheme && (strcmp(info.scheme, "file") == 0)
-               && info.mime && (strcmp(info.mime, "NULL") != 0)) {
-               query = __make_query(query, info.op, "NULL",
-                       info.mime, info.m_type, info.s_type);
+       ret = aul_sock_recv_reply_pkt(fd, &pkt);
+       if (ret < 0) {
+               _E("Failed to recieve reply packet. error(%d)", ret);
+               return AUL_SVC_RET_ERROR;
        }
 
-       query = _svc_db_query_builder_or(query2, query);
-       query = _svc_db_query_builder_build(query);
-       _svc_db_exec_query(query, &pkg_list, uid);
-       if (query) {
-               free(query);
-               query = NULL;
+       if (pkt->cmd != APP_GET_INFO_OK) {
+               free(pkt);
+               return AUL_SVC_RET_ERROR;
        }
 
-       if (info.category)
-               __get_list_with_category(info.category, &pkg_list, uid);
-
-       __get_list_with_submode(info.op, info.win_id, &pkg_list, uid);
-
-       pkg_count = g_slist_length(pkg_list);
-       if (pkg_count == 0) {
-               _E("Cannot find associated application");
-
-               __free_resolve_info_data(&info);
-               return AUL_SVC_RET_ENOMATCH;
+       if (pkt->opt & AUL_SOCK_BUNDLE) {
+               b = bundle_decode(pkt->data, pkt->len);
+               if (!b) {
+                       _E("Failed to decode bundle");
+                       free(pkt);
+                       return AUL_SVC_RET_ENOMEM;
+               }
        }
+       free(pkt);
 
-       for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
-               pkgname = iter->data;
-               SECURE_LOGD("PKGNAME : %s", pkgname);
-               if (iter_fn(pkgname, data) != 0)
-                       break;
-               g_free(pkgname);
+       if (!b) {
+               _E("Invalid packet");
+               return AUL_SVC_RET_ERROR;
        }
 
-       g_slist_free(pkg_list);
-       __free_resolve_info_data(&info);
+       *response = b;
 
        return AUL_SVC_RET_OK;
 }
@@ -1299,24 +862,41 @@ API int aul_svc_get_all_defapps(aul_svc_info_iter_fn iter_fn, void *data)
 API int aul_svc_get_all_defapps_for_uid(aul_svc_info_iter_fn iter_fn,
                void *data, uid_t uid)
 {
-       char *pkgname = NULL;
-       int ret = -1;
+       const char **appid_list;
+       int len = 0;
+       bundle *request;
+       bundle *response;
+       int ret;
+       int i;
 
-       GSList *pkg_list = NULL;
-       GSList *iter = NULL;
+       if (!iter_fn) {
+               _E("Invalid parameter");
+               return AUL_SVC_RET_EINVAL;
+       }
 
-       ret = _svc_db_get_list_with_all_defapps(&pkg_list, uid);
-       if (ret < 0)
+       request = bundle_create();
+       if (!request) {
+               _E("Out of memory");
+               return AUL_SVC_RET_ENOMEM;
+       }
+
+       ret = __send_and_receive(APP_GET_APP_CONTROL_DEFAULT_APPS, request,
+                       &response);
+       bundle_free(request);
+       if (ret != AUL_SVC_RET_OK)
                return ret;
 
-       for (iter = pkg_list; iter != NULL; iter = g_slist_next(iter)) {
-               pkgname = iter->data;
-               if (iter_fn(pkgname, data) != 0)
-                       break;
-               g_free(pkgname);
+       appid_list = bundle_get_str_array(response, AUL_K_APPID_LIST, &len);
+       if (!appid_list) {
+               bundle_free(response);
+               return AUL_SVC_RET_ERROR;
        }
 
-       g_slist_free(pkg_list);
+       for (i = 0; i < len; ++i) {
+               if (iter_fn(appid_list[i], data) != 0)
+                       break;
+       }
+       bundle_free(response);
 
        return AUL_SVC_RET_OK;
 }
@@ -1419,93 +999,24 @@ API int aul_svc_send_result(bundle *b, aul_svc_result_val result)
        return ret;
 }
 
-API int aul_svc_set_defapp(const char *op, const char *mime_type,
-                               const char *uri, const char *defapp)
+API int aul_svc_data_is_array(bundle *b, const char *key)
 {
-       return aul_svc_set_defapp_for_uid(op, mime_type, uri, defapp, getuid());
+       int type;
+       type = bundle_get_type(b, key);
+
+       if (type <= 0)
+               return 0;
+
+       if (type & BUNDLE_TYPE_ARRAY)
+               return 1;
+       return 0;
 }
 
-API int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type,
-                               const char *uri, const char *defapp, uid_t uid)
+API int aul_svc_allow_transient_app(bundle *b, int wid)
 {
-       int ret;
+       char win_id[MAX_LOCAL_BUFSZ];
 
-       if (op == NULL || defapp == NULL)
-               return AUL_SVC_RET_EINVAL;
-
-       ret = _svc_db_add_app(op, mime_type, uri, defapp, uid);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_unset_defapp(const char *defapp)
-{
-       return aul_svc_unset_defapp_for_uid(defapp, getuid());
-}
-
-API int aul_svc_unset_defapp_for_uid(const char *defapp, uid_t uid)
-{
-       int ret;
-
-       if (defapp == NULL)
-               return AUL_SVC_RET_EINVAL;
-
-       ret = _svc_db_delete_with_pkgname(defapp, uid);
-
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_unset_all_defapps()
-{
-       return aul_svc_unset_all_defapps_for_uid(getuid());
-}
-
-API int aul_svc_unset_all_defapps_for_uid(uid_t uid)
-{
-       int ret;
-
-       ret = _svc_db_delete_all(uid);
-
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       __invalidate_cache(uid);
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_is_defapp(const char *pkg_name)
-{
-       return aul_svc_is_defapp_for_uid(pkg_name, getuid());
-}
-
-API int aul_svc_is_defapp_for_uid(const char *pkg_name, uid_t uid)
-{
-       return _svc_db_is_defapp(pkg_name, uid);
-}
-
-API int aul_svc_data_is_array(bundle *b, const char *key)
-{
-       int type;
-       type = bundle_get_type(b, key);
-
-       if (type <= 0)
-               return 0;
-
-       if (type & BUNDLE_TYPE_ARRAY)
-               return 1;
-       return 0;
-}
-
-API int aul_svc_allow_transient_app(bundle *b, int wid)
-{
-       char win_id[MAX_LOCAL_BUFSZ];
-
-       snprintf(win_id, MAX_LOCAL_BUFSZ, "%d", wid);
+       snprintf(win_id, MAX_LOCAL_BUFSZ, "%d", wid);
 
        if (b == NULL) {
                _E("bundle is NULL");
@@ -1618,96 +1129,6 @@ API int aul_svc_set_background_launch(bundle *b, int enabled)
        return AUL_R_OK;
 }
 
-API int aul_svc_set_alias_appid(const char *alias_appid, const char *appid)
-{
-       return aul_svc_set_alias_appid_for_uid(alias_appid, appid, getuid());
-}
-
-API int aul_svc_set_alias_appid_for_uid(const char *alias_appid,
-               const char *appid, uid_t uid)
-{
-       int ret;
-
-       ret = _svc_db_add_alias_appid(alias_appid, appid, uid);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_unset_alias_appid(const char *alias_appid)
-{
-       return aul_svc_unset_alias_appid_for_uid(alias_appid, getuid());
-}
-
-API int aul_svc_unset_alias_appid_for_uid(const char *alias_appid, uid_t uid)
-{
-       int ret;
-
-       ret = _svc_db_delete_alias_appid(alias_appid, uid);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_alias_info(void (*callback)(const char *alias_appid,
-                       const char *appid, void *data), void *user_data)
-{
-       return aul_svc_foreach_alias_info_for_uid(callback, getuid(),
-                       user_data);
-}
-
-API int aul_svc_foreach_alias_info_for_uid(void (*callback)(
-                       const char *alias_appid, const char *appid,
-                       void *data), uid_t uid, void *user_data)
-{
-       int ret;
-
-       if (callback == NULL) {
-               _E("Invalid parameter");
-               return AUL_SVC_RET_EINVAL;
-       }
-
-       ret = _svc_db_foreach_alias_info(callback, uid, user_data);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_enable_alias_info(const char *appid)
-{
-       return aul_svc_enable_alias_info_for_uid(appid, getuid());
-}
-
-API int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid)
-{
-       int ret;
-
-       ret = _svc_db_enable_alias_info(appid, uid);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_disable_alias_info(const char *appid)
-{
-       return aul_svc_disable_alias_info_for_uid(appid, getuid());
-}
-
-API int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid)
-{
-       int ret;
-
-       ret = _svc_db_disable_alias_info(appid, uid);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
 API int aul_svc_get_appid_by_alias_appid(const char *alias_appid, char **appid)
 {
        return aul_svc_get_appid_by_alias_appid_for_uid(alias_appid,
@@ -1717,90 +1138,41 @@ API int aul_svc_get_appid_by_alias_appid(const char *alias_appid, char **appid)
 API int aul_svc_get_appid_by_alias_appid_for_uid(const char *alias_appid,
                char **appid, uid_t uid)
 {
+       const char *val;
+       bundle *request;
+       bundle *response;
        int ret;
 
-       ret = _svc_db_get_appid_from_alias_info(alias_appid, appid, uid);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_alias_info_by_appid(int (*callback)(
-                       const char *alias_appid, const char *appid, void *data),
-               const char *appid, void *user_data)
-{
-       return aul_svc_foreach_alias_info_by_appid_for_uid(callback, appid,
-                       getuid(), user_data);
-}
-
-API int aul_svc_foreach_alias_info_by_appid_for_uid(int (*callback)(
-                       const char *alias_appid, const char *appid, void *data),
-               const char *appid, uid_t uid, void *user_data)
-{
-       int ret;
-
-       if (callback == NULL || appid == NULL) {
+       if (!alias_appid || !appid) {
                _E("Invalid parameter");
                return AUL_SVC_RET_EINVAL;
        }
 
-       ret = _svc_db_foreach_alias_info_by_appid(callback, appid,
-                       uid, user_data);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_allowed_info(int (*callback)(const char *appid,
-                       const char *allowed_appid, void *data), void *user_data)
-{
-       return aul_svc_foreach_allowed_info_for_uid(callback,
-                       getuid(), user_data);
-}
-
-API int aul_svc_foreach_allowed_info_for_uid(int (*callback)(const char *appid,
-                       const char *allowed_appid, void *data),
-               uid_t uid, void *user_data)
-{
-       int ret;
-
-       if (callback == NULL) {
-               _E("Invalid parameter");
-               return AUL_SVC_RET_EINVAL;
+       request = bundle_create();
+       if (!request) {
+               _E("Out of memory");
+               return AUL_SVC_RET_ENOMEM;
        }
 
-       ret = _svc_db_foreach_allowed_info(callback, uid, user_data);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
-
-       return AUL_SVC_RET_OK;
-}
-
-API int aul_svc_foreach_allowed_info_by_appid(int (*callback)(
-                       const char *appid, const char *allowed_appid, void *data),
-               const char *appid, void *user_data)
-{
-       return aul_svc_foreach_allowed_info_by_appid_for_uid(callback,
-                       appid, getuid(), user_data);
-}
-
-API int aul_svc_foreach_allowed_info_by_appid_for_uid(int (*callback)(
-                       const char *appid, const char *allowed_appid, void *data),
-               const char *appid, uid_t uid, void *user_data)
-{
-       int ret;
+       bundle_add(request, AUL_K_ALIAS_APPID, alias_appid);
+       ret = __send_and_receive(APP_GET_APPID_BY_ALIAS_APPID, request,
+                       &response);
+       bundle_free(request);
+       if (ret != AUL_SVC_RET_OK)
+               return ret;
 
-       if (callback == NULL || appid == NULL) {
-               _E("Invalid parameter");
-               return AUL_SVC_RET_EINVAL;
+       val = bundle_get_val(response, AUL_K_APPID);
+       if (!val) {
+               bundle_free(response);
+               return AUL_SVC_RET_ERROR;
        }
 
-       ret = _svc_db_foreach_allowed_info_by_appid(callback, appid,
-                       uid, user_data);
-       if (ret < 0)
-               return AUL_SVC_RET_ERROR;
+       *appid = strdup(val);
+       bundle_free(response);
+       if (!*appid) {
+               _E("Out of memory");
+               return AUL_SVC_RET_ENOMEM;
+       }
 
        return AUL_SVC_RET_OK;
 }
@@ -2262,3 +1634,167 @@ API void aul_svc_free_appid_array(char **appid_array, unsigned int len)
 
        free(appid_array);
 }
+
+API int aul_svc_set_defapp(const char *op, const char *mime_type,
+               const char *uri, const char *defapp)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_set_defapp_for_uid(const char *op, const char *mime_type,
+               const char *uri, const char *defapp, uid_t uid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_unset_defapp(const char *defapp)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_unset_defapp_for_uid(const char *defapp, uid_t uid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_unset_all_defapps()
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_unset_all_defapps_for_uid(uid_t uid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_is_defapp(const char *pkg_name)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_is_defapp_for_uid(const char *pkg_name, uid_t uid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_set_alias_appid(const char *alias_appid, const char *appid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_set_alias_appid_for_uid(const char *alias_appid,
+               const char *appid, uid_t uid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_unset_alias_appid(const char *alias_appid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_unset_alias_appid_for_uid(const char *alias_appid, uid_t uid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_foreach_alias_info(
+               void (*callback)(const char *, const char *, void *),
+               void *user_data)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_foreach_alias_info_for_uid(
+               void (*callback)(const char *, const char *, void *),
+               uid_t uid, void *user_data)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_enable_alias_info(const char *appid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_enable_alias_info_for_uid(const char *appid, uid_t uid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_disable_alias_info(const char *appid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_disable_alias_info_for_uid(const char *appid, uid_t uid)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_foreach_alias_info_by_appid(
+               int (*callback)(const char *, const char *, void *),
+               const char *appid, void *user_data)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_foreach_alias_info_by_appid_for_uid(
+               int (*callback)(const char *, const char *, void *),
+               const char *appid, uid_t uid, void *user_data)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_foreach_allowed_info(
+               int (*callback)(const char *, const char *, void *),
+               void *user_data)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_foreach_allowed_info_for_uid(
+               int (*callback)(const char *, const char *, void *),
+               uid_t uid, void *user_data)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_foreach_allowed_info_by_appid(
+               int (*callback)(const char *, const char *, void *),
+               const char *appid, void *user_data)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
+API int aul_svc_foreach_allowed_info_by_appid_for_uid(
+               int (*callback)(const char *, const char *, void *),
+               const char *appid, uid_t uid, void *user_data)
+{
+       DEPRECATION_WARNING();
+       return AUL_SVC_RET_OK;
+}
+
diff --git a/src/service_db.c b/src/service_db.c
deleted file mode 100644 (file)
index 008d572..0000000
+++ /dev/null
@@ -1,1197 +0,0 @@
-/*
- * Copyright (c) 2015 - 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 <string.h>
-#include <stdlib.h>
-#include <sys/stat.h>
-#include <glib.h>
-#include <unistd.h>
-#include <ctype.h>
-#include <linux/limits.h>
-#include <sqlite3.h>
-#include <tzplatform_config.h>
-#include <pkgmgr-info.h>
-
-#include "aul_svc_db.h"
-#include "aul_db.h"
-#include "aul_util.h"
-
-#define APP_SVC_DB ".appsvc.db"
-#define PKGMGR_PARSER_DB ".pkgmgr_parser.db"
-#define APP_SVC_COLLATION "appsvc_collation"
-#define QUERY_MAX_LEN   8192
-
-struct alias_info_s {
-       char *alias_appid;
-       char *appid;
-};
-
-struct allowed_info_s {
-       uid_t uid;
-       char *appid;
-       char *allowed_appid;
-};
-
-static sqlite3 *__open_app_svc_db(uid_t uid, bool readonly)
-{
-       sqlite3 *db;
-       char *path;
-
-       path = aul_db_get_path(APP_SVC_DB, uid);
-       if (!path) {
-               _E("Failed to get db path");
-               return NULL;
-       }
-
-       db = aul_db_open(path, readonly);
-       free(path);
-
-       return db;
-}
-
-static int __collate_appsvc(void *ucol, int str1_len, const void *str1,
-               int str2_len, const void *str2)
-{
-       char *saveptr1 = NULL;
-       char *saveptr2 = NULL;
-       char *dup_str1;
-       char *dup_str2;
-       char *token;
-       char *in_op;
-       char *in_uri;
-       char *in_mime;
-       char *op;
-       char *uri;
-       char *mime;
-
-       if (str1 == NULL || str2 == NULL)
-               return -1;
-
-       dup_str1 = strndup(str1, str1_len);
-       if (dup_str1 == NULL)
-               return -1;
-
-       dup_str2 = strndup(str2, str2_len);
-       if (dup_str2 == NULL) {
-               free(dup_str1);
-               return -1;
-       }
-
-       in_op = strtok_r(dup_str2, "|", &saveptr1);
-       in_uri = strtok_r(NULL, "|", &saveptr1);
-       in_mime = strtok_r(NULL, "|", &saveptr1);
-
-       if (!(in_op && in_uri && in_mime)) {
-               SECURE_LOGD("op(%s) uri(%s) mime(%s)", in_op, in_uri, in_mime);
-               free(dup_str1);
-               free(dup_str2);
-               return -1;
-       }
-
-       token = strtok_r(dup_str1, ";", &saveptr1);
-       if (token == NULL) {
-               free(dup_str1);
-               free(dup_str2);
-               return -1;
-       }
-
-       do {
-               op = strtok_r(token, "|", &saveptr2);
-               uri = strtok_r(NULL, "|", &saveptr2);
-               mime = strtok_r(NULL, "|", &saveptr2);
-
-               if (!(op && uri && mime)) {
-                       SECURE_LOGD("op(%s) uri(%s) mime(%s)", op, uri, mime);
-                       continue;
-               }
-
-               if ((strcmp(op, in_op) == 0) && (strcmp(mime, in_mime) == 0)) {
-                       SECURE_LOGD("%s %s %s %s %s %s",
-                                       op, in_op, mime, in_mime, uri, in_uri);
-                       if (g_pattern_match_simple(uri, in_uri)) {
-                               SECURE_LOGD("in_uri : %s | uri : %s",
-                                               in_uri, uri);
-                               free(dup_str1);
-                               free(dup_str2);
-                               return 0;
-                       }
-               }
-       } while ((token = strtok_r(NULL, ";", &saveptr1)));
-
-       free(dup_str1);
-       free(dup_str2);
-
-       return -1;
-}
-
-static sqlite3 *__open_pkgmgr_parser_db(uid_t uid)
-{
-       sqlite3 *db;
-       char *path;
-       int ret;
-
-       path = aul_db_get_path(PKGMGR_PARSER_DB, uid);
-       if (!path) {
-               _E("Failed to get db path");
-               return NULL;
-       }
-
-       db = aul_db_open(path, true);
-       free(path);
-
-       ret = sqlite3_exec(db, "PRAGMA journal_mode = PERSIST",
-                       NULL, NULL, NULL);
-       if (ret != SQLITE_OK) {
-               _E("sqlite3_exec() is failed. error(%s)", sqlite3_errmsg(db));
-               aul_db_close(db);
-               return NULL;
-       }
-
-       sqlite3_create_collation(db, APP_SVC_COLLATION, SQLITE_UTF8,
-                       NULL, __collate_appsvc);
-
-       return db;
-}
-
-static int __insert_info(sqlite3 *db, const char *op, const char *mime_type,
-               const char *uri, const char *appid)
-{
-       const char query[] = "INSERT OR REPLACE INTO "
-               "appsvc(operation, mime_type, uri, pkg_name) "
-               "VALUES(?, ?, ?, ?)";
-       sqlite3_stmt *stmt;
-       int idx = 1;
-
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       __BIND_TEXT(db, stmt, idx++, op);
-       __BIND_TEXT(db, stmt, idx++, mime_type ? mime_type : "NULL");
-       __BIND_TEXT(db, stmt, idx++, uri ? uri : "NULL");
-       __BIND_TEXT(db, stmt, idx++, appid);
-
-       __STEP(db, stmt);
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-int _svc_db_add_app(const char *op, const char *mime_type, const char *uri,
-               const char *pkg_name, uid_t uid)
-{
-       sqlite3 *db;
-       int ret;
-
-       if (!op) {
-               _E("Invalid parameter");
-               return -1;
-       }
-
-       db = __open_app_svc_db(uid, false);
-       if (!db)
-               return -1;
-
-       ret = __insert_info(db, op, mime_type, uri, pkg_name);
-       aul_db_close(db);
-
-       return ret;
-}
-
-static int __delete_info(sqlite3 *db, const char *appid)
-{
-       const char query[] = "DELETE FROM appsvc WHERE pkg_name = ?;";
-       sqlite3_stmt *stmt;
-       int idx = 1;
-
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       __BIND_TEXT(db, stmt, idx++, appid);
-
-       __STEP(db, stmt);
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-int _svc_db_delete_with_pkgname(const char *pkg_name, uid_t uid)
-{
-       sqlite3 *db;
-       int ret;
-
-       if (!pkg_name) {
-               _E("Invalid parameter");
-               return -1;
-       }
-
-       db = __open_app_svc_db(uid, false);
-       if (!db)
-               return -1;
-
-       ret = __delete_info(db, pkg_name);
-       aul_db_close(db);
-
-       return ret;
-}
-
-int _svc_db_delete_all(uid_t uid)
-{
-       const char query[] = "DELETE FROM appsvc;";
-       sqlite3 *db;
-       int ret;
-
-       db = __open_app_svc_db(uid, false);
-       if (!db)
-               return -1;
-
-       ret = sqlite3_exec(db, query, NULL, NULL, NULL);
-       if (ret != SQLITE_OK) {
-               _E("sqlite3_exec() is failed. error(%s)", sqlite3_errmsg(db));
-               aul_db_close(db);
-               return -1;
-       }
-       aul_db_close(db);
-
-       return 0;
-}
-
-static int __get_count(sqlite3 *db, const char *appid)
-{
-       const char query[] = "SELECT COUNT(*) FROM appsvc WHERE pkg_name = ?;";
-       sqlite3_stmt *stmt;
-       int idx = 1;
-       int count;
-       int r;
-
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       __BIND_TEXT(db, stmt, idx++, appid);
-
-       r = sqlite3_step(stmt);
-       if (r == SQLITE_ROW)
-               count = sqlite3_column_int(stmt, 0);
-       else
-               count = 0;
-
-       sqlite3_finalize(stmt);
-
-       return count;
-}
-
-int _svc_db_is_defapp(const char *pkg_name, uid_t uid)
-{
-       sqlite3 *db;
-       int count;
-
-       if (!pkg_name) {
-               _E("Invalid parameter");
-               return 0;
-       }
-
-       db = __open_app_svc_db(uid, true);
-       if (!db)
-               return 0;
-
-       count = __get_count(db, pkg_name);
-       aul_db_close(db);
-
-       if (count < 1)
-               return 0;
-
-       return 1;
-}
-
-static int __get_appid(sqlite3 *db, const char *op, const char *mime_type,
-               const char *uri, char **appid)
-{
-       const char query[] =
-               "SELECT pkg_name FROM appsvc WHERE operation = ? "
-               "AND mime_type = ? AND uri = ?;";
-       sqlite3_stmt *stmt;
-       int idx = 1;
-       int ret;
-
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       __BIND_TEXT(db, stmt, idx++, op);
-       __BIND_TEXT(db, stmt, idx++, mime_type ? mime_type : "NULL");
-       __BIND_TEXT(db, stmt, idx++, uri ? uri : "NULL");
-
-       ret = sqlite3_step(stmt);
-       if (ret != SQLITE_ROW) {
-               _E("sqlite3_step() is failed. error(%s)", sqlite3_errmsg(db));
-               sqlite3_finalize(stmt);
-               return -1;
-       }
-
-       ret = aul_db_save_column_str(stmt, 0, appid);
-       sqlite3_finalize(stmt);
-       if (ret != 0)
-               return ret;
-
-       return 0;
-}
-
-char *_svc_db_get_app(const char *op, const char *mime_type, const char *uri,
-               uid_t uid)
-{
-       sqlite3 *db;
-       char *appid;
-       int ret;
-
-       if (!op) {
-               _E("Invalid parameter");
-               return NULL;
-       }
-
-       db = __open_app_svc_db(uid, true);
-       if (!db)
-               return NULL;
-
-       ret = __get_appid(db, op, mime_type, uri, &appid);
-       aul_db_close(db);
-       if (ret != 0)
-               return NULL;
-
-       SECURE_LOGD("appid: %s", appid);
-       return appid;
-}
-
-static int __adjust_list_with_submode(sqlite3 *db, int mainapp_mode,
-               const char *win_id, GSList **list)
-{
-       const char query[] =
-               "SELECT ac.app_id, ai.app_submode_mainid "
-               "FROM package_app_app_control as ac, package_app_info ai "
-               "WHERE ac.app_id = ai.app_id AND ai.app_submode_mainid != '';";
-       sqlite3_stmt *stmt;
-       char *sub_appid;
-       char *submode_mainid;
-       char *excluded_appid;
-       GSList *found_subapp;
-       GSList *found_mainapp;
-
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               sub_appid = (char *)sqlite3_column_text(stmt, 0);
-               if (sub_appid == NULL)
-                       continue;
-
-               found_subapp = g_slist_find_custom(*list, sub_appid,
-                               (GCompareFunc)strcmp);
-               if (found_subapp == NULL)
-                       continue;
-
-               submode_mainid = (char *)sqlite3_column_text(stmt, 1);
-               if (submode_mainid == NULL)
-                       continue;
-
-               found_mainapp = g_slist_find_custom(*list, submode_mainid,
-                               (GCompareFunc)strcmp);
-               if (found_mainapp == NULL)
-                       continue;
-
-               if (win_id && !mainapp_mode)
-                       excluded_appid = (char *)found_mainapp->data;
-               else
-                       excluded_appid = (char *)found_subapp->data;
-
-               if (excluded_appid) {
-                       _E("Remove %s from app list with submode",
-                                       excluded_appid);
-                       *list = g_slist_remove(*list, excluded_appid);
-                       free(excluded_appid);
-               }
-       }
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-int _svc_db_adjust_list_with_submode(int mainapp_mode, char *win_id,
-               GSList **pkg_list, uid_t uid)
-{
-       sqlite3 *global_user_db;
-       sqlite3 *user_db;
-       int ret;
-
-       user_db = __open_pkgmgr_parser_db(uid);
-       if (!user_db)
-               return 0;
-
-       ret = __adjust_list_with_submode(user_db, mainapp_mode, win_id,
-                       pkg_list);
-       aul_db_close(user_db);
-       if (ret < 0)
-               return ret;
-
-       if (uid != GLOBAL_USER) {
-               global_user_db = __open_pkgmgr_parser_db(GLOBAL_USER);
-               if (!global_user_db)
-                       return 0;
-
-               ret = __adjust_list_with_submode(global_user_db, mainapp_mode,
-                               win_id, pkg_list);
-               aul_db_close(global_user_db);
-               if (ret < 0)
-                       return ret;
-       }
-
-       return 0;
-}
-
-static int __get_list_with_query(sqlite3 *db, const char *query, GSList **list)
-{
-       sqlite3_stmt *stmt;
-       GSList *found;
-       char *appid;
-       int ret;
-
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               ret = aul_db_save_column_str(stmt, 0, &appid);
-               if (ret != 0)
-                       break;
-
-               found = g_slist_find_custom(*list, appid, (GCompareFunc)strcmp);
-               if (found) {
-                       free(appid);
-                       continue;
-               }
-
-               *list = g_slist_append(*list, appid);
-               _D("%s is added", appid);
-       }
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-int _svc_db_get_list_with_all_defapps(GSList **pkg_list, uid_t uid)
-{
-       const char query[] = "SELECT pkg_name FROM appsvc;";
-       sqlite3 *db;
-       int ret;
-
-       db = __open_app_svc_db(uid, true);
-       if (!db)
-               return -1;
-
-       ret = __get_list_with_query(db, query, pkg_list);
-       aul_db_close(db);
-
-       return ret;
-}
-
-char *_svc_db_query_builder_add(char *old_query, char *op, char *uri,
-               char *mime, bool collate)
-{
-       char *query;
-       char *q;
-
-       if (collate) {
-               if (old_query) {
-                       query = sqlite3_mprintf("%s, '%q|%q|%q'",
-                                       old_query, op, uri, mime);
-                       free(old_query);
-               } else {
-                       query = sqlite3_mprintf("'%q|%q|%q'",
-                                       op, uri, mime);
-               }
-       } else {
-               if (old_query) {
-                       query = sqlite3_mprintf("%s OR ac.app_control like "
-                                       "'%%%q|%q|%q%%' ",
-                                       old_query, op, uri, mime);
-                       free(old_query);
-               } else {
-                       query = sqlite3_mprintf("ac.app_control like "
-                                       "'%%%q|%q|%q%%' ",
-                                       op, uri, mime);
-               }
-       }
-
-       q = strdup(query);
-       sqlite3_free(query);
-       return q;
-}
-
-char *_svc_db_query_builder_or(char *q1, char *q2)
-{
-       char query[QUERY_MAX_LEN];
-
-       snprintf(query, sizeof(query), "(%s) or (%s)", q1, q2);
-       free(q1);
-       free(q2);
-
-       return strdup(query);
-}
-
-char *_svc_db_query_builder_in(const char *field, char *args)
-{
-       char query[QUERY_MAX_LEN];
-
-       snprintf(query, sizeof(query), "%s in(%s)", field, args);
-       free(args);
-
-       return strdup(query);
-}
-
-char *_svc_db_query_builder_build(char *old_query)
-{
-       char query[QUERY_MAX_LEN];
-
-       if (old_query == NULL)
-               return NULL;
-
-       snprintf(query, sizeof(query),
-                       "SELECT ac.app_id FROM package_app_app_control "
-                       "as ac, package_app_info ai "
-                       "WHERE ac.app_id = ai.app_id "
-                       "AND ai.component_type='uiapp' AND (%s)",
-                       old_query);
-
-       free(old_query);
-
-       return strdup(query);
-}
-
-int _svc_db_exec_query(const char *query, GSList **pkg_list, uid_t uid)
-{
-       sqlite3 *global_user_db;
-       sqlite3 *user_db;
-       int ret;
-
-       if (!query) {
-               _E("Invalid parameter");
-               return -1;
-       }
-
-       user_db = __open_pkgmgr_parser_db(uid);
-       if (!user_db)
-               return 0;
-
-       ret = __get_list_with_query(user_db, query, pkg_list);
-       aul_db_close(user_db);
-       if (ret < 0)
-               return ret;
-
-       if (uid != GLOBAL_USER) {
-               global_user_db = __open_pkgmgr_parser_db(GLOBAL_USER);
-               if (!global_user_db)
-                       return 0;
-
-               ret = __get_list_with_query(global_user_db, query, pkg_list);
-               aul_db_close(global_user_db);
-               if (ret < 0)
-                       return ret;
-       }
-
-       return 0;
-}
-
-static int __add_alias_appid(sqlite3 *db, const char *alias_appid,
-               const char *appid)
-{
-       const char query[] =
-               "INSERT OR REPLACE INTO alias_info(alias_appid, appid) "
-               "values(?,?);";
-       sqlite3_stmt *stmt;
-       int idx = 1;
-
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       __BIND_TEXT(db, stmt, idx++, alias_appid);
-       __BIND_TEXT(db, stmt, idx++, appid);
-
-       __STEP(db, stmt);
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-int _svc_db_add_alias_appid(const char *alias_appid, const char *appid,
-               uid_t uid)
-{
-       sqlite3 *db;
-       int ret;
-
-       if (!alias_appid || !appid) {
-               _E("Invalid parameters");
-               return -1;
-       }
-
-       db = __open_app_svc_db(uid, false);
-       if (!db)
-               return -1;
-
-       ret = __add_alias_appid(db, alias_appid, appid);
-       aul_db_close(db);
-
-       return ret;
-}
-
-static int __delete_alias_appid(sqlite3 *db, const char *alias_appid)
-{
-       const char query[] = "DELETE FROM alias_info WHERE alias_appid = ?;";
-       sqlite3_stmt *stmt;
-
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       __BIND_TEXT(db, stmt, 1, alias_appid);
-
-       __STEP(db, stmt);
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-int _svc_db_delete_alias_appid(const char *alias_appid, uid_t uid)
-{
-       sqlite3 *db;
-       int ret;
-
-       if (!alias_appid) {
-               _E("Invalid parameter");
-               return -1;
-       }
-
-       db = __open_app_svc_db(uid, false);
-       if (!db)
-               return -1;
-
-       ret = __delete_alias_appid(db, alias_appid);
-       aul_db_close(db);
-
-       return ret;
-}
-
-static int __get_appid_from_alias_info(sqlite3 *db, const char *alias_appid,
-               uid_t uid, uid_t db_uid, char **appid)
-{
-       const char global_user_query[] =
-               "SELECT appid FROM alias_info WHERE "
-               "alias_info.alias_appid = ? AND alias_info.appid NOT IN "
-               "(SELECT appid FROM alias_info_for_uid WHERE uid = ?);";
-       const char user_query[] =
-               "SELECT appid FROM alias_info WHERE "
-               "alias_appid = ? AND enable = 'true';";
-       sqlite3_stmt *stmt;
-       const char *query;
-       int idx = 1;
-       int ret;
-
-       query = (db_uid == GLOBAL_USER) ? global_user_query : user_query;
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       __BIND_TEXT(db, stmt, idx++, alias_appid);
-       if (db_uid == GLOBAL_USER)
-               __BIND_INT(db, stmt, idx++, uid);
-
-       ret = sqlite3_step(stmt);
-       if (ret != SQLITE_ROW) {
-               if (ret != SQLITE_DONE) {
-                       _W("sqlite3_step() is failed. error(%s)",
-                                       sqlite3_errmsg(db));
-               }
-
-               sqlite3_finalize(stmt);
-               return -1;
-       }
-
-       ret = aul_db_save_column_str(stmt, 0, appid);
-       sqlite3_finalize(stmt);
-       if (ret != 0)
-               return ret;
-
-       SECURE_LOGD("alias_appid(%s), appid(%s)", alias_appid, *appid);
-
-       return 0;
-}
-
-static int __alias_info_get_appid(const char *alias_appid, uid_t uid,
-               uid_t db_uid, char **appid)
-{
-       sqlite3 *db;
-       int ret;
-
-       db = __open_app_svc_db(db_uid, true);
-       if (!db)
-               return -1;
-
-       ret = __get_appid_from_alias_info(db, alias_appid, uid, db_uid, appid);
-       aul_db_close(db);
-
-       return ret;
-}
-
-int _svc_db_get_appid_from_alias_info(const char *alias_appid, char **appid,
-               uid_t uid)
-{
-       int ret;
-
-       ret = __alias_info_get_appid(alias_appid, uid, uid, appid);
-       if (ret < 0) {
-               ret = __alias_info_get_appid(alias_appid, uid, GLOBAL_USER,
-                               appid);
-       }
-
-       return ret;
-}
-
-static void __destroy_alias_info(gpointer data)
-{
-       struct alias_info_s *info = (struct alias_info_s *)data;
-
-       free(info->appid);
-       free(info->alias_appid);
-       free(info);
-}
-
-static int __get_alias_info_list(sqlite3 *db, uid_t uid, uid_t db_uid,
-               GHashTable *list)
-{
-       const char global_user_query[] =
-               "SELECT alias_appid, appid FROM alias_info WHERE "
-               "alias_info.appid NOT IN "
-               "(SELECT appid FROM alias_info_for_uid WHERE uid = ?);";
-       const char user_query[] =
-               "SELECT alias_appid, appid FROM alias_info WHERE "
-               "enable = 'true';";
-       struct alias_info_s *info;
-       sqlite3_stmt *stmt;
-       const char *query;
-       int idx = 1;
-       int ret;
-
-       query = (db_uid == GLOBAL_USER) ? global_user_query : user_query;
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       if (db_uid == GLOBAL_USER)
-               __BIND_INT(db, stmt, idx++, uid);
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               info = calloc(1, sizeof(struct alias_info_s));
-               if (!info) {
-                       _E("Out of memory");
-                       break;
-               }
-
-               idx = 0;
-               ret = aul_db_save_column_str(stmt, idx++, &info->alias_appid);
-               if (ret != 0) {
-                       __destroy_alias_info(info);
-                       break;
-               }
-
-               ret = aul_db_save_column_str(stmt, idx++, &info->appid);
-               if (ret != 0) {
-                       __destroy_alias_info(info);
-                       break;
-               }
-
-               g_hash_table_insert(list, info->alias_appid, info);
-       }
-
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-static int __alias_info_get_list(uid_t uid, uid_t db_uid, GHashTable *list)
-{
-       sqlite3 *db;
-       int ret;
-
-       db = __open_app_svc_db(db_uid, true);
-       if (!db)
-               return -1;
-
-       ret = __get_alias_info_list(db, uid, db_uid, list);
-       aul_db_close(db);
-
-       return ret;
-}
-
-int _svc_db_foreach_alias_info(void (*callback)(const char *alias_appid,
-                       const char *appid, void *data),
-               uid_t uid, void *user_data)
-{
-       struct alias_info_s *info;
-       GHashTableIter iter;
-       GHashTable *list;
-       gpointer value;
-       int ret;
-
-       list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
-                       __destroy_alias_info);
-       if (list == NULL) {
-               _E("out of memory");
-               return -1;
-       }
-
-       ret = __alias_info_get_list(uid, uid, list);
-       if (ret == 0 && uid != GLOBAL_USER)
-               ret = __alias_info_get_list(uid, GLOBAL_USER, list);
-
-       if (ret != 0) {
-               _E("Failed to get alias info list");
-               g_hash_table_destroy(list);
-               return -1;
-       }
-
-       g_hash_table_iter_init(&iter, list);
-       while (g_hash_table_iter_next(&iter, NULL, &value)) {
-               info = (struct alias_info_s *)value;
-               callback(info->alias_appid, info->appid, user_data);
-       }
-
-       g_hash_table_destroy(list);
-
-       return 0;
-}
-
-static int __enable_or_disable_alias_info(sqlite3 *db, const char *appid,
-               uid_t uid, uid_t db_uid, bool enable)
-{
-       const char global_user_query[] =
-               "INSERT OR REPLACE INTO alias_info_for_uid(appid, uid, "
-               "is_enabled) values((SELECT appid FROM alias_info "
-               "WHERE appid = ?), ?, ?);";
-       const char user_query[] =
-               "UPDATE alias_info set enable = ? WHERE appid = ?;";
-       sqlite3_stmt *stmt;
-       const char *query;
-       int idx = 1;
-
-       if (!appid) {
-               _E("Invalid parameter");
-               return -1;
-       }
-
-       query = (db_uid == GLOBAL_USER) ? global_user_query : user_query;
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       if (db_uid == GLOBAL_USER) {
-               __BIND_TEXT(db, stmt, idx++, appid);
-               __BIND_INT(db, stmt, idx++, uid);
-               __BIND_TEXT(db, stmt, idx++, enable ? "true" : "false");
-       } else {
-               __BIND_TEXT(db, stmt, idx++, enable ? "true" : "false");
-               __BIND_TEXT(db, stmt, idx++, appid);
-       }
-
-       __STEP(db, stmt);
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-static int __alias_info_enable(const char *appid, uid_t uid, uid_t db_uid,
-               bool enable)
-{
-       sqlite3 *db;
-       int ret;
-
-       db = __open_app_svc_db(db_uid, false);
-       if (!db)
-               return -1;
-
-       ret = __enable_or_disable_alias_info(db, appid, uid, db_uid, enable);
-       aul_db_close(db);
-
-       return ret;
-}
-
-int _svc_db_enable_alias_info(const char *appid, uid_t uid)
-{
-       int ret;
-
-       ret = __alias_info_enable(appid, uid, uid, true);
-       if (ret < 0 && uid != GLOBAL_USER)
-               ret = __alias_info_enable(appid, uid, GLOBAL_USER, true);
-
-       return ret;
-}
-
-int _svc_db_disable_alias_info(const char *appid, uid_t uid)
-{
-       int ret;
-
-       ret = __alias_info_enable(appid, uid, uid, false);
-       if (ret < 0 && uid != GLOBAL_USER)
-               ret = __alias_info_enable(appid, uid, GLOBAL_USER, false);
-
-       return ret;
-}
-
-static int __get_alias_info_list_by_appid(sqlite3 *db, const char *appid,
-               uid_t uid, uid_t db_uid, GHashTable *list)
-{
-       const char global_user_query[] =
-               "SELECT alias_appid, appid FROM alias_info WHERE "
-               "alias_info.appid = ? AND alias_info.appid NOT IN "
-               "(SELECT appid FROM alias_info_for_uid WHERE uid = ?);";
-       const char user_query[] =
-               "SELECT alias_appid, appid FROM alias_info WHERE "
-               "appid = ? AND enable = 'true';";
-       struct alias_info_s *info;
-       sqlite3_stmt *stmt;
-       const char *query;
-       int idx = 1;
-       int ret;
-
-       query = (db_uid == GLOBAL_USER) ? global_user_query : user_query;
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       __BIND_TEXT(db, stmt, idx++, appid);
-       if (db_uid == GLOBAL_USER)
-               __BIND_INT(db, stmt, idx++, uid);
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               info = calloc(1, sizeof(struct alias_info_s));
-               if (!info) {
-                       _E("Out of memory");
-                       break;
-               }
-
-               idx = 0;
-               ret = aul_db_save_column_str(stmt, idx++, &info->alias_appid);
-               if (ret != 0) {
-                       __destroy_alias_info(info);
-                       break;
-               }
-
-               ret = aul_db_save_column_str(stmt, idx++, &info->appid);
-               if (ret != 0) {
-                       __destroy_alias_info(info);
-                       break;
-               }
-
-               g_hash_table_insert(list, info->alias_appid, info);
-       }
-
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-static int __alias_info_get_list_by_appid(const char *appid, uid_t uid,
-               uid_t db_uid, GHashTable *list)
-{
-       sqlite3 *db;
-       int ret;
-
-       db = __open_app_svc_db(db_uid, true);
-       if (!db)
-               return -1;
-
-       ret = __get_alias_info_list_by_appid(db, appid, uid, db_uid, list);
-       aul_db_close(db);
-
-       return ret;
-}
-
-int _svc_db_foreach_alias_info_by_appid(
-               int (*callback)(const char *, const char *, void *),
-               const char *appid, uid_t uid, void *user_data)
-{
-       struct alias_info_s *info;
-       GHashTableIter iter;
-       GHashTable *list;
-       gpointer value;
-       int ret;
-
-       list = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
-                       __destroy_alias_info);
-       if (list == NULL) {
-               _E("out of memory");
-               return -1;
-       }
-
-       ret = __alias_info_get_list_by_appid(appid, uid, uid, list);
-       if (ret == 0 && uid != GLOBAL_USER) {
-               ret = __alias_info_get_list_by_appid(appid, uid, GLOBAL_USER,
-                               list);
-       }
-
-       if (ret != 0) {
-               _E("Failed to get alias info list");
-               g_hash_table_destroy(list);
-               return -1;
-       }
-
-       g_hash_table_iter_init(&iter, list);
-       while (g_hash_table_iter_next(&iter, NULL, &value)) {
-               info = (struct alias_info_s *)value;
-               callback(info->alias_appid, info->appid, user_data);
-       }
-       g_hash_table_destroy(list);
-
-       return 0;
-}
-
-static void __destroy_allowed_info(gpointer data)
-{
-       struct allowed_info_s *info = (struct allowed_info_s *)data;
-
-       free(info->allowed_appid);
-       free(info->appid);
-       free(info);
-}
-
-static int __get_allowed_info_list(sqlite3 *db, const char *appid,
-               uid_t uid, GHashTable *tbl)
-{
-       const char appid_query[] =
-               "SELECT appid, allowed_appid FROM allowed_info WHERE "
-               "appid = ?;";
-       const char all_query[] =
-               "SELECT appid, allowed_appid FROM allowed_info;";
-       struct allowed_info_s *info;
-       sqlite3_stmt *stmt;
-       const char *query;
-       GList *list;
-       char *id;
-       int idx = 1;
-       int ret;
-
-       query = appid ? appid_query : all_query;
-       __PREPARE_V2(db, query, strlen(query), stmt);
-
-       if (appid)
-               __BIND_TEXT(db, stmt, idx++, appid);
-
-       while (sqlite3_step(stmt) == SQLITE_ROW) {
-               idx = 0;
-               ret = aul_db_save_column_str(stmt, idx++, &id);
-               if (ret != 0)
-                       break;
-
-               list = g_hash_table_lookup(tbl, id);
-               if (list) {
-                       info = (struct allowed_info_s *)list->data;
-                       if (info->uid != uid) {
-                               free(id);
-                               continue;
-                       }
-               }
-
-               info = calloc(1, sizeof(struct allowed_info_s));
-               if (!info) {
-                       _E("Out of memory");
-                       free(id);
-                       break;
-               }
-
-               info->appid = id;
-
-               ret = aul_db_save_column_str(stmt, idx++, &info->allowed_appid);
-               if (ret != 0) {
-                       __destroy_allowed_info(info);
-                       break;
-               }
-
-               info->uid = uid;
-
-               if (list) {
-                       list = g_list_append(list, info);
-               } else {
-                       list = g_list_append(list, info);
-                       g_hash_table_insert(tbl, info->appid, list);
-               }
-       }
-
-       sqlite3_finalize(stmt);
-
-       return 0;
-}
-
-static int __allowed_info_get_list(const char *appid, uid_t uid,
-               GHashTable *tbl)
-{
-       sqlite3 *db;
-       int ret;
-
-       db = __open_app_svc_db(uid, true);
-       if (!db)
-               return -1;
-
-       ret = __get_allowed_info_list(db, appid, uid, tbl);
-       aul_db_close(db);
-
-       return ret;
-}
-
-static void __destroy_allowed_info_list(gpointer data)
-{
-       GList *list = (GList *)data;
-
-       g_list_free_full(list, __destroy_allowed_info);
-}
-
-int _svc_db_foreach_allowed_info_by_appid(
-               int (*callback)(const char *, const char *, void *),
-               const char *appid, uid_t uid, void *user_data)
-{
-       struct allowed_info_s *info;
-       GHashTableIter hash_iter;
-       GHashTable *tbl;
-       gpointer value;
-       GList *iter;
-       int ret;
-
-       tbl = g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
-                       __destroy_allowed_info_list);
-       if (tbl == NULL) {
-               _E("out of memory");
-               return -1;
-       }
-
-       ret = __allowed_info_get_list(appid, uid, tbl);
-       if (ret == 0 && uid != GLOBAL_USER)
-               ret = __allowed_info_get_list(appid, GLOBAL_USER, tbl);
-
-       if (ret != 0) {
-               _E("Failed to get allowed info table");
-               g_hash_table_destroy(tbl);
-               return -1;
-       }
-
-       g_hash_table_iter_init(&hash_iter, tbl);
-       while (g_hash_table_iter_next(&hash_iter, NULL, &value)) {
-               iter = (GList *)value;
-               while (iter) {
-                       info = (struct allowed_info_s *)iter->data;
-                       callback(info->appid, info->allowed_appid, user_data);
-                       iter = g_list_next(iter);
-               }
-       }
-
-       g_hash_table_destroy(tbl);
-
-       return 0;
-}
-
-int _svc_db_foreach_allowed_info(
-               int (*callback)(const char *, const char *, void *),
-               uid_t uid, void *user_data)
-{
-       return _svc_db_foreach_allowed_info_by_appid(callback, NULL,
-                       uid, user_data);
-}
index 441acda..9b6657b 100644 (file)
@@ -32,7 +32,6 @@
 #include "aul_api.h"
 #include "aul_app_com.h"
 #include "aul_cmd.h"
-#include "aul_db.h"
 #include "aul_error.h"
 #include "aul_sock.h"
 #include "aul_util.h"
@@ -62,7 +61,6 @@ struct widget_event_s {
 
 #define WIDGET_LOG_BUFFER_SIZE 10000
 #define WIDGET_LOG_BUFFER_STRING_SIZE 256
-#define WIDGET_SERVICE_DB ".widget.db"
 
 static int __log_index;
 static int __log_fd;
@@ -668,77 +666,6 @@ API int aul_widget_service_set_disable(const char *widget_id, bool is_disable)
        return ret;
 }
 
-static const char *__get_widget_db_path(uid_t uid)
-{
-#define ROOT_USER 0
-#define GLOBALAPP_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-       const char *path;
-
-       if (uid == ROOT_USER || uid == GLOBALAPP_USER) {
-               path = tzplatform_mkpath(TZ_SYS_DB, WIDGET_SERVICE_DB);
-       } else {
-               tzplatform_set_user(uid);
-               path = tzplatform_mkpath(TZ_USER_DB, WIDGET_SERVICE_DB);
-               tzplatform_reset_user();
-       }
-
-       return path;
-}
-
-static sqlite3 *__open_widget_service_db(uid_t uid, bool readonly)
-{
-       const char *path;
-
-       path = __get_widget_db_path(uid);
-       if (!path) {
-               _E("Failed to get db path");
-               return NULL;
-       }
-
-       return aul_db_open(path, readonly);
-}
-
-API int aul_widget_service_set_disable_db(const char *widget_id, bool is_disable)
-{
-       int ret;
-       sqlite3 *db;
-       sqlite3_stmt *stmt;
-       char *query;
-
-       query = sqlite3_mprintf("UPDATE widget_class SET is_disable= %d"
-                       " WHERE classid = %Q", (int)is_disable, widget_id);
-
-       db = __open_widget_service_db(getuid(), false);
-       if (db == NULL) {
-               _E("widget db null");
-               sqlite3_free(query);
-               return AUL_R_ERROR;
-       }
-
-       ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
-       if (ret != SQLITE_OK) {
-               _E("widget db prepare error: %s", sqlite3_errmsg(db));
-               sqlite3_free(query);
-               sqlite3_close_v2(db);
-               return AUL_R_ERROR;
-       }
-
-       ret = sqlite3_step(stmt);
-       if (ret != SQLITE_DONE && ret != SQLITE_OK) {
-               _E("widget set disable db error: %s", sqlite3_errmsg(db));
-               sqlite3_free(query);
-               sqlite3_finalize(stmt);
-               sqlite3_close_v2(db);
-               return AUL_R_ERROR;
-       }
-
-       sqlite3_free(query);
-       sqlite3_finalize(stmt);
-       sqlite3_close_v2(db);
-
-       return AUL_R_OK;
-}
-
 static int __aul_widget_event_cb(const char *endpoint,
                aul_app_com_result_e result,
                bundle *envelope,
index 636520e..439181e 100644 (file)
@@ -5,12 +5,12 @@ SET(TARGET_APPSVC_DB_RECOVERY "appsvc-db-recovery")
 
 ADD_EXECUTABLE(${TARGET_APPSVC_DB_RECOVERY}
   ${CMAKE_CURRENT_SOURCE_DIR}/appsvc_db_recovery.c
-  ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul_db.c)
+  ${CMAKE_CURRENT_SOURCE_DIR}/db_internal.c)
 SET_TARGET_PROPERTIES(${TARGET_APPSVC_DB_RECOVERY} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
 SET_TARGET_PROPERTIES(${TARGET_APPSVC_DB_RECOVERY} PROPERTIES LINK_FLAGS "-pie")
 
 TARGET_INCLUDE_DIRECTORIES(${TARGET_APPSVC_DB_RECOVERY} PUBLIC
-  ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+  ${CMAKE_CURRENT_SOURCE_DIR})
 
 APPLY_PKG_CONFIG(${TARGET_APPSVC_DB_RECOVERY} PUBLIC
   DLOG_DEPS
@@ -27,12 +27,12 @@ SET(TARGET_COMPONENT_DB_RECOVERY "component-db-recovery")
 
 ADD_EXECUTABLE(${TARGET_COMPONENT_DB_RECOVERY}
   ${CMAKE_CURRENT_SOURCE_DIR}/component_db_recovery.c
-  ${CMAKE_CURRENT_SOURCE_DIR}/../../src/aul_db.c)
+  ${CMAKE_CURRENT_SOURCE_DIR}/db_internal.c)
 SET_TARGET_PROPERTIES(${TARGET_COMPONENT_DB_RECOVERY} PROPERTIES COMPILE_FLAGS ${CFLAGS} "-fPIE")
 SET_TARGET_PROPERTIES(${TARGET_COMPONENT_DB_RECOVERY} PROPERTIES LINK_FLAGS "-pie")
 
 TARGET_INCLUDE_DIRECTORIES(${TARGET_COMPONENT_DB_RECOVERY} PUBLIC
-  ${CMAKE_CURRENT_SOURCE_DIR}/../../src)
+  ${CMAKE_CURRENT_SOURCE_DIR})
 
 APPLY_PKG_CONFIG(${TARGET_COMPONENT_DB_RECOVERY} PUBLIC
   DLOG_DEPS
index abfb1f1..0a53cc7 100644 (file)
@@ -19,7 +19,7 @@
 #include <stdlib.h>
 #include <tzplatform_config.h>
 
-#include "aul_db.h"
+#include "db_internal.h"
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
 #define ROOT_UID 0
@@ -71,19 +71,19 @@ static int __check_db_integrity(uid_t uid)
        char *db_path;
        int ret;
 
-       db_path = aul_db_get_path(".appsvc.db", uid);
+       db_path = _db_get_path(".appsvc.db", uid);
        if (!db_path) {
                fprintf(stderr, "Failed to get appsvc db path\n");
                return -1;
        }
 
-       ret = aul_db_verify(db_path, tables, ARRAY_SIZE(tables));
+       ret = _db_verify(db_path, tables, ARRAY_SIZE(tables));
        if (ret == 0) {
                free(db_path);
                return 0;
        }
 
-       ret = aul_db_recovery(db_path, QUERY_CREATE_APPSVC, uid);
+       ret = _db_recovery(db_path, QUERY_CREATE_APPSVC, uid);
        if (ret != 0) {
                fprintf(stderr, "Failed to recovery %s\n", db_path);
                free(db_path);
index c9d7b68..69dbe42 100644 (file)
@@ -19,7 +19,7 @@
 #include <stdlib.h>
 #include <tzplatform_config.h>
 
-#include "aul_db.h"
+#include "db_internal.h"
 
 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
 #define ROOT_UID 0
@@ -56,19 +56,19 @@ static int __check_db_integrity(uid_t uid)
        char *db_path;
        int ret;
 
-       db_path = aul_db_get_path(".component.db", uid);
+       db_path = _db_get_path(".component.db", uid);
        if (!db_path) {
                fprintf(stderr, "Failed to get component db path\n");
                return -1;
        }
 
-       ret = aul_db_verify(db_path, tables, ARRAY_SIZE(tables));
+       ret = _db_verify(db_path, tables, ARRAY_SIZE(tables));
        if (ret == 0) {
                free(db_path);
                return 0;
        }
 
-       ret = aul_db_recovery(db_path, QUERY_CREATE_COMPONENT, uid);
+       ret = _db_recovery(db_path, QUERY_CREATE_COMPONENT, uid);
        if (ret != 0) {
                fprintf(stderr, "Failed to recovery %s\n", db_path);
                free(db_path);
similarity index 89%
rename from src/aul_db.c
rename to tool/recovery/db_internal.c
index 2b953e1..d36b420 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 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.
  */
 
 #define _GNU_SOURCE
+#include <errno.h>
 #include <linux/limits.h>
 #include <pwd.h>
 #include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
 #include <sys/smack.h>
 #include <sys/stat.h>
 #include <sys/types.h>
 #include <tzplatform_config.h>
 
-#include "aul_db.h"
+#include "db_internal.h"
 
 #define BUSY_WAITING_USEC 50000
 #define BUSY_WAITING_MAX 100
+#define REGULAR_UID_MIN 5000
 
-char *aul_db_get_path(const char *file, uid_t uid)
+char *_db_get_path(const char *file, uid_t uid)
 {
        char buf[PATH_MAX];
 
@@ -56,7 +60,7 @@ static int __db_busy_handler(void *data, int count)
        return 0;
 }
 
-sqlite3 *aul_db_open(const char *path, bool readonly)
+sqlite3 *_db_open(const char *path, bool readonly)
 {
        sqlite3 *db;
        int flags;
@@ -81,7 +85,7 @@ sqlite3 *aul_db_open(const char *path, bool readonly)
        return db;
 }
 
-sqlite3 *aul_db_create(const char *path)
+sqlite3 *_db_create(const char *path)
 {
        sqlite3 *db;
        int ret;
@@ -97,12 +101,12 @@ sqlite3 *aul_db_create(const char *path)
        return db;
 }
 
-void aul_db_close(sqlite3 *db)
+void _db_close(sqlite3 *db)
 {
        sqlite3_close_v2(db);
 }
 
-int aul_db_save_column_str(sqlite3_stmt *stmt, int idx, char **str)
+int _db_save_column_str(sqlite3_stmt *stmt, int idx, char **str)
 {
        const char *val;
 
@@ -127,21 +131,21 @@ static int __integrity_check(sqlite3 *db)
 
        ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
        if (ret != SQLITE_OK) {
-               LOGE("sqlite3_prepare_v2() is failed. error(%s)",
+               _E("sqlite3_prepare_v2() is failed. error(%s)",
                                sqlite3_errmsg(db));
                return -1;
        }
 
        ret = sqlite3_step(stmt);
        if (ret != SQLITE_ROW) {
-               LOGE("sqlite3_step() is failed. error(%s)", sqlite3_errmsg(db));
+               _E("sqlite3_step() is failed. error(%s)", sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
                return -1;
        }
 
        res = (const char *)sqlite3_column_text(stmt, 0);
        if (!res) {
-               LOGE("Failed to check integrity db. error(%s)",
+               _E("Failed to check integrity db. error(%s)",
                                sqlite3_errmsg(db));
                sqlite3_finalize(stmt);
                return -1;
@@ -170,7 +174,7 @@ static int __check_table(sqlite3 *db, const char **tables, int table_count)
        while (sqlite3_step(stmt) == SQLITE_ROW && count < table_count) {
                val = (const char *)sqlite3_column_text(stmt, 0);
                if (val) {
-                       _W("%s %s", val, tables[count]);
+                       _E("%s %s", val, tables[count]);
                        if (strcmp(tables[count], val) != 0)
                                continue;
                        count++;
@@ -187,7 +191,7 @@ static int __check_table(sqlite3 *db, const char **tables, int table_count)
        return 0;
 }
 
-int aul_db_verify(const char *path, const char **tables, int table_count)
+int _db_verify(const char *path, const char **tables, int table_count)
 {
        sqlite3 *db;
        int ret;
@@ -203,7 +207,7 @@ int aul_db_verify(const char *path, const char **tables, int table_count)
                return -1;
        }
 
-       db = aul_db_open(path, true);
+       db = _db_open(path, true);
        if (!db) {
                _E("Failed to open database(%s)", path);
                return -1;
@@ -212,12 +216,12 @@ int aul_db_verify(const char *path, const char **tables, int table_count)
        ret = __integrity_check(db);
        if (ret != 0) {
                _E("Database(%s) is corrupted", path);
-               aul_db_close(db);
+               _db_close(db);
                return -1;
        }
 
        ret = __check_table(db, tables, table_count);
-       aul_db_close(db);
+       _db_close(db);
        if (ret != 0) {
                _E("Database(%s) is corrupted", path);
                return -1;
@@ -314,7 +318,7 @@ static int __change_smack(const char *path)
        return 0;
 }
 
-int aul_db_recovery(const char *path, const char *query, uid_t uid)
+int _db_recovery(const char *path, const char *query, uid_t uid)
 {
        char *errmsg = NULL;
        sqlite3 *db;
@@ -329,14 +333,14 @@ int aul_db_recovery(const char *path, const char *query, uid_t uid)
        if (ret == 0)
                unlink(path);
 
-       db = aul_db_create(path);
+       db = _db_create(path);
        if (!db) {
                _E("Failed to open database(%s)", path);
                return -1;
        }
 
        ret = sqlite3_exec(db, query, NULL, NULL, &errmsg);
-       aul_db_close(db);
+       _db_close(db);
        if (ret != SQLITE_OK) {
                _E("sqlite3_exec() is failed. error(%d:%s)", ret, errmsg);
                sqlite3_free(errmsg);
similarity index 80%
rename from src/aul_db.h
rename to tool/recovery/db_internal.h
index 684f4dd..f778219 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2021 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.
  * limitations under the License.
  */
 
-#define _GNU_SOURCE
+#ifndef __DB_INTERNAL_H__
+#define __DB_INTERNAL_H__
+
+#include <sqlite3.h>
 #include <stdbool.h>
+#include <stdio.h>
 #include <unistd.h>
-#include <sqlite3.h>
-
-#include "aul_util.h"
-
-#pragma once
 
 #ifdef __cplusplus
 extern "C" {
 #endif
 
+#define _E(fmt, ...)                                                           \
+       fprintf(stderr, "%s(%d): "fmt"\n",                                     \
+                       __FUNCTION__, __LINE__, ##__VA_ARGS__)
+
 #define __PREPARE_V2(db, query, length, stmt) do {                             \
        if (sqlite3_prepare_v2(db, query, length, &stmt, NULL) != SQLITE_OK) { \
                _E("sqlite3_prepare_v2() is failed. error(%s)",                \
@@ -62,18 +65,18 @@ extern "C" {
        }                                                                      \
 } while (0)
 
-char *aul_db_get_path(const char *file, uid_t uid);
+char *_db_get_path(const char *file, uid_t uid);
 
-sqlite3 *aul_db_open(const char *path, bool readonly);
+sqlite3 *_db_open(const char *path, bool readonly);
 
-void aul_db_close(sqlite3* db);
+void _db_close(sqlite3* db);
 
-int aul_db_save_column_str(sqlite3_stmt *stmt, int idx, char **str);
+int _db_verify(const char *path, const char **tables, int table_count);
 
-int aul_db_verify(const char *path, const char **tables, int table_count);
-
-int aul_db_recovery(const char *path, const char *query, uid_t uid);
+int _db_recovery(const char *path, const char *query, uid_t uid);
 
 #ifdef __cplusplus
 }
 #endif
+
+#endif /* __DB_INTERNAL_H__ */