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<std::string> 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()
auto encryptWorker = [masterKey, options, this]() {
try {
+ showProgressUI("Encrypting");
+ ::sleep(1);
+
INFO(SINK, "Closing all known systemd services that might be using internal storage.");
stopKnownSystemdUnits();
unmountInternalStorage(source);
}
- showProgressUI("Encrypting");
-
INFO(SINK, "Encryption started.");
::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted");
engine->encrypt(masterKey, options);
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();
}
}
- showProgressUI("Decrypting");
-
INFO(SINK, "Decryption started.");
::vconf_set_str(VCONFKEY_ODE_CRYPTO_STATE, "error_partially_encrypted");
engine->decrypt(masterKey, getOptions());