# How Expert Mode Is Implemented in UAD-ng: Features and Safety Mechanisms

> Discover how Expert Mode is implemented in UAD-ng, unlocking advanced features while safeguarding against accidental removal of critical system apps. Learn about its safety mechanisms.

- Repository: [Universal-Debloater-Alliance/universal-android-debloater-next-generation](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation)
- Tags: internals
- Published: 2026-06-18

---

**UAD-ng implements Expert Mode as a global boolean flag stored in [`config.toml`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/config.toml) that gates the ability to uninstall packages marked as `Removal::Unsafe`, preventing accidental removal of system-critical apps that could cause bootloops.**

The Universal Android Debloater Next Generation (UAD-ng) repository at `Universal-Debloater-Alliance/universal-android-debloater-next-generation` uses a comprehensive safety system to protect users from accidentally removing critical system packages. Expert Mode serves as the master switch that distinguishes between standard debloating operations and advanced modifications that carry significant stability risks. Understanding how this mechanism is implemented at the code level reveals the layered safety architecture built into the Rust-based application.

## Configuration Storage in config.toml

At the core of the Expert Mode system lies a simple but persistent boolean value stored in the application's configuration file.

### The GeneralSettings Struct

The flag resides in [`crates/uad-core/src/config.rs`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/crates/uad-core/src/config.rs) within the `GeneralSettings` struct as a standard `bool` field. This struct handles serialization and deserialization via `serde`, ensuring the preference persists across application sessions.

```rust
// crates/uad-core/src/config.rs
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct GeneralSettings {
    pub theme: String,
    pub expert_mode: bool,          // ← the flag
    pub backup_folder: PathBuf,
}

```

When the application initializes, it loads the [`config.toml`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/config.toml) file and populates this structure. Any modifications to the flag trigger an immediate writeback to disk through the `Config::save_device_settings` method, ensuring the user's preference is never lost.

## User Interface Implementation

The settings view provides the primary interface for toggling Expert Mode, implementing both the visual control and the persistence logic.

### Settings Panel Checkbox

In [`crates/uad-gui/src/views/settings.rs`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/crates/uad-gui/src/views/settings.rs), the interface renders a checkbox with an explicit warning label indicating the potential dangers of the feature.

```rust
// crates/uad-gui/src/views/settings.rs
let expert_mode_checkbox = checkbox(self.general.expert_mode)
    .label("Allow to uninstall packages marked as \"unsafe\" (I KNOW WHAT I AM DOING)")
    .on_toggle(Message::ExpertMode)
    .size(20)
    .style(style::CheckBox::SettingsEnabled);

```

### Message Handler Logic

The `handle_expert_mode` function processes toggle events by updating the in-memory state and immediately persisting the change to the configuration file.

```rust
// crates/uad-gui/src/views/settings.rs
fn handle_expert_mode(&mut self, _phone: &Phone, toggled: bool) -> Task<Message> {
    self.general.expert_mode = toggled;
    let mut config = Config::load_configuration_file();
    config.save_device_settings(self.device.clone(), self.general.clone());
    Task::none()
}

```

This implementation ensures that the `expert_mode` value in [`config.toml`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/config.toml) always reflects the current UI state, maintaining consistency even if the application crashes or the system restarts.

## Package List Enforcement

The actual safety enforcement occurs at the package level, where the UI conditionally renders controls based on the Expert Mode state combined with package metadata.

### Conditional UI Rendering in PackageRow

In [`crates/uad-gui/src/widgets/package_row.rs`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/crates/uad-gui/src/widgets/package_row.rs), the rendering logic evaluates three conditions before enabling the selection checkbox: whether the package is unsafe, whether it's currently enabled, and whether Expert Mode is active.

```rust
// crates/uad-gui/src/widgets/package_row.rs
// Disable any removal action for unsafe packages if expert_mode is disabled
if self.removal != Removal::Unsafe
    || self.state != PackageState::Enabled
    || settings.general.expert_mode
{
    // enabled checkbox + action button
} else {
    // disabled checkbox, no action button
}

```

This logic ensures that **unsafe packages can only be selected for removal when Expert Mode is explicitly enabled**. If the flag is disabled, the UI renders a disabled checkbox, effectively preventing the user from triggering the uninstall action regardless of their intent.

## Features Enabled by Expert Mode

Enabling Expert Mode unlocks specific capabilities that are otherwise restricted by the safety system:

- **Uninstallation of unsafe packages**: Permits the removal of packages marked with `Removal::Unsafe` in the application database, which typically includes critical system components that could cause bootloops or loss of core functionality.
- **Checkbox activation for restricted apps**: Makes the selection controls interactive for packages known to cause device instability when removed.
- **Persistent preference storage**: The setting survives application restarts, eliminating the need to re-enable the mode for each session.

No other application features—such as backup/restore operations or multi-user handling—depend on this flag. Its sole purpose is to gate the dangerous uninstall operation.

## Programmatically Controlling Expert Mode

You can interact with the Expert Mode setting programmatically using the UAD-ng core configuration API.

### Toggle Expert Mode via Code

```rust
use uad_core::config::Config;
use uad_core::config::GeneralSettings;

// Load current config
let mut cfg = Config::load_configuration_file();

// Enable expert mode
cfg.general.expert_mode = true;

// Persist the change (device settings can be empty for this example)
cfg.save_device_settings(Default::default(), cfg.general.clone());

```

### Check Prerequisites Before Unsafe Uninstalls

```rust
use uad_core::config::Config;

fn can_remove_unsafe() -> bool {
    Config::load_configuration_file().general.expert_mode
}

// Example usage inside a command handler
if package.removal == Removal::Unsafe && !can_remove_unsafe() {
    println!("Refusing to uninstall unsafe package – enable Expert Mode first.");
} else {
    // proceed with uninstall
}

```

## Summary

- **Expert Mode** is a global boolean flag stored in `GeneralSettings.expert_mode` within [`config.toml`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/config.toml) that controls access to dangerous package removal operations.
- The setting persists across sessions via the `Config::save_device_settings` method in [`crates/uad-core/src/config.rs`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/crates/uad-core/src/config.rs).
- The UI exposes the control through a checkbox in [`crates/uad-gui/src/views/settings.rs`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/crates/uad-gui/src/views/settings.rs), complete with explicit warnings about the risks.
- Safety enforcement happens in [`crates/uad-gui/src/widgets/package_row.rs`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/crates/uad-gui/src/widgets/package_row.rs), where the UI disables selection checkboxes for `Removal::Unsafe` packages unless Expert Mode is active.
- The flag exclusively gates the uninstall action for unsafe packages and does not affect backup, restore, or other device management features.

## Frequently Asked Questions

### What is Expert Mode in UAD-ng?

Expert Mode is a safety feature that unlocks the ability to uninstall packages marked as **unsafe**—system applications that could cause bootloops, loss of cellular functionality, or other critical failures if removed. When disabled, the UI prevents selection of these packages regardless of user permissions on the device.

### Where is the Expert Mode setting stored?

The setting persists in the [`config.toml`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/config.toml) configuration file as the `expert_mode` boolean field within the `GeneralSettings` struct, defined in [`crates/uad-core/src/config.rs`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/crates/uad-core/src/config.rs). The application writes changes immediately via `Config::save_device_settings` whenever the user toggles the checkbox in the settings panel.

### Does Expert Mode affect backup and restore operations?

No. According to the UAD-ng source code, the `expert_mode` flag exclusively controls the package removal action for unsafe apps. Backup and restore functionality operates independently of this setting, allowing users to create backups of any package regardless of the Expert Mode state.

### How does UAD-ng prevent accidental uninstallation of unsafe packages?

The application implements a three-condition check in [`crates/uad-gui/src/widgets/package_row.rs`](https://github.com/Universal-Debloater-Alliance/universal-android-debloater-next-generation/blob/main/crates/uad-gui/src/widgets/package_row.rs) that enables the selection checkbox only if the package is **not** unsafe, **not** currently enabled, or if Expert Mode is **on**. This means unsafe, enabled packages render with disabled checkboxes when Expert Mode is off, making accidental selection and removal impossible through the standard UI flow.