@@ -42,31 +42,47 @@ class AppHelper @Inject constructor() {
42
42
try {
43
43
val packageManager = context.packageManager
44
44
val componentName = ComponentName (context, FakeHomeActivity ::class .java)
45
+
45
46
packageManager.setComponentEnabledSetting(
46
47
componentName,
47
48
PackageManager .COMPONENT_ENABLED_STATE_ENABLED ,
48
49
PackageManager .DONT_KILL_APP
49
50
)
51
+
50
52
val selector = Intent (Intent .ACTION_MAIN )
51
53
selector.addCategory(Intent .CATEGORY_HOME )
52
54
context.startActivity(selector)
55
+
53
56
packageManager.setComponentEnabledSetting(
54
57
componentName,
55
58
PackageManager .COMPONENT_ENABLED_STATE_DISABLED ,
56
59
PackageManager .DONT_KILL_APP
57
60
)
58
61
} catch (e: Exception ) {
59
62
e.printStackTrace()
63
+ // Additional step to open the launcher settings if the first method fails
64
+ try {
65
+ val intent = Intent (" android.settings.HOME_SETTINGS" )
66
+ context.startActivity(intent)
67
+ } catch (e: ActivityNotFoundException ) {
68
+ // Fallback to general settings if specific launcher settings are not found
69
+ try {
70
+ val intent = Intent (Settings .ACTION_SETTINGS )
71
+ context.startActivity(intent)
72
+ } catch (e: Exception ) {
73
+ e.printStackTrace()
74
+ }
75
+ }
60
76
}
61
77
}
62
78
79
+
63
80
@SuppressLint(" WrongConstant" , " PrivateApi" )
64
81
fun expandNotificationDrawer (context : Context ) {
65
82
try {
66
- val statusBarService = context.getSystemService(Constants .NOTIFICATION_SERVICE )
67
- val statusBarManager = Class .forName(Constants .NOTIFICATION_MANAGER )
68
- val method = statusBarManager.getMethod(Constants .NOTIFICATION_METHOD )
69
- method.invoke(statusBarService)
83
+ Class .forName(Constants .NOTIFICATION_MANAGER )
84
+ .getMethod(Constants .NOTIFICATION_METHOD )
85
+ .invoke(context.getSystemService(Constants .NOTIFICATION_SERVICE ))
70
86
} catch (exception: Exception ) {
71
87
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
72
88
MyAccessibilityService .runAccessibilityMode(context)
@@ -79,10 +95,9 @@ class AppHelper @Inject constructor() {
79
95
@SuppressLint(" WrongConstant" , " PrivateApi" )
80
96
private fun expandQuickSettings (context : Context ) {
81
97
try {
82
- val statusBarService = context.getSystemService(Constants .QUICKSETTINGS_SERVICE )
83
- val statusBarManager = Class .forName(Constants .QUICKSETTINGS_MANAGER )
84
- val method = statusBarManager.getMethod(Constants .QUICKSETTINGS_METHOD )
85
- method.invoke(statusBarService)
98
+ Class .forName(Constants .QUICKSETTINGS_MANAGER )
99
+ .getMethod(Constants .QUICKSETTINGS_METHOD )
100
+ .invoke(context.getSystemService(Constants .QUICKSETTINGS_SERVICE ))
86
101
} catch (exception: Exception ) {
87
102
if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .P ) {
88
103
MyAccessibilityService .runAccessibilityMode(context)
0 commit comments