Skip to content

Commit

Permalink
Lockscreen: Separate 'Allow RPC While Locked' for USB/BLE (#343)
Browse files Browse the repository at this point in the history
* Lockscreen: Separate 'Allow RPC While Locked' for USB/Bluetooth (BLE)

- #330, split of the `allow_locked_rpc_commands` bool into `allow_locked_rpc_usb` and `allow_locked_rpc_ble` to allow the connections separately.

* Shorter wording

* Update changelog

---------

Co-authored-by: Willy-JL <[email protected]>
  • Loading branch information
956MB and Willy-JL authored Jan 13, 2025
1 parent 7d4ea20 commit 34379f1
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 25 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
### Breaking Changes:
- Lockscreen: Separate 'Allow RPC While Locked' settings for USB/BLE (#343 by @956MB)
- Both default to OFF like before
- If you had enabled this option before, you will need to re-enable

### Added:
- Apps:
- Games: Pinball0 (by @rdefeo)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,20 @@ static void momentum_app_scene_interface_lockscreen_bad_pins_format_changed(Vari
}

static void
momentum_app_scene_interface_lockscreen_allow_locked_rpc_commands_changed(VariableItem* item) {
momentum_app_scene_interface_lockscreen_allow_locked_rpc_usb_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
bool value = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
momentum_settings.allow_locked_rpc_commands = value;
momentum_settings.allow_locked_rpc_usb = value;
app->save_settings = true;
}

static void
momentum_app_scene_interface_lockscreen_allow_locked_rpc_ble_changed(VariableItem* item) {
MomentumApp* app = variable_item_get_context(item);
bool value = variable_item_get_current_value_index(item);
variable_item_set_current_value_text(item, value ? "ON" : "OFF");
momentum_settings.allow_locked_rpc_ble = value;
app->save_settings = true;
}

Expand Down Expand Up @@ -126,13 +135,23 @@ void momentum_app_scene_interface_lockscreen_on_enter(void* context) {

item = variable_item_list_add(
var_item_list,
"Allow RPC While Locked",
"Allow USB RPC While Locked",
2,
momentum_app_scene_interface_lockscreen_allow_locked_rpc_usb_changed,
app);
variable_item_set_current_value_index(item, momentum_settings.allow_locked_rpc_usb);
variable_item_set_current_value_text(
item, momentum_settings.allow_locked_rpc_usb ? "ON" : "OFF");

item = variable_item_list_add(
var_item_list,
"Allow BLE RPC While Locked",
2,
momentum_app_scene_interface_lockscreen_allow_locked_rpc_commands_changed,
momentum_app_scene_interface_lockscreen_allow_locked_rpc_ble_changed,
app);
variable_item_set_current_value_index(item, momentum_settings.allow_locked_rpc_commands);
variable_item_set_current_value_index(item, momentum_settings.allow_locked_rpc_ble);
variable_item_set_current_value_text(
item, momentum_settings.allow_locked_rpc_commands ? "ON" : "OFF");
item, momentum_settings.allow_locked_rpc_ble ? "ON" : "OFF");

item = variable_item_list_add(
var_item_list,
Expand Down
34 changes: 21 additions & 13 deletions applications/services/desktop/desktop.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,13 +391,17 @@ void desktop_lock(Desktop* desktop, bool with_pin) {
furi_hal_rtc_set_pin_fails(0);
}

if(with_pin && !momentum_settings.allow_locked_rpc_commands) {
Cli* cli = furi_record_open(RECORD_CLI);
cli_session_close(cli);
furi_record_close(RECORD_CLI);
Bt* bt = furi_record_open(RECORD_BT);
bt_close_rpc_connection(bt);
furi_record_close(RECORD_BT);
if(with_pin) {
if(!momentum_settings.allow_locked_rpc_usb) {
Cli* cli = furi_record_open(RECORD_CLI);
cli_session_close(cli);
furi_record_close(RECORD_CLI);
}
if(!momentum_settings.allow_locked_rpc_ble) {
Bt* bt = furi_record_open(RECORD_BT);
bt_close_rpc_connection(bt);
furi_record_close(RECORD_BT);
}
}

desktop_auto_lock_inhibit(desktop);
Expand Down Expand Up @@ -426,12 +430,16 @@ void desktop_unlock(Desktop* desktop) {
furi_hal_rtc_set_pin_fails(0);

if(with_pin) {
Cli* cli = furi_record_open(RECORD_CLI);
cli_session_open(cli, &cli_vcp);
furi_record_close(RECORD_CLI);
Bt* bt = furi_record_open(RECORD_BT);
bt_open_rpc_connection(bt);
furi_record_close(RECORD_BT);
if(!momentum_settings.allow_locked_rpc_usb) {
Cli* cli = furi_record_open(RECORD_CLI);
cli_session_open(cli, &cli_vcp);
furi_record_close(RECORD_CLI);
}
if(!momentum_settings.allow_locked_rpc_ble) {
Bt* bt = furi_record_open(RECORD_BT);
bt_open_rpc_connection(bt);
furi_record_close(RECORD_BT);
}
}

DesktopStatus status = {.locked = false};
Expand Down
7 changes: 4 additions & 3 deletions applications/services/rpc/rpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,10 @@ static void
}

RpcSession* rpc_session_open(Rpc* rpc, RpcOwner owner) {
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock) &&
!momentum_settings.allow_locked_rpc_commands)
return NULL;
if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)) {
if(owner == RpcOwnerUsb && !momentum_settings.allow_locked_rpc_usb) return NULL;
if(owner == RpcOwnerBle && !momentum_settings.allow_locked_rpc_ble) return NULL;
}

furi_check(rpc);

Expand Down
6 changes: 4 additions & 2 deletions lib/momentum/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ MomentumSettings momentum_settings = {
.menu_style = MenuStyleDsi, // DSi
.lock_on_boot = false, // OFF
.bad_pins_format = false, // OFF
.allow_locked_rpc_commands = false, // OFF
.allow_locked_rpc_usb = false, // OFF
.allow_locked_rpc_ble = false, // OFF
.lockscreen_poweroff = true, // ON
.lockscreen_time = true, // ON
.lockscreen_seconds = false, // OFF
Expand Down Expand Up @@ -82,7 +83,8 @@ static const struct {
{setting_bool(unlock_anims)},
{setting_enum(menu_style, MenuStyleCount)},
{setting_bool(bad_pins_format)},
{setting_bool(allow_locked_rpc_commands)},
{setting_bool(allow_locked_rpc_usb)},
{setting_bool(allow_locked_rpc_ble)},
{setting_bool(lock_on_boot)},
{setting_bool(lockscreen_poweroff)},
{setting_bool(lockscreen_time)},
Expand Down
3 changes: 2 additions & 1 deletion lib/momentum/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ typedef struct {
MenuStyle menu_style;
bool lock_on_boot;
bool bad_pins_format;
bool allow_locked_rpc_commands;
bool allow_locked_rpc_usb;
bool allow_locked_rpc_ble;
bool lockscreen_poweroff;
bool lockscreen_time;
bool lockscreen_seconds;
Expand Down

0 comments on commit 34379f1

Please sign in to comment.