package com.foxx.androidcast;

/*********************************************************************
 * TrayForegroundService.java
 * Created at: Sun 17 May 2026 22:49:49 +0200
 * Updated at: Wed 20 May 2026 15:17:13 +0200 by Anton Afanasyeu <a.afanasieff@gmail.com>
 * Commit: 5d8e82d2e60a21fff3138d2a394ee4e8b4c6dcb8
 * class TrayForegroundService
 * Contributors:
 *    - Anton Afanasyeu <a.afanasieff@gmail.com> (2 commits, 48 lines)
 *    - Cursor Agent (project assistant)
 * Digest: SHA256	5697518674c876a08eb78c08ca151686a079c96d2d3dc238c32666d83b5e88b8
**********************************************************************/
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

import androidx.annotation.Nullable;

/**
 * Holds the persistent tray notification so it cannot be swiped away
 * (non-FGS status notifications are dismissible on Android 13+).
 */
public class TrayForegroundService extends Service {
    @Override
    public void onCreate() {
        super.onCreate();
        CastTrayNotifier.startForegroundTray(this);
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        if (!AppPreferences.isShowTrayIcon(this)) {
            stopSelf();
            return START_NOT_STICKY;
        }
        CastTrayNotifier.startForegroundTray(this);
        return START_STICKY;
    }

    @Override
    public void onDestroy() {
        stopForeground(STOP_FOREGROUND_REMOVE);
        super.onDestroy();
    }

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }
}
