Fixed image build log 54/77654/2 accepted/tizen/mobile/20160701.034446 submit/tizen/20160701.015900
authorSEUNGTAEK HAN <s.t.han@samsung.com>
Thu, 30 Jun 2016 11:07:40 +0000 (20:07 +0900)
committerSEUNGTAEK HAN <s.t.han@samsung.com>
Fri, 1 Jul 2016 01:45:23 +0000 (10:45 +0900)
Change-Id: I070def99bcbfd05ee205cf718a0e435e513ddb0b

client/inc/PrivacyGuardClient.h
client/src/PrivacyGuardClient.cpp
pkgmgr_plugin/privileges.cpp

index 894bcdd..6e08104 100755 (executable)
 #include <vector>
 #include <memory>
 #include "PrivacyGuardTypes.h"
+#include <sqlite3.h>
 
 class SocketClient;
 
 class EXTERN_API PrivacyGuardClient
 {
 private:
+       std::mutex m_dbMutex;
+       sqlite3* m_sqlHandler;
+       sqlite3_stmt* m_stmt;
+       bool m_bDBOpen;
+
        static PrivacyGuardClient* m_pInstance;
        static const std::string INTERFACE_NAME;
 
@@ -44,6 +50,10 @@ private:
 public:
        static PrivacyGuardClient* getInstance(void);
 
+       virtual void openSqliteDB(void);
+
+       int PgAddMonitorPolicyOffline(const int userId, const std::string packageId, const std::list < std::string > privacyList, bool monitorPolicy);
+
        int PgAddPrivacyAccessLog(const int userId, const std::string packageId, const std::string privacyId);
 
        int PgAddPrivacyAccessLogTest(const int userId, const std::string packageId, const std::string privacyId);
index a9b8a80..04d40a6 100755 (executable)
@@ -45,6 +45,69 @@ PrivacyGuardClient::getInstance(void)
        return m_pInstance;
 }
 
+void
+PrivacyGuardClient::openSqliteDB(void)
+{
+       int res = -1;
+       res = sqlite3_open_v2(PRIVACY_DB_PATH, &m_sqlHandler, SQLITE_OPEN_READWRITE, NULL);
+       if(res == SQLITE_OK) {
+               PG_LOGI("monitor db is opened successfully");
+               m_bDBOpen = true;
+       }
+       else {
+               PG_LOGE("fail : monitor db open(%d)", res);
+       }
+}
+
+int
+PrivacyGuardClient::PgAddMonitorPolicyOffline(const int userId, const std::string packageId, const std::list < std::string > privacyList, bool monitorPolicy)
+{
+       int res = -1;
+
+       static const std::string QUERY_INSERT = std::string("INSERT INTO MonitorPolicy(USER_ID, PKG_ID, PRIVACY_ID, MONITOR_POLICY) VALUES(?, ?, ?, ?)");
+
+       m_dbMutex.lock();
+       m_sqlHandler = NULL;
+       m_stmt = NULL;
+       m_bDBOpen = false;
+       
+       // open db
+       if(m_bDBOpen == false) {
+               openSqliteDB();
+       }
+       TryCatchResLogReturn(m_bDBOpen == true, m_dbMutex.unlock(), PRIV_GUARD_ERROR_IO_ERROR, "openSqliteDB : %d", res);
+
+       // prepare
+       res = sqlite3_prepare_v2(m_sqlHandler, QUERY_INSERT.c_str(), -1, &m_stmt, NULL);
+       TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_prepare_v2 : %d", res);
+
+       for (std::list <std::string>::const_iterator iter = privacyList.begin(); iter != privacyList.end(); ++iter) {
+               PG_LOGD("User ID: [%d], Package ID: [%s], PrivacyID: [%s], Monitor Policy: [%d]", userId, packageId.c_str(), iter->c_str(), monitorPolicy);
+
+               // bind
+               res = sqlite3_bind_int(m_stmt, 1, userId);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+
+               res = sqlite3_bind_text(m_stmt, 2, packageId.c_str(), -1, SQLITE_TRANSIENT);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
+
+               res = sqlite3_bind_text(m_stmt, 3, iter->c_str(), -1, SQLITE_TRANSIENT);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
+
+               res = sqlite3_bind_int(m_stmt, 4, monitorPolicy);
+               TryCatchResLogReturn(res == SQLITE_OK, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
+
+               res = sqlite3_step(m_stmt);
+               TryCatchResLogReturn(res == SQLITE_DONE, m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_step : %d", res);
+
+               sqlite3_reset(m_stmt);
+       }
+       m_dbMutex.unlock();
+
+       return PRIV_GUARD_ERROR_SUCCESS;
+}
+
+
 int
 PrivacyGuardClient::PgAddPrivacyAccessLog(const int userId, const std::string packageId, const std::string privacyId)
 {
@@ -123,9 +186,19 @@ PrivacyGuardClient::PgAddMonitorPolicy(const int userId, const std::string pkgId
                return PRIV_GUARD_ERROR_SUCCESS;
        }
 
+       bool isServerOperation = false;
+
        res = m_pSocketClient->connect();
+       if(res != PRIV_GUARD_ERROR_SUCCESS) {
+               isServerOperation = false;
+               PG_LOGD("Failed to connect. So change to the offline mode");
+       }
+       else {
+               isServerOperation = true;
+       }
        TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
 
+       if (isServerOperation == true) {
        int result = PRIV_GUARD_ERROR_SUCCESS;
 
        res = m_pSocketClient->call("PgAddMonitorPolicy", userId, pkgId, privacyList, monitorPolicy, &result);
@@ -136,6 +209,10 @@ PrivacyGuardClient::PgAddMonitorPolicy(const int userId, const std::string pkgId
 
        return result;
 }
+       else    {
+               return PgAddMonitorPolicyOffline(userId, pkgId, privacyList, monitorPolicy);
+       }
+}
 
 int
 PrivacyGuardClient::PgDeleteAllLogsAndMonitorPolicy(void)
index fb0c208..d6f3780 100755 (executable)
@@ -56,13 +56,16 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
 {
        if (packageId == NULL) {
                LOGE("Package ID is NULL");
+               printf("Package ID is NULL");
                return -EINVAL;
        }
 
        LOGD("PKGMGR_PARSER_PLUGIN_INSTALL() called with [%s].", packageId);
+       printf("PKGMGR_PARSER_PLUGIN_INSTALL() called with [%s].", packageId);
 
        uid_t user_id = getuid();
        LOGD("user_id is %d.", user_id);
+       printf("user_id is %d.", user_id);
 
        int ret = 0;
 
@@ -70,12 +73,18 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
        xmlNodePtr curPtr = xmlFirstElementChild(xmlDocGetRootElement(docPtr));
        if (curPtr == NULL) {
                LOGE("Failed to get the element. xmlFirstElementChild() returned NULL.");
+               printf("Failed to get the element. xmlFirstElementChild() returned NULL.");
                return -EINVAL;
        }
+       else {
+               LOGD("Succeeded to get the element. xmlFirstElementChild().");
+               printf("Succeeded to get the element. xmlFirstElementChild().");
+       }
 
        curPtr = curPtr->xmlChildrenNode;
        if (curPtr == NULL) {
                LOGE("No privileges");
+               printf("No privileges");
                return -EINVAL;
        }
 
@@ -85,9 +94,12 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                        xmlChar* pPrivilege = xmlNodeListGetString(docPtr, curPtr->xmlChildrenNode, 1);
                        if (pPrivilege == NULL) {
                                LOGE("Failed to get privilege value.");
+                               printf("Failed to get privilege value.");
                                return -EINVAL;
                        } else {
                                privilegeList.push_back(std::string( reinterpret_cast<char*> (pPrivilege)));
+                               LOGD("Succeeded to get privilege value.");
+                               printf("Succeeded to get privilege value.");
                        }
                }
                curPtr = curPtr->next;
@@ -100,9 +112,14 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
                ppPrivilegeList[i] = (char*)calloc(strlen(iter->c_str()) + 1, sizeof(char));
                if (ppPrivilegeList[i] == NULL) {
                        LOGE("Failed allocate memory.");
+                       printf("Failed allocate memory.");
                        destroy_char_list(ppPrivilegeList, privilegeList.size() + 1);
                        return -ENOMEM;
                }
+               else {
+                       LOGD("Succeeded allocate memory.");
+                       printf("Succeeded allocate memory.");
+               }
                memcpy(ppPrivilegeList[i], iter->c_str(), strlen(iter->c_str()));
                ++iter;
        }
@@ -115,6 +132,7 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
 
        while (*ppPrivilegeList[0] != '\0') {
                LOGD("privilege in the List: %s", *ppPrivilegeList);
+               printf("privilege in the List: %s", *ppPrivilegeList);
                privilege_List.push_back(std::string(*ppPrivilegeList++));
        }
 
@@ -122,7 +140,13 @@ int PKGMGR_PARSER_PLUGIN_INSTALL(xmlDocPtr docPtr, const char* packageId)
        ret = pInst->PgAddMonitorPolicy(user_id, std::string(packageId), privilege_List, monitor_policy);
        if (ret != PRIV_GUARD_ERROR_SUCCESS) {
                LOGE("Failed to add monitor policy: [%d]", ret);
-               return -EIO;
+               printf("Failed to add monitor policy: [%d]", ret);
+//             return -EIO;
+               return 0;
+       }
+       else {
+               LOGD("Succeeded to add monitor policy: [%d]", ret);
+               printf("Succeeded to add monitor policy: [%d]", ret);
        }
 
        if (temp)