From 47082e474479eb4cf12fc148e3485d657571dcb0 Mon Sep 17 00:00:00 2001 From: seolheui kim Date: Wed, 9 May 2018 21:31:43 +0900 Subject: [PATCH] Apply encryption progress UI service Change-Id: Ibfe33fb459bf57a16a660bcabb9b9d34c878d7b0 Signed-off-by: seolheui kim --- server/internal-encryption.cpp | 46 +++++++++++++++++------------------------- server/progress-bar.cpp | 1 + 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/server/internal-encryption.cpp b/server/internal-encryption.cpp index 46f7942..bfac022 100644 --- a/server/internal-encryption.cpp +++ b/server/internal-encryption.cpp @@ -233,32 +233,22 @@ void stopDependedSystemdUnits() void showProgressUI(const std::string type) { - ::tzplatform_set_user(::tzplatform_getuid(TZ_SYS_DEFAULT_USER)); - std::string defaultUserHome(::tzplatform_getenv(TZ_USER_HOME)); - ::tzplatform_reset_user(); - - try { - runtime::File shareDirectory("/opt/home/root/share"); - if (!shareDirectory.exists()) { - shareDirectory.makeDirectory(true); - } + dbus::Connection& systemDBus = dbus::Connection::getSystem(); + std::string unit("ode-progress-ui@"+type+".service"); - runtime::File elmConfigDir(shareDirectory.getPath() + "/.elementary"); - if (!elmConfigDir.exists()) { - runtime::File defaultElmConfigDir(defaultUserHome + "/share/.elementary"); - defaultElmConfigDir.copyTo(shareDirectory.getPath()); - } - } catch (runtime::Exception &e) { - ERROR(SINK, "Failed to set up elm configuration: " + std::string(e.what())); - } + JobWatch watch(systemDBus); + INFO(SINK, "Start unit: " + unit); - std::vector args = { - "ode", "progress", type, "Internal" - }; + const char* job = NULL; + systemDBus.methodcall("org.freedesktop.systemd1", + "/org/freedesktop/systemd1", + "org.freedesktop.systemd1.Manager", + "StartUnit", + -1, "(o)", "(ss)", unit.c_str(), "replace").get("(o)", &job); - runtime::Process proc("/usr/bin/ode", args); - if (proc.execute() == -1) - ERROR(SINK, "Failed to execute progress UI"); + INFO(SINK, "Waiting for job: " + std::string(job)); + if (!watch.waitForJob(job)) + throw runtime::Exception("Starting unit: " + unit + " failed"); } unsigned int getOptions() @@ -428,6 +418,9 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int auto encryptWorker = [masterKey, options, this]() { try { + showProgressUI("Encrypting"); + ::sleep(1); + INFO(SINK, "Closing all known systemd services that might be using internal storage."); stopKnownSystemdUnits(); @@ -442,8 +435,6 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int unmountInternalStorage(source); } - showProgressUI("Encrypting"); - INFO(SINK, "Encryption started."); ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted"); engine->encrypt(masterKey, options); @@ -481,6 +472,9 @@ int InternalEncryptionServer::decrypt(const std::string& password) auto decryptWorker = [masterKey, this]() { try { + showProgressUI("Decrypting"); + ::sleep(1); + if (engine->isMounted()) { INFO(SINK, "Closing all known systemd services that might be using internal storage."); stopKnownSystemdUnits(); @@ -498,8 +492,6 @@ int InternalEncryptionServer::decrypt(const std::string& password) } } - showProgressUI("Decrypting"); - INFO(SINK, "Decryption started."); ::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted"); engine->decrypt(masterKey, getOptions()); diff --git a/server/progress-bar.cpp b/server/progress-bar.cpp index bb79711..6feef7c 100644 --- a/server/progress-bar.cpp +++ b/server/progress-bar.cpp @@ -21,6 +21,7 @@ namespace ode { ProgressBar::ProgressBar(UpdateFunc const &updater) : updater(updater), updateValue(0) { + updater(0); } ProgressBar::~ProgressBar() -- 2.7.4