Miscellaneous cleanups and cosmetics 83/155283/2
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Thu, 12 Oct 2017 15:08:35 +0000 (17:08 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Mon, 16 Oct 2017 11:24:46 +0000 (11:24 +0000)
Change-Id: Id13214285f62c0e84131e5c8f846c91904a99600

server/external-encryption.cpp

index 2b69c13..0955fbe 100644 (file)
 
 #include "external-encryption.h"
 
-#define EXTERNAL_PATH  "/opt/media/SDCardA1"
-#define EXTERNAL_STATE_VCONF_KEY VCONFKEY_SDE_CRYPTO_STATE
-#define EXTERNAL_OPTION_ONLY_NEW_FILE_VCONF_KEY VCONFKEY_SDE_ENCRYPT_NEWFILE
-#define EXTERNAL_OPTION_EXCEPT_FOR_MEDIA_FILE_VCONF_KEY VCONFKEY_SDE_EXCLUDE_MEDIAFILE
-
-#define PRIVILEGE_PLATFORM "http://tizen.org/privilege/internal/default/platform"
 
 namespace ode {
 
@@ -47,13 +41,30 @@ namespace {
 
 bool isBootCompleted = false;
 
+const char *EXTERNAL_PATH              = "/media/SDCardA1";
+const char *PRIVILEGE_PLATFORM = "http://tizen.org/privilege/internal/default/platform";
+
+void spawnUI()
+{
+       INFO(SINK, "Launching SD card password popup.");
+       try {
+               AppBundle bundle;
+               bundle.add("viewtype", "SD_CARD_PASSWORD");
+
+               Launchpad launchpad(::tzplatform_getuid(TZ_SYS_DEFAULT_USER));
+               launchpad.launch("org.tizen.ode", bundle);
+       } catch (runtime::Exception &e) {
+               ERROR(SINK, "Failed to launch SD card password popup: " + std::string(e.what()));
+       }
+}
+
 void externalCallback(dbus::Variant parameters)
 {
        int intparams[6];
        char* strparams[7];
 
        parameters.get("(issssssisibii)",
-               &intparams[0], // block type: 0 - scsi, 1 : mmc, 2 : mapper
+               &intparams[0], // block type: 0 - scsi, 1 : mmc
                &strparams[0], // devnode
                &strparams[1], // syspath
                &strparams[2], // usage
@@ -65,7 +76,7 @@ void externalCallback(dbus::Variant parameters)
                &intparams[2], // state: 0 - unmount, 1 - mount
                &intparams[3], // primary: 0 - flase, 1 - true
                &intparams[4], // flags: 1 - unmounted 2 - broken filesystem 4 - no filesystem 8 - not supported 16 - readonly
-               &intparams[5]); // strage id
+               &intparams[5]); // storage id
 
        if (intparams[0] != 1 || (std::string(strparams[3]) != "vfat" &&
                                                          std::string(strparams[3]) != "ext4")) {
@@ -77,21 +88,12 @@ void externalCallback(dbus::Variant parameters)
                INFO(SINK, "SD card not mounted, ignoring.");
        } else {
                INFO(SINK, "SD card mounted.");
-               char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY);
+               char *value = ::vconf_get_str(VCONFKEY_SDE_CRYPTO_STATE);
                if (value != NULL) {
                        std::string valueStr(value);
                        free(value);
                        if (valueStr == "encrypted" && isBootCompleted) {
-                               try {
-                                       INFO(SINK, "Launching SD card password popup.");
-                                       AppBundle bundle;
-                                       bundle.add("viewtype", "SD_CARD_PASSWORD");
-
-                                       Launchpad launchpad(::tzplatform_getuid(TZ_SYS_DEFAULT_USER));
-                                       launchpad.launch("org.tizen.ode", bundle);
-                               } catch (runtime::Exception &e) {
-                                       ERROR(SINK, "Failed to launch SD card password popup: " + std::string(e.what()));
-                               }
+                               spawnUI();
                        }
                }
        }
@@ -105,20 +107,12 @@ void bootCompletionCallback(dbus::Variant parameters)
 
                INFO(SINK, "Boot completed.");
 
-               char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY);
+               char *value = ::vconf_get_str(VCONFKEY_SDE_CRYPTO_STATE);
                if (value != NULL) {
                        std::string valueStr(value);
                        free(value);
                        if (valueStr == "encrypted") {
-                               try {
-                                       INFO(SINK, "Launching SD card password popup.");
-                                       AppBundle bundle;
-                                       bundle.add("viewtype", "SD_CARD_PASSWORD");
-                                       Launchpad launchpad(::tzplatform_getuid(TZ_SYS_DEFAULT_USER));
-                                       launchpad.launch("org.tizen.ode", bundle);
-                               } catch (runtime::Exception &e) {
-                                       ERROR(SINK, "Failed to launch SD card password popup: " + std::string(e.what()));
-                               }
+                               spawnUI();
                        }
                }
                isBootCompleted = true;
@@ -151,13 +145,13 @@ unsigned int getOptions()
        int value;
 
        value = 0;
-       ::vconf_get_bool(EXTERNAL_OPTION_EXCEPT_FOR_MEDIA_FILE_VCONF_KEY, &value);
+       ::vconf_get_bool(VCONFKEY_SDE_EXCLUDE_MEDIAFILE, &value);
        if (value) {
                result |= ExternalEncryption::Option::OnlyNewFile;
        }
 
        value = 0;
-       ::vconf_get_bool(EXTERNAL_OPTION_ONLY_NEW_FILE_VCONF_KEY, &value);
+       ::vconf_get_bool(VCONFKEY_SDE_ENCRYPT_NEWFILE, &value);
        if (value) {
                result |= ExternalEncryption::Option::ExceptForMediaFile;
        }
@@ -174,14 +168,14 @@ void setOptions(unsigned int options)
        } else {
                value = false;
        }
-       ::vconf_set_bool(EXTERNAL_OPTION_EXCEPT_FOR_MEDIA_FILE_VCONF_KEY, value);
+       ::vconf_set_bool(VCONFKEY_SDE_EXCLUDE_MEDIAFILE, value);
 
        if (options & ExternalEncryption::Option::ExceptForMediaFile) {
                value = true;
        } else {
                value = false;
        }
-       ::vconf_set_bool(EXTERNAL_OPTION_ONLY_NEW_FILE_VCONF_KEY, value);
+       ::vconf_set_bool(VCONFKEY_SDE_ENCRYPT_NEWFILE, value);
 }
 
 } // namsepace
@@ -318,13 +312,13 @@ int ExternalEncryptionServer::encrypt(const std::string &password, unsigned int
                        setOptions(options & getSupportedOptions());
 
                        INFO(SINK, "Encryption completed.");
-                       ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "encrypted");
+                       ::vconf_set_str(VCONFKEY_SDE_CRYPTO_STATE, "encrypted");
                        server.notify("ExternalEncryptionServer::mount");
 
                        INFO(SINK, "Syncing disk.");
                        sync();
                } catch (runtime::Exception &e) {
-                       ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
+                       ::vconf_set_str(VCONFKEY_SDE_CRYPTO_STATE, "error_partially_encrypted");
                        ERROR(SINK, "Encryption failed: " + std::string(e.what()));
                }
        };
@@ -367,11 +361,11 @@ int ExternalEncryptionServer::decrypt(const std::string &password)
                        }
 
                        INFO(SINK, "Decryption started.");
-                       ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "error_partially_encrypted");
+                       ::vconf_set_str(VCONFKEY_SDE_CRYPTO_STATE, "error_partially_encrypted");
                        engine->decrypt(MasterKey, getOptions());
 
                        INFO(SINK, "Decryption completed.");
-                       ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "unencrypted");
+                       ::vconf_set_str(VCONFKEY_SDE_CRYPTO_STATE, "unencrypted");
 
                        INFO(SINK, "Syncing disk.");
                        sync();
@@ -398,7 +392,7 @@ int ExternalEncryptionServer::recovery()
        }
 
        engine->clearKeyMeta();
-       ::vconf_set_str(EXTERNAL_STATE_VCONF_KEY, "unencrypted");
+       ::vconf_set_str(VCONFKEY_SDE_CRYPTO_STATE, "unencrypted");
 
        return 0;
 }
@@ -466,7 +460,7 @@ int ExternalEncryptionServer::verifyPassword(const std::string& password)
 
 int ExternalEncryptionServer::getState()
 {
-       char *value = ::vconf_get_str(EXTERNAL_STATE_VCONF_KEY);
+       char *value = ::vconf_get_str(VCONFKEY_SDE_CRYPTO_STATE);
        if (value == NULL) {
                throw runtime::Exception("Failed to get vconf value.");
        }