Summary
This feature allows users to take full ownership of their data by creating portable backups. Users can export their entire usage history, settings, and sessions into a single compressed file. Conversely, they can restore this data later, which is essential for migrating to a new device or recovering from data loss. The system includes safeguards to validate files before importing and provides real-time progress estimates during long operations.How It Works
Exporting Data
The export process involves calculating the data size, asking the user for a save location, and then streaming the database content into a compressed file.Preflight Estimation
When the user opens the export screen, the app immediately runs a “preflight” check. It counts all the rows in the database to estimate the final file size and how long the backup will take. This helps the user decide if they have enough time and storage space.
File Creation
The user clicks “Create Backup,” launching the system’s file picker. The user chooses where to save the file (e.g., Google Drive or local storage). The app creates a compressed file (GZIP) to minimize storage usage.
Streaming Data
The app reads data from the local database table by table. It converts this data into a text format (JSON) and compresses it on the fly. This happens in chunks so the app doesn’t run out of memory, even with very large databases.
Importing Data
The import process is designed to be safe. It verifies the file contents before making any changes to the local database.File Selection & Validation
The user selects a backup file. Before importing, the app reads just the “Header” of the file. This header contains metadata like the backup version, the date it was created, and the range of dates the data covers.
User Confirmation
The app displays the information found in the header (e.g., “Backup from Jan 1 to Dec 31”). The user must review this and confirm they want to proceed, often acknowledging that this might overwrite existing data.
Data Stored
The backup file contains a comprehensive snapshot of the user’s activity. The following categories of data are included:| Data Category | Description |
|---|---|
| Scroll Sessions | Detailed records of continuous usage sessions (start time, duration). |
| App Events | Raw usage events generated by the operating system. |
| App Metadata | Names, icons, and categories of installed apps. |
| Unlock Sessions | Records of when the device was unlocked and locked. |
| Daily Summaries | Aggregated stats for device usage per day. |
| App Usage | Aggregated stats for specific app usage per day. |
| Insights | Calculated behavioral insights and trends. |
| Notifications | History of notification counts and interactions. |
| Limits & Groups | User-defined usage limits and app groupings. |
| Nudge Stats | Statistics on how often intervention “nudges” were triggered. |
Key Components
Export/Import Sheets
The user interface components that guide the user through the process, displaying progress bars, time estimates, and success/failure messages.
ViewModels
ExportViewModel and ImportViewModel manage the state of the operation. They calculate the percentage complete, handle cancellations, and format the “Time Remaining” for the UI.BackupRepository
The heavy lifter that actually talks to the database and the file system. It handles the complex logic of converting database rows to JSON (and back) and managing file compression.
Preflight System
A logic component that quickly scans the database before an export begins to provide accurate size and time estimates based on previous performance metrics.