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 Miscellaneous setting and Hide app icon option #2462

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
ILoveOpenSourceApplications marked this conversation as resolved.
Show resolved Hide resolved

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, true)
ILoveOpenSourceApplications marked this conversation as resolved.
Show resolved Hide resolved
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(enabled: Boolean) {
preferences.edit()
.putBoolean(CheckIn.HIDE_APP_ICON, enabled)
.apply()
}

private fun queryGcm(p: Array<out String>): Cursor = MatrixCursor(p).addRow(p) { key ->
when (key) {
Gcm.ENABLE_GCM -> getSettingsBoolean(key, false)
Expand Down
12 changes: 12 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,17 @@ fun NavController.navigate(context: Context, @IdRes resId: Int, args: Bundle? =
} else null)
}

fun Context.hideAppIcon(hide: Boolean) {
packageManager.setComponentEnabledSetting(
ComponentName.createRelative(this, "org.microg.gms.ui.SettingsActivity"),
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
17 changes: 17 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,17 @@
<?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/colorAccent">
<path
android:fillColor="#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 @@ -600,7 +600,9 @@
android:label="@string/gms_settings_name"
android:process=":ui"
android:roundIcon="@mipmap/ic_app_settings"
android:taskAffinity="org.microg.gms.settings">
android:taskAffinity="org.microg.gms.settings"
android:enabled="false"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<data
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 All @@ -75,6 +76,7 @@
import static android.view.View.VISIBLE;
import static android.view.inputmethod.InputMethodManager.SHOW_IMPLICIT;
import static org.microg.gms.auth.AuthPrefs.isAuthVisible;
import static org.microg.gms.checkin.CheckinPreferences.hideAppIcon;
ILoveOpenSourceApplications marked this conversation as resolved.
Show resolved Hide resolved
import static org.microg.gms.common.Constants.GMS_PACKAGE_NAME;
import static org.microg.gms.common.Constants.GMS_VERSION_CODE;

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, enabled: Boolean) {
SettingsContract.setSettings(context, CheckIn.getContentUri(context)) {
put(CheckIn.HIDE_APP_ICON, enabled)
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ 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 androidx.preference.SwitchPreferenceCompat
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 @@ -171,6 +171,8 @@ This can take a couple of minutes."</string>

<string name="pref_about_title">About microG Services</string>
<string name="pref_about_summary">Version information and used libraries</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="gcm_app_error_unregistering">Error unregistering</string>
<string name="gcm_app_not_installed_anymore">No longer installed</string>
Expand Down
5 changes: 5 additions & 0 deletions play-services-core/src/main/res/xml/preferences_start.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
android:title="@string/service_name_location"/>
</PreferenceCategory>
<PreferenceCategory android:layout="@layout/preference_category_no_label" android:key="prefcat_footer">
<SwitchPreferenceCompat
ILoveOpenSourceApplications marked this conversation as resolved.
Show resolved Hide resolved
android:key="hideAppIcon"
ILoveOpenSourceApplications marked this conversation as resolved.
Show resolved Hide resolved
android:title="@string/pref_hide_app_icon"
android:icon="@drawable/ic_hide_app_icon"
android:defaultValue="false"/>
<Preference
android:icon="@drawable/ic_info_outline"
android:key="pref_about"
Expand Down
Loading