diff --git a/play-services-base/core/src/main/kotlin/org/microg/gms/ui/Utils.kt b/play-services-base/core/src/main/kotlin/org/microg/gms/ui/Utils.kt index d97e233f26..974963b54e 100644 --- a/play-services-base/core/src/main/kotlin/org/microg/gms/ui/Utils.kt +++ b/play-services-base/core/src/main/kotlin/org/microg/gms/ui/Utils.kt @@ -5,6 +5,7 @@ package org.microg.gms.ui +import android.content.ComponentName import android.content.Context import android.content.pm.ApplicationInfo import android.content.pm.PackageManager @@ -45,6 +46,18 @@ fun NavController.navigate(context: Context, @IdRes resId: Int, args: Bundle? = } else null) } +fun Context.hideAppIcon(hide: Boolean) { + val componentName = ComponentName("org.microg.gms.ui", "org.microg.gms.ui.SettingsActivity") + packageManager.setComponentEnabledSetting( + componentName, + when (hide) { + true -> PackageManager.COMPONENT_ENABLED_STATE_DISABLED + false -> PackageManager.COMPONENT_ENABLED_STATE_ENABLED + }, + PackageManager.DONT_KILL_APP + ) +} + val Context.systemAnimationsEnabled: Boolean get() { val duration: Float diff --git a/play-services-base/core/src/main/res/drawable/ic_hide_app_icon.xml b/play-services-base/core/src/main/res/drawable/ic_hide_app_icon.xml new file mode 100644 index 0000000000..87e132f89b --- /dev/null +++ b/play-services-base/core/src/main/res/drawable/ic_hide_app_icon.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/play-services-base/core/src/main/res/drawable/ic_miscellaneous.xml b/play-services-base/core/src/main/res/drawable/ic_miscellaneous.xml new file mode 100644 index 0000000000..d91ac876df --- /dev/null +++ b/play-services-base/core/src/main/res/drawable/ic_miscellaneous.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/play-services-core/src/main/AndroidManifest.xml b/play-services-core/src/main/AndroidManifest.xml index 2ccf69c711..d36bf2eb1e 100644 --- a/play-services-core/src/main/AndroidManifest.xml +++ b/play-services-core/src/main/AndroidManifest.xml @@ -629,7 +629,9 @@ android:roundIcon="@mipmap/ic_app_settings" android:process=":ui" android:targetActivity="org.microg.gms.ui.MainSettingsActivity" - android:taskAffinity="org.microg.gms.settings"> + android:taskAffinity="org.microg.gms.settings" + android:enabled="true" + android:exported="true"> diff --git a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt index 529e10371b..e3d48c81dd 100644 --- a/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt +++ b/play-services-core/src/main/kotlin/org/microg/gms/ui/SettingsFragment.kt @@ -5,20 +5,24 @@ package org.microg.gms.ui +import android.content.ComponentName +import android.content.pm.PackageManager import android.os.Bundle import android.util.Log import androidx.lifecycle.lifecycleScope import androidx.navigation.fragment.findNavController import androidx.preference.Preference import androidx.preference.PreferenceCategory +import androidx.preference.SwitchPreferenceCompat import com.google.android.gms.R +import org.microg.gms.base.core.BuildConfig import org.microg.gms.checkin.CheckinPreferences import org.microg.gms.gcm.GcmDatabase import org.microg.gms.gcm.GcmPrefs -import org.microg.gms.vending.VendingPreferences import org.microg.gms.safetynet.SafetyNetPreferences import org.microg.gms.ui.settings.SettingsProvider import org.microg.gms.ui.settings.getAllSettingsProviders +import org.microg.gms.vending.VendingPreferences import org.microg.tools.ui.ResourceSettingsFragment class SettingsFragment : ResourceSettingsFragment() { @@ -60,6 +64,21 @@ class SettingsFragment : ResourceSettingsFragment() { summary = getString(org.microg.tools.ui.R.string.about_version_str, AboutFragment.getSelfVersion(context)) } + val hideAppIconPref = findPreference("pref_hide_app_icon") ?: return + + if (BuildConfig.IS_HUAWEI_BUILD) { + hideAppIconPref.isVisible = false + } else { + val componentName = ComponentName("org.microg.gms.ui", "org.microg.gms.ui.SettingsActivity") + val state = requireContext().packageManager.getComponentEnabledSetting(componentName) + hideAppIconPref.isChecked = (state == PackageManager.COMPONENT_ENABLED_STATE_ENABLED) + hideAppIconPref.setOnPreferenceChangeListener { _, newValue -> + val enabled = newValue as Boolean + requireActivity().hideAppIcon(enabled) + true + } + } + for (entry in getAllSettingsProviders(requireContext()).flatMap { it.getEntriesStatic(requireContext()) }) { entry.createPreference() } diff --git a/play-services-core/src/main/res/values/strings.xml b/play-services-core/src/main/res/values/strings.xml index bbe47e70a9..35a88de817 100644 --- a/play-services-core/src/main/res/values/strings.xml +++ b/play-services-core/src/main/res/values/strings.xml @@ -169,6 +169,9 @@ This can take a couple of minutes." Ask before registering a new app to receive push notifications Ping interval: %1$s + Miscellaneous + Hide app icon + Hides app icon from the launcher About microG Services Version information and used libraries diff --git a/play-services-core/src/main/res/xml/preferences_hide_app_icon.xml b/play-services-core/src/main/res/xml/preferences_hide_app_icon.xml new file mode 100644 index 0000000000..4692d210fb --- /dev/null +++ b/play-services-core/src/main/res/xml/preferences_hide_app_icon.xml @@ -0,0 +1,28 @@ + + + + + + + \ No newline at end of file diff --git a/play-services-core/src/main/res/xml/preferences_start.xml b/play-services-core/src/main/res/xml/preferences_start.xml index 8f71c018f9..5d96d61572 100644 --- a/play-services-core/src/main/res/xml/preferences_start.xml +++ b/play-services-core/src/main/res/xml/preferences_start.xml @@ -62,12 +62,16 @@ + android:title="@string/service_name_location" /> - + + - + \ No newline at end of file