override fun onReceive()

in health-services/PassiveGoals/app/src/main/java/com/example/passivegoals/StartupReceiver.kt [46:63]


    override fun onReceive(context: Context, intent: Intent) {
        if (intent.action != Intent.ACTION_BOOT_COMPLETED) return

        runBlocking {
            if (repository.passiveGoalsEnabled.first()) {
                // Make sure we have permission.
                val result =
                    context.checkSelfPermission(android.Manifest.permission.ACTIVITY_RECOGNITION)
                if (result == PackageManager.PERMISSION_GRANTED) {
                    scheduleWorker(context)
                } else {
                    // We may have lost the permission somehow. Mark that goal subscriptions are
                    // disabled so the state is consistent the next time the user opens the app UI.
                    repository.setPassiveGoalsEnabled(false)
                }
            }
        }
    }