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()29static bool WipeProvisionedFlag() { 30 // The magic is at 0x3048 in vendor space, or (0x800 + 0x3048) since the start of /misc. 31 constexpr size_t kProvisionedFlagOffsetInVendorSpace = 0x3048; 32 MiscWriter misc_writer(MiscWriterActions::kClearDarkThemeFlag); 33 if (!misc_writer.PerformAction(kProvisionedFlagOffsetInVendorSpace)) { 34 LOG(ERROR) << "Failed to clear the dark theme flag"; 35 return false; 36 } 37 LOG(INFO) << "Provisioned flag wiped successful"; 38 return true; 39 } 40 41 class WalleyeDevice : public Device { 42 public: WalleyeDevice(ScreenRecoveryUI * ui)43 WalleyeDevice(ScreenRecoveryUI* ui) : Device(ui) {} 44 45 // Hook to wipe user data not stored in /data. PostWipeData()46 bool PostWipeData() override { 47 // Try to do everything but report a failure if anything wasn't successful. 48 bool total_success = true; 49 auto ui = GetUI(); 50 ui->Print("Wiping provisioned flag...\n"); 51 if (!WipeProvisionedFlag()) { 52 total_success = false; 53 } 54 return total_success; 55 } 56 }; 57 make_device()58Device* make_device() { 59 return new WalleyeDevice(new ScreenRecoveryUI); 60 } 61