# Inspect storage & WorkManager

Source: https://olef.dev/docs/guides/inspect-storage-and-work

**Outcome:** prove that a UI action persisted the expected rows, preferences, or background work—instead of trusting what the screen remembered in memory.

## Prerequisites

You need a debuggable build of your app on a connected device or emulator. Read-only snapshots run from the host over `run-as`; live SQLite queries/writes (`--live`) and live WorkManager cancellations attach the in-process Olef runtime automatically when needed.

## Ask your agent

```text
Toggle "Offline sync" in Settings, restart the app, and verify with Olef that:
1) the preference or DataStore value actually persisted on disk,
2) a sync WorkManager job was enqueued with the expected input data and constraints, and
3) after triggering the job, the Room database contains the synced rows.
Report the exact evidence and any unmet WorkManager constraints.
```

## 1. Inspect SQLite & Room databases

List every database, SharedPreferences file, and DataStore file owned by the app:

```bash
olef storage ls --app com.example.app
```

Inspect a database's schema and run parameterized, read-only SQL queries against a WAL-consistent snapshot (with column redaction when tables hold PII):

```bash
olef storage db schema --app com.example.app --db app.db
olef storage db query --app com.example.app --db app.db \
  --sql "SELECT id, title, synced FROM items WHERE synced = ?" \
  --param 0 --limit 20
```

When a database uses Android-specific collations such as `LOCALIZED`, or you need to mutate state inside a transaction to set up a test scenario, add `--live`:

```bash
olef storage db query --app com.example.app --db app.db --live \
  --sql "SELECT id, name FROM contacts ORDER BY name COLLATE LOCALIZED LIMIT 10"
olef storage db exec --app com.example.app --db app.db --live \
  --sql "UPDATE items SET synced = 0 WHERE id = ?" --param 42
```

## 2. Inspect SharedPreferences & DataStore

SharedPreferences reads and edits respect Android's `.xml.bak` recovery behavior and refuse `EncryptedSharedPreferences` without side effects:

```bash
olef storage prefs get --app com.example.app --file user_prefs
olef storage prefs set --app com.example.app --file user_prefs \
  --key offline_sync --type bool --value true --restart
```

For Jetpack DataStore, decode `.preferences_pb` files directly or inspect raw protobuf fields:

```bash
olef storage datastore read --app com.example.app --file settings.preferences_pb
```

## 3. Diagnose AndroidX WorkManager jobs

Background sync bugs are notorious for succeeding at `enqueue()` and then silently waiting forever. Inspect WorkManager's database (`no_backup/androidx.work.workdb`), decoded binary `Data` inputs/outputs, and OS `JobScheduler` constraint correlations:

```bash
olef work list --app com.example.app
olef work show <work-uuid> --app com.example.app
```

Trigger an enqueued job immediately (reporting whether Android executed or deferred it) or cancel a job and observe downstream dependent transitions:

```bash
olef work run <work-uuid> --app com.example.app
olef work cancel <work-uuid> --app com.example.app
```

## Limits

- `olef storage` and `olef work` require a debuggable build (`run-as` access).
- Custom Proto DataStore files decode as raw protobuf wire fields; schema interpretation depends on your `.proto` definitions.
- Requesting `work run` still respects OS scheduling constraints—always verify completion state and resulting storage rows afterward.

See the full CLI flags in [`olef storage`](https://olef.dev/docs/reference/cli/storage) and [`olef work`](https://olef.dev/docs/reference/cli/work).
