SafetySec is a native Android application that connects users who want to share their safety status with designated monitors.
The application supports two complementary roles:
- Protected user: activates monitoring, controls shared information and sends emergency alerts;
- Monitor: follows associated users, receives alerts and configures monitoring rules.
SafetySec combines background location tracking, mobile sensors, geofencing, emergency notifications, Firebase services and privacy controls in a single Android application.
Important
SafetySec is an educational prototype. It is not a certified medical device, emergency-response service or substitute for contacting local emergency services.
A protected user can:
- Create and manage an account;
- Activate or stop background monitoring;
- Associate monitors through a temporary code;
- Remove previously associated monitors;
- Trigger a manual panic alert;
- Cancel a false alert using a personal cancellation PIN;
- Share real-time location;
- Share current speed;
- Share battery level;
- Allow or disable emergency video sharing;
- View the list of associated monitors;
- Contact a monitor by phone;
- View alert history;
- Export alert history to CSV;
- Configure a monitoring schedule;
- Receive notifications about monitoring and association changes.
A monitor can:
- Associate with a protected user through a temporary code;
- View all associated protected users;
- Prioritise users currently marked as being in danger;
- View location and status information;
- View current battery level;
- Inspect alert histories;
- View alert statistics;
- Export alerts to CSV;
- Clear alert history;
- Reset a user's danger state;
- Remove an association;
- View emergency video evidence when sharing is permitted;
- Configure individual monitoring rules.
For each protected user, a monitor can configure:
- Fall detection;
- Accident detection;
- Maximum speed;
- Inactivity timeout;
- Geofenced safe zones;
- Entry notifications;
- Exit notifications;
- Days and hours during which monitoring is active.
The protected user can manually activate a panic alert.
Before the alert is confirmed, the interface provides a countdown period during which the user can cancel the alert with a personal PIN.
The foreground monitoring service uses the device accelerometer to identify a possible free-fall event followed by a significant impact.
When the configured conditions are detected, an emergency event is generated and presented to the protected user before being communicated to associated monitors.
Possible accidents are detected by combining:
- A high-impact accelerometer reading;
- The recent speed reported by the location service.
This approach reduces the likelihood of treating an isolated device movement as a vehicle-related accident.
The application tracks the time since meaningful movement was detected.
When the configured inactivity threshold is exceeded, and the device is not charging, the event is added to the user's alert history.
The device speed is obtained from location updates and converted to kilometres per hour.
An alert is created when the configured speed limit is exceeded.
Monitors can create one or more circular safe zones defined by:
- Name;
- Latitude;
- Longitude;
- Radius.
The application can generate events when the protected user enters or exits the configured zones.
The protected user remains in control of the information shared with monitors.
The application supports individual permissions for:
| Permission | Purpose |
|---|---|
| Location | Share current geographical position |
| Speed | Share the speed reported by the device |
| Battery | Share the current battery percentage |
| Emergency video | Allow CameraX evidence recording during an emergency |
Permission changes are recorded and communicated through the application's monitoring flow.
SafetySec includes:
- Firebase email and password authentication;
- Password reset;
- Email-based verification flow;
- Optional multi-factor authentication;
- Biometric login;
- Encrypted local credential storage;
- Session validation;
- User-controlled cancellation PIN;
- Role-based application flows.
Biometric credentials are stored through Android encrypted preferences rather than ordinary plaintext preferences.
The project follows an MVVM-style presentation architecture.
flowchart TD
UI[Jetpack Compose UI]
VM[ViewModels]
FU[Firebase Utilities]
AS[Android Services]
FB[(Firebase)]
DP[Android Platform APIs]
UI --> VM
VM --> FU
VM --> AS
FU --> FB
AS --> FB
AS --> DP
FB --> AUTH[Authentication]
FB --> FS[Cloud Firestore]
FB --> RTDB[Realtime Database]
FB --> STORAGE[Cloud Storage]
FB --> FCM[Cloud Messaging]
DP --> LOCATION[Location Services]
DP --> SENSORS[Accelerometer]
DP --> CAMERA[CameraX]
DP --> BIOMETRIC[Biometric API]
DP --> NOTIFICATIONS[Android Notifications]
The presentation layer is implemented with:
- Jetpack Compose;
- Material 3;
- Navigation Compose;
- Reusable composables;
- Role-specific dashboards;
- StateFlow and Compose state;
- ViewModels.
The ViewModels coordinate:
- Authentication;
- Profile management;
- Protected-user state;
- Monitor state;
- Association workflows;
- Monitoring configuration;
- Alert history;
- CSV exports;
- Video evidence.
The application contains foreground and background components for:
- Location updates;
- Accelerometer monitoring;
- Battery monitoring;
- Boot recovery;
- Firebase Cloud Messaging;
- Monitor notifications;
- Emergency broadcasts.
Firebase is used for:
| Service | Responsibility |
|---|---|
| Authentication | Account creation, login and password recovery |
| Cloud Firestore | Users, associations, settings and alert history |
| Realtime Database | Emergency video transfer |
| Cloud Storage | User and application media |
| Cloud Messaging | Push notifications |
| Analytics | Application analytics |
| Area | Technology |
|---|---|
| Language | Kotlin 2.0.21 |
| UI | Jetpack Compose and Material 3 |
| Architecture | MVVM-style presentation |
| Navigation | Navigation Compose |
| Authentication | Firebase Authentication |
| Cloud persistence | Cloud Firestore |
| Real-time data | Firebase Realtime Database |
| File storage | Firebase Storage |
| Notifications | Firebase Cloud Messaging |
| Location | Fused Location Provider |
| Maps | Google Maps Compose |
| Sensors | Android SensorManager |
| Camera | CameraX |
| Video playback | AndroidX Media3 |
| Biometrics | AndroidX Biometric |
| Local encryption | AndroidX Security Crypto |
| Images | Coil |
| Asynchronous work | Kotlin Coroutines |
| Build system | Gradle Kotlin DSL |
| Property | Value |
|---|---|
| Application ID | pt.isec.safetysec |
| Minimum SDK | 24 |
| Target SDK | 36 |
| Compile SDK | 36 |
| JVM target | 11 |
| Gradle wrapper | 8.13 |
SafetySec requests permissions only for functionality related to monitoring and emergency handling.
| Permission group | Reason |
|---|---|
| Internet | Firebase and cloud communication |
| Notifications | Monitoring and emergency alerts |
| Fine/coarse location | Current location, speed and geofencing |
| Background location | Continued monitoring outside the main screen |
| Activity recognition | Movement-related monitoring |
| Camera | Emergency video recording |
| Microphone | Audio accompanying emergency video |
| Biometric | Biometric login |
| Boot completed | Restore monitoring after device restart |
| Media access | User media and exported content |
Some features may be unavailable when the corresponding permission is denied.
app/src/main/java/pt/isec/safetysec/
├── MainActivity.kt
├── SafetYSecApplication.kt
├── model/
│ ├── data/
│ │ ├── Alert.kt
│ │ ├── AlertState.kt
│ │ ├── GeofenceZone.kt
│ │ ├── Protegido.kt
│ │ ├── SafetySettings.kt
│ │ └── User.kt
│ └── utils/
│ ├── BiometricAuthManager.kt
│ ├── CameraManager.kt
│ ├── CredentialManager.kt
│ ├── CsvExportUtil.kt
│ ├── FAuthUtil.kt
│ ├── FMFAUtil.kt
│ ├── FStorageUtil.kt
│ └── FVideoUtil.kt
├── receivers/
│ ├── BootReceiver.kt
│ ├── EmergencyReceiver.kt
│ └── StopServiceReceiver.kt
├── services/
│ ├── FMessagingService.kt
│ ├── LocationService.kt
│ └── MonitorService.kt
├── ui/
│ ├── composables/
│ ├── navigation/
│ ├── screens/
│ └── theme/
└── viewmodels/
├── FirebaseViewModel.kt
├── MonitorViewModel.kt
├── ProfileViewModel.kt
├── ProtectedDetailsViewModel.kt
└── ProtectedViewModel.kt
Install:
- Android Studio;
- Android SDK 36;
- JDK 17 for running the Android Gradle Plugin;
- An Android device or emulator running API 24 or newer;
- A Firebase project;
- A Google Maps Platform project.
A physical Android device is recommended for testing:
- Accelerometer-based detection;
- Background location;
- Boot recovery;
- Camera recording;
- Biometric authentication.
git clone https://github.com/DaviGama08/safetysec-android.git
cd safetysec-androidCreate a Firebase project and register an Android application with:
pt.isec.safetysec
Enable:
- Email/password authentication;
- Cloud Firestore;
- Realtime Database;
- Cloud Storage;
- Cloud Messaging.
Download the Firebase configuration file and place it at:
app/google-services.json
The file is excluded from version control.
Enable the Maps SDK for Android and create an Android-restricted API key.
Add the key to the local local.properties file:
MAPS_API_KEY=YOUR_ANDROID_MAPS_API_KEYDo not commit this value.
Open the project in Android Studio and select:
File → Sync Project with Gradle Files
Alternatively:
./gradlew tasksOn Linux or macOS:
./gradlew assembleDebugOn Windows:
gradlew.bat assembleDebugThe debug APK will be generated under:
app/build/outputs/apk/debug/
./gradlew testDebugUnitTestRun Android instrumentation tests with a connected device or emulator:
./gradlew connectedDebugAndroidTest./gradlew lintDebug- Create an account;
- Select the protected-user role;
- Configure a cancellation PIN;
- Generate an association code;
- Share the code with a monitor;
- Enable monitoring;
- Configure privacy permissions;
- Test a manual panic alert;
- Review the alert history.
- Create an account;
- Select the monitor role;
- Enter the protected user's association code;
- Open the protected-user dashboard;
- Configure speed, inactivity and geofencing rules;
- View location and status information;
- Review alerts and statistics;
- Export the history to CSV.
The current version is an academic prototype and has the following limitations:
- Emergency detection uses heuristic sensor thresholds;
- Detection results may vary between devices;
- Continuous location monitoring can increase battery usage;
- Cloud behaviour depends on correctly configured Firebase security rules;
- Emergency video transfer is not optimised for large recordings;
- The application has not been certified for medical or emergency use;
- Automated tests currently cover only part of the application.
Future work could include:
- Dependency injection with Hilt;
- Repository interfaces separating ViewModels from Firebase;
- WorkManager for deferrable background operations;
- Firebase App Check;
- More comprehensive unit and UI tests;
- Improved offline support;
- More efficient video upload and streaming;
- Device-specific sensor calibration;
- Accessibility testing;
- End-to-end encrypted emergency evidence;
- A dedicated backend for notification and OTP delivery.
SafetySec was developed collaboratively for the Mobile Architectures course of the Bachelor's Degree in Computer Engineering at the Instituto Superior de Engenharia de Coimbra — ISEC, during the 2025/2026 academic year.
The project focused on native Android development, mobile sensors, cloud services, background execution, privacy controls and responsive interfaces.
This project was developed collaboratively.
Before publishing the repository, add all team members and their respective GitHub profiles to this section.
Developed as a mobile software engineering project.
