Skip to content

Commit

Permalink
Wipe Device Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
RogueMaster committed Jul 24, 2023
1 parent 4b49d22 commit 2fd0602
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 17 deletions.
5 changes: 3 additions & 2 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ This software is for experimental purposes only and is not meant for any illegal
- Updated: [Password Generator (By anakod)](https://github.com/anakod/flipper_passgen) [(Updates By henrygab)](https://github.com/anakod/flipper_passgen/pull/6)
- Updated: [Enhanced Sub-Ghz Chat (By twisted-pear)](https://github.com/twisted-pear/esubghz_chat)
- Updated: [IR Remote (By Hong5489)](https://github.com/Hong5489/ir_remote) [Hold Option (By d4ve10)](https://github.com/d4ve10/ir_remote/tree/infrared_hold_option)
- Updated: SD Card Assets: Includes NFC Assets: 67 RM Pro Trained Level 50 Sm@sh Amiib0 (By RogueMaster) (19 More Added)
- Fix Evil Portal Assets folder
- Updated: [SD Card Assets: Includes NFC Assets: 67 RM Pro Trained Level 50 Sm@sh Amiib0 (By RogueMaster) (19 More Added)](https://www.patreon.com/RogueMaster/membership)
- [Fix Evil Portal Assets folder](https://github.com/RogueMaster/flipperzero-firmware-wPlugins/commit/22e6c87e293121ba30a6243d69d018c4f8146aca)
- Wipe Device option from Lock Menu and Storage Settings (By ClaraCrazy Ported By RogueMaster)

<a name="release">

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ bool desktop_scene_lock_menu_on_event(void* context, SceneManagerEvent event) {
power_off(power);
furi_record_close(RECORD_POWER);
break;
case DesktopLockMenuEventWipe:
loader_start_with_gui_error(desktop->loader, "Storage", "wipe");
break;
case DesktopLockMenuEventDummyModeOn:
desktop_set_dummy_mode_state(desktop, true);
scene_manager_search_and_switch_to_previous_scene(
Expand Down
1 change: 1 addition & 0 deletions applications/services/desktop/views/desktop_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef enum {
DesktopLockMenuEventExit,
DesktopLockMenuEventLock,
DesktopLockMenuEventLockShutdown,
DesktopLockMenuEventWipe,
DesktopLockMenuEventDummyModeOn,
DesktopLockMenuEventDummyModeOff,
DesktopLockMenuEventStealthModeOn,
Expand Down
28 changes: 20 additions & 8 deletions applications/services/desktop/views/desktop_view_lock_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ typedef enum {
DesktopLockMenuIndexBasicLock,
DesktopLockMenuIndexBasicLockShutdown,
DesktopLockMenuIndexBasicGameMode,
DesktopLockMenuIndexBasicWipe,
DesktopLockMenuIndexBasicStealth,
DesktopLockMenuIndexBasicDummy,

Expand Down Expand Up @@ -189,12 +190,13 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) {
}

if(m->show_lock_menu) {
canvas_set_font(canvas, FontSecondary);
elements_bold_rounded_frame(canvas, 24, 4, 80, 56);
canvas_draw_str_aligned(canvas, 64, 16, AlignCenter, AlignCenter, "Lock");
canvas_draw_str_aligned(canvas, 64, 32, AlignCenter, AlignCenter, "Lock + OFF");
canvas_draw_str_aligned(canvas, 64, 48, AlignCenter, AlignCenter, "Game Mode");
elements_frame(canvas, 28, 8 + m->pin_lock * 16, 72, 15);
canvas_set_font(canvas, FontBatteryPercent);
elements_bold_rounded_frame(canvas, 24, 2, 82, 56);
canvas_draw_str_aligned(canvas, 64, 10, AlignCenter, AlignCenter, "Lock");
canvas_draw_str_aligned(canvas, 64, 22, AlignCenter, AlignCenter, "Lock + OFF");
canvas_draw_str_aligned(canvas, 64, 34, AlignCenter, AlignCenter, "Game Mode");
canvas_draw_str_aligned(canvas, 64, 46, AlignCenter, AlignCenter, "Wipe Device");
elements_frame(canvas, 28, 4 + m->pin_lock * 12, 72, 13);
}
} else {
canvas_set_color(canvas, ColorBlack);
Expand All @@ -215,6 +217,9 @@ void desktop_lock_menu_draw_callback(Canvas* canvas, void* model) {
case DesktopLockMenuIndexBasicGameMode:
str = "Game Mode";
break;
case DesktopLockMenuIndexBasicWipe:
str = "Wipe Device";
break;
case DesktopLockMenuIndexBasicStealth:
if(m->stealth_mode) {
str = "Sound Mode";
Expand Down Expand Up @@ -279,11 +284,11 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
if(event->key == InputKeyUp) {
model->pin_lock--;
if(model->pin_lock < 0) {
model->pin_lock = 2;
model->pin_lock = 3;
}
} else if(event->key == InputKeyDown) {
model->pin_lock++;
if(model->pin_lock > 2) {
if(model->pin_lock > 3) {
model->pin_lock = 0;
}
} else if(event->key == InputKeyBack || event->key == InputKeyOk) {
Expand Down Expand Up @@ -347,6 +352,10 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
desktop_view_lock_menu_dumbmode_changed(1);
desktop_event = DesktopLockMenuEventExit;
break;
case 3:
dolphin_deed(getRandomDeed());
desktop_event = DesktopLockMenuEventWipe;
break;
default:
break;
}
Expand Down Expand Up @@ -481,6 +490,9 @@ bool desktop_lock_menu_input_callback(InputEvent* event, void* context) {
dolphin_deed(getRandomDeed());
desktop_view_lock_menu_dumbmode_changed(1);
lock_menu->callback(DesktopLockMenuEventExit, lock_menu->context);
} else if((idx == DesktopLockMenuIndexBasicWipe) && (event->type == InputTypeShort)) {
dolphin_deed(getRandomDeed());
lock_menu->callback(DesktopLockMenuEventWipe, lock_menu->context);
} else if(idx == DesktopLockMenuIndexBasicStealth) {
if((stealth_mode == false) && (event->type == InputTypeShort)) {
lock_menu->callback(DesktopLockMenuEventStealthModeOn, lock_menu->context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ ADD_SCENE(storage_settings, sd_info, SDInfo)
ADD_SCENE(storage_settings, internal_info, InternalInfo)
ADD_SCENE(storage_settings, benchmark, Benchmark)
ADD_SCENE(storage_settings, factory_reset, FactoryReset)
ADD_SCENE(storage_settings, wipe_device, WipeDevice)
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ bool storage_settings_scene_format_confirm_on_event(void* context, SceneManagerE
consumed = scene_manager_previous_scene(app->scene_manager);
break;
case DialogExResultRight:
scene_manager_set_scene_state(app->scene_manager, StorageSettingsFormatting, false);
scene_manager_next_scene(app->scene_manager, StorageSettingsFormatting);
consumed = true;
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "../storage_settings.h"
#include <power/power_service/power.h>

static const NotificationMessage message_green_165 = {
.type = NotificationMessageTypeLedGreen,
Expand Down Expand Up @@ -47,8 +48,12 @@ void storage_settings_scene_formatting_on_enter(void* context) {
dialog_ex_set_text(
dialog_ex, storage_error_get_desc(error), 64, 32, AlignCenter, AlignCenter);
} else {
dialog_ex_set_icon(dialog_ex, 72, 17, &I_DolphinCommon_56x48);
dialog_ex_set_header(dialog_ex, "Format\ncomplete!", 14, 15, AlignLeft, AlignTop);
if(scene_manager_get_scene_state(app->scene_manager, StorageSettingsFormatting)) {
power_reboot(PowerBootModeNormal);
} else {
dialog_ex_set_icon(dialog_ex, 72, 17, &I_DolphinCommon_56x48);
dialog_ex_set_header(dialog_ex, "Format\ncomplete!", 14, 15, AlignLeft, AlignTop);
}
}
dialog_ex_set_center_button_text(dialog_ex, "OK");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ enum StorageSettingsStartSubmenuIndex {
StorageSettingsStartSubmenuIndexUnmount,
StorageSettingsStartSubmenuIndexFormat,
StorageSettingsStartSubmenuIndexBenchy,
StorageSettingsStartSubmenuIndexFactoryReset
StorageSettingsStartSubmenuIndexFactoryReset,
StorageSettingsStartSubmenuIndexWipeDevice,
};

static void storage_settings_scene_start_submenu_callback(void* context, uint32_t index) {
Expand Down Expand Up @@ -55,6 +56,12 @@ void storage_settings_scene_start_on_enter(void* context) {
StorageSettingsStartSubmenuIndexFactoryReset,
storage_settings_scene_start_submenu_callback,
app);
submenu_add_item(
submenu,
"Wipe Device",
StorageSettingsStartSubmenuIndexWipeDevice,
storage_settings_scene_start_submenu_callback,
app);

submenu_set_selected_item(
submenu, scene_manager_get_scene_state(app->scene_manager, StorageSettingsStart));
Expand Down Expand Up @@ -108,6 +115,14 @@ bool storage_settings_scene_start_on_event(void* context, SceneManagerEvent even
scene_manager_next_scene(app->scene_manager, StorageSettingsFactoryReset);
consumed = true;
break;
case StorageSettingsStartSubmenuIndexWipeDevice:
scene_manager_set_scene_state(
app->scene_manager,
StorageSettingsStart,
StorageSettingsStartSubmenuIndexWipeDevice);
scene_manager_next_scene(app->scene_manager, StorageSettingsWipeDevice);
consumed = true;
break;
}
}
return consumed;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#include "../storage_settings.h"
#include <furi_hal.h>

#define STORAGE_SETTINGS_SCENE_WIPE_DEVICE_CONFIRM_COUNT 5

static void
storage_settings_scene_wipe_device_dialog_callback(DialogExResult result, void* context) {
StorageSettings* app = context;

view_dispatcher_send_custom_event(app->view_dispatcher, result);
}

void storage_settings_scene_wipe_device_on_enter(void* context) {
StorageSettings* app = context;
DialogEx* dialog_ex = app->dialog_ex;

dialog_ex_set_context(dialog_ex, app);
dialog_ex_set_result_callback(dialog_ex, storage_settings_scene_wipe_device_dialog_callback);

dialog_ex_set_left_button_text(dialog_ex, "Cancel");
dialog_ex_set_right_button_text(dialog_ex, "Erase");

dialog_ex_set_header(dialog_ex, "Confirm full Wipe", 64, 10, AlignCenter, AlignCenter);
dialog_ex_set_text(
dialog_ex,
"Everything will be erased\r\nData and settings will be lost!",
64,
32,
AlignCenter,
AlignCenter);

view_dispatcher_switch_to_view(app->view_dispatcher, StorageSettingsViewDialogEx);
}

bool storage_settings_scene_wipe_device_on_event(void* context, SceneManagerEvent event) {
StorageSettings* app = context;
bool consumed = false;

uint32_t counter =
scene_manager_get_scene_state(app->scene_manager, StorageSettingsWipeDevice);

if(event.type == SceneManagerEventTypeCustom) {
switch(event.event) {
case DialogExResultLeft:
scene_manager_set_scene_state(app->scene_manager, StorageSettingsWipeDevice, 0);
consumed = scene_manager_previous_scene(app->scene_manager);
if(!consumed) {
view_dispatcher_stop(app->view_dispatcher);
}
break;
case DialogExResultRight:
counter++;
if(counter < STORAGE_SETTINGS_SCENE_WIPE_DEVICE_CONFIRM_COUNT) {
furi_string_printf(
app->text_string,
"%ld presses left",
STORAGE_SETTINGS_SCENE_WIPE_DEVICE_CONFIRM_COUNT - counter);
dialog_ex_set_text(
app->dialog_ex,
furi_string_get_cstr(app->text_string),
64,
32,
AlignCenter,
AlignCenter);
scene_manager_set_scene_state(
app->scene_manager, StorageSettingsWipeDevice, counter);
} else {
furi_hal_rtc_set_flag(FuriHalRtcFlagFactoryReset);
scene_manager_set_scene_state(app->scene_manager, StorageSettingsFormatting, true);
scene_manager_next_scene(app->scene_manager, StorageSettingsFormatting);
}

consumed = true;
break;
}
} else if(event.type == SceneManagerEventTypeBack) {
consumed = true;
}

return consumed;
}

void storage_settings_scene_wipe_device_on_exit(void* context) {
StorageSettings* app = context;
DialogEx* dialog_ex = app->dialog_ex;

dialog_ex_reset(dialog_ex);

furi_string_reset(app->text_string);
}
11 changes: 7 additions & 4 deletions applications/settings/storage_settings/storage_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ static StorageSettings* storage_settings_alloc() {
view_dispatcher_add_view(
app->view_dispatcher, StorageSettingsViewDialogEx, dialog_ex_get_view(app->dialog_ex));

scene_manager_next_scene(app->scene_manager, StorageSettingsStart);

return app;
}

Expand All @@ -65,10 +63,15 @@ static void storage_settings_free(StorageSettings* app) {
free(app);
}

int32_t storage_settings_app(void* p) {
UNUSED(p);
int32_t storage_settings_app(char* p) {
StorageSettings* app = storage_settings_alloc();

if(p && strlen(p) && strcmp(p, "wipe") == 0) {
scene_manager_next_scene(app->scene_manager, StorageSettingsWipeDevice);
} else {
scene_manager_next_scene(app->scene_manager, StorageSettingsStart);
}

view_dispatcher_run(app->view_dispatcher);

storage_settings_free(app);
Expand Down

0 comments on commit 2fd0602

Please sign in to comment.