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

Commit

Permalink
Refactor: Updated the set default launcher script.
Browse files Browse the repository at this point in the history
  • Loading branch information
CreativeCodeCat committed Aug 23, 2024
1 parent 471d361 commit e409040
Showing 1 changed file with 0 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import android.content.Context
import android.content.DialogInterface
import android.content.Intent
import android.content.pm.LauncherApps
import android.content.pm.PackageManager
import android.content.res.Resources
import android.net.Uri
import android.os.Build
Expand Down Expand Up @@ -230,39 +229,6 @@ fun getDefaultLauncherPackage(context: Context): String {
}

fun resetDefaultLauncher(context: Context) {
val manufacturer = Build.MANUFACTURER.lowercase()
when (manufacturer) {
"google", "essential" -> runningStockAndroid(context)
else -> notRunningStockAndroid(context)
}
}

private fun runningStockAndroid(context: Context) {
try {
val packageManager = context.packageManager
val componentName = ComponentName(context, FakeHomeActivity::class.java)

packageManager.setComponentEnabledSetting(
componentName,
PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
PackageManager.DONT_KILL_APP
)

val selector = Intent(Intent.ACTION_MAIN)
selector.addCategory(Intent.CATEGORY_HOME)
context.startActivity(selector)

packageManager.setComponentEnabledSetting(
componentName,
PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
PackageManager.DONT_KILL_APP
)
} catch (e: Exception) {
e.printStackTrace()
}
}

private fun notRunningStockAndroid(context: Context) {
try {
val intent = Intent("android.settings.HOME_SETTINGS")
context.startActivity(intent)
Expand Down

0 comments on commit e409040

Please sign in to comment.