<commit_before>package com.jereksel.libresubstratum.domain

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.os.Build.VERSION.RELEASE
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.N
import android.os.Build.VERSION_CODES.N_MR1
import android.provider.Settings
import com.jereksel.libresubstratum.domain.overlayService.nougat.WDUCommitsOverlayService
import com.jereksel.libresubstratum.domain.overlayService.nougat.WODUCommitsOverlayService
import com.jereksel.libresubstratum.extensions.getLogger

object OverlayServiceFactory {

    val log = getLogger()

    fun getOverlayService(context: Context): OverlayService {

        val supportedAndroidVersions = listOf(N, N_MR1)

        if (!supportedAndroidVersions.contains(SDK_INT)) {
            log.error("Not supported android version: {} {}", SDK_INT, RELEASE)
            return InvalidOverlayService("This app works only on Android Nougat")
        }

        try {
            Settings.Secure.getInt(context.contentResolver, "force_authorize_substratum_packages")
            log.debug("force_authorize_substratum_packages supported")
        } catch (e: Settings.SettingNotFoundException) {
            log.error("force_authorize_substratum_packages not supported", e)
            return InvalidOverlayService("Your ROM is too old to support this app (3-rd party apps in Interfacer are not supported)")
        }

        if (isNewInterfacerPermissionAvailable(context)) {
            log.debug("DU commits available")
            return WDUCommitsOverlayService(context)
        } else {
            log.debug("DU commits not available")
            return WODUCommitsOverlayService(context)
        }

    }

    private fun isNewInterfacerPermissionAvailable(context: Context): Boolean {

        try {

            val info = context.packageManager.getPackageInfo("projekt.interfacer", PackageManager.GET_PERMISSIONS)

            return info.permissions.firstOrNull { it.name == "projekt.interfacer.permission.ACCESS_SERVICE_INNER" } != null

        } catch (e: Exception) {
            return false
        }

    }


}<commit_msg>Check if Interfacer is installed<commit_after>package com.jereksel.libresubstratum.domain

import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
import android.os.Build.VERSION.RELEASE
import android.os.Build.VERSION.SDK_INT
import android.os.Build.VERSION_CODES.N
import android.os.Build.VERSION_CODES.N_MR1
import android.provider.Settings
import com.jereksel.libresubstratum.domain.overlayService.nougat.WDUCommitsOverlayService
import com.jereksel.libresubstratum.domain.overlayService.nougat.WODUCommitsOverlayService
import com.jereksel.libresubstratum.extensions.getLogger

object OverlayServiceFactory {

    val log = getLogger()

    fun getOverlayService(context: Context): OverlayService {

        val supportedAndroidVersions = listOf(N, N_MR1)

        if (!supportedAndroidVersions.contains(SDK_INT)) {
            log.error("Not supported android version: {} {}", SDK_INT, RELEASE)
            return InvalidOverlayService("This app works only on Android Nougat")
        }

        try {
            context.packageManager.getApplicationInfo("projekt.interfacer", 0)
        } catch (e: PackageManager.NameNotFoundException) {
            log.error("Interfacer is not installed")
            return InvalidOverlayService("Interfacer is not installed. Are you using Substratum compatible ROM?")
        }

        try {
            Settings.Secure.getInt(context.contentResolver, "force_authorize_substratum_packages")
            log.debug("force_authorize_substratum_packages supported")
        } catch (e: Settings.SettingNotFoundException) {
            log.error("force_authorize_substratum_packages not supported")
            return InvalidOverlayService("Your ROM is too old to support this app (3-rd party apps in Interfacer are not supported)")
        }

        if (isNewInterfacerPermissionAvailable(context)) {
            log.debug("DU commits available")
            return WDUCommitsOverlayService(context)
        } else {
            log.debug("DU commits not available")
            return WODUCommitsOverlayService(context)
        }

    }

    private fun isNewInterfacerPermissionAvailable(context: Context): Boolean {

        try {

            val info = context.packageManager.getPackageInfo("projekt.interfacer", PackageManager.GET_PERMISSIONS)

            return info.permissions.firstOrNull { it.name == "projekt.interfacer.permission.ACCESS_SERVICE_INNER" } != null

        } catch (e: Exception) {
            return false
        }

    }


}
{'fraction_non_alphanumeric': 0.08120109959822372, 'fraction_numerical': 0.00148022837809262, 'mean_word_length': 3.3235831809872027, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3959866', 'n_tokens_mistral': 1334, 'n_tokens_neox': 1292, 'n_words': 258}