2 * Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
20 #include "engine/erase/mmc-engine.h"
21 #include "rmi/secure-erase.h"
23 #define ERASE_ENGINE MMCEraseEngine
24 #define PRIVILEGE_PLATFORM "http://tizen.org/privilege/internal/default/platform"
30 std::unique_ptr<ERASE_ENGINE> engine;
32 void dropCachePage(void)
36 file.open("/proc/sys/vm/drop_caches");
38 throw runtime::Exception("failed to access drop_caches file");
49 SecureErase::SecureErase(ODEControlContext &ctx) :
52 context.expose(this, PRIVILEGE_PLATFORM, (int)(SecureErase::erase)(std::string));
53 context.expose(this, PRIVILEGE_PLATFORM, (int)(SecureErase::clean)(std::string));
55 engine.reset(new ERASE_ENGINE(ProgressBar([](int v) {
56 ::vconf_set_str(VCONFKEY_ODE_ERASE_PROGRESS, std::to_string(v).c_str());
61 SecureErase::~SecureErase()
65 int SecureErase::erase(const std::string &name)
67 auto eraseWorker = [name, this]() {
69 runtime::File file(name);
70 if (file.isDevice()) {
71 engine->eraseDevice(name);
73 engine->eraseFiles(name);
76 } catch (runtime::Exception &e) {}
79 std::thread asyncWork(eraseWorker);
85 int SecureErase::clean(const std::string &name)
87 auto cleanWorker = [name, this]() {
89 engine->cleanDevice(name);
91 } catch (runtime::Exception &e) {}
94 std::thread asyncWork(cleanWorker);