Skip to content

Instantly share code, notes, and snippets.

@pratul
pratul / android-versionname-git-describe.gradle
Created February 9, 2017 17:46
A gradle method to generate the versionName for an Android app, using git describe.
def getVersionName = { ->
try {
def stdout = new ByteArrayOutputStream()
exec {
commandLine 'git', 'describe', '--dirty'
standardOutput = stdout
}
return stdout.toString().trim()
}
catch (ignored) {
courtesy: cmpxchg aka tim murray
suspend is the big hammer. in suspend, you turn off all peripherals, turn off the CPUs entirely,
put the DRAM into self-refresh. power consumption is very low. if you've ever put a tablet on
a table and come back a month later to find that it's still on, that's because it's been suspend
99.9% of the time, and it's drawing a tiny amount the whole time.
problem with suspend is that it takes a nontrivial amount of time to enter/exit, so you can't
do it when somebody has to interact with the phone soon. on Android, suspend never happens while
the screen is on. if you ever wondered what a wakelock actually does, it prevents suspend. that's it.