Skip to content

mahmoud-adel-sayed/math-equations-scheduler

Repository files navigation

Math Equations Scheduler

This is a sample app that communicates with a math engine service to perform some arithmetic (addition, subtraction, multiplication, and division between two operands). The math engine service is a background service and is responsible for executing the math equations entered by the user as scheduled tasks and notifying the app about the results.

Important Implementation Details

  1. The default implementation code is written in Java and there is another implementation written in Kotlin, to run the kotlin implementation you have to edit the AndroidManifest file and replace Java class references with their corresponding kotlin classes.
  2. The background service relies on the WorkManager for scheduling tasks.
  3. Delay duration won't be exact if the device enters Doze Mode, WorkManager will batch jobs during maintenance windows to optimize battery usage, if we want the tasks to be executed at exact time, we can use Alarm Manager API and call setExactAndAllowWhileIdle() but this practice is discouraged, as it is not good for battery performance.
  4. The background service will be restarted after being destroyed by the OS or after device boot.
  5. The service does not handle persisting the operation results locally in a database (we could query the workManager and filter for the finished workers and get the outputData which has the results).
  6. App relies on Fused Location Provider API to get location information with High Accuracy and 10 seconds Frequency, that may cause significant battery drain but we could increase the Frequency and lower the accuracy to minimize the battery usage.
  7. The project is simply structured but in a real project we should consider using some well known architectures like (MVVM or MVP).
  8. The app UI is simple and represented by single Activity, but could be split into multiple Fragments.
  9. Unit & Instrumentation Tests code is written in Kotlin and tests java implementation, we could also replicate the tests to test the kotlin implementation.
  10. LocationManagerTest does not test location settings, so currently we have to enable it on the test device before running the tests.
  11. The project is tested only on Android Versions 7.0, 8.0, and 11.0.

Upcoming Integration

  1. Jetpack Compose Integration.
  2. Flutter Module Integration.

Known Issues

  • Memory Leak caused by MathEngineService$LocalBinder.

Analysis and Profiling

  • Battery profiling data files are located in profiling/battery directory, these files are generated by the Batterystats Tool and we can visualize/analyze them using Battery Historian.
  • The captured heap dump file is located in profiling/memory directory, we can import the HPROF (.hprof) file into the Memory Profiler.

Build & Installation Instructions

There are two gradle custom tasks that could be used to clean, build, and install the app, one for the QA flavor and the other for the Prod flavor

  • On Windows, run the following commands in a terminal window: use gradlew cleanBuildInstallQA to install the QA version of the app. use gradlew cleanBuildInstallProd to install the Prod version of the app.
  • On Linux or Mac, run the following commands in a terminal window: use ./gradlew cleanBuildInstallQA to install the QA version of the app. use ./gradlew cleanBuildInstallProd to install the Prod version of the app.

Other Notes

  • The project could be implemented using some Jetpack libraries like (Data Binding, ViewModel, LiveData, etc..).
  • We could use a dependency injection framework like Dagger.

About

This is a sample app that communicates with a math engine service to perform some arithmetic (addition, subtraction, multiplication, and division between two operands).

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published