Android-Native-Root-Detector

repository·main·Indexed 20 days ago

https://github.com/reveny/android-native-root-detector

A library for detecting root access on Android devices using native C++ methods via JNI. It provides the Native.getDetections() function to perform checks and includes components like AppSettingsDataStore, AppSettingsRepository, and SettingsViewModel for managing application configurations and experimental detection flags.

Tokens
1K
Snippets
1
Records
6
Agent score
80%

What's inside android-native-root-detector

  1. Use SettingsViewModel to manage application settings

    main

    The SettingsViewModel is a Hilt-injected ViewModel used to update application-wide settings via the AppSettingsRepository. All setter methods are asynchronous and execute within the viewModelScope.

    Available methods for updating settings include:

    • setLanguage(language: Language): Updates the application language.
    • setThemeColor(themeColor: ThemeColor): Updates the selected theme color.
    • setDynamicColor(dynamicColor: Boolean): Toggles dynamic color support.
    • setDarkTheme(mode: Boolean): Toggles dark theme mode.
    • setContrastMode(contrast: Boolean): Toggles high contrast mode.
    • setDisableTelemetry(disableTelemetry: Boolean): Toggles telemetry collection.
    • setEnableExperimentalDetections(enableExperimentalDetections: Boolean): Toggles experimental root detection features.
  2. Manage application settings with AppSettingsRepository

    main

    The AppSettingsRepository provides a high-level API to access and modify application configuration settings, such as language, theme, and telemetry preferences. It wraps an underlying AppSettingsDataStore to persist these settings.

    Accessing Settings

    You can observe the current application settings by accessing the data property, which returns a stream of the current configuration.

    Modifying Settings

    Most modification methods are suspend functions and should be called from a coroutine scope. Available settings include:

    • setLanguage(value: Language)
    • setThemeColor(value: ThemeColor)
    • setDynamicColor(value: Boolean)
    • setDarkTheme(value: Boolean)
    • setContrastMode(value: Boolean)
    • setDisableTelemetry(value: Boolean)
    • setEnableExperimentalDetections(value: Boolean)

    Syncing Dark Theme with System Settings

    You can use updateDarkThemeBasedOnSystem(context: Context) to automatically synchronize the application's dark theme preference with the Android system's current UI mode.

  3. Perform root detection using Native.getDetections()

    main
    The Native class provides a bridge to the native C++ detection engine via JNI. To perform root detection, call the getDetections external function. This function requires the application Context, the PackageManager, and a boolean flag enableExperimental to toggle experimental detection methods. It returns an Array<DetectionData> containing the results of the various root detection checks performed by the native library.
  4. Manage application settings with AppSettingsDataStore

    main

    The AppSettingsDataStore class provides a high-level API for reading and updating application settings using Jetpack DataStore. It exposes the current settings as a Flow<AppSettings> and provides individual suspend functions to update specific configuration values.

    Reading Settings

    Access the current settings stream via the data property:

    val settingsFlow: Flow<AppSettings> = appSettingsDataStore.data

    Updating Settings

    Use the following suspend functions to modify settings. These operations are atomic and should be called from a coroutine scope:

    MethodParameterDescription
    setLanguage(value: Language)LanguageSets the application language
    setThemeColor(value: ThemeColor)ThemeColorSets the theme color
    setDynamicColor(value: Boolean)BooleanEnables/disables dynamic color support
    setDarkTheme(value: Boolean)BooleanEnables/disables dark theme
    setContrastMode(value: Boolean)BooleanEnables/disables high contrast mode
    setDisableTelemetry(value: Boolean)BooleanEnables/disables telemetry collection
    setEnableExperimentalDetections(value: Boolean)BooleanEnables/disables experimental root detection features
  5. Native.getDetections() signature

    main

    The getDetections function is an external native method that executes the core detection logic.

    Parameters:

    • context: Context: The Android application context.
    • pm: PackageManager: The system package manager.
    • enableExperimental: Boolean: A flag to enable or disable experimental detection techniques.

    Returns:

    • Array<DetectionData>: An array of detection results.