Skip to content

Commit

Permalink
additional wakelock checks
Browse files Browse the repository at this point in the history
  • Loading branch information
jvde-github committed Jul 31, 2024
1 parent 20a9fd7 commit 3c2ff2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.jvdegithub.aiscatcher"
minSdk 23
targetSdk 34
versionCode 104
versionName '1.04'
versionCode 105
versionName '1.05'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
Expand Down
43 changes: 24 additions & 19 deletions app/src/main/java/com/jvdegithub/aiscatcher/AisService.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,23 @@ private Notification buildNotification(String msg) {
}


public void acquireLocks()
{
public void acquireLocks() {
PowerManager powerManager = (PowerManager) getSystemService(POWER_SERVICE);
wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE,
"AIS-catcher:WakeLock");
wakeLock.acquire();
if (powerManager != null) {
wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "AIS-catcher:WakeLock");
if (wakeLock != null && !wakeLock.isHeld()) {
wakeLock.acquire();
}
}
}

public void releaseLocks()
{
wakeLock.release();
public void releaseLocks() {
if (wakeLock != null && wakeLock.isHeld()) {
wakeLock.release();
}
}


@Override
public int onStartCommand(Intent intent, int flags, int startId) {

Expand All @@ -118,19 +122,20 @@ public int onStartCommand(Intent intent, int flags, int startId) {
String msg = "Receiver running - " + DeviceManager.getDeviceTypeDescription() + " @ " + AisCatcherJava.getRateDescription();
startForeground(1001, buildNotification(msg));

new Thread(
() -> {
acquireLocks();

AisCatcherJava.Run();
AisCatcherJava.Close();
new Thread(() -> {
try {
acquireLocks();
AisCatcherJava.Run();
AisCatcherJava.Close();
sendBroadcast();

stopForeground(true);
stopSelf();
sendBroadcast();
} finally {
releaseLocks();

releaseLocks();
}).start();
stopForeground(true);
stopSelf();
}
}).start();
} else {
String msg = "Receiver creation failed";
startForeground(1001, buildNotification(msg));
Expand Down

0 comments on commit 3c2ff2d

Please sign in to comment.