# Private app data

`app.data`: stopped, debuggable-app private files and SQLite bundles. Guide:
[Private app data](../../guide/app-data.md).

## <kbd>class</kbd> `AppData`
Private files under a debuggable app's credential-encrypted data directory. 

Obtain from ``app.data``. Except ``capabilities``, access requires **all processes under the app UID to be stopped**, including secondary/native/shared-UID processes. Call ``app.force_stop()`` explicitly; Tap never stops/relaunches/restores app data implicitly. Do not concurrently drive the app through UI, notifications, another ADB client or an external actor. This is not an OS filesystem lock. Paths are normalized relative UTF-8, without traversal, symlink components, control characters or reserved ``.tap-private-`` components. Transfers are binary-safe and bounded to 64 MiB; contents and paths are omitted from event records. Transport loss during mutation is not a reason to retry blindly. 

### <kbd>method</kbd> `AppData.__init__`

```python
__init__(app: 'App')
```

---

### <kbd>method</kbd> `AppData.capabilities`

```python
capabilities() → AppDataAccess
```

Probe actual run-as access; safe while the app runs. No root fallback. 

---

### <kbd>method</kbd> `AppData.delete`

```python
delete(path: 'str') → None
```

Delete one regular file; no directory/root/recursive deletion. App must be stopped. 

---

### <kbd>method</kbd> `AppData.export_database`

```python
export_database(name: 'str', timeout: 'float | None' = None) → DatabaseBundle
```

Export ``databases/name`` with existing WAL/journal, at most 64 MiB total. 

A stopped app may retain committed WAL; copying the base database alone is not a backup. 

---

### <kbd>method</kbd> `AppData.import_database`

```python
import_database(
    bundle: 'DatabaseBundle',
    name: 'str | None' = None,
    overwrite: 'bool' = False,
    timeout: 'float | None' = None
) → None
```

Stage and import a database bundle, optionally under another basename. 

Discard old sidecars, including SHM. Refuse existing files unless ``overwrite=True``. Multi-file replacement is not an OS transaction: after interrupted commit, do not launch or repeat blindly. Inspect/repair the retained private backup or explicitly clear data. No app restart, SQL validation, schema conversion or decryption is performed. 

---

### <kbd>method</kbd> `AppData.list`

```python
list(path: 'str' = '') → list[PrivateFileEntry]
```

List immediate children (at most 1024); empty ``path`` lists the private root. 

---

### <kbd>method</kbd> `AppData.read`

```python
read(path: 'str', timeout: 'float | None' = None) → bytes
```

Read one regular file, at most 64 MiB, with server-side size/SHA-256 verification. 

---

### <kbd>method</kbd> `AppData.write`

```python
write(
    path: 'str',
    data: 'bytes',
    overwrite: 'bool' = False,
    timeout: 'float | None' = None
) → None
```

Write at most 64 MiB. Create missing parents; refuse an existing file by default. 

Verify staged bytes before replacement. Changes are not restored on session release. 

## <kbd>class</kbd> `AppDataAccess`
Actual run-as capability for the current Android user; not just a debug-build label. 

### <kbd>method</kbd> `AppDataAccess.__init__`

```python
__init__(available: 'bool', reason: 'str | None' = None) → None
```

## <kbd>class</kbd> `PrivateFileEntry`
One immediate child. Symlinks can be listed but data operations never follow them. 

### <kbd>method</kbd> `PrivateFileEntry.__init__`

```python
__init__(
    name: 'str',
    size_bytes: 'int',
    is_directory: 'bool',
    is_symlink: 'bool'
) → None
```

## <kbd>class</kbd> `DatabaseBundle`
Opaque SQLite base file plus persistent WAL/rollback journal, never rebuildable SHM. 

Import needs the app's own schema, keys and migrations. No SQL/decryption is performed. ``name`` is a database basename, not a path. Together the bytes may be at most 64 MiB. 

### <kbd>method</kbd> `DatabaseBundle.__init__`

```python
__init__(
    name: 'str',
    database: 'bytes',
    wal: 'bytes | None' = None,
    journal: 'bytes | None' = None
) → None
```

