[fix] the exercise gets started automatically if the timer finishes with active app.

This commit is contained in:
coderPaddyS 2024-11-15 11:55:30 +01:00
commit e7feedb61e
3 changed files with 13 additions and 11 deletions

View file

@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_SPECIAL_USE" />
<application
android:name=".PFAktivpause"
@ -119,7 +120,8 @@
<service
android:name="org.secuso.aktivpause.service.TimerService"
android:enabled="true"
android:exported="false" />
android:exported="false"
android:foregroundServiceType="specialUse"/>
<service
android:name=".backup.PFABackupService"
android:enabled="true"

View file

@ -12,7 +12,6 @@ import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.IBinder;
import android.preference.PreferenceManager;
import androidx.annotation.NonNull;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.constraintlayout.widget.ConstraintSet;
import androidx.core.app.ActivityCompat;
@ -117,12 +116,9 @@ public class TimerActivity extends BaseActivity implements LoaderManager.LoaderC
boolean isRunning = intent.getBooleanExtra("isRunning", false);
boolean isPaused = intent.getBooleanExtra("isPaused", false);
//if(intent.getBooleanExtra("done" ,false)) {
// TODO: show a dialog here to start the exercise?
//}
//Log.d(TAG, millisUntilDone + "/" + initialDuration + " (" + (isRunning ? "Running" : "") + (isPaused ? "Paused" : "") + (!isRunning && !isPaused ? "Stopped" : "") + ")");
if (millisUntilDone <= 0) {
startActivity(new Intent(TimerActivity.this, ExerciseActivity.class));
}
updateUI(isRunning, isPaused, initialDuration, millisUntilDone);
}
};

View file

@ -9,12 +9,14 @@ import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.ServiceInfo;
import android.os.Binder;
import android.os.CountDownTimer;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.provider.Settings;
import androidx.core.app.NotificationCompat;
import androidx.core.app.ServiceCompat;
import androidx.core.content.ContextCompat;
import org.secuso.aktivpause.R;
@ -33,6 +35,7 @@ import static org.secuso.aktivpause.activities.tutorial.FirstLaunchManager.WORK_
import static org.secuso.aktivpause.receivers.NotificationCancelReceiver.ACTION_NOTIFICATION_CANCELED;
import static org.secuso.aktivpause.receivers.NotificationDeletedReceiver.ACTION_NOTIFICATION_DELETED;
import kotlin.Unit;
/**
* The main timer service. It handles the work timer and sends updates to the notification and the {@link TimerActivity}.
* When the work time is up, an alarm will fire to start the exercises.
@ -139,9 +142,10 @@ public class TimerService extends Service {
public void onCreate() {
super.onCreate();
registerReceiver(timerReceiver, new IntentFilter(TIMER_BROADCAST));
registerReceiver(notificationDeletedReceiver, new IntentFilter(ACTION_NOTIFICATION_DELETED));
registerReceiver(notificationPreferenceChangedReceiver, new IntentFilter(ACTION_NOTIFICATION_CANCELED));
ContextCompat.registerReceiver(this, notificationDeletedReceiver, new IntentFilter(ACTION_NOTIFICATION_DELETED), ContextCompat.RECEIVER_NOT_EXPORTED);
ContextCompat.registerReceiver(this, notificationPreferenceChangedReceiver, new IntentFilter(ACTION_NOTIFICATION_CANCELED), ContextCompat.RECEIVER_NOT_EXPORTED);
}
@Override
@ -363,7 +367,7 @@ public class TimerService extends Service {
private void updateNotification() {
if(isRunning() || isPaused()) {
startForeground(NOTIFICATION_ID, buildNotification());
ServiceCompat.startForeground(this, NOTIFICATION_ID, buildNotification(), ServiceInfo.FOREGROUND_SERVICE_TYPE_SPECIAL_USE);
} else {
stopForeground(true);
}