Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Hide app icon option #2462

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Open
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ object SettingsContract {
const val SECURITY_TOKEN = "securityToken"
const val VERSION_INFO = "versionInfo"
const val DEVICE_DATA_VERSION_INFO = "deviceDataVersionInfo"
const val HIDE_APP_ICON = "hideAppIcon"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not belong into the Checkin settings contract. In fact it's not needed at all in SettingsContract or SettingsProvider, see my other comment


val PROJECTION = arrayOf(
ENABLED,
Expand All @@ -43,6 +44,7 @@ object SettingsContract {
SECURITY_TOKEN,
VERSION_INFO,
DEVICE_DATA_VERSION_INFO,
HIDE_APP_ICON,
)
const val PREFERENCES_NAME = "checkin"
const val INITIAL_DIGEST = "1-929a0dca0eee55513280171a8585da7dcd3700f8"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class SettingsProvider : ContentProvider() {
CheckIn.SECURITY_TOKEN -> checkInPrefs.getLong(key, 0)
CheckIn.VERSION_INFO -> checkInPrefs.getString(key, "") ?: ""
CheckIn.DEVICE_DATA_VERSION_INFO -> checkInPrefs.getString(key, "") ?: ""
CheckIn.HIDE_APP_ICON -> getSettingsBoolean(key, false)
else -> throw IllegalArgumentException()
}
}
Expand All @@ -134,6 +135,10 @@ class SettingsProvider : ContentProvider() {
// special case: not saved in checkInPrefs
updateCheckInEnabled(value as Boolean)
}
if (key == CheckIn.HIDE_APP_ICON) {
// special case: not saved in checkInPrefs
updateHideAppIcon(value as Boolean)
}
when (key) {
CheckIn.ANDROID_ID -> editor.putLong(key, value as Long)
CheckIn.DIGEST -> editor.putString(key, value as String?)
Expand All @@ -152,6 +157,12 @@ class SettingsProvider : ContentProvider() {
.apply()
}

private fun updateHideAppIcon(hide: Boolean) {
preferences.edit()
.putBoolean(CheckIn.HIDE_APP_ICON, hide)
.apply()
}

private fun queryGcm(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
when (key) {
Gcm.ENABLE_GCM -> getSettingsBoolean(key, false)
Expand Down
13 changes: 13 additions & 0 deletions play-services-base/core/src/main/kotlin/org/microg/gms/ui/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
19 changes: 19 additions & 0 deletions play-services-base/core/src/main/res/drawable/ic_hide_app_icon.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ SPDX-FileCopyrightText: 2019, The Android Open Source Project
~ SPDX-FileCopyrightText: 2020, microG Project Team
~ SPDX-License-Identifier: Apache-2.0
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="48"
android:viewportHeight="48"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="#FF000000"
android:strokeWidth="1"
android:strokeColor="#FF000000"
android:pathData="M39.6,43.85 L35.9,40.2Q33.4,42 30.4,43Q27.4,44 24,44Q19.75,44 16.1,42.475Q12.45,40.95 9.75,38.25Q7.05,35.55 5.525,31.9Q4,28.25 4,24Q4,20.6 5,17.6Q6,14.6 7.8,12.1L4.1,8.4Q3.65,7.95 3.675,7.35Q3.7,6.75 4.15,6.3Q4.6,5.85 5.225,5.85Q5.85,5.85 6.3,6.3L41.75,41.75Q42.2,42.2 42.2,42.8Q42.2,43.4 41.75,43.85Q41.3,44.3 40.675,44.3Q40.05,44.3 39.6,43.85ZM24,41Q26.75,41 29.2,40.225Q31.65,39.45 33.75,38.05L9.95,14.25Q8.55,16.35 7.775,18.8Q7,21.25 7,24Q7,31.25 11.875,36.125Q16.75,41 24,41ZM40.2,35.9 L38.05,33.75Q39.45,31.65 40.225,29.2Q41,26.75 41,24Q41,16.75 36.125,11.875Q31.25,7 24,7Q21.25,7 18.8,7.775Q16.35,8.55 14.25,9.95L12.1,7.8Q14.6,6 17.6,5Q20.6,4 24,4Q28.2,4 31.85,5.55Q35.5,7.1 38.2,9.8Q40.9,12.5 42.45,16.15Q44,19.8 44,24Q44,27.4 43,30.4Q42,33.4 40.2,35.9ZM26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85Q26.15,21.85 26.15,21.85ZM21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Q21.85,26.15 21.85,26.15Z" />
</vector>
4 changes: 3 additions & 1 deletion play-services-core/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.microg.gms.people.PeopleManager;
import org.microg.gms.profile.Build;
import org.microg.gms.profile.ProfileManager;
import org.microg.gms.ui.UtilsKt;

import java.io.IOException;
import java.security.MessageDigest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,11 @@ object CheckinPreferences {
context.sendOrderedBroadcast(Intent(context, TriggerReceiver::class.java), null)
}
}
@JvmStatic
fun hideAppIcon(context: Context, hide: Boolean) {
SettingsContract.setSettings(context, CheckIn.getContentUri(context)) {
put(CheckIn.HIDE_APP_ICON, hide)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ 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.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.settings.SettingsContract
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() {
Expand Down Expand Up @@ -60,6 +62,14 @@ class SettingsFragment : ResourceSettingsFragment() {
summary = getString(org.microg.tools.ui.R.string.about_version_str, AboutFragment.getSelfVersion(context))
}

findPreference<SwitchPreferenceCompat>(SettingsContract.CheckIn.HIDE_APP_ICON)!!.apply {
setOnPreferenceChangeListener { _, newValue ->
requireActivity().hideAppIcon(newValue as Boolean)
true
}

}

for (entry in getAllSettingsProviders(requireContext()).flatMap { it.getEntriesStatic(requireContext()) }) {
entry.createPreference()
}
Expand Down
2 changes: 2 additions & 0 deletions play-services-core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ This can take a couple of minutes."</string>
<string name="pref_gcm_confirm_new_apps_summary">Ask before registering a new app to receive push notifications</string>
<string name="pref_gcm_ping_interval">Ping interval: <xliff:g example="10 minutes">%1$s</xliff:g></string>

<string name="pref_hide_app_icon_title">Hide app icon</string>
<string name="pref_hide_app_icon_summary">Hides app icon from the launcher</string>
<string name="pref_about_title">About microG Services</string>
<string name="pref_about_summary">Version information and used libraries</string>

Expand Down
8 changes: 7 additions & 1 deletion play-services-core/src/main/res/xml/preferences_start.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,15 @@
android:title="@string/service_name_location"/>
</PreferenceCategory>
<PreferenceCategory android:layout="@layout/preference_category_no_label" android:key="prefcat_footer">
<SwitchPreferenceCompat
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this setting is so important that it deserves a prime location at the top level settings dialog. I suggest to create a new section for these kind of things, although I don't know how to name it or what else would belong there.

Copy link
Member

@ale5000-git ale5000-git Oct 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mar-v-in
Some ideas:

  1. Other settings
  2. Minor settings
  3. Trivial settings
  4. UI settings

android:defaultValue="false"
android:icon="@drawable/ic_hide_app_icon"
android:key="pref_hide_app_icon"
android:summary="@string/pref_hide_app_icon_summary"
android:title="@string/pref_hide_app_icon_title" />
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Preferences should not be directly modified from the :ui process as shared preferences are not safe for multi-process use. That's why we generally use the SettingsProvider to store settings.

However, in this case, the settings provider is not needed, as the ground truth of the component enabled state is in the PackageManager. With your code, if someone enables or disables the component without using this setting (e.g. by directly invoking pm disable via adb), the setting would no longer match the actual live state.

I suggest you make the setting non-persistent (by settings android:persistent="false") and configure it from code by taking the value from getComponentEnabledSetting when realizing the setting.

<Preference
android:icon="@drawable/ic_info_outline"
android:key="pref_about"
android:title="@string/pref_about_title" />
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>