Android: Login and offline mode
Technical specification for authentication and offline operation of the PestControlOS Android app.
Firebase Authentication
- Provider: Email/password sign-in via
FirebaseAuth.signInWithEmailAndPassword(). User display name is derived from email and passed to Main Activity. - Session: Managed by Firebase Auth SDK; no custom session store. UID and ID token used for Firestore/Storage rules and Cloud Function context.
- Identity: User identity is resolved from
request.auth.uidin Firestore rules; app may read from ausersor staff collection keyed by UID or user ID for display name and role.
Offline login and default offline report creation
- Entry point: "Offline login" on the login screen; no Firebase credentials required.
- Identity: User enters as "Offline User". No Firestore/Storage access; all data is local or unavailable.
- UI restrictions: Main menu shows only Create Report, View Reports, and Logout. Notifications, Work View, Contracts, Jobs, and other Firebase-dependent features are hidden. In View Reports, Stored Reports (Firebase Storage) is hidden.
- Offline report creation: Offline users have full access to default offline report creation and offline custom templates. Report selection offers "Custom Report (PDF Template)" and "Create Custom Report"; PDF Template Settings is available; user can choose PestControlOS template or My Template and create as many custom templates as needed, all stored locally and reusable.
Custom templates and custom report: all users
- All users (authenticated and offline) have the same custom template and custom report capability. There is no distinction: both offline and logged-in users can use PDF Template Settings, create and name custom templates, and reuse them.
- Create as many custom templates as needed: Users can save multiple named templates (main header, logo, watermark, header blocks). Each saved template is stored locally (
PdfTemplateStorage: SharedPreferences + JSON; logo/watermark files incontext.getFilesDir()/pdf_template/). View Templates lists all saved templates; Use opens Create Report with that template; Delete removes it with confirmation. Templates can be reused for any new report. - Default offline report creation: When offline, the app supports full report creation using either the default (PestControlOS) template or any saved custom template. No server required; all generation and storage are local until the user later uploads (when logged in) or shares the file.
- Logged-in users: Same access to custom templates and custom report creation as offline users. Logged-in users can create and reuse custom templates, use PestControlOS or My Template, and optionally upload the resulting report to Firebase after save.
Implementation notes
- Offline mode is a distinct code path: no writes to Firestore/Storage; no reads from Firestore. Local state (e.g. SharedPreferences,
PdfTemplateStorage) is used for template settings and saved templates for both offline and authenticated users. - Role and user-ID checks (e.g. 001, 002, 003, 004) apply only when logged in for Firebase-dependent features (Work View, Contracts, Jobs, etc.); custom templates and report creation are available to all users regardless of role.