1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #include <string>
18 
19 #include <android-base/logging.h>
20 #include <bootloader_message/bootloader_message.h>
21 #include <misc_writer/misc_writer.h>
22 #include <recovery_ui/device.h>
23 #include <recovery_ui/screen_ui.h>
24 
25 using android::hardware::google::pixel::MiscWriter;
26 using android::hardware::google::pixel::MiscWriterActions;
27 
28 // Wipes the provisioned flag as part of data wipe.
WipeProvisionedFlag()29 static bool WipeProvisionedFlag() {
30     MiscWriter misc_writer(MiscWriterActions::kClearDarkThemeFlag);
31     if (!misc_writer.PerformAction()) {
32         LOG(ERROR) << "Failed to clear the dark theme flag";
33         return false;
34     }
35     LOG(INFO) << "Provisioned flag wiped successful";
36     return true;
37 }
38 
39 class TaimenDevice : public Device {
40   public:
TaimenDevice(ScreenRecoveryUI * ui)41     TaimenDevice(ScreenRecoveryUI* ui) : Device(ui) {}
42 
43     // Hook to wipe user data not stored in /data.
PostWipeData()44     bool PostWipeData() override {
45         // Try to do everything but report a failure if anything wasn't successful.
46         bool total_success = true;
47         auto ui = GetUI();
48         ui->Print("Wiping provisioned flag...\n");
49         if (!WipeProvisionedFlag()) {
50             total_success = false;
51         }
52         return total_success;
53     }
54 };
55 
make_device()56 Device* make_device() {
57     return new TaimenDevice(new ScreenRecoveryUI);
58 }
59