1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "update_service_restorer.h"
17
18 #include "fs_manager/mount.h"
19 #include "updaterkits/updaterkits.h"
20
21 #include "update_define.h"
22 #include "update_log.h"
23 #include "update_system_event.h"
24
25 namespace OHOS {
26 namespace UpdateEngine {
27 const std::string MISC_PATH = "/misc";
28 const std::string MISC_FILE = "/dev/block/by-name/misc";
29 const std::string CMD_WIPE_DATA = "--user_wipe_data";
30
FactoryReset(BusinessError & businessError)31 int32_t UpdateServiceRestorer::FactoryReset(BusinessError &businessError)
32 {
33 #ifndef UPDATER_UT
34 businessError.errorNum = CallResult::SUCCESS;
35 auto miscBlockDev = Updater::GetBlockDeviceByMountPoint(MISC_PATH);
36 ENGINE_LOGI("FactoryReset::misc path : %{public}s", miscBlockDev.c_str());
37 ENGINE_CHECK(!miscBlockDev.empty(), miscBlockDev = MISC_FILE, "cannot get block device of partition");
38 int32_t ret = RebootAndCleanUserData(miscBlockDev, CMD_WIPE_DATA) ? INT_CALL_SUCCESS : INT_CALL_FAIL;
39 ENGINE_LOGI("FactoryReset result : %{public}d", ret);
40 SYS_EVENT_SYSTEM_RESET(
41 0, ret == INT_CALL_SUCCESS ? UpdateSystemEvent::EVENT_SUCCESS_RESULT : UpdateSystemEvent::EVENT_FAILED_RESULT);
42 return ret;
43 #else
44 return INT_CALL_SUCCESS;
45 #endif
46 }
47 } // namespace UpdateEngine
48 } // namespace OHOS
49