Revert "Stop alarm on screen on/off"

This reverts commit c49d83b3eb.
pull/213/head
M66B 1 year ago
parent c49d83b3eb
commit db496e7254

@ -1,10 +1,7 @@
package eu.faircode.email; package eu.faircode.email;
import android.app.NotificationManager; import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioAttributes; import android.media.AudioAttributes;
import android.media.AudioManager; import android.media.AudioManager;
import android.media.MediaPlayer; import android.media.MediaPlayer;
@ -52,8 +49,6 @@ public class MediaPlayerHelper {
private static void play(Context context, Uri uri, boolean alarm, int duration) throws IOException { private static void play(Context context, Uri uri, boolean alarm, int duration) throws IOException {
Semaphore sem = new Semaphore(0); Semaphore sem = new Semaphore(0);
Log.i("Play uri=" + uri);
AudioAttributes attrs = new AudioAttributes.Builder() AudioAttributes attrs = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(alarm ? AudioAttributes.USAGE_ALARM : AudioAttributes.USAGE_NOTIFICATION) .setUsage(alarm ? AudioAttributes.USAGE_ALARM : AudioAttributes.USAGE_NOTIFICATION)
@ -79,35 +74,15 @@ public class MediaPlayerHelper {
}); });
mediaPlayer.prepareAsync(); mediaPlayer.prepareAsync();
BroadcastReceiver receiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("Received " + intent);
if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF) ||
intent.getAction().equals(Intent.ACTION_SCREEN_ON))
sem.release();
}
};
try { try {
IntentFilter iff = new IntentFilter(); boolean acquired = sem.tryAcquire(duration, TimeUnit.SECONDS);
iff.addAction(Intent.ACTION_SCREEN_OFF); EntityLog.log(context, "Alarm acquired=" + acquired);
iff.addAction(Intent.ACTION_SCREEN_ON); if (!acquired) {
context.registerReceiver(receiver, iff); mediaPlayer.stop();
mediaPlayer.release();
try {
boolean acquired = sem.tryAcquire(duration, TimeUnit.SECONDS);
EntityLog.log(context, "Alarm acquired=" + acquired +
" playing=" + mediaPlayer.isPlaying());
if (!acquired || mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.release();
}
} catch (Throwable ex) {
Log.w(ex);
} }
} finally { } catch (Throwable ex) {
context.unregisterReceiver(receiver); Log.w(ex);
} }
} }

Loading…
Cancel
Save