Home | History | Annotate | Download | only in recovery
      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.
     25 static bool WipeProvisionedFlag() {
     26     // Must be consistent with the one in init.hardware.rc (10-byte `theme-dark`).
     27     const std::string wipe_str(10, '\x00');
     28     constexpr size_t kProvisionedFlagOffsetInVendorSpace = 0;
     29     if (std::string err; !WriteMiscPartitionVendorSpace(
     30             wipe_str.data(), wipe_str.size(), kProvisionedFlagOffsetInVendorSpace, &err)) {
     31         LOG(ERROR) << "Failed to write wipe string: " << err;
     32         return false;
     33     }
     34     LOG(INFO) << "Provisioned flag wiped successful";
     35     return true;
     36 }
     37 
     38 class TaimenDevice : public Device {
     39   public:
     40     TaimenDevice(ScreenRecoveryUI* ui) : Device(ui) {}
     41 
     42     // Hook to wipe user data not stored in /data.
     43     bool PostWipeData() override {
     44         // Try to do everything but report a failure if anything wasn't successful.
     45         bool total_success = true;
     46         auto ui = GetUI();
     47         ui->Print("Wiping provisioned flag...\n");
     48         if (!WipeProvisionedFlag()) {
     49             total_success = false;
     50         }
     51         return total_success;
     52     }
     53 };
     54 
     55 Device* make_device() {
     56     return new TaimenDevice(new ScreenRecoveryUI);
     57 }
     58