Skip to content

Commit

Permalink
refactor: Cleaned up a few functions
Browse files Browse the repository at this point in the history
  • Loading branch information
CreativeCodeCat committed May 23, 2024
1 parent bfc2d4f commit 355096c
Showing 1 changed file with 23 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,47 @@ class AppHelper @Inject constructor() {
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()
// Additional step to open the launcher settings if the first method fails
try {
val intent = Intent("android.settings.HOME_SETTINGS")
context.startActivity(intent)
} catch (e: ActivityNotFoundException) {
// Fallback to general settings if specific launcher settings are not found
try {
val intent = Intent(Settings.ACTION_SETTINGS)
context.startActivity(intent)
} catch (e: Exception) {
e.printStackTrace()
}
}
}
}


@SuppressLint("WrongConstant", "PrivateApi")
fun expandNotificationDrawer(context: Context) {
try {
val statusBarService = context.getSystemService(Constants.NOTIFICATION_SERVICE)
val statusBarManager = Class.forName(Constants.NOTIFICATION_MANAGER)
val method = statusBarManager.getMethod(Constants.NOTIFICATION_METHOD)
method.invoke(statusBarService)
Class.forName(Constants.NOTIFICATION_MANAGER)
.getMethod(Constants.NOTIFICATION_METHOD)
.invoke(context.getSystemService(Constants.NOTIFICATION_SERVICE))
} catch (exception: Exception) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
MyAccessibilityService.runAccessibilityMode(context)
Expand All @@ -79,10 +95,9 @@ class AppHelper @Inject constructor() {
@SuppressLint("WrongConstant", "PrivateApi")
private fun expandQuickSettings(context: Context) {
try {
val statusBarService = context.getSystemService(Constants.QUICKSETTINGS_SERVICE)
val statusBarManager = Class.forName(Constants.QUICKSETTINGS_MANAGER)
val method = statusBarManager.getMethod(Constants.QUICKSETTINGS_METHOD)
method.invoke(statusBarService)
Class.forName(Constants.QUICKSETTINGS_MANAGER)
.getMethod(Constants.QUICKSETTINGS_METHOD)
.invoke(context.getSystemService(Constants.QUICKSETTINGS_SERVICE))
} catch (exception: Exception) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
MyAccessibilityService.runAccessibilityMode(context)
Expand Down

0 comments on commit 355096c

Please sign in to comment.