Skip to content

Commit

Permalink
fix #145
Browse files Browse the repository at this point in the history
  • Loading branch information
wuan committed May 28, 2016
1 parent 4fafd06 commit 261ff76
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ class AlertHandler(
}

fun checkStrikes(strikes: Collection<Strike>?) {
Log.v(Main.LOG_TAG, "AlertHandler.checkStrikes() strikes: ${strikes != null}, location: ${currentLocation != null}")
val alertResult = checkStrikes(strikes, currentLocation)
processResult(alertResult)
}
Expand Down Expand Up @@ -223,7 +224,7 @@ class AlertHandler(
if (alertResult != null) {
handleAlert(alertResult)
} else {
Log.v(Main.LOG_TAG, "AlertHandler.processResult() no result")
Log.v(Main.LOG_TAG, "AlertHandler.processResult() no result ")
broadcastResult(null)
}
}
Expand Down
40 changes: 26 additions & 14 deletions app/src/main/java/org/blitzortung/android/app/AppService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -114,29 +114,41 @@ class AppService protected constructor(private val handler: Handler, private val
Log.i(Main.LOG_TAG, "AppService.onStartCommand() startId: $startId $intent")

if (intent != null && RETRIEVE_DATA_ACTION == intent.action) {
acquireWakeLock()
if (acquireWakeLock()) {
Log.v(Main.LOG_TAG, "AppService.onStartCommand() ${LogUtil.timestamp} with wake lock " + wakeLock)

Log.v(Main.LOG_TAG, "AppService.onStartCommand() ${LogUtil.timestamp} with wake lock " + wakeLock)

disableHandler()
handler.post(this)
disableHandler()
handler.post(this)
} else {
Log.v(Main.LOG_TAG, "AppService.onStartCommand() ${LogUtil.timestamp} skip with held wake lock " + wakeLock)
}
}

return Service.START_STICKY
}

private fun acquireWakeLock() {
Log.v(Main.LOG_TAG, "AppService.acquireWakeLock() before: $wakeLock")
wakeLock.acquire()
private fun acquireWakeLock(): Boolean {
synchronized(wakeLock) {
if (!wakeLock.isHeld) {
Log.v(Main.LOG_TAG, "AppService.acquireWakeLock() before: $wakeLock")
wakeLock.acquire()
return true
} else {
Log.v(Main.LOG_TAG, "AppService.acquireWakeLock() skip")
return false
}
}
}

fun releaseWakeLock() {
if (wakeLock.isHeld) {
try {
wakeLock.release()
Log.v(Main.LOG_TAG, "AppService.releaseWakeLock() after $wakeLock")
} catch (e: Exception) {
Log.v(Main.LOG_TAG, "AppService.releaseWakeLock() failed", e)
synchronized(wakeLock) {
if (wakeLock.isHeld) {
try {
wakeLock.release()
Log.v(Main.LOG_TAG, "AppService.releaseWakeLock() after $wakeLock")
} catch (e: Exception) {
Log.v(Main.LOG_TAG, "AppService.releaseWakeLock() failed", e)
}
}
}
}
Expand Down

0 comments on commit 261ff76

Please sign in to comment.