Skip to content

Commit

Permalink
Build: Change system for optional components
Browse files Browse the repository at this point in the history
- Nearby can now be configured through local build property, enabled by default
- Exposure Notifications is not displayed in settings if not used for >14 days
- Flavors per map type remain (but moved maps implementations)
  • Loading branch information
mar-v-in committed Sep 16, 2023
1 parent 2c80de5 commit dd8c560
Show file tree
Hide file tree
Showing 906 changed files with 364 additions and 207 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* SPDX-FileCopyrightText: 2023 microG Project Team
* SPDX-License-Identifier: Apache-2.0
*/

package org.microg.gms.ui.settings

import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.graphics.drawable.Drawable
import android.os.Bundle
import android.util.Log
import androidx.navigation.NavController

private const val TAG = "SettingsProvider"

interface SettingsProvider {
fun getEntriesStatic(context: Context): List<Entry>
suspend fun getEntriesDynamic(context: Context): List<Entry> = getEntriesStatic(context)

fun preProcessSettingsIntent(intent: Intent)

fun extendNavigation(navController: NavController)

companion object {
enum class Group {
HEADER,
GOOGLE,
OTHER,
FOOTER
}

data class Entry(
val key: String,
val group: Group,
val navigationId: Int,
val title: String,
val summary: String? = null,
val icon: Drawable? = null,
)
}
}

fun getAllSettingsProviders(context: Context): List<SettingsProvider> {
val metaData = runCatching { context.packageManager.getApplicationInfo(context.packageName, PackageManager.GET_META_DATA).metaData }.getOrNull() ?: Bundle.EMPTY
return metaData.keySet().asSequence().filter {
it.startsWith("org.microg.gms.ui.settings.entry:")
}.mapNotNull {
runCatching { metaData.getString(it) }.onFailure { Log.w(TAG, it) }.getOrNull()
}.mapNotNull {
runCatching { Class.forName(it) }.onFailure { Log.w(TAG, it) }.getOrNull()
}.filter {
SettingsProvider::class.java.isAssignableFrom(it)
}.mapNotNull {
runCatching { it.getDeclaredField("INSTANCE").get(null) as SettingsProvider }.onFailure { Log.w(TAG, it) }.getOrNull()
}.toList()
}
7 changes: 7 additions & 0 deletions play-services-base/core/src/main/res/values-be/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
<string name="list_item_see_all">Паказаць усё</string>

<string name="open_app">Aдкрыць</string>

<string name="service_status_disabled">Выключана</string>
<string name="service_status_enabled">Уключана</string>
<string name="service_status_automatic">Аўтаматычна</string>
<string name="service_status_manual">Уручную</string>
<string name="service_status_enabled_short">Укл.</string>
<string name="service_status_disabled_short">Выкл.</string>
</resources>
7 changes: 7 additions & 0 deletions play-services-base/core/src/main/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
<string name="list_item_see_all">Alle anzeigen</string>

<string name="open_app">Öffnen</string>

<string name="service_status_disabled">Deaktiviert</string>
<string name="service_status_enabled">Aktiviert</string>
<string name="service_status_automatic">Automatisch</string>
<string name="service_status_manual">Manuell</string>
<string name="service_status_enabled_short">Ein</string>
<string name="service_status_disabled_short">Aus</string>
</resources>
7 changes: 7 additions & 0 deletions play-services-base/core/src/main/res/values-es/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@
<string name="list_item_see_all">Ver todo</string>

<string name="open_app">Abrir</string>

<string name="service_status_disabled">Desactivado</string>
<string name="service_status_enabled">Activado</string>
<string name="service_status_automatic">Automático</string>
<string name="service_status_manual">Manual</string>
<string name="service_status_enabled_short">Encendido</string>
<string name="service_status_disabled_short">Apagado</string>
</resources>
5 changes: 5 additions & 0 deletions play-services-base/core/src/main/res/values-fr/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
<string name="menu_advanced">Avancé</string>

<string name="list_no_item_none">Aucun</string>

<string name="service_status_disabled">Désactivé</string>
<string name="service_status_enabled">Activé</string>
<string name="service_status_automatic">Automatique</string>
<string name="service_status_manual">Manuel</string>
</resources>
7 changes: 7 additions & 0 deletions play-services-base/core/src/main/res/values-it/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
<string name="list_no_item_none">Nessuna</string>
<string name="list_item_see_all">Mostra tutte</string>
<string name="open_app">Apri</string>

<string name="service_status_disabled">Disabilitato</string>
<string name="service_status_enabled">Abilitato</string>
<string name="service_status_automatic">Automatico</string>
<string name="service_status_manual">Manuale</string>
<string name="service_status_enabled_short">Abilitato</string>
<string name="service_status_disabled_short">Disabilitato</string>
</resources>
7 changes: 7 additions & 0 deletions play-services-base/core/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,11 @@
<string name="list_item_see_all">全て表示</string>

<string name="open_app">開く</string>

<string name="service_status_disabled">無効</string>
<string name="service_status_enabled">有効</string>
<string name="service_status_automatic">自動</string>
<string name="service_status_manual">手動</string>
<string name="service_status_enabled_short">On</string>
<string name="service_status_disabled_short">Off</string>
</resources>
5 changes: 5 additions & 0 deletions play-services-base/core/src/main/res/values-pl/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
<string name="menu_advanced">Zaawansowane</string>

<string name="list_no_item_none">Brak</string>

<string name="service_status_disabled">Nieaktywny</string>
<string name="service_status_enabled">Aktywny</string>
<string name="service_status_automatic">Automatyczny</string>
<string name="service_status_manual">Ręczny</string>
</resources>
7 changes: 7 additions & 0 deletions play-services-base/core/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
<string name="list_item_see_all">Показать всё</string>

<string name="open_app">Открыть</string>

<string name="service_status_disabled">Выключено</string>
<string name="service_status_enabled">Включено</string>
<string name="service_status_automatic">Автоматически</string>
<string name="service_status_manual">Вручную</string>
<string name="service_status_enabled_short">Вкл.</string>
<string name="service_status_disabled_short">Выкл.</string>
</resources>
5 changes: 5 additions & 0 deletions play-services-base/core/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
<string name="menu_advanced">Додатково</string>

<string name="list_no_item_none">Порожньо</string>

<string name="service_status_disabled">Вимкнуто</string>
<string name="service_status_enabled">Увімкнуто</string>
<string name="service_status_automatic">Автоматично</string>
<string name="service_status_manual">Вручну</string>
</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@
<string name="list_no_item_none">无</string>
<string name="list_item_see_all">全部显示</string>
<string name="open_app">打开</string>

<string name="service_status_disabled">已禁用</string>
<string name="service_status_enabled">已启用</string>
<string name="service_status_automatic">自动</string>
<string name="service_status_manual">手动</string>
<string name="service_status_enabled_short">开</string>
<string name="service_status_disabled_short">关</string>
</resources>
7 changes: 7 additions & 0 deletions play-services-base/core/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
<string name="list_item_see_all">See all</string>

<string name="open_app">Open</string>

<string name="service_status_disabled">Disabled</string>
<string name="service_status_enabled">Enabled</string>
<string name="service_status_automatic">Automatic</string>
<string name="service_status_manual">Manual</string>
<string name="service_status_enabled_short">On</string>
<string name="service_status_disabled_short">Off</string>
</resources>
43 changes: 18 additions & 25 deletions play-services-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'

def hasModule(String name, boolean enabledByDefault) {
return localProperties.getProperty("modules." + name, enabledByDefault.toString()).toBoolean()
}

configurations {
withMapboxImplementation
withVtmImplementation
withNearbyImplementation
withoutNearbyImplementation
mapboxRuntimeOnly
vtmRuntimeOnly
defaultRuntimeOnly
}

dependencies {
Expand All @@ -35,8 +38,6 @@ dependencies {
implementation project(':play-services-gmscompliance-core')
implementation project(':play-services-location-core')
implementation project(':play-services-location-core-base')
implementation project(':play-services-location-core-provider')
withNearbyImplementation project(':play-services-nearby-core')
implementation project(':play-services-oss-licenses-core')
implementation project(':play-services-pay-core')
implementation project(':play-services-recaptcha-core')
Expand All @@ -63,8 +64,11 @@ dependencies {
implementation project(':play-services-safetynet')
implementation project(':play-services-tasks-ktx')

withMapboxImplementation project(':play-services-maps-core-mapbox')
withVtmImplementation project(':play-services-maps-core-vtm')
mapboxRuntimeOnly project(':play-services-maps-core-mapbox')
vtmRuntimeOnly project(':play-services-maps-core-vtm')
defaultRuntimeOnly project(':play-services-location-core-provider')

if (hasModule("nearby", true)) runtimeOnly project(':play-services-nearby-core-package')

// AndroidX UI
implementation "androidx.multidex:multidex:$multidexVersion"
Expand Down Expand Up @@ -123,12 +127,6 @@ android {
main {
java.srcDirs += 'src/main/kotlin'
}
withNearby {
java.srcDirs += 'src/withNearby/kotlin'
}
withoutNearby {
java.srcDirs += 'src/withoutNearby/kotlin'
}
}

lintOptions {
Expand All @@ -142,21 +140,16 @@ android {
}
}

flavorDimensions 'maps', 'nearby'
flavorDimensions = ['maps', 'target']
productFlavors {
withMapbox {
dimension 'maps'
"default" {
dimension 'target'
}
withVtm {
"mapbox" {
dimension 'maps'
versionNameSuffix '-vtm'
}
withNearby {
dimension 'nearby'
}
withoutNearby {
dimension 'nearby'
versionNameSuffix '-noen'
"vtm" {
dimension 'maps'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
import androidx.navigation.ui.NavigationUI;

import com.google.android.gms.R;
import org.microg.gms.ui.settings.SettingsProvider;

import static org.microg.gms.ui.settings.SettingsProviderKt.getAllSettingsProviders;

public class SettingsActivity extends AppCompatActivity {
private AppBarConfiguration appBarConfiguration;
Expand All @@ -24,10 +27,16 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

Intent intent = getIntent();
NearbyPreferencesIntegration.Companion.preProcessSettingsIntent(intent);
for (SettingsProvider settingsProvider : getAllSettingsProviders(this)) {
settingsProvider.preProcessSettingsIntent(intent);
}

setContentView(R.layout.settings_root_activity);

for (SettingsProvider settingsProvider : getAllSettingsProviders(this)) {
settingsProvider.extendNavigation(getNavController());
}

appBarConfiguration = new AppBarConfiguration.Builder(getNavController().getGraph()).build();
NavigationUI.setupActionBarWithNavController(this, getNavController(), appBarConfiguration);
}
Expand Down
Loading

0 comments on commit dd8c560

Please sign in to comment.