Skip to content

Repository files navigation

SafetySec logo

SafetySec Android

Mobile safety monitoring with real-time alerts, location tracking and privacy controls

Android Kotlin Jetpack Compose Firebase Status

Overview

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.

Main Features

Protected User

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.

Monitor

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.

Configurable 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.

Emergency Detection

Panic Alert

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.

Fall Detection

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.

Accident Detection

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.

Inactivity Detection

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.

Speed Monitoring

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.

Geofencing

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.

Privacy Controls

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.

Authentication and Account Security

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.

Architecture

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]
Loading

Presentation Layer

The presentation layer is implemented with:

  • Jetpack Compose;
  • Material 3;
  • Navigation Compose;
  • Reusable composables;
  • Role-specific dashboards;
  • StateFlow and Compose state;
  • ViewModels.

Domain and Application State

The ViewModels coordinate:

  • Authentication;
  • Profile management;
  • Protected-user state;
  • Monitor state;
  • Association workflows;
  • Monitoring configuration;
  • Alert history;
  • CSV exports;
  • Video evidence.

Platform Services

The application contains foreground and background components for:

  • Location updates;
  • Accelerometer monitoring;
  • Battery monitoring;
  • Boot recovery;
  • Firebase Cloud Messaging;
  • Monitor notifications;
  • Emergency broadcasts.

Cloud Services

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

Technology Stack

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

Android Configuration

Property Value
Application ID pt.isec.safetysec
Minimum SDK 24
Target SDK 36
Compile SDK 36
JVM target 11
Gradle wrapper 8.13

Required Permissions

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.

Project Structure

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

Getting Started

Prerequisites

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.

1. Clone the Repository

git clone https://github.com/DaviGama08/safetysec-android.git
cd safetysec-android

2. Configure Firebase

Create 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.

3. Configure Google Maps

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_KEY

Do not commit this value.

4. Synchronise Gradle

Open the project in Android Studio and select:

File → Sync Project with Gradle Files

Alternatively:

./gradlew tasks

5. Build

On Linux or macOS:

./gradlew assembleDebug

On Windows:

gradlew.bat assembleDebug

The debug APK will be generated under:

app/build/outputs/apk/debug/

6. Run Tests

./gradlew testDebugUnitTest

Run Android instrumentation tests with a connected device or emulator:

./gradlew connectedDebugAndroidTest

7. Run Lint

./gradlew lintDebug

Demonstration Workflow

Protected User

  1. Create an account;
  2. Select the protected-user role;
  3. Configure a cancellation PIN;
  4. Generate an association code;
  5. Share the code with a monitor;
  6. Enable monitoring;
  7. Configure privacy permissions;
  8. Test a manual panic alert;
  9. Review the alert history.

Monitor

  1. Create an account;
  2. Select the monitor role;
  3. Enter the protected user's association code;
  4. Open the protected-user dashboard;
  5. Configure speed, inactivity and geofencing rules;
  6. View location and status information;
  7. Review alerts and statistics;
  8. Export the history to CSV.

Limitations

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.

Potential Improvements

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.

Academic Context

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.

Contributors

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.

About

Android safety-monitoring app built with Kotlin and Jetpack Compose, featuring emergency alerts, geofencing, sensor-based detection, Firebase and biometric login.

Topics

Resources

Security policy

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages