Integrate changes from Tizen 2.4 86/42486/1
authorMu-Woong <muwoong.lee@samsung.com>
Mon, 29 Jun 2015 09:32:29 +0000 (18:32 +0900)
committerMu-Woong <muwoong.lee@samsung.com>
Mon, 29 Jun 2015 09:32:29 +0000 (18:32 +0900)
- Add a smack rule for security API
- Fix the prevent issue 451595
- Add a missing smack rule, media-data::cb
- Remove mediahistory.admin privilege entries
- Modify launching sequence.
- Break the dependency to context-internal, which is removed from the snapshot.
- Replace deprecated privilege checker API with security server
- Update smack & privilege w.r.t. security and pkgmgr
- Remove a smack rule 'ail::db'
- Switch to ecore mainloop to support ecore event handling

Change-Id: Ib21644a3466c54212b73c3b1bdb5d7cdd5570cf1
Signed-off-by: Mu-Woong <muwoong.lee@samsung.com>
CMakeLists.txt
data/access-config.xml
packaging/context-service.manifest
packaging/context-service.spec
packaging/context-service.xml
src/access_control/privilege.cpp
src/dbus_server_impl.cpp
src/server.cpp
src/server.h

index e2d02aa..5acec26 100644 (file)
@@ -17,7 +17,6 @@ SET(DEPS
        capi-system-info
        capi-appfw-app-manager
        appsvc
-       capi-security-privilege-manager
        alarm-service
        notification
        cynara-creds-gdbus
@@ -44,6 +43,14 @@ ELSE("${ARCH}" STREQUAL "arm")
        ADD_DEFINITIONS("-D_EMULATOR")
 ENDIF("${ARCH}" STREQUAL "arm")
 
+IF("${MAINLOOP}" STREQUAL "ecore")
+       ADD_DEFINITIONS("-D_USE_ECORE_MAIN_LOOP_")
+       SET(DEPS
+               ${DEPS}
+               ecore
+       )
+ENDIF("${MAINLOOP}" STREQUAL "ecore")
+
 # Common Options
 INCLUDE(FindPkgConfig)
 INCLUDE_DIRECTORIES(
index 2c4f6c0..5471300 100644 (file)
                <Allow subject="video/history/play_freq"/>\r
        </Privilege>\r
 \r
-       <Privilege name="mediahistory.admin">\r
-               <Allow subject="music/event/start"/>\r
-               <Allow subject="music/event/stop"/>\r
-               <Allow subject="video/event/start"/>\r
-               <Allow subject="video/event/stop"/>\r
-       </Privilege>\r
-\r
        <Privilege name="callhistory.read">\r
                <Allow subject="contact/history/comm_freq"/>\r
        </Privilege>\r
index 2e4fdb5..2bd5615 100644 (file)
@@ -7,16 +7,13 @@
                <request>
                        <smack request="xorg" type="rw"/>
                        <smack request="security-server::api-cookie-check" type="w"/>
-                       <smack request="security-server::api-privilege-by-pid" type="w"/>
+                       <smack request="security-server::api-app-privilege-by-name" type="rlw"/>
+                       <smack request="security-server::api-permissions" type="rlw"/>
                        <smack request="vasum::manage" type="rw"/>
                        <smack request="sys-assert::core" type="rwxat"/>
                        <smack request="device::app_logging" type="rw"/>
                        <smack request="device::sys_logging" type="rw"/>
                        <smack request="deviced::display" type="rw"/>
-                       <smack request="ail::db" type="rlx"/>
-                       <smack request="pkgmgr" type="r"/>
-                       <smack request="pkgmgr::db" type="rwx"/>
-                       <smack request="pkgmgr::info" type="r"/>
                        <smack request="alarm-server::alarm" type="rw"/>
                        <smack request="libaccounts-svc" type="r"/>
                        <smack request="libaccounts-svc::db" type="rl"/>
@@ -53,6 +50,8 @@
                        <smack request="tizen::vconf::message" type="r"/>
                        <smack request="tizen::vconf::setting::admin" type="rl"/>
                        <smack request="tizen::vconf::volume::set" type="rl"/>
+                       <smack request="sound_server" type="rlwx"/>
+                       <smack request="media-data::db" type="rlw"/>
                </request>
        </define>
        <request>
index ff876cb..4c2c528 100644 (file)
@@ -8,6 +8,9 @@ Source0:    %{name}-%{version}.tar.gz
 Source1:       context-service.service
 Source2:       org.tizen.context.service
 
+# For active window hooking, we need to use 'ecore' mainloop instead of the 'glib' mainloop.
+%define MAINLOOP ecore
+
 BuildRequires: cmake
 BuildRequires: sed
 BuildRequires: pkgconfig(vconf)
@@ -16,16 +19,18 @@ BuildRequires: pkgconfig(sqlite3)
 BuildRequires: pkgconfig(capi-system-info)
 BuildRequires: pkgconfig(capi-appfw-app-manager)
 BuildRequires: pkgconfig(appsvc)
-BuildRequires: pkgconfig(capi-security-privilege-manager)
 BuildRequires: pkgconfig(alarm-service)
 BuildRequires: pkgconfig(notification)
 
+%if "%{MAINLOOP}" == "ecore"
+BuildRequires: pkgconfig(ecore)
+%endif
+
 BuildRequires: pkgconfig(cynara-creds-gdbus)
 
 BuildRequires: pkgconfig(clips)
 BuildRequires: pkgconfig(context-common)
 BuildRequires: pkgconfig(context)
-BuildRequires: context-internal
 
 BuildRequires: pkgconfig(device-context-provider)
 BuildRequires: pkgconfig(statistics-context-provider)
@@ -66,7 +71,7 @@ export   CFLAGS+=" -DTIZEN_ENGINEER_MODE"
 export CXXFLAGS+=" -DTIZEN_ENGINEER_MODE"
 export   FFLAGS+=" -DTIZEN_ENGINEER_MODE"
 
-cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCH=%{ARCH} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{?tizen_profile_name}
+cmake . -DCMAKE_INSTALL_PREFIX=%{_prefix} -DARCH=%{ARCH} -DMAJORVER=${MAJORVER} -DFULLVER=%{version} -DPROFILE=%{?tizen_profile_name} -DMAINLOOP=%{MAINLOOP}
 make %{?jobs:-j%jobs}
 
 %install
index 9ed1f7b..61c5d87 100644 (file)
@@ -17,5 +17,6 @@
        </service-application>
        <privileges>
                <privilege>http://tizen.org/privilege/location</privilege>
+               <privilege>http://tizen.org/privilege/packagemanager.info</privilege>
        </privileges>
 </manifest>
index 4ea16ba..e1d7936 100644 (file)
@@ -16,7 +16,7 @@
 
 #include <string>
 #include <map>
-#include <privilege_checker.h>
+#include <security-server.h>
 #include <types_internal.h>
 #include "config_loader.h"
 #include "privilege.h"
@@ -62,10 +62,13 @@ bool ctx::privilege_manager::is_allowed(const char* pkg_id, const char* subject)
                return true;
        }
 
-       _D("PkgId: %s, Priv: %s", pkg_id, (it->second).c_str());
-       std::string priv = "http://tizen.org/privilege/";
+       std::string priv = "org.tizen.privilege.";
        priv += (it->second).c_str();
-       int ret = privilege_checker_check_package_privilege(pkg_id, priv.c_str());
-       _D("Privilege Check Result: %#x", ret);
-       return (ret == PRIV_CHECKER_ERR_NONE);
+       int result = 0;
+       int err = security_server_app_has_privilege(pkg_id, PERM_APP_TYPE_EFL, priv.c_str(), &result);
+
+       _D("PkgId: %s, PrivName: %s, Enabled: %d", pkg_id, (it->second).c_str(), result);
+       IF_FAIL_RETURN_TAG(err == SECURITY_SERVER_API_SUCCESS, false, _E, "Privilege checking failed");
+
+       return (result == 1);
 }
index 21b10d3..856e899 100644 (file)
@@ -26,6 +26,8 @@
 #include "zone_util_impl.h"
 #include "dbus_server_impl.h"
 
+static bool conn_acquired = false;
+static bool name_acquired = false;
 static ctx::dbus_server_impl *_instance = NULL;
 static GDBusConnection *dbus_connection = NULL;
 static guint dbus_owner_id = 0;
@@ -98,7 +100,7 @@ static void handle_request(const char *sender, GVariant *param, GDBusMethodInvoc
                return;
        }
 
-       g_dbus_method_invocation_return_value(invocation, g_variant_new("(iss)", ERR_OPERATION_FAILED, EMPTY_JSON_OBJECT, EMPTY_JSON_OBJECT));
+       delete request;
 }
 
 static void handle_method_call(GDBusConnection *conn, const gchar *sender,
@@ -130,12 +132,22 @@ static void on_bus_acquired(GDBusConnection *conn, const gchar *name, gpointer u
                raise(SIGTERM);
        }
 
+       conn_acquired = true;
        dbus_connection = conn;
+
+       _I("Dbus connection acquired");
+
+       if (name_acquired)
+               ctx::server::activate();
 }
 
 static void on_name_acquired(GDBusConnection *conn, const gchar *name, gpointer user_data)
 {
+       name_acquired = true;
        _SI("Dbus name acquired: %s", name);
+
+       if (conn_acquired)
+               ctx::server::activate();
 }
 
 static void on_name_lost(GDBusConnection *conn, const gchar *name, gpointer user_data)
index 6af2a0a..3ee030f 100644 (file)
@@ -14,8 +14,6 @@
  * limitations under the License.
  */
 
-//#define _USE_ECORE_MAIN_LOOP_
-
 #include <stdlib.h>
 #include <new>
 #include <glib.h>
@@ -45,13 +43,8 @@ static ctx::db_manager_impl *database_mgr = NULL;
 static ctx::dbus_server_impl *dbus_handle = NULL;
 static ctx::context_trigger *trigger = NULL;
 
-void ctx::server::run()
+void ctx::server::initialize()
 {
-       if (started) {
-               _W("Started already");
-               return;
-       }
-
        _I("Init MainLoop");
 #ifdef _USE_ECORE_MAIN_LOOP_
        ecore_init();
@@ -60,6 +53,26 @@ void ctx::server::run()
        mainloop = g_main_loop_new(NULL, FALSE);
 #endif
 
+       _I("Init Dbus Connection");
+       dbus_handle = new(std::nothrow) ctx::dbus_server_impl();
+       IF_FAIL_VOID_TAG(dbus_handle, _E, "Memory allocation failed");
+
+       dbus_server::set_instance(dbus_handle);
+       IF_FAIL_VOID_TAG(dbus_handle->init(), _E, "Initialization Failed");
+
+       // Start the main loop
+       _I(CYAN("Launching Context-Service"));
+#ifdef _USE_ECORE_MAIN_LOOP_
+       ecore_main_loop_begin();
+#else
+       g_main_loop_run(mainloop);
+#endif
+}
+
+void ctx::server::activate()
+{
+       IF_FAIL_VOID(!started);
+
        bool result = false;
 
        _I("Init vasum context");
@@ -97,38 +110,43 @@ void ctx::server::run()
        result = trigger->init(context_mgr);
        IF_FAIL_CATCH_TAG(result, _E, "Initialization Failed");
 
-       _I("Init Dbus Connection");
-       dbus_handle = new(std::nothrow) ctx::dbus_server_impl();
-       IF_FAIL_CATCH_TAG(dbus_handle, _E, "Memory allocation failed");
-       dbus_server::set_instance(dbus_handle);
-       result = dbus_handle->init();
-       IF_FAIL_CATCH_TAG(result, _E, "Initialization Failed");
-
-       // Start the main loop
        started = true;
        _I(CYAN("Context-Service Launched"));
+       return;
+
+CATCH:
+       _E(RED("Launching Failed"));
+
+       // Stop the main loop
 #ifdef _USE_ECORE_MAIN_LOOP_
-       ecore_main_loop_begin();
+       ecore_main_loop_quit();
 #else
-       g_main_loop_run(mainloop);
+       g_main_loop_quit(mainloop);
 #endif
+}
 
+void ctx::server::release()
+{
        _I(CYAN("Terminating Context-Service"));
-
        _I("Release Context Trigger");
-       trigger->release();
+       if (trigger)
+               trigger->release();
 
        _I("Release Analyzer Manager");
-       context_mgr->release();
+       if (context_mgr)
+               context_mgr->release();
 
        _I("Release Dbus Connection");
-       dbus_handle->release();
+       if (dbus_handle)
+               dbus_handle->release();
 
        _I("Close the Database");
-       database_mgr->release();
+       if (database_mgr)
+               database_mgr->release();
 
        _I("Release Timer Manager");
-       timer_mgr->release();
+       if (timer_mgr)
+               timer_mgr->release();
 
        _I("Release Access control configuration");
        ctx::privilege_manager::release();
@@ -147,15 +165,6 @@ void ctx::server::run()
        delete dbus_handle;
        delete database_mgr;
        delete timer_mgr;
-       return;
-
-CATCH:
-       _E(RED("Launching Failed"));
-       delete trigger;
-       delete context_mgr;
-       delete dbus_handle;
-       delete database_mgr;
-       delete timer_mgr;
 }
 
 void ctx::server::send_request(ctx::request_info* request)
@@ -192,7 +201,8 @@ int main(int argc, char* argv[])
        g_type_init();
 #endif
 
-       ctx::server::run();
+       ctx::server::initialize();
+       ctx::server::release();
 
        return EXIT_SUCCESS;
 }
index 1807998..5e4cb68 100644 (file)
@@ -23,7 +23,9 @@ namespace ctx {
 
        namespace server {
 
-               void run();
+               void initialize();
+               void activate();
+               void release();
                void send_request(request_info* request);
 
        };      /* namespace ctx::server */