Synchronize access to WakeLocker

Resolves #72
This commit is contained in:
Trevor Slocum 2020-02-26 17:38:02 -08:00
parent ca8dd83fd4
commit 13f42723a0
3 changed files with 20 additions and 11 deletions

View File

@ -1,3 +1,6 @@
1.5.9:
- Resolve possible crash when waking device
1.5.8:
- Resolve minor sound delay by preloading sounds
- Increase session message maximum length from 160 to 4096

View File

@ -550,7 +550,7 @@ public class MeditationAssistant extends Application {
public void cacheSessionSounds() {
String label;
for (int i = 0;i < 3;i++) {
for (int i = 0; i < 3; i++) {
switch (i) {
case 0:
label = "start";
@ -608,7 +608,7 @@ public class MeditationAssistant extends Application {
Log.d("MeditationAssistant", "Failed to cache sound");
return; // Failed to load sound
}
MediaPlayer mp = mediaPlayers.get(cacheKey);
MediaPlayer mp = mediaPlayers.get(cacheKey);
if (mp.isPlaying()) {
Log.d("MeditationAssistant", "Failed to play sound: already playing");
@ -671,9 +671,9 @@ public class MeditationAssistant extends Application {
String soundPath = prefs.getString("pref_meditation_sound_" + label, "");
if (!soundPath.equals("none")) {
if (soundPath.equals("custom")) {
playSound(0, prefs.getString("pref_meditation_sound_" + label + "_custom", ""), restoreVolume);
playSound(0, prefs.getString("pref_meditation_sound_" + label + "_custom", ""), restoreVolume);
} else {
playSound(MeditationSounds.getMeditationSound(soundPath), "", restoreVolume);
playSound(MeditationSounds.getMeditationSound(soundPath), "", restoreVolume);
}
}
}
@ -2455,16 +2455,22 @@ public class MeditationAssistant extends Application {
return BuildConfig.VERSION_CODE;
}
public synchronized String acquireWakeLock(Boolean fullWakeUp) {
return wakeLocker.acquire(getApplicationContext(), fullWakeUp);
public String acquireWakeLock(Boolean fullWakeUp) {
synchronized (wakeLocker) {
return wakeLocker.acquire(getApplicationContext(), fullWakeUp);
}
}
public synchronized void releaseWakeLock(String wakeLockID) {
wakeLocker.release(wakeLockID);
public void releaseWakeLock(String wakeLockID) {
synchronized (wakeLocker) {
wakeLocker.release(wakeLockID);
}
}
public synchronized void releaseAllWakeLocks() {
wakeLocker.releaseAll();
public void releaseAllWakeLocks() {
synchronized (wakeLocker) {
wakeLocker.releaseAll();
}
}
public enum TrackerName {

View File

@ -43,7 +43,7 @@ Translation is handled [online](https://medinet.rocketnine.space/translate/).
## Download
APKs may be downloaded from [F-Droid](https://f-droid.org/packages/sh.ftp.rocketninelabs.meditationassistant.opensource/) (preferred).
They may also be downloaded from [the developer](http://medinet.rocketnine.space/download/).
They may also be downloaded from [the developer](http://medinet.rocketnine.space/download/?sort=name&order=desc).
## Build