• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <recovery_ui/device.h>
22 #include <recovery_ui/screen_ui.h>
23 
24 // Wipes the provisioned flag as part of data wipe.
WipeProvisionedFlag()25 static bool WipeProvisionedFlag() {
26     // Must be consistent with the one in init.hardware.rc (10-byte `theme-dark`). The magic is at
27     // 0x3048 in vendor space, or (0x800 + 0x3048) since the start of /misc.
28     const std::string wipe_str(10, '\x00');
29     constexpr size_t kProvisionedFlagOffsetInVendorSpace = 0x3048;
30     if (std::string err; !WriteMiscPartitionVendorSpace(
31             wipe_str.data(), wipe_str.size(), kProvisionedFlagOffsetInVendorSpace, &err)) {
32         LOG(ERROR) << "Failed to write wipe string: " << err;
33         return false;
34     }
35     LOG(INFO) << "Provisioned flag wiped successful";
36     return true;
37 }
38 
39 class WalleyeDevice : public Device {
40   public:
WalleyeDevice(ScreenRecoveryUI * ui)41     WalleyeDevice(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 WalleyeDevice(new ScreenRecoveryUI);
58 }
59