Set up project skeleton (milestone 1)
- Architecture and feature overview in docs/ARCHITECTURE.md - Gradle 9.8 / AGP 9.4 / Kotlin 2.4 with version catalog and convention plugins - Modules :app, :core:*, :device-profiles, :feature:* (placeholder screens) - Flavors core (no INTERNET, enforced by a build check) and full - Material You theme, navigation, expert mode and dry-run settings (DataStore) - Pixel 8-10 device detection, unit tests, GPLv3 license, English README with Obtainium badge Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
plugins {
|
||||
alias(libs.plugins.pixelwall.android.library)
|
||||
alias(libs.plugins.pixelwall.android.hilt)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "org.pixelwall.core.data"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":core:domain"))
|
||||
implementation(libs.androidx.datastore.preferences)
|
||||
implementation(libs.kotlinx.coroutines.android)
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package org.pixelwall.core.data
|
||||
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.core.booleanPreferencesKey
|
||||
import androidx.datastore.preferences.core.edit
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import org.pixelwall.core.domain.UserPreferences
|
||||
import org.pixelwall.core.domain.UserPreferencesRepository
|
||||
import javax.inject.Inject
|
||||
|
||||
class DataStoreUserPreferencesRepository @Inject constructor(
|
||||
private val dataStore: DataStore<Preferences>,
|
||||
) : UserPreferencesRepository {
|
||||
|
||||
override val preferences: Flow<UserPreferences> = dataStore.data.map { prefs ->
|
||||
UserPreferences(
|
||||
expertMode = prefs[EXPERT_MODE] ?: false,
|
||||
dryRun = prefs[DRY_RUN] ?: false,
|
||||
)
|
||||
}
|
||||
|
||||
override suspend fun setExpertMode(enabled: Boolean) {
|
||||
dataStore.edit { it[EXPERT_MODE] = enabled }
|
||||
}
|
||||
|
||||
override suspend fun setDryRun(enabled: Boolean) {
|
||||
dataStore.edit { it[DRY_RUN] = enabled }
|
||||
}
|
||||
|
||||
private companion object {
|
||||
val EXPERT_MODE = booleanPreferencesKey("expert_mode")
|
||||
val DRY_RUN = booleanPreferencesKey("dry_run")
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package org.pixelwall.core.data.di
|
||||
|
||||
import android.content.Context
|
||||
import androidx.datastore.core.DataStore
|
||||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
|
||||
import androidx.datastore.preferences.core.Preferences
|
||||
import androidx.datastore.preferences.preferencesDataStoreFile
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.android.qualifiers.ApplicationContext
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import org.pixelwall.core.data.DataStoreUserPreferencesRepository
|
||||
import org.pixelwall.core.domain.UserPreferencesRepository
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
abstract class DataModule {
|
||||
|
||||
@Binds
|
||||
abstract fun bindUserPreferencesRepository(impl: DataStoreUserPreferencesRepository): UserPreferencesRepository
|
||||
|
||||
companion object {
|
||||
@Provides
|
||||
@Singleton
|
||||
fun providePreferencesDataStore(@ApplicationContext context: Context): DataStore<Preferences> =
|
||||
PreferenceDataStoreFactory.create { context.preferencesDataStoreFile("user_preferences") }
|
||||
}
|
||||
}
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
package org.pixelwall.core.data
|
||||
|
||||
import androidx.datastore.preferences.core.PreferenceDataStoreFactory
|
||||
import com.google.common.truth.Truth.assertThat
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.test.TestScope
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.runTest
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import org.pixelwall.core.domain.UserPreferences
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class DataStoreUserPreferencesRepositoryTest {
|
||||
|
||||
@get:Rule
|
||||
val tmp = TemporaryFolder()
|
||||
|
||||
private val testScope = TestScope(UnconfinedTestDispatcher())
|
||||
|
||||
private fun repository() = DataStoreUserPreferencesRepository(
|
||||
PreferenceDataStoreFactory.create(scope = testScope.backgroundScope) {
|
||||
tmp.newFile("test.preferences_pb")
|
||||
},
|
||||
)
|
||||
|
||||
@Test
|
||||
fun defaultsAreSafe() = testScope.runTest {
|
||||
assertThat(repository().preferences.first()).isEqualTo(UserPreferences(expertMode = false, dryRun = false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun togglesArePersisted() = testScope.runTest {
|
||||
val repo = repository()
|
||||
repo.setExpertMode(true)
|
||||
repo.setDryRun(true)
|
||||
assertThat(repo.preferences.first()).isEqualTo(UserPreferences(expertMode = true, dryRun = true))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
plugins {
|
||||
alias(libs.plugins.pixelwall.jvm.library)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":core:model"))
|
||||
implementation(libs.kotlinx.coroutines.core)
|
||||
implementation(libs.javax.inject)
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package org.pixelwall.core.domain
|
||||
|
||||
import org.pixelwall.core.model.DeviceInfo
|
||||
|
||||
fun interface DeviceInfoProvider {
|
||||
fun current(): DeviceInfo
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package org.pixelwall.core.domain
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
data class UserPreferences(
|
||||
/** Zeigt rohe Settings-Keys und Shell-Befehle an. */
|
||||
val expertMode: Boolean = false,
|
||||
/** Änderungen werden nur angezeigt, nie ausgeführt. */
|
||||
val dryRun: Boolean = false,
|
||||
)
|
||||
|
||||
interface UserPreferencesRepository {
|
||||
val preferences: Flow<UserPreferences>
|
||||
suspend fun setExpertMode(enabled: Boolean)
|
||||
suspend fun setDryRun(enabled: Boolean)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
plugins {
|
||||
alias(libs.plugins.pixelwall.jvm.library)
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package org.pixelwall.core.model
|
||||
|
||||
/** Unveränderliche Beschreibung des laufenden Geräts, unabhängig von android.os.Build. */
|
||||
data class DeviceInfo(
|
||||
val manufacturer: String,
|
||||
val brand: String,
|
||||
/** Codename, z. B. "shiba" (Pixel 8) oder "tokay" (Pixel 9). */
|
||||
val device: String,
|
||||
val model: String,
|
||||
val sdkInt: Int,
|
||||
val release: String,
|
||||
/** Format JJJJ-MM-TT, wie in Build.VERSION.SECURITY_PATCH. */
|
||||
val securityPatch: String,
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
package org.pixelwall.core.model
|
||||
|
||||
/**
|
||||
* Rechte, mit denen Pixelwall eine Einstellung lesen oder ändern kann.
|
||||
* Die Reihenfolge ist relevant: eine höhere Stufe schließt die Fähigkeiten der niedrigeren ein,
|
||||
* mit Ausnahme von [ADB_GRANT], das nur Settings schreiben kann (siehe docs/ARCHITECTURE.md §3).
|
||||
*/
|
||||
enum class PrivilegeLevel {
|
||||
/** Nur lesen und per Intent zur Systemeinstellung führen. */
|
||||
NORMAL,
|
||||
|
||||
/** WRITE_SECURE_SETTINGS wurde einmalig per ADB erteilt. */
|
||||
ADB_GRANT,
|
||||
|
||||
/** Shizuku läuft und hat der App Zugriff gewährt (Shell-UID). */
|
||||
SHIZUKU,
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package org.pixelwall.core.model
|
||||
|
||||
enum class Risk { LOW, MEDIUM, HIGH }
|
||||
|
||||
enum class Category { PERMISSIONS, NETWORK, SYSTEM, GOOGLE, APPS }
|
||||
@@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
alias(libs.plugins.pixelwall.android.library)
|
||||
alias(libs.plugins.pixelwall.android.hilt)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "org.pixelwall.core.privileged"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":core:domain"))
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
/**
|
||||
* Privilegierte Ausführung (Shizuku, WRITE_SECURE_SETTINGS) – folgt in Meilenstein 4.
|
||||
* Siehe docs/ARCHITECTURE.md §3 und §4.
|
||||
*/
|
||||
package org.pixelwall.core.privileged
|
||||
@@ -0,0 +1,13 @@
|
||||
plugins {
|
||||
alias(libs.plugins.pixelwall.android.library)
|
||||
alias(libs.plugins.pixelwall.android.hilt)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "org.pixelwall.core.system"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":core:domain"))
|
||||
implementation(libs.androidx.core.ktx)
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.pixelwall.core.system
|
||||
|
||||
import android.os.Build
|
||||
import org.pixelwall.core.domain.DeviceInfoProvider
|
||||
import org.pixelwall.core.model.DeviceInfo
|
||||
import javax.inject.Inject
|
||||
|
||||
class BuildDeviceInfoProvider @Inject constructor() : DeviceInfoProvider {
|
||||
override fun current() = DeviceInfo(
|
||||
manufacturer = Build.MANUFACTURER,
|
||||
brand = Build.BRAND,
|
||||
device = Build.DEVICE,
|
||||
model = Build.MODEL,
|
||||
sdkInt = Build.VERSION.SDK_INT,
|
||||
release = Build.VERSION.RELEASE,
|
||||
securityPatch = Build.VERSION.SECURITY_PATCH,
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package org.pixelwall.core.system.di
|
||||
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import org.pixelwall.core.domain.DeviceInfoProvider
|
||||
import org.pixelwall.core.system.BuildDeviceInfoProvider
|
||||
|
||||
@Module
|
||||
@InstallIn(SingletonComponent::class)
|
||||
abstract class SystemModule {
|
||||
@Binds
|
||||
abstract fun bindDeviceInfoProvider(impl: BuildDeviceInfoProvider): DeviceInfoProvider
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
plugins {
|
||||
alias(libs.plugins.pixelwall.jvm.library)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":core:domain"))
|
||||
api(libs.junit)
|
||||
api(libs.kotlinx.coroutines.test)
|
||||
}
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
package org.pixelwall.core.testing
|
||||
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableStateFlow
|
||||
import kotlinx.coroutines.flow.update
|
||||
import org.pixelwall.core.domain.UserPreferences
|
||||
import org.pixelwall.core.domain.UserPreferencesRepository
|
||||
|
||||
class FakeUserPreferencesRepository(initial: UserPreferences = UserPreferences()) : UserPreferencesRepository {
|
||||
private val state = MutableStateFlow(initial)
|
||||
override val preferences: Flow<UserPreferences> = state
|
||||
override suspend fun setExpertMode(enabled: Boolean) = state.update { it.copy(expertMode = enabled) }
|
||||
override suspend fun setDryRun(enabled: Boolean) = state.update { it.copy(dryRun = enabled) }
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package org.pixelwall.core.testing
|
||||
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.test.TestDispatcher
|
||||
import kotlinx.coroutines.test.UnconfinedTestDispatcher
|
||||
import kotlinx.coroutines.test.resetMain
|
||||
import kotlinx.coroutines.test.setMain
|
||||
import org.junit.rules.TestWatcher
|
||||
import org.junit.runner.Description
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
class MainDispatcherRule(
|
||||
val dispatcher: TestDispatcher = UnconfinedTestDispatcher(),
|
||||
) : TestWatcher() {
|
||||
override fun starting(description: Description) = Dispatchers.setMain(dispatcher)
|
||||
override fun finished(description: Description) = Dispatchers.resetMain()
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
plugins {
|
||||
alias(libs.plugins.pixelwall.android.library)
|
||||
alias(libs.plugins.pixelwall.android.compose)
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "org.pixelwall.core.ui"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(project(":core:model"))
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package org.pixelwall.core.ui.component
|
||||
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.heading
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import androidx.compose.ui.unit.dp
|
||||
import org.pixelwall.core.ui.R
|
||||
|
||||
/** Platzhalter für Bereiche, deren Meilenstein noch aussteht. */
|
||||
@Composable
|
||||
fun PlaceholderScreen(title: String, description: String, modifier: Modifier = Modifier) {
|
||||
Column(
|
||||
modifier = modifier
|
||||
.fillMaxSize()
|
||||
.padding(24.dp),
|
||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
||||
) {
|
||||
Text(
|
||||
text = title,
|
||||
style = MaterialTheme.typography.headlineSmall,
|
||||
modifier = Modifier.semantics { heading() },
|
||||
)
|
||||
Text(text = description, style = MaterialTheme.typography.bodyLarge)
|
||||
Text(
|
||||
text = stringResource(R.string.placeholder_coming_soon),
|
||||
style = MaterialTheme.typography.bodyMedium,
|
||||
color = MaterialTheme.colorScheme.onSurfaceVariant,
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package org.pixelwall.core.ui.component
|
||||
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.outlined.AdminPanelSettings
|
||||
import androidx.compose.material.icons.outlined.Terminal
|
||||
import androidx.compose.material.icons.outlined.TouchApp
|
||||
import androidx.compose.material3.AssistChip
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.res.stringResource
|
||||
import androidx.compose.ui.semantics.contentDescription
|
||||
import androidx.compose.ui.semantics.semantics
|
||||
import org.pixelwall.core.model.PrivilegeLevel
|
||||
import org.pixelwall.core.ui.R
|
||||
|
||||
/** Zeigt die Berechtigungsstufe an, die eine Einstellung benötigt. */
|
||||
@Composable
|
||||
fun PrivilegeChip(level: PrivilegeLevel, modifier: Modifier = Modifier) {
|
||||
val label = stringResource(level.labelRes())
|
||||
val description = stringResource(R.string.privilege_required, label)
|
||||
AssistChip(
|
||||
onClick = {},
|
||||
enabled = true,
|
||||
label = { Text(label) },
|
||||
leadingIcon = {
|
||||
Icon(
|
||||
imageVector = when (level) {
|
||||
PrivilegeLevel.NORMAL -> Icons.Outlined.TouchApp
|
||||
PrivilegeLevel.ADB_GRANT -> Icons.Outlined.AdminPanelSettings
|
||||
PrivilegeLevel.SHIZUKU -> Icons.Outlined.Terminal
|
||||
},
|
||||
contentDescription = null,
|
||||
)
|
||||
},
|
||||
modifier = modifier.semantics { contentDescription = description },
|
||||
)
|
||||
}
|
||||
|
||||
fun PrivilegeLevel.labelRes(): Int = when (this) {
|
||||
PrivilegeLevel.NORMAL -> R.string.privilege_normal
|
||||
PrivilegeLevel.ADB_GRANT -> R.string.privilege_adb
|
||||
PrivilegeLevel.SHIZUKU -> R.string.privilege_shizuku
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.pixelwall.core.ui.theme
|
||||
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.darkColorScheme
|
||||
import androidx.compose.material3.dynamicDarkColorScheme
|
||||
import androidx.compose.material3.dynamicLightColorScheme
|
||||
import androidx.compose.material3.lightColorScheme
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
|
||||
private val LightFallback = lightColorScheme(
|
||||
primary = Color(0xFF2B5EA7),
|
||||
secondary = Color(0xFF555F71),
|
||||
tertiary = Color(0xFF6E5676),
|
||||
)
|
||||
|
||||
private val DarkFallback = darkColorScheme(
|
||||
primary = Color(0xFFA8C8FF),
|
||||
secondary = Color(0xFFBDC7DC),
|
||||
tertiary = Color(0xFFDABDE2),
|
||||
)
|
||||
|
||||
/** Material You: dynamische Farben sind ab minSdk 34 immer verfügbar; Fallback nur für Previews. */
|
||||
@Composable
|
||||
fun PixelwallTheme(
|
||||
darkTheme: Boolean = isSystemInDarkTheme(),
|
||||
dynamicColor: Boolean = true,
|
||||
content: @Composable () -> Unit,
|
||||
) {
|
||||
val context = LocalContext.current
|
||||
val colorScheme = when {
|
||||
dynamicColor && darkTheme -> dynamicDarkColorScheme(context)
|
||||
dynamicColor -> dynamicLightColorScheme(context)
|
||||
darkTheme -> DarkFallback
|
||||
else -> LightFallback
|
||||
}
|
||||
MaterialTheme(colorScheme = colorScheme, content = content)
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="privilege_normal">Normal</string>
|
||||
<string name="privilege_adb">ADB-Freigabe</string>
|
||||
<string name="privilege_shizuku">Shizuku</string>
|
||||
<string name="privilege_required">Benötigt: %1$s</string>
|
||||
<string name="placeholder_coming_soon">Dieser Bereich ist noch nicht umgesetzt.</string>
|
||||
</resources>
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="privilege_normal">Normal</string>
|
||||
<string name="privilege_adb">ADB grant</string>
|
||||
<string name="privilege_shizuku">Shizuku</string>
|
||||
<string name="privilege_required">Requires: %1$s</string>
|
||||
<string name="placeholder_coming_soon">This area is not implemented yet.</string>
|
||||
</resources>
|
||||
Reference in New Issue
Block a user