Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Enforcing Green Code With Android Lint


Published on

Nowadays, energy efficiency is recognized as a core quality attribute of applications (apps) running on Android-powered devices constrained by their battery. Indeed, energy hogging apps are a liability to both the end-user and software developer. Yet, there are very few tools available to help developers increase the quality of their native code by ridding it of energy-related bugs. Android Studio is the official IDE for millions of developers worldwide and there's no better place to enforce green coding rules in everyday projects. Indeed, Android Studio provides a code scanning tool called Android lint that can be extended with lacking green checks in order to foster the design of more eco-responsible apps.

Published in: Software
  • Be the first to comment

  • Be the first to like this

Enforcing Green Code With Android Lint

  1. 1. Enforcing Green Code With Android Lint Olivier Le Goaer @ A-MOBILE 2020 - September 21, 2020 - Melbourne, Australia -
  2. 2. Context of Work ✗ Green Software – Beyond fast-paced hardware advances, foster development of energy-efficient software ✗ Mobile Software – Battery-powered device non-connected to permanent power (e.g. SmartPhone) – Overconsumption of mobile apps implies more frequent charges and ultimately battery depletion
  3. 3. Greenness is a matter of quality ✗ Poorly designed apps may drain the battery excessively ✗ Greenness is a quality attribute that may be statically checked by a lint tool ✗ Ultimately, the quality level reached by apps should be rewarded by a green badge/score
  4. 4. Green Bugs within Android apps ✗ Green bugs are symptoms that something may be wrong with the app's battery usage ✗ Android-specific green bugs are not classic code smells merely applied to Android – Refactoring of “God Class”, “God Method”, and “Feature Envy” is even counterproductive* * An Empirical Study on the Impact of Android Code Smells on Resource Usage, Oliveira et al., SEKE 2018
  5. 5. Catalog of Android Green Bugs ✗ Define a catalog of smells that have an actual impact on power consumption ✗ Energy-related smells reside in an Android project, not only in source code (.java/.kt) ✗ 13 green bugs were described in the paper. The latest catalog describes 26 bugs –
  6. 6. The 13 Android Green Bugs Name Severity Scope Everlasting Service ERROR Source code Sensor Leak ERROR Source code Internet In The Loop ERROR Source code Dark UI WARNING Manifest, Style, Drawable Sensor Coalesce WARNING Source code Durable Wake Lock WARNING Source code Uncompressed Data Transmission WARNING Source code Rigid Alarm WARNING Source code, Gradle Dirty Boot WARNING Source code, Manifest Keep Screen On INFORMATIONAL Source code, Layout Keep CPU On INFORMATIONAL Source code, Manifest Battery-Efficient Location INFORMATIONAL Source code, Gradle Bluetooth Low-Energy INFORMATIONAL Source code
  7. 7. Keep Screen On (example) « To avoid draining the battery, an Android device that is left idle quickly falls asleep. However, there are times when an application needs to wake up the screen and keep it awake to complete some work. » [Doc]  Programmatically (Java) Declaratively (xml)
  8. 8. Android Lint Framework ✗ Extensible Framework : add custom checks to the 350 built-in checks ✗ Jetbrain UAST = AST unifying Java and Kotlin ✗ Complete scan of an Android project (code, ressources, manifest, …) ✗ Both on-the-fly and manual inspections within Android Studio IDE
  9. 9. Greenness is not performance ✗ Power-saving may be a side effect of performance, but not necessarily so ✗ Greenness merits its full-fledged category NEW
  10. 10. Implementation details ✗ Green Bugs are issues in a registry ✗ Issues are reported by detectors ✗ A detector implements one or more scanners ✗ Visitor-style programming (in Java or Kotlin) ✗ Utils avoid doing things « the hard way »
  11. 11. Live demo: Dark UI
  12. 12. Research: what's next? ✗ Discovering unexplainable green bugs – As opposed to the current green bugs that are explained by the Android Reference Documentation ✗ Green bugs assessment at large scale – Runtime testbed and automated UI test for millions of apps is still a scientific challenge
  13. 13. Tooling: what's next? Green Linter Web-based Backend (Green Quality Gates) + Gamification Score 3/5
  14. 14. Summary ✗ Green coding habits should be rewarded ✗ Real-life Android development is predominantly native, either in Java or Kotlin, with Android Studio IDE ✗ Static analysis applies to and scales for any app under development ✗ Android developers trust Android Lint
  15. 15. Thank you for your attention - Questions? -