Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
Enable InstallActivity only in root mode
Browse files Browse the repository at this point in the history
  • Loading branch information
SanmerDev committed Feb 29, 2024
1 parent 2ba7f37 commit 39c3fe4
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/src/main/kotlin/com/sanmer/mrepo/ui/activity/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.sanmer.mrepo.ui.activity

import android.content.ComponentName
import android.content.pm.PackageManager
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
Expand Down Expand Up @@ -61,6 +63,7 @@ class MainActivity : ComponentActivity() {

ProviderCompat.init(userPreferences!!.workingMode)
NetworkUtils.setEnableDoh(userPreferences!!.useDoh)
setInstallActivityEnabled(userPreferences!!.isRoot)
}

CompositionLocalProvider(
Expand Down Expand Up @@ -92,4 +95,22 @@ class MainActivity : ComponentActivity() {
MediaStoreUtils.PermissionState()
}
}

private fun setInstallActivityEnabled(enable: Boolean) {
val component = ComponentName(
this, InstallActivity::class.java
)

val state = if (enable) {
PackageManager.COMPONENT_ENABLED_STATE_ENABLED
} else {
PackageManager.COMPONENT_ENABLED_STATE_DISABLED
}

packageManager.setComponentEnabledSetting(
component,
state,
PackageManager.DONT_KILL_APP
)
}
}

0 comments on commit 39c3fe4

Please sign in to comment.