2 * Copyright 2021,2023 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Cell <https://www.stoutner.com/privacy-cell>.
6 * Privacy Cell is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Cell is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Cell. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacycell.receivers
22 import android.content.BroadcastReceiver
23 import android.content.Context
24 import android.content.Intent
25 import androidx.preference.PreferenceManager
26 import com.stoutner.privacycell.R
27 import com.stoutner.privacycell.services.RealtimeMonitoringService
29 class OnBootCompletedReceiver : BroadcastReceiver() {
30 override fun onReceive(context: Context, intent: Intent) {
31 // Check to make sure the system ACTION_BOOT_COMPLETED initiated the receiver.
32 if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
33 // Get a handle for the shared preferences.
34 val sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context)
36 // Get the realtime monitoring preference.
37 val realtimeMonitoring = sharedPreferences.getBoolean(context.getString(R.string.realtime_monitoring_key), false)
39 // Start the realtime monitoring service if it is enabled.
40 if (realtimeMonitoring) {
41 context.startForegroundService(Intent(context, RealtimeMonitoringService::class.java))