Skip to content

Commit

Permalink
Create a separate product flavor to publish on F-Droid
Browse files Browse the repository at this point in the history
  • Loading branch information
mjaakko committed Jan 28, 2024
1 parent 295cf5a commit 60a8960
Show file tree
Hide file tree
Showing 18 changed files with 127 additions and 63 deletions.
6 changes: 5 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ android {
}

productFlavors {
fdroid {
dimension "version"
}
full {
dimension "version"
}
Expand Down Expand Up @@ -130,7 +133,8 @@ dependencies {
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-jdk8'
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-play-services'

implementation 'com.google.android.gms:play-services-location:21.0.1'
fullImplementation 'com.google.android.gms:play-services-location:21.0.1'

implementation "androidx.datastore:datastore-preferences:1.0.0"

def room_version = "2.6.1"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package xyz.malkki.neostumbler.location

import android.content.Context


class LocationSourceProvider(private val context: Context) {
fun getLocationSource(): LocationSource {
return PlatformLocationSource(context)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package xyz.malkki.neostumbler.ui.screens.settings


import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import xyz.malkki.neostumbler.ui.composables.ExportDataButton
import xyz.malkki.neostumbler.ui.composables.ReportReuploadButton

@Composable
fun SettingsScreen() {
Column {
ExportDataButton()
Spacer(modifier = Modifier.height(8.dp))
ReportReuploadButton()
}
}
35 changes: 35 additions & 0 deletions app/src/full/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" tools:node="merge" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" tools:node="merge"/>

<application tools:node="merge">

<receiver
android:name=".scanner.autoscan.LocationReceiver"
android:enabled="true"
android:exported="true"
tools:node="merge" />

<receiver
android:name=".scanner.autoscan.RescheduleReceiver"
android:enabled="true"
android:exported="true"
tools:node="merge">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<receiver
android:name=".scanner.autoscan.ActivityTransitionReceiver"
android:enabled="true"
android:exported="true"
tools:node="merge" />
</application>
</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package xyz.malkki.neostumbler.extensions

import android.content.Context
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability

/**
* Checks if Google APIs are available
*
* @return true is Google APIs are available, false if not
*/
fun Context.isGoogleApisAvailable(): Boolean {
return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(applicationContext) == ConnectionResult.SUCCESS
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package xyz.malkki.neostumbler.location

import android.content.Context
import androidx.datastore.preferences.core.booleanPreferencesKey
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.runBlocking
import timber.log.Timber
import xyz.malkki.neostumbler.StumblerApplication
import xyz.malkki.neostumbler.constants.PreferenceKeys
import xyz.malkki.neostumbler.extensions.isGoogleApisAvailable

class LocationSourceProvider(private val context: Context) {
private val settingsStore = (context.applicationContext as StumblerApplication).settingsStore

private fun preferFusedLocation(): Boolean = runBlocking {
settingsStore.data
.map { it[booleanPreferencesKey(PreferenceKeys.PREFER_FUSED_LOCATION)] }
.firstOrNull() ?: true
}

fun getLocationSource(): LocationSource {
return if (preferFusedLocation() && context.isGoogleApisAvailable()) {
Timber.i("Using fused location source")
FusedLocationSource(context)
} else {
Timber.i("Using platform location source")
PlatformLocationSource(context)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.malkki.neostumbler.ui.composables
package xyz.malkki.neostumbler.ui.composables.autoscan

import android.Manifest
import android.annotation.SuppressLint
Expand Down Expand Up @@ -31,6 +31,8 @@ import xyz.malkki.neostumbler.constants.PreferenceKeys
import xyz.malkki.neostumbler.extensions.checkMissingPermissions
import xyz.malkki.neostumbler.extensions.getActivity
import xyz.malkki.neostumbler.scanner.autoscan.ActivityTransitionReceiver
import xyz.malkki.neostumbler.ui.composables.PermissionsDialog
import xyz.malkki.neostumbler.ui.composables.ToggleWithAction
import xyz.malkki.neostumbler.utils.PermissionHelper

private fun DataStore<Preferences>.autoScanEnabled(): Flow<Boolean?> = data
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package xyz.malkki.neostumbler.ui.screens
package xyz.malkki.neostumbler.ui.screens.settings

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
Expand All @@ -9,10 +9,10 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import xyz.malkki.neostumbler.R
import xyz.malkki.neostumbler.constants.PreferenceKeys
import xyz.malkki.neostumbler.ui.composables.AutoScanToggle
import xyz.malkki.neostumbler.ui.composables.ExportDataButton
import xyz.malkki.neostumbler.ui.composables.ReportReuploadButton
import xyz.malkki.neostumbler.ui.composables.SettingsToggle
import xyz.malkki.neostumbler.ui.composables.autoscan.AutoScanToggle

@Composable
fun SettingsScreen() {
Expand Down
4 changes: 4 additions & 0 deletions app/src/full/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<resources>
<string name="prefer_fused_location">Prefer fused location provider</string>
<string name="autoscan_when_moving">Automatic scanning while moving</string>
</resources>
24 changes: 0 additions & 24 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
Expand All @@ -13,7 +12,6 @@
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_DATA_SYNC" />
<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"/>
Expand All @@ -40,28 +38,6 @@
android:theme="@style/Theme.NeoStumbler"
tools:targetApi="31">

<receiver
android:name=".scanner.autoscan.LocationReceiver"
android:enabled="true"
android:exported="true" />

<receiver
android:name=".scanner.autoscan.RescheduleReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>

<receiver
android:name=".scanner.autoscan.ActivityTransitionReceiver"
android:enabled="true"
android:exported="true" />

<service
android:name=".scanner.ScannerService"
android:enabled="true"
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/xyz/malkki/neostumbler/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import xyz.malkki.neostumbler.ui.composables.ReportMap
import xyz.malkki.neostumbler.ui.screens.ReportsScreen
import xyz.malkki.neostumbler.ui.screens.SettingsScreen
import xyz.malkki.neostumbler.ui.screens.settings.SettingsScreen
import xyz.malkki.neostumbler.ui.theme.NeoStumblerTheme

class MainActivity : ComponentActivity() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import android.os.Build
import android.provider.Settings
import androidx.core.content.getSystemService
import androidx.core.os.LocaleListCompat
import com.google.android.gms.common.ConnectionResult
import com.google.android.gms.common.GoogleApiAvailability
import java.util.Locale

/**
Expand Down Expand Up @@ -52,13 +50,4 @@ fun Context.isWifiScanThrottled(): Boolean? {
else -> null
}
}
}

/**
* Checks if Google APIs are available
*
* @return true is Google APIs are available, false if not
*/
fun Context.isGoogleApisAvailable(): Boolean {
return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(applicationContext) == ConnectionResult.SUCCESS
}
22 changes: 2 additions & 20 deletions app/src/main/java/xyz/malkki/neostumbler/scanner/ScannerService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,16 @@ import androidx.core.app.NotificationCompat.FOREGROUND_SERVICE_IMMEDIATE
import androidx.core.content.getSystemService
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.channelFlow
import kotlinx.coroutines.flow.emptyFlow
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.firstOrNull
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.runningFold
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import org.altbeacon.beacon.Beacon
Expand All @@ -46,16 +43,13 @@ import xyz.malkki.neostumbler.MainActivity
import xyz.malkki.neostumbler.R
import xyz.malkki.neostumbler.StumblerApplication
import xyz.malkki.neostumbler.common.LocationWithSource
import xyz.malkki.neostumbler.constants.PreferenceKeys
import xyz.malkki.neostumbler.extensions.buffer
import xyz.malkki.neostumbler.extensions.checkMissingPermissions
import xyz.malkki.neostumbler.extensions.combineAny
import xyz.malkki.neostumbler.extensions.filterNotNullPairs
import xyz.malkki.neostumbler.extensions.isGoogleApisAvailable
import xyz.malkki.neostumbler.extensions.timestampMillis
import xyz.malkki.neostumbler.extensions.timestampMillisCompat
import xyz.malkki.neostumbler.location.FusedLocationSource
import xyz.malkki.neostumbler.location.PlatformLocationSource
import xyz.malkki.neostumbler.location.LocationSourceProvider
import xyz.malkki.neostumbler.utils.getBeaconFlow
import xyz.malkki.neostumbler.utils.getCellInfoFlow
import xyz.malkki.neostumbler.utils.getWifiScanFlow
Expand Down Expand Up @@ -155,12 +149,6 @@ class ScannerService : Service() {
return binder
}

private fun preferFusedLocation(): Boolean = runBlocking {
settingsStore.data
.map { it[booleanPreferencesKey(PreferenceKeys.PREFER_FUSED_LOCATION)] }
.firstOrNull() ?: true
}

@SuppressLint("MissingPermission")
private fun startScanning() = coroutineScope.launch {
if (scanning) {
Expand All @@ -169,13 +157,7 @@ class ScannerService : Service() {

scanning = true

val locationSource = if (preferFusedLocation() && isGoogleApisAvailable()) {
Timber.i("Using fused location source")
FusedLocationSource(this@ScannerService)
} else {
Timber.i("Using platform location source")
PlatformLocationSource(this@ScannerService)
}
val locationSource = LocationSourceProvider(this@ScannerService).getLocationSource()

val locationFlow = locationSource.getLocations(LOCATION_INTERVAL)
.filter {
Expand Down
3 changes: 0 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
<string name="start_scanning">Start scanning</string>
<string name="stop_scanning">Stop scanning</string>

<string name="prefer_fused_location">Prefer fused location provider</string>
<string name="autoscan_when_moving">Automatic scanning while moving</string>

<string name="notification_wireless_scanning_active">Wireless scanning active</string>

<string name="notification_reports_created">%d reports created</string>
Expand Down

0 comments on commit 60a8960

Please sign in to comment.