Skip to content

Commit 24c148f

Browse files
committed
fix #71 : Use activity alias in hide icon in launcher option to prevent gone battery optimization options in HyperOS
1 parent 213929f commit 24c148f

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

play-services-core/src/main/AndroidManifest.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,26 @@
366366
<activity
367367
android:name="org.microg.gms.ui.MainSettingsActivity"
368368
android:configChanges="orientation|screenSize|keyboard|keyboardHidden"
369-
android:enabled="false"
370369
android:exported="true"
371370
android:taskAffinity="org.microg.gms.settings">
372371
<intent-filter>
373372
<action android:name="android.intent.action.MAIN" />
374-
<category android:name="android.intent.category.LAUNCHER" />
373+
<category android:name="android.intent.category.DEFAULT" />
375374
</intent-filter>
376375
</activity>
377376

377+
<!--Hide microG Settings from launcher activity control-->
378+
<activity-alias
379+
android:name="org.microg.gms.ui.SettingsActivityLauncher"
380+
android:enabled="false"
381+
android:exported="true"
382+
android:targetActivity="org.microg.gms.ui.MainSettingsActivity">
383+
<intent-filter>
384+
<action android:name="android.intent.action.MAIN" />
385+
<category android:name="android.intent.category.LAUNCHER" />
386+
</intent-filter>
387+
</activity-alias>
388+
378389
<!-- Allow microG Settings from opening by other applications -->
379390
<activity-alias
380391
android:name="org.microg.gms.ui.SettingsActivity"

play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt

Lines changed: 17 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class SettingsFragment : ResourceSettingsFragment() {
4545
const val PREF_HIDE_LAUNCHER_ICON = "pref_hide_launcher_icon"
4646
const val PREF_GITHUB = "pref_github"
4747

48+
private const val ACTIVITY_LAUNCHER_CONTROL = "org.microg.gms.ui.SettingsActivityLauncher"
4849
private const val PREF_GITHUB_URL = "https://github.com/MorpheApp/MicroG-RE"
4950
const val PREF_IGNORE_BATTERY_OPTIMIZATION = "pref_ignore_battery_optimization"
5051
}
@@ -63,17 +64,18 @@ class SettingsFragment : ResourceSettingsFragment() {
6364
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
6465
super.onCreatePreferences(savedInstanceState, rootKey)
6566
setupStaticPreferenceClickListeners()
67+
updateLauncherIconSwitchState()
68+
updateBatteryOptimizationPreference()
6669
updateAboutSummary()
6770
loadStaticEntries()
68-
updateBatteryOptimizationPreference()
6971
}
7072

7173
override fun onResume() {
7274
super.onResume()
7375
activity?.findViewById<ExtendedFloatingActionButton>(R.id.preference_fab)?.visibility =
7476
View.GONE
7577
updateBatteryOptimizationPreference()
76-
updateHideLauncherIconSwitchState()
78+
updateLauncherIconSwitchState()
7779
updateGcmSummary()
7880
updateCheckinSummary()
7981
updateDynamicEntries()
@@ -97,7 +99,8 @@ class SettingsFragment : ResourceSettingsFragment() {
9799
true
98100
}
99101
findPreference<SwitchPreferenceCompat>(PREF_HIDE_LAUNCHER_ICON)?.setOnPreferenceChangeListener { _, newValue ->
100-
toggleActivityVisibility(MainSettingsActivity::class.java, !(newValue as Boolean))
102+
val hide = newValue as Boolean
103+
toggleLauncherIconVisibility(show = !hide)
101104
true
102105
}
103106
findPreference<Preference>(PREF_GITHUB)?.setOnPreferenceClickListener {
@@ -172,35 +175,24 @@ class SettingsFragment : ResourceSettingsFragment() {
172175
}
173176
}
174177

175-
private fun toggleActivityVisibility(activityClass: Class<*>, showActivity: Boolean) {
176-
val ctx = context ?: return
177-
val component = ComponentName(ctx, activityClass)
178-
val newState = if (showActivity) PackageManager.COMPONENT_ENABLED_STATE_ENABLED
178+
private fun toggleLauncherIconVisibility(show: Boolean) {
179+
val newState = if (show) PackageManager.COMPONENT_ENABLED_STATE_ENABLED
179180
else PackageManager.COMPONENT_ENABLED_STATE_DISABLED
181+
182+
val ctx = context ?: return
183+
val component = ComponentName(ctx, ACTIVITY_LAUNCHER_CONTROL)
180184
ctx.packageManager.setComponentEnabledSetting(
181185
component, newState, PackageManager.DONT_KILL_APP
182186
)
183187
}
184188

185-
private fun updateHideLauncherIconSwitchState() {
186-
val isVisible = isIconActivityVisible(MainSettingsActivity::class.java)
187-
findPreference<SwitchPreferenceCompat>(PREF_HIDE_LAUNCHER_ICON)?.isChecked = !isVisible
188-
}
189+
private fun updateLauncherIconSwitchState() {
190+
val ctx = context ?: return
191+
val component = ComponentName(ctx, ACTIVITY_LAUNCHER_CONTROL)
192+
val state = ctx.packageManager.getComponentEnabledSetting(component)
189193

190-
private fun isIconActivityVisible(activityClass: Class<*>): Boolean {
191-
val ctx = context ?: return false
192-
val component = ComponentName(ctx, activityClass)
193-
return when (ctx.packageManager.getComponentEnabledSetting(component)) {
194-
PackageManager.COMPONENT_ENABLED_STATE_ENABLED -> true
195-
PackageManager.COMPONENT_ENABLED_STATE_DISABLED -> false
196-
else -> {
197-
try {
198-
ctx.packageManager.getActivityInfo(component, 0).enabled
199-
} catch (_: PackageManager.NameNotFoundException) {
200-
false
201-
}
202-
}
203-
}
194+
val isEnabled = state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED || state == PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
195+
findPreference<SwitchPreferenceCompat>(PREF_HIDE_LAUNCHER_ICON)?.isChecked = !isEnabled
204196
}
205197

206198
private fun updateGcmSummary() {
@@ -227,7 +219,6 @@ class SettingsFragment : ResourceSettingsFragment() {
227219
findPreference<Preference>(PREF_CHECKIN)?.setSummary(summaryRes)
228220
}
229221

230-
231222
private fun openGithub() {
232223
try {
233224
startActivity(Intent(Intent.ACTION_VIEW, PREF_GITHUB_URL.toUri()))

0 commit comments

Comments
 (0)