package com.miraclegarden.smsmessage.service;

import android.content.Context;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.work.Worker;
import androidx.work.WorkerParameters;

import com.miraclegarden.smsmessage.KeepAliveSettings;

public class MonitoredAppKeepAliveWorker extends Worker {

    private static final String TAG = "MonitoredAppKeepAlive";

    public MonitoredAppKeepAliveWorker(@NonNull Context context, @NonNull WorkerParameters params) {
        super(context, params);
    }

    @NonNull
    @Override
    public Result doWork() {
        if (!KeepAliveSettings.isEnabled(getApplicationContext())) {
            return Result.success();
        }
        if (!NotificationService.isMonitoringActive(getApplicationContext())) {
            Log.d(TAG, "monitoring off, skip");
            return Result.success();
        }
        Log.i(TAG, "periodic keep-alive tick");
        MonitoredAppActivator.activateAll(getApplicationContext());
        return Result.success();
    }
}
