diff --git a/provider/android/.gitignore b/provider/android/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/provider/android/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/provider/android/app/.gitignore b/provider/android/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/provider/android/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/provider/android/app/build.gradle.kts b/provider/android/app/build.gradle.kts new file mode 100644 index 0000000..eec0f3c --- /dev/null +++ b/provider/android/app/build.gradle.kts @@ -0,0 +1,94 @@ +// Module-level build file +// build.gradle.kts (Module: app) + +plugins { + // Apply the plugins declared in the root build.gradle.kts + // or directly by their ID if not using the root declaration pattern + id("com.android.application") + id("org.jetbrains.kotlin.android") + // If you had defined an alias for compose, e.g., in libs.versions.toml as + // kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } + // You might also add: id("org.jetbrains.kotlin.plugin.compose") + // However, with modern AGP and composeOptions, it's often implicitly handled. +} + +android { + namespace = "com.star.provider" + compileSdk = 35 + + defaultConfig { + applicationId = "com.star.provider" + minSdk = 32 // Ensure this is appropriate for the APIs used + targetSdk = 35 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + vectorDrawables { + useSupportLibrary = true + } + } + + buildTypes { + release { + isMinifyEnabled = false // Set to true for actual releases + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + + compileOptions { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 + } + + kotlinOptions { + jvmTarget = "1.8" + } + + buildFeatures { + compose = true + } + + composeOptions { + // Ensure this version is compatible with your Kotlin and Compose BOM versions + // Refer to: https://developer.android.com/jetpack/androidx/releases/compose-kotlin + kotlinCompilerExtensionVersion = "1.5.3" // Example, update to your required version + } + + packaging { + resources { + excludes += "/META-INF/{AL2.0,LGPL2.1}" + } + } +} + +dependencies { + // Core Android & Jetpack Compose Dependencies (from version catalog) + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) // Ensure this BOM version is up-to-date + implementation(libs.androidx.ui) + implementation(libs.androidx.ui.graphics) + implementation(libs.androidx.ui.tooling.preview) + implementation(libs.androidx.material3) + implementation("androidx.compose.material3:material3:1.2.1") // Or your current M3 version + implementation("androidx.compose.material:material-icons-core:1.6.7") // Or latest + implementation("androidx.compose.material:material-icons-extended:1.6.7") // Or latest - for all icons + // Added Dependencies for STAR Provider Service (explicitly versioned for clarity, or add to TOML) + implementation("com.squareup.okhttp3:okhttp:4.12.0") + implementation("org.json:json:20231013") + implementation("com.google.code.gson:gson:2.10.1") + + // Testing Dependencies (from version catalog) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) // For Compose testing + androidTestImplementation(libs.androidx.ui.test.junit4) + debugImplementation(libs.androidx.ui.tooling) + debugImplementation(libs.androidx.ui.test.manifest) +} \ No newline at end of file diff --git a/provider/android/app/proguard-rules.pro b/provider/android/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/provider/android/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/provider/android/app/src/androidTest/java/com/star/provider/ExampleInstrumentedTest.kt b/provider/android/app/src/androidTest/java/com/star/provider/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..47e44d6 --- /dev/null +++ b/provider/android/app/src/androidTest/java/com/star/provider/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.star.provider + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.star.provider", appContext.packageName) + } +} \ No newline at end of file diff --git a/provider/android/app/src/main/AndroidManifest.xml b/provider/android/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..93d7db2 --- /dev/null +++ b/provider/android/app/src/main/AndroidManifest.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/provider/android/app/src/main/java/com/star/provider/MainActivity.kt b/provider/android/app/src/main/java/com/star/provider/MainActivity.kt new file mode 100644 index 0000000..58d5280 --- /dev/null +++ b/provider/android/app/src/main/java/com/star/provider/MainActivity.kt @@ -0,0 +1,473 @@ +package com.star.provider // Ensure this matches your package name + +import android.content.ComponentName +import android.content.Context +import android.content.Intent +import android.content.ServiceConnection +import android.content.SharedPreferences +import android.os.Build +import android.os.Bundle +import android.os.IBinder +import android.util.Log +import androidx.activity.ComponentActivity +import androidx.activity.compose.setContent +import androidx.activity.result.contract.ActivityResultContracts +import androidx.compose.foundation.background +import androidx.compose.foundation.layout.* +import androidx.compose.foundation.lazy.LazyColumn +import androidx.compose.foundation.lazy.items +import androidx.compose.foundation.rememberScrollState +import androidx.compose.foundation.text.KeyboardActions +import androidx.compose.foundation.text.KeyboardOptions +import androidx.compose.foundation.verticalScroll +import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Add +import androidx.compose.material.icons.filled.Build +import androidx.compose.material.icons.filled.Delete +import androidx.compose.material.icons.filled.Settings +import androidx.compose.material3.* +import androidx.compose.runtime.* +import androidx.compose.ui.Alignment +import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalFocusManager +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.text.input.ImeAction +import androidx.compose.ui.text.input.KeyboardType +import androidx.compose.ui.tooling.preview.Preview +import androidx.compose.ui.unit.dp +import androidx.compose.ui.unit.sp +import androidx.compose.ui.window.Dialog +import androidx.core.content.ContextCompat +import com.star.provider.ui.theme.StarProviderTheme +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import java.util.Locale +import com.star.provider.ServiceStateListener +import com.star.provider.ServiceLogListener +import com.star.provider.PersistedVoiceConfig +import com.star.provider.DialogVoiceInfo +import com.star.provider.DialogEngineInfo + +// SharedPreferences Keys +const val PREFS_NAME = "StarProviderPrefs" +const val KEY_SERVER_URLS = "server_urls" // MODIFIED +const val KEY_PROVIDER_NAME = "provider_name" + +class MainActivity : ComponentActivity(), ServiceStateListener, ServiceLogListener { + + private var starProviderService: StarProviderService? = null + private var serviceBinder: StarProviderService.LocalBinder? = null + private var isBound = false + private lateinit var sharedPreferences: SharedPreferences + + // MODIFIED: From single URL to list of URLs + private val _serverUrls = mutableStateListOf() + private val _providerName = mutableStateOf("MyAndroidTTS") + private val _currentStatus = mutableStateOf("Status: Disconnected") + private val _logMessages = mutableStateOf("Logs will appear here...") + private val _isServiceRunningState = mutableStateOf(false) + private val _showVoiceConfigDialog = mutableStateOf(false) + private val _showEngineConfigDialog = mutableStateOf(false) // NEW + + private val connection = object : ServiceConnection { + override fun onServiceConnected(className: ComponentName, service: IBinder) { + serviceBinder = service as StarProviderService.LocalBinder + starProviderService = serviceBinder?.getService() + isBound = true + Log.d("MainActivity", "Service connected") + serviceBinder?.registerStateListener(this@MainActivity) + serviceBinder?.registerLogListener(this@MainActivity) + starProviderService?.requestCurrentStatus() + } + + override fun onServiceDisconnected(arg0: ComponentName) { + if (isBound) { + serviceBinder?.unregisterStateListener(this@MainActivity) + serviceBinder?.unregisterLogListener(this@MainActivity) + isBound = false + serviceBinder = null + starProviderService = null + Log.d("MainActivity", "Service disconnected") + } + _currentStatus.value = "Status: Service Unbound" + _isServiceRunningState.value = false + } + } + + private val requestPermissionLauncher = registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted: Boolean -> + if (isGranted) { Log.i("MainActivity", "Notification permission granted.") } + else { Log.w("MainActivity", "Notification permission denied.") } + } + + override fun onStatusUpdate(status: String, isRunning: Boolean) { CoroutineScope(Dispatchers.Main).launch { _currentStatus.value = status; _isServiceRunningState.value = isRunning } } + override fun onLogMessage(message: String) { CoroutineScope(Dispatchers.Main).launch { _logMessages.value = (_logMessages.value + "\n" + message).takeLast(2000) } } + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + sharedPreferences = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE) + + // MODIFIED: Load a set of URLs, provide a default if empty + val savedUrls = sharedPreferences.getStringSet(KEY_SERVER_URLS, null) + if (savedUrls.isNullOrEmpty()) { + _serverUrls.add("ws://localhost:8765") + } else { + _serverUrls.addAll(savedUrls) + } + + _providerName.value = sharedPreferences.getString(KEY_PROVIDER_NAME, "MyAndroidTTS") ?: "MyAndroidTTS" + + setContent { + StarProviderTheme { + StarProviderScreen( + serverUrls = _serverUrls, + onAddServerUrl = { url -> + val trimmedUrl = url.trim() + if (trimmedUrl.isNotBlank() && !_serverUrls.contains(trimmedUrl)) { + _serverUrls.add(trimmedUrl) + saveUrls() + } + }, + onRemoveServerUrl = { url -> _serverUrls.remove(url); saveUrls() }, + providerName = _providerName.value, + onProviderNameChange = { _providerName.value = it; sharedPreferences.edit().putString(KEY_PROVIDER_NAME, it).apply() }, + currentStatus = _currentStatus.value, + logMessages = _logMessages.value, + isServiceRunning = _isServiceRunningState.value, + onStartStopClick = { toggleService() }, + onConfigureVoicesClick = { _showVoiceConfigDialog.value = true }, + onConfigureEnginesClick = { _showEngineConfigDialog.value = true } // NEW + ) + if (_showVoiceConfigDialog.value) { + VoiceConfigurationDialog(onDismiss = { _showVoiceConfigDialog.value = false }, starProviderService = starProviderService) + } + if (_showEngineConfigDialog.value) { + EngineConfigurationDialog(onDismiss = { _showEngineConfigDialog.value = false }, starProviderService = starProviderService) + } + } + } + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { requestNotificationPermission() } + } + + private fun saveUrls() { + sharedPreferences.edit().putStringSet(KEY_SERVER_URLS, _serverUrls.toSet()).apply() + } + + override fun onStart() { + super.onStart() + Intent(this, StarProviderService::class.java).also { intent -> + try { + bindService(intent, connection, Context.BIND_AUTO_CREATE) + } catch (e: SecurityException) { + Log.e("MainActivity", "Failed to bind to service", e) + _currentStatus.value = "Error: Cannot bind to service." + } + } + } + + override fun onStop() { + super.onStop() + if (isBound) { + serviceBinder?.unregisterStateListener(this) + serviceBinder?.unregisterLogListener(this) + unbindService(connection) + isBound = false + } + } + + private fun requestNotificationPermission() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + requestPermissionLauncher.launch(android.Manifest.permission.POST_NOTIFICATIONS) + } + } + + private fun startProviderService() { + saveUrls() // Ensure latest URLs are saved before starting + sharedPreferences.edit().putString(KEY_PROVIDER_NAME, _providerName.value).apply() + + // MODIFIED: Pass a list of URLs + val serviceIntent = Intent(this, StarProviderService::class.java).apply { + putStringArrayListExtra(StarProviderService.EXTRA_SERVER_URLS, ArrayList(_serverUrls)) + putExtra("PROVIDER_NAME", _providerName.value) + } + try { + ContextCompat.startForegroundService(this, serviceIntent) + if (!isBound) { + bindService(serviceIntent, connection, Context.BIND_AUTO_CREATE) + } + } catch (e: Exception) { + Log.e("MainActivity", "Error starting service", e) + _currentStatus.value = "Error: Could not start service. ${e.message}" + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S && e is SecurityException) { + _currentStatus.value = "Error: FG Service start restricted by OS." + } + } + } + + private fun stopProviderService() { + starProviderService?.stopServiceInternal() ?: run { + val serviceIntent = Intent(this, StarProviderService::class.java) + try { + stopService(serviceIntent) + Log.i("MainActivity", "stopService() called directly.") + } catch (e: Exception) { + Log.e("MainActivity", "Error calling stopService()", e) + } + } + if (!isBound) { + _currentStatus.value = "Status: Disconnected" + _isServiceRunningState.value = false + } + } + + private fun toggleService() { + if (_isServiceRunningState.value) { + stopProviderService() + } else { + startProviderService() + } + } +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun StarProviderScreen( + serverUrls: List, onAddServerUrl: (String) -> Unit, onRemoveServerUrl: (String) -> Unit, + providerName: String, onProviderNameChange: (String) -> Unit, + currentStatus: String, logMessages: String, isServiceRunning: Boolean, + onStartStopClick: () -> Unit, onConfigureVoicesClick: () -> Unit, onConfigureEnginesClick: () -> Unit +) { + val logScrollState = rememberScrollState() + val columnScrollState = rememberScrollState() + LaunchedEffect(logMessages) { logScrollState.animateScrollTo(logScrollState.maxValue) } + + Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) { + Column( + modifier = Modifier + .fillMaxSize() + .padding(16.dp) + .verticalScroll(columnScrollState), + horizontalAlignment = Alignment.CenterHorizontally + ) { + Text("STAR Android TTS Provider", style = MaterialTheme.typography.headlineSmall, modifier = Modifier.padding(bottom = 16.dp)) + + Text("Coagulator Hosts", style = MaterialTheme.typography.titleMedium, modifier = Modifier.fillMaxWidth()) + Spacer(Modifier.height(8.dp)) + Column(Modifier.fillMaxWidth().heightIn(max = 150.dp)) { + LazyColumn(modifier = Modifier.background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha=0.2f)).padding(horizontal = 8.dp).fillMaxWidth()) { + items(serverUrls, key = { it }) { url -> + Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.padding(vertical = 4.dp)) { + Text(url, modifier = Modifier.weight(1f)) + IconButton(onClick = { onRemoveServerUrl(url) }, modifier = Modifier.size(36.dp)) { + Icon(Icons.Default.Delete, contentDescription = "Remove host") + } + } + HorizontalDivider() + } + } + } + var newHostUrl by remember { mutableStateOf("ws://") } + val focusManager = LocalFocusManager.current + OutlinedTextField( + value = newHostUrl, onValueChange = { newHostUrl = it }, + label = { Text("Add new host URL") }, singleLine = true, + keyboardOptions = KeyboardOptions(keyboardType = KeyboardType.Uri, imeAction = ImeAction.Done), + keyboardActions = KeyboardActions(onDone = { onAddServerUrl(newHostUrl); newHostUrl="ws://"; focusManager.clearFocus() }), + modifier = Modifier.fillMaxWidth().padding(top=4.dp), + trailingIcon = { IconButton(onClick = { onAddServerUrl(newHostUrl); newHostUrl="ws://"; focusManager.clearFocus() }) { Icon(Icons.Default.Add, "Add Host") } } + ) + Spacer(modifier = Modifier.height(16.dp)) + + OutlinedTextField(value = providerName, onValueChange = onProviderNameChange, label = { Text("Provider Name") }, singleLine = true, modifier = Modifier.fillMaxWidth()) + Spacer(modifier = Modifier.height(16.dp)) + + Row(Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.SpaceBetween, verticalAlignment = Alignment.CenterVertically) { + Button(onClick = onStartStopClick, modifier = Modifier.weight(1f)) { + Text(if (isServiceRunning) "Stop Provider" else "Start Provider") + } + Spacer(Modifier.width(8.dp)) + IconButton(onClick = onConfigureEnginesClick) { Icon(Icons.Filled.Build, contentDescription = "Configure Engines") } + IconButton(onClick = onConfigureVoicesClick) { Icon(Icons.Filled.Settings, contentDescription = "Configure Voices") } + } + + Spacer(modifier = Modifier.height(16.dp)); Text(currentStatus, style = MaterialTheme.typography.bodyLarge, modifier = Modifier.fillMaxWidth()) + Spacer(modifier = Modifier.height(16.dp)); Text("Logs:", style = MaterialTheme.typography.titleSmall, modifier = Modifier.fillMaxWidth()) + Box(modifier = Modifier.fillMaxWidth().height(200.dp).background(MaterialTheme.colorScheme.surfaceVariant.copy(alpha = 0.3f)).padding(8.dp)) { + Text(text = logMessages, modifier = Modifier.fillMaxSize().verticalScroll(logScrollState), style = TextStyle(fontFamily = FontFamily.Monospace, fontSize = 12.sp)) + } + } + } +} + +@Composable +fun EngineConfigurationDialog(onDismiss: () -> Unit, starProviderService: StarProviderService?) { + var engineConfigItems by remember { mutableStateOf>(emptyList()) } + var isLoading by remember { mutableStateOf(true) } + + LaunchedEffect(starProviderService) { + isLoading = true + if (starProviderService != null) { + // This can be called even if the service isn't "running" (connected) yet, as engine discovery happens on create. + engineConfigItems = starProviderService.getSystemEnginesForConfiguration() + } + isLoading = false + } + + Dialog(onDismissRequest = onDismiss) { + Surface(modifier = Modifier.fillMaxWidth(0.95f).fillMaxHeight(0.85f), shape = MaterialTheme.shapes.medium, tonalElevation = AlertDialogDefaults.TonalElevation) { + Column(modifier = Modifier.padding(16.dp)) { + Text("Configure TTS Engines", style = MaterialTheme.typography.headlineSmall, modifier = Modifier.padding(bottom = 16.dp)) + if (isLoading) { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { CircularProgressIndicator() } + } else if (engineConfigItems.isEmpty()) { + Text("No TTS engines found or service not ready.", modifier = Modifier.align(Alignment.CenterHorizontally).padding(16.dp)) + } else { + LazyColumn(modifier = Modifier.weight(1f)) { + items(engineConfigItems, key = { it.packageName }) { item -> + Row(modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp), verticalAlignment = Alignment.CenterVertically) { + Column(modifier = Modifier.weight(1f)) { + Text(item.label, style = MaterialTheme.typography.bodyLarge) + Text(item.packageName, style = MaterialTheme.typography.bodySmall, color = MaterialTheme.colorScheme.onSurfaceVariant) + } + Spacer(modifier = Modifier.width(8.dp)) + Switch( + checked = item.isEnabled, + onCheckedChange = { newEnabled -> + engineConfigItems = engineConfigItems.map { + if (it.packageName == item.packageName) it.copy(isEnabled = newEnabled) else it + } + } + ) + } + HorizontalDivider() + } + } + } + Spacer(modifier = Modifier.height(16.dp)) + Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { + TextButton(onClick = onDismiss) { Text("Cancel") } + Spacer(modifier = Modifier.width(8.dp)) + Button(onClick = { + val configsToSave = engineConfigItems.associate { it.packageName to it.isEnabled } + starProviderService?.saveAndReloadEngineConfigs(configsToSave) + onDismiss() + }, enabled = !isLoading && engineConfigItems.isNotEmpty()) { + Text("Save & Apply") + } + } + } + } + } +} + + +data class VoiceConfigItem( + val id: String, // Composite ID format: "engineName:originalName" + val displayName: String, + var alias: String, + var isEnabled: Boolean, + val locale: String, + val isNetwork: Boolean +) + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun VoiceConfigurationDialog( + onDismiss: () -> Unit, + starProviderService: StarProviderService? +) { + // *** START OF FIX *** + // REMOVED the `if (starProviderService?.isRunning() != true)` check. + // The dialog should open if the service is bound, not necessarily "running". + // The isLoading state handles the rest. + + var voiceConfigItems by remember { mutableStateOf>(emptyList()) } + var isLoading by remember { mutableStateOf(true) } + + // Simplified the LaunchedEffect key. It only needs to know about the service instance. + LaunchedEffect(starProviderService) { + isLoading = true + if (starProviderService != null) { + val systemVoicesData = starProviderService.getSystemVoicesForConfiguration() + voiceConfigItems = systemVoicesData.map { dialogInfo -> + val engineShortName = dialogInfo.engineName.split('.').lastOrNull() ?: dialogInfo.engineName + VoiceConfigItem( + id = "${dialogInfo.engineName}:${dialogInfo.originalName}", + displayName = "${dialogInfo.originalName} (${dialogInfo.locale.toLanguageTag()}, Engine: $engineShortName)", + alias = dialogInfo.currentAlias, + isEnabled = dialogInfo.currentIsEnabled, + locale = dialogInfo.locale.toLanguageTag(), + isNetwork = dialogInfo.isNetwork + ) + } + } + isLoading = false + } + + Dialog(onDismissRequest = onDismiss) { + Surface(modifier = Modifier.fillMaxWidth(0.95f).fillMaxHeight(0.85f), shape = MaterialTheme.shapes.medium, tonalElevation = AlertDialogDefaults.TonalElevation) { + Column(modifier = Modifier.padding(16.dp)) { + Text("Configure Voices", style = MaterialTheme.typography.headlineSmall, modifier = Modifier.padding(bottom = 16.dp)) + if (isLoading) { + Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { CircularProgressIndicator() } + } else if (voiceConfigItems.isEmpty()) { + Text("No voices available. Check TTS engine configuration or logs.", modifier = Modifier.align(Alignment.CenterHorizontally).padding(16.dp)) + } else { + LazyColumn(modifier = Modifier.weight(1f)) { + items(voiceConfigItems, key = { it.id }) { item -> + VoiceConfigRow( + item = item, + onAliasChange = { newAlias -> voiceConfigItems = voiceConfigItems.map { if (it.id == item.id) it.copy(alias = newAlias) else it } }, + onEnabledChange = { newEnabled -> voiceConfigItems = voiceConfigItems.map { if (it.id == item.id) it.copy(isEnabled = newEnabled) else it } } + ) + HorizontalDivider() + } + } + } + Spacer(modifier = Modifier.height(16.dp)) + Row(modifier = Modifier.fillMaxWidth(), horizontalArrangement = Arrangement.End) { + TextButton(onClick = onDismiss) { Text("Cancel") } + Spacer(modifier = Modifier.width(8.dp)) + Button( + onClick = { + val configsToSave = voiceConfigItems.mapNotNull { item -> + val idParts = item.id.split(":", limit = 2) + if (idParts.size == 2) { + PersistedVoiceConfig(originalName = idParts[1], engineName = idParts[0], starLabel = item.alias, isEnabled = item.isEnabled) + } else { + Log.w("MainActivity", "Skipping invalid voice config item with ID: ${item.id}") + null + } + } + starProviderService?.savePersistedVoiceConfigs(configsToSave) + onDismiss() + }, + enabled = !isLoading && voiceConfigItems.isNotEmpty() + ) { Text("Save & Apply") } + } + } + } + } + // *** END OF FIX *** +} + +@OptIn(ExperimentalMaterial3Api::class) +@Composable +fun VoiceConfigRow(item: VoiceConfigItem, onAliasChange: (String) -> Unit, onEnabledChange: (Boolean) -> Unit) { + Row(modifier = Modifier.fillMaxWidth().padding(vertical = 8.dp), verticalAlignment = Alignment.CenterVertically) { + Column(modifier = Modifier.weight(1f)) { + Text(item.displayName, style = MaterialTheme.typography.bodyLarge) + OutlinedTextField( + value = item.alias, + onValueChange = onAliasChange, + label = { Text("STAR Label (Alias)") }, + singleLine = true, + modifier = Modifier.fillMaxWidth().padding(top = 4.dp) + ) + } + Spacer(modifier = Modifier.width(8.dp)) + Switch(checked = item.isEnabled, onCheckedChange = onEnabledChange) + } +} \ No newline at end of file diff --git a/provider/android/app/src/main/java/com/star/provider/starProviderService.kt b/provider/android/app/src/main/java/com/star/provider/starProviderService.kt new file mode 100644 index 0000000..8d03fec --- /dev/null +++ b/provider/android/app/src/main/java/com/star/provider/starProviderService.kt @@ -0,0 +1,785 @@ +package com.star.provider + +import android.app.Notification +import android.app.NotificationChannel +import android.app.NotificationManager +import android.app.PendingIntent +import android.app.Service +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import android.os.Binder +import android.os.Build +import android.os.Bundle +import android.os.Handler +import android.os.IBinder +import android.os.Looper +import android.speech.tts.TextToSpeech +import android.speech.tts.UtteranceProgressListener +import android.speech.tts.Voice +import android.util.Log +import androidx.core.app.NotificationCompat +import okhttp3.* +import okhttp3.Credentials +import okhttp3.HttpUrl.Companion.toHttpUrlOrNull +import okio.ByteString +import okio.ByteString.Companion.toByteString +import org.json.JSONArray +import org.json.JSONException +import org.json.JSONObject +import java.io.File +import java.io.FileOutputStream +import java.io.IOException +import java.nio.ByteBuffer +import java.nio.ByteOrder +import java.text.SimpleDateFormat +import java.util.Date +import java.util.Locale +import java.util.UUID +import java.util.concurrent.ConcurrentHashMap +import java.util.concurrent.CopyOnWriteArrayList +import java.util.concurrent.TimeUnit +import java.util.concurrent.atomic.AtomicInteger +import kotlin.math.pow +import com.star.provider.R + + +interface ServiceStateListener { + fun onStatusUpdate(status: String, isRunning: Boolean) +} + +interface ServiceLogListener { + fun onLogMessage(message: String) +} + +private data class CoagulatorConnection( + val hostUrl: String, + var webSocket: WebSocket? = null, + var status: String = "Idle", + var reconnectAttempts: Int = 0, + var isManuallyStopped: Boolean = false, + val handler: Handler = Handler(Looper.getMainLooper()), + val client: OkHttpClient +) + +data class PersistedVoiceConfig( + val originalName: String, + val engineName: String, + var starLabel: String, + var isEnabled: Boolean +) + +data class StarVoiceConfig( + val originalName: String, + val engineName: String, + val androidVoice: Voice, + var starLabel: String, + var isEnabled: Boolean = true, + val systemLocaleTag: String = androidVoice.locale.toLanguageTag(), + val systemIsNetwork: Boolean = androidVoice.isNetworkConnectionRequired +) + +data class DialogVoiceInfo( + val originalName: String, + val engineName: String, + val locale: Locale, + val isNetwork: Boolean, + val currentAlias: String, + val currentIsEnabled: Boolean +) + +data class DialogEngineInfo( + val packageName: String, + val label: String, + val isEnabled: Boolean +) + +class StarProviderService : Service() { + + private val binder = LocalBinder() + private val ttsEngines = mutableMapOf() + private val ttsInitializedEngines = mutableSetOf() + private var ttsDiscoveryInstance: TextToSpeech? = null + private var allEnginesDiscovered = false + private val engineLabels = mutableMapOf() + private var allSystemVoices: MutableList = mutableListOf() + private var activeStarVoices: Map = mapOf() + private val connections = ConcurrentHashMap() + private val synthesisQueue = ConcurrentHashMap() + private val utteranceContexts = ConcurrentHashMap() + private val NOTIFICATION_ID = 101 + private val CHANNEL_ID = "StarProviderServiceChannel" + private var providerNameInternal: String = "AndroidProvider" + private val providerRevision = 4 + private var currentStatus: String = "Service Idle" + private var isServiceCurrentlyRunning = false + private val canceledRequests = ConcurrentHashMap.newKeySet() + private var isManuallyStopped = false + private val stateListeners = CopyOnWriteArrayList() + private val logListeners = CopyOnWriteArrayList() + private lateinit var sharedPreferences: SharedPreferences + private val VOICE_CONFIG_PREF_KEY = "voice_configurations" + private val ENGINE_CONFIG_PREF_KEY = "engine_configurations" + private val LOG_FILE_NAME = "star_provider_service.log" + private val BACKUP_LOG_FILE_NAME = "star_provider_service.log.1" + private val MAX_LOG_SIZE_BYTES = 1 * 1024 * 1024 + private var logFile: File? = null + + private data class SynthesisRequest( + val starRequestId: String, + val text: String, + val voiceStarLabel: String, + val rate: Float, + val pitch: Float + ) + + inner class LocalBinder : Binder() { + fun getService(): StarProviderService = this@StarProviderService + fun registerStateListener(listener: ServiceStateListener) { + stateListeners.add(listener) + listener.onStatusUpdate(currentStatus, isServiceCurrentlyRunning) + } + fun unregisterStateListener(listener: ServiceStateListener) { stateListeners.remove(listener) } + fun registerLogListener(listener: ServiceLogListener) { logListeners.add(listener) } + fun unregisterLogListener(listener: ServiceLogListener) { logListeners.remove(listener) } + } + + override fun onBind(intent: Intent): IBinder = binder + + override fun onCreate() { + super.onCreate() + Log.d("StarProviderService", "onCreate") + sharedPreferences = getSharedPreferences("StarProviderPrefs", Context.MODE_PRIVATE) + initializeLogFile() + logToFile("Service onCreate") + ttsDiscoveryInstance = TextToSpeech(this) { status -> + if (status == TextToSpeech.SUCCESS) { + discoverAllSystemEnginesAndInitialize() + } else { + val errorMsg = "TTS Discovery Engine failed to initialize. Status: $status" + logToFile("CRITICAL: $errorMsg") + updateStatus(errorMsg, false); stopSelf() + } + } + createNotificationChannel() + } + + override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int { + Log.d("StarProviderService", "onStartCommand received") + isManuallyStopped = false + val hostUrls = intent?.getStringArrayListExtra(EXTRA_SERVER_URLS) + providerNameInternal = intent?.getStringExtra("PROVIDER_NAME") ?: "MyAndroidTTS" + + if (hostUrls.isNullOrEmpty()) { + val errorMsg = "Error: Server URLs are missing." + logToFile(errorMsg); updateStatus(errorMsg, false); stopSelf() + return START_NOT_STICKY + } + logToFile("Service starting with ${hostUrls.size} hosts: ${hostUrls.joinToString()}") + startForegroundService() + isServiceCurrentlyRunning = true + updateStatus("Service Starting, Initializing...", true) + + connections.clear() + hostUrls.forEach { url -> + val parseableUrl = url.replaceFirst("ws://", "http://", true).replaceFirst("wss://", "https://", true) + val httpUrl = parseableUrl.toHttpUrlOrNull() + if (httpUrl == null) { + logToActivity("Invalid host URL format: $url. Skipping.") + logToFile("ERROR: Invalid host URL format '$url'. Could not parse.") + return@forEach + } + val user = httpUrl.username + val pass = httpUrl.password + val clientBuilder = OkHttpClient.Builder().readTimeout(0, TimeUnit.MILLISECONDS).pingInterval(30, TimeUnit.SECONDS) + if (user.isNotBlank()) { + val credential = Credentials.basic(user, pass) + clientBuilder.authenticator { _, response -> response.request.newBuilder().header("Authorization", credential).build() } + } + connections[url] = CoagulatorConnection(hostUrl = url, client = clientBuilder.build()) + logToFile("Configured connection for: $url") + } + + if (connections.isEmpty()) { + val errorMsg = "No valid host URLs provided." + logToFile(errorMsg); updateStatus(errorMsg, false); stopSelf() + return START_NOT_STICKY + } + + if (isTtsReady()) { + connections.keys.forEach { connectWebSocket(it) } + } else { + logToFile("TTS not ready, connections will be attempted after initialization.") + } + return START_STICKY + } + + private fun startForegroundService() { + val notificationIntent = Intent(this, MainActivity::class.java) + val pendingIntentFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_UPDATE_CURRENT + val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, pendingIntentFlags) + val notification = NotificationCompat.Builder(this, CHANNEL_ID) + .setContentTitle("STAR Provider Active").setContentText("Initializing...") + .setSmallIcon(R.drawable.ic_stat_name).setContentIntent(pendingIntent) + .setOngoing(true).build() + startForeground(NOTIFICATION_ID, notification) + } + + private fun discoverAllSystemEnginesAndInitialize() { + logToFile("Starting initial discovery of all system TTS engines...") + val allSystemEngineInfos = ttsDiscoveryInstance?.engines ?: run { + updateStatus("Error: Could not query TTS engines.", false); stopSelf(); return + } + if (allSystemEngineInfos.isEmpty()) { + updateStatus("No TTS engines found on this device.", false); stopSelf(); return + } + engineLabels.clear() + allSystemEngineInfos.forEach { engineInfo -> engineLabels[engineInfo.name] = engineInfo.label } + allEnginesDiscovered = true + logToFile("Discovered ${engineLabels.size} total engines: ${engineLabels.values.joinToString()}") + initializeEnabledEngines() + } + + private fun initializeEnabledEngines(onComplete: (() -> Unit)? = null) { + logToFile("Initializing enabled engines...") + val enabledEngineConfigs = loadEngineConfigurations() + val enginesToInitialize = engineLabels.filter { (packageName, _) -> enabledEngineConfigs.getOrDefault(packageName, true) } + logToFile("Engines to be initialized: ${enginesToInitialize.values.joinToString()}") + + if (enginesToInitialize.isEmpty()) { + logToActivity("No engines are enabled.") + populateAvailableVoices() + onComplete?.invoke() + return + } + + val initializationCounter = AtomicInteger(enginesToInitialize.size) + enginesToInitialize.forEach { (enginePackageName, engineLabel) -> + try { + val ttsInstance = TextToSpeech(this, { status -> + if (status == TextToSpeech.SUCCESS) { + ttsInitializedEngines.add(enginePackageName) + ttsEngines[enginePackageName]?.setOnUtteranceProgressListener(StarUtteranceListener()) + logToFile("TTS Engine initialized successfully: $engineLabel") + } else { + logToFile("TTS Engine failed to initialize: $engineLabel, Status: $status") + } + if (initializationCounter.decrementAndGet() == 0) { + logToFile("All requested engines have finished initialization process.") + populateAvailableVoices() + onComplete?.invoke() + } + }, enginePackageName) + ttsEngines[enginePackageName] = ttsInstance + } catch (e: Exception) { + logToFile("Failed to instantiate TTS engine $engineLabel: ${e.message}") + if (initializationCounter.decrementAndGet() == 0) { + logToFile("All requested engines have finished initialization process (with errors).") + populateAvailableVoices() + onComplete?.invoke() + } + } + } + } + + fun saveAndReloadEngineConfigs(newConfigs: Map) { + // 1. Save the new configuration. This is now the single source of truth. + sharedPreferences.edit().putString(ENGINE_CONFIG_PREF_KEY, JSONObject(newConfigs as Map<*, *>).toString()).apply() + logToFile("Saved updated engine configurations. Performing full state refresh.") + logToActivity("Applying new engine configuration...") + + // 2. Define the action to take AFTER the new state is fully initialized. + val onRefreshComplete = { + logToActivity("Engine refresh complete. Repopulating voice list from active engines.") + populateAvailableVoices() // This will now use the new, correct list of running engines. + + // The original code re-registered on the existing connection, which the Python + // coagulator does not handle as a "refresh". We must force a disconnect/reconnect. + logToActivity("Forcing reconnection to servers to apply new engine configuration.") + val hostsToReconnect = connections.keys.toList() // Iterate over a copy + hostsToReconnect.forEach { hostUrl -> + connections[hostUrl]?.let { conn -> + conn.webSocket?.close(1000, "Re-registering new engine configuration") + conn.webSocket = null + conn.handler.removeCallbacksAndMessages(null) + conn.reconnectAttempts = 0 + logToFile("Force-reconnecting to $hostUrl to apply engine changes.") + connectWebSocket(hostUrl) + } + } + } + + // 3. SHUT DOWN ALL currently running TTS engines. This is the crucial "tear down" step. + // It ensures we start from a completely clean slate, preventing any state corruption. + logToFile("Shutting down all current TTS engines before re-initialization.") + // We iterate over a copy of the values to avoid concurrent modification issues. + ttsEngines.values.toList().forEach { engine -> + try { + // IMPORTANT: We do NOT clear engineLabels. This is the master list + // for the configuration dialog and must be preserved. + engine.shutdown() + } catch (e: Exception) { + logToFile("Error during engine shutdown: ${e.message}") + } + } + // Clear the maps/sets that track the RUNNING state. + ttsEngines.clear() + ttsInitializedEngines.clear() + logToFile("All running engines shut down and active state cleared.") + + // 4. Re-initialize from scratch using the new configuration we just saved. + // The `initializeEnabledEngines` function is perfect for this. We pass our + // final action as the completion handler. + logToFile("Starting re-initialization of enabled engines...") + initializeEnabledEngines(onComplete = onRefreshComplete) + } + + fun getSystemEnginesForConfiguration(): List { + if (!allEnginesDiscovered) return emptyList() + val persistedConfigs = loadEngineConfigurations() + return engineLabels.map { (packageName, label) -> + DialogEngineInfo(packageName, label, persistedConfigs.getOrDefault(packageName, true)) + }.sortedBy { it.label } + } + + private fun loadEngineConfigurations(): Map { + val jsonString = sharedPreferences.getString(ENGINE_CONFIG_PREF_KEY, null) + return if (jsonString != null) { + try { + val json = JSONObject(jsonString) + json.keys().asSequence().associateWith { key -> json.getBoolean(key) } + } catch (e: Exception) { + Log.e("StarProviderService", "Error parsing engine configurations", e); emptyMap() + } + } else { emptyMap() } + } + + fun getSystemVoicesForConfiguration(): List { + if (!isTtsReady() && ttsInitializedEngines.isEmpty()) return emptyList() + val persistedConfigs = loadVoiceConfigurations().associateBy { "${it.engineName}:${it.originalName}" } + return ttsInitializedEngines.flatMap { engineName -> + val tts = ttsEngines[engineName] ?: return@flatMap emptyList() + try { + tts.voices?.mapNotNull { voice -> + val configKey = "$engineName:${voice.name}" + val persisted = persistedConfigs[configKey] + val shortEngineName = getShortEngineName(engineName) + val defaultAlias = "${shortEngineName}_${voice.name}".replace(Regex("[^a-zA-Z0-9_\\-]"), "_") + DialogVoiceInfo(voice.name, engineName, voice.locale, voice.isNetworkConnectionRequired, + persisted?.starLabel ?: defaultAlias, persisted?.isEnabled ?: true) + } ?: emptyList() + } catch (e: Exception) { + Log.e("StarProviderService", "Error getting voices for engine $engineName: ${e.message}", e); emptyList() + } + } + } + + fun savePersistedVoiceConfigs(configs: List) { + sharedPreferences.edit().putString(VOICE_CONFIG_PREF_KEY, convertPersistedVoiceConfigListToJson(configs)).apply() + logToFile("Saved updated voice configurations from MainActivity.") + logToActivity("Applying new voice settings...") + + // First, update the service's internal list of what voices *should* be active. + populateAvailableVoices() + + // The original code re-registered on the existing connection. However, the Python + // coagulator does not clear the old voice list on re-registration; it only + // clears voices when a provider disconnects. + // The correct logic, to mimic the Python provider being restarted, is to + // force a disconnect and reconnect. This makes the coagulator drop the old + // voice list and receive a fresh one on the new connection. + + logToActivity("Forcing reconnection to servers to apply new voice list.") + val hostsToReconnect = connections.keys.toList() // Avoid ConcurrentModificationException by iterating over a copy. + hostsToReconnect.forEach { hostUrl -> + connections[hostUrl]?.let { conn -> + // Close the existing socket cleanly. + conn.webSocket?.close(1000, "Re-registering new voice configuration") + conn.webSocket = null // Ensure the connection is seen as closed immediately. + + // Clear any pending automatic reconnect tasks to avoid conflicts. + conn.handler.removeCallbacksAndMessages(null) + + // Reset the reconnect backoff counter for a clean slate. + conn.reconnectAttempts = 0 + + // Initiate a new connection attempt immediately. + logToFile("Force-reconnecting to $hostUrl to apply voice changes.") + connectWebSocket(hostUrl) + } + } + } + + private fun loadVoiceConfigurations(): List { + val jsonString = sharedPreferences.getString(VOICE_CONFIG_PREF_KEY, null) + return if (jsonString != null) { + try { parsePersistedVoiceConfigListFromJson(jsonString) + } catch (e: Exception) { Log.e("StarProviderService", "Error parsing voice configurations from JSON", e); emptyList() } + } else { emptyList() } + } + + private fun convertPersistedVoiceConfigListToJson(configs: List): String { + val jsonArray = JSONArray() + configs.forEach { config -> + val jsonObj = JSONObject() + jsonObj.put("originalName", config.originalName); jsonObj.put("engineName", config.engineName) + jsonObj.put("starLabel", config.starLabel); jsonObj.put("isEnabled", config.isEnabled) + jsonArray.put(jsonObj) + } + return jsonArray.toString() + } + + private fun parsePersistedVoiceConfigListFromJson(jsonString: String): List { + val configs = mutableListOf() + try { + val jsonArray = JSONArray(jsonString) + for (i in 0 until jsonArray.length()) { + val jsonObj = jsonArray.getJSONObject(i) + configs.add(PersistedVoiceConfig( + originalName = jsonObj.getString("originalName"), engineName = jsonObj.getString("engineName"), + starLabel = jsonObj.getString("starLabel"), isEnabled = jsonObj.getBoolean("isEnabled") + )) + } + } catch (e: JSONException) { Log.e("StarProviderService", "Manual JSON parsing error for voice configs: ${e.message}", e) } + return configs + } + + private fun getShortEngineName(engineName: String): String { + return when { + engineName.contains("google") -> "google" + engineName.contains("rhvoice") -> "rhvoice" + engineName.contains("espeak") -> "espeak" + engineName.contains("dectalk") -> "dectalk" + engineName.contains("samsung") -> "samsung" + else -> engineName.split(".").lastOrNull() ?: "eng" + } + } + + private fun populateAvailableVoices() { + allSystemVoices.clear() + val persistedVoiceConfigs = loadVoiceConfigurations().associateBy { "${it.engineName}:${it.originalName}" } + var voiceDetailsLog = "Populating available voices based on active engines...\n" + val activeEngines = ttsInitializedEngines.toList() + voiceDetailsLog += "Active initialized engines: ${activeEngines.joinToString { engineLabels[it] ?: it }}\n" + activeEngines.forEach { engineName -> + val tts = ttsEngines[engineName] ?: return@forEach + val engineLabel = engineLabels[engineName] ?: "Unknown" + try { + tts.voices?.forEach { voice -> + val configKey = "$engineName:${voice.name}" + val persistedConfig = persistedVoiceConfigs[configKey] + val shortEngineName = getShortEngineName(engineName) + val defaultStarLabel = "${shortEngineName}_${voice.name}".replace(Regex("[^a-zA-Z0-9_\\-]"), "_") + val starLabel = persistedConfig?.starLabel ?: defaultStarLabel + val isEnabled = persistedConfig?.isEnabled ?: true + val voiceConfig = StarVoiceConfig(originalName = voice.name, engineName = engineName, androidVoice = voice, starLabel = starLabel, isEnabled = isEnabled) + allSystemVoices.add(voiceConfig) + voiceDetailsLog += " Found voice: ${voice.name} (Engine: $engineLabel), STAR Label: ${voiceConfig.starLabel}, Enabled: ${voiceConfig.isEnabled}\n" + } + } catch (e: Exception) { + voiceDetailsLog += " Error populating voices for $engineName: ${e.message}\n" + } + } + val finalActiveVoices = mutableMapOf() + val usedLabels = mutableSetOf() + allSystemVoices.filter { it.isEnabled }.forEach { config -> + var currentLabel = config.starLabel; var counter = 1 + while(usedLabels.contains(currentLabel)) { currentLabel = "${config.starLabel}_${counter++}" } + usedLabels.add(currentLabel) + finalActiveVoices[currentLabel] = config.copy(starLabel = currentLabel) + } + activeStarVoices = finalActiveVoices + logToFile(voiceDetailsLog.trim()) + if (activeStarVoices.isEmpty()) { + logToActivity("Warning: No active TTS voices found or configured.") + } + updateCombinedStatus() + } + + private fun connectWebSocket(hostUrl: String) { + val connection = connections[hostUrl] + if (connection == null) { logToFile("Error: Attempted to connect to an unconfigured host: $hostUrl"); return } + if (connection.webSocket != null) { logToActivity("WebSocket for $hostUrl already connected or connecting."); return } + val connectMsg = "Attempting to connect to: $hostUrl (Attempt: ${connection.reconnectAttempts + 1})" + logToFile(connectMsg) + val request = Request.Builder().url(hostUrl).build() + connection.client.newWebSocket(request, StarWebSocketListener(hostUrl)) + connection.status = "Connecting... (Attempt ${connection.reconnectAttempts + 1})" + updateCombinedStatus() + } + + private fun scheduleReconnect(hostUrl: String) { + val connection = connections[hostUrl] ?: return + val maxReconnectAttempts = 10 + val initialReconnectDelayMs = 1000L + if (connection.isManuallyStopped || connection.reconnectAttempts >= maxReconnectAttempts) { + logToFile("Max reconnects for $hostUrl or manually stopped. Giving up.") + connection.status = "Disconnected (Max retries)"; updateCombinedStatus(); return + } + val delay = (initialReconnectDelayMs * 2.0.pow(connection.reconnectAttempts.toDouble())).toLong() + connection.reconnectAttempts++ + logToFile("Scheduling reconnect for $hostUrl in ${delay}ms.") + logToActivity("Connection to $hostUrl lost. Reconnecting in ${delay/1000}s...") + connection.status = "Reconnecting (Attempt ${connection.reconnectAttempts})..." + updateCombinedStatus() + connection.handler.postDelayed({ + if (!connection.isManuallyStopped) { + logToFile("Executing reconnect for $hostUrl.") + connectWebSocket(hostUrl) + } else { + logToFile("Reconnect for $hostUrl cancelled.") + } + }, delay) + } + + private fun registerWithCoagulator(webSocket: WebSocket) { + if (!isTtsReady() && activeStarVoices.isEmpty()) { + logToActivity("TTS not fully ready, but sending available voices (${activeStarVoices.size})") + } + val registrationPayload = JSONObject().apply { + put("provider", providerRevision) + put("provider_name", providerNameInternal) + put("voices", JSONArray(activeStarVoices.keys.toList())) + }.toString() + logToFile("TX Registration to ${webSocket.request().url}: $registrationPayload") + val sent = webSocket.send(registrationPayload) + if (sent) { logToActivity("Registration sent to ${webSocket.request().url.host}.") } + else { logToActivity("Failed to send registration to ${webSocket.request().url.host}.") } + } + + private inner class StarWebSocketListener(private val hostUrl: String) : WebSocketListener() { + override fun onOpen(webSocket: WebSocket, response: Response) { + val connection = connections[hostUrl] ?: return + connection.webSocket = webSocket; connection.reconnectAttempts = 0; connection.status = "Connected" + val msg = "WebSocket Connected to $hostUrl" + Log.i("StarProviderService", msg); logToActivity(msg); updateCombinedStatus(); registerWithCoagulator(webSocket) + } + override fun onMessage(webSocket: WebSocket, text: String) { + Log.d("StarProviderService", "RX Text from ${webSocket.request().url.host}: $text"); logToActivity("RX: $text") + try { + val json = JSONObject(text) + if (json.has("abort")) { + val requestIdToCancel = json.optString("abort"); if (requestIdToCancel.isNotEmpty()) { + canceledRequests.add(requestIdToCancel); logToActivity("Abort request for ID: $requestIdToCancel.") + }; return + } + if (!json.has("voice") || !json.has("text") || !json.has("id")) { + logToActivity("Invalid request (missing fields): $text"); return + } + handleSynthesisRequest(json.getString("voice"), json.getString("text"), json.getString("id"), + json.optDouble("rate", 1.0).toFloat(), json.optDouble("pitch", 1.0).toFloat(), webSocket) + } catch (e: JSONException) { logToActivity("Error parsing JSON from server: ${e.message}") } + } + override fun onClosing(webSocket: WebSocket, code: Int, reason: String) { + val msg = "WebSocket Closing for $hostUrl: $code / $reason" + Log.i("StarProviderService", msg); logToActivity(msg); cleanupWebSocket(hostUrl) + if (code != 1000 && !(connections[hostUrl]?.isManuallyStopped ?: false)) { scheduleReconnect(hostUrl) + } else { connections[hostUrl]?.status = "Disconnected"; updateCombinedStatus() } + } + override fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) { + val msg = "WebSocket Failure for $hostUrl: ${t.message}" + Log.e("StarProviderService", msg, t); logToActivity(msg); cleanupWebSocket(hostUrl) + if (!(connections[hostUrl]?.isManuallyStopped ?: false)) { scheduleReconnect(hostUrl) + } else { connections[hostUrl]?.status = "Disconnected (Failure)"; updateCombinedStatus() } + } + override fun onMessage(webSocket: WebSocket, bytes: ByteString) { val msg = "RX Binary from ${webSocket.request().url.host}: ${bytes.hex()}"; Log.d("StarProviderService", msg); logToActivity(msg) } + } + + private fun cleanupWebSocket(hostUrl: String) { + logToFile("Cleaning up WebSocket for $hostUrl.") + val connection = connections[hostUrl]; connection?.webSocket?.close(1000, "Client closing"); connection?.webSocket = null; updateCombinedStatus() + } + + private fun handleSynthesisRequest(voiceStarLabel: String, textToSpeak: String, starRequestId: String, rate: Float, pitch: Float, sourceSocket: WebSocket) { + logToFile("Handling synthesis ID: $starRequestId from ${sourceSocket.request().url.host}, Voice: $voiceStarLabel, Text: \"${textToSpeak.take(50)}...\"") + if (canceledRequests.contains(starRequestId)) { + canceledRequests.remove(starRequestId); logToActivity("Synthesis for ID $starRequestId canceled by client before starting.") + sendError(starRequestId, "Request canceled by client.", sourceSocket); return + } + if (!isTtsReady()) { sendError(starRequestId, "TTS not ready on Android provider for request $starRequestId.", sourceSocket); return } + val voiceConfig = activeStarVoices[voiceStarLabel] + if (voiceConfig == null) { + val errorMsg = "Voice '$voiceStarLabel' not found or not active. Active: ${activeStarVoices.keys.joinToString()}" + sendError(starRequestId, errorMsg, sourceSocket); logToActivity(errorMsg); return + } + val tts = ttsEngines[voiceConfig.engineName] + if (tts == null) { + val errorMsg = "TTS engine '${voiceConfig.engineName}' for voice '$voiceStarLabel' is not available or failed to initialize." + sendError(starRequestId, errorMsg, sourceSocket); logToActivity(errorMsg); return + } + val utteranceId = UUID.randomUUID().toString() + synthesisQueue[utteranceId] = SynthesisRequest(starRequestId, textToSpeak, voiceStarLabel, rate, pitch) + utteranceContexts[utteranceId] = sourceSocket + tts.voice = voiceConfig.androidVoice; tts.setSpeechRate(rate.coerceIn(0.1f, 4.0f)); tts.setPitch(pitch.coerceIn(0.1f, 4.0f)) + val tempAudioFile = File(cacheDir, "$utteranceId.wav") + logToActivity("Synthesizing for $starRequestId (utt: $utteranceId) using Engine: ${engineLabels[voiceConfig.engineName] ?: "Unknown"}, Voice: ${voiceConfig.androidVoice.name}") + val result = tts.synthesizeToFile(textToSpeak, Bundle(), tempAudioFile, utteranceId) + if (result != TextToSpeech.SUCCESS) { + val errorMsg = "TTS synthesizeToFile failed for $utteranceId (STAR ID: $starRequestId). Code: $result" + Log.e("StarProviderService", errorMsg); logToFile(errorMsg) + synthesisQueue.remove(utteranceId); utteranceContexts.remove(utteranceId) + sendError(starRequestId, "Android TTS synthesis command failed (code: $result).", sourceSocket) + tempAudioFile.delete() + } + } + + private inner class StarUtteranceListener : UtteranceProgressListener() { + override fun onStart(utteranceId: String?) { + Log.d("TTSListener", "Utterance started: $utteranceId") + synthesisQueue[utteranceId]?.let { logToActivity("TTS synthesis started for STAR ID: ${it.starRequestId} (Utt: $utteranceId)") } + } + override fun onDone(utteranceId: String?) { + Log.d("TTSListener", "Utterance done: $utteranceId") + val requestDetails = synthesisQueue.remove(utteranceId) + val sourceSocket = utteranceContexts.remove(utteranceId) + if (utteranceId != null && requestDetails != null && sourceSocket != null) { + if (canceledRequests.contains(requestDetails.starRequestId)) { + canceledRequests.remove(requestDetails.starRequestId) + logToActivity("Synthesis for ID ${requestDetails.starRequestId} completed but was canceled. Audio not sent.") + File(cacheDir, "$utteranceId.wav").delete(); return + } + val audioFile = File(cacheDir, "$utteranceId.wav") + if (audioFile.exists() && audioFile.length() > 0) { + logToActivity("TTS synthesis done for ${requestDetails.starRequestId}, sending audio (${audioFile.length()} bytes).") + sendAudioData(requestDetails.starRequestId, audioFile, sourceSocket) + } else { + sendError(requestDetails.starRequestId, "Synthesized audio file not found or was empty.", sourceSocket) + } + audioFile.delete() + } + } + override fun onError(utteranceId: String?, errorCode: Int) { + val errorDetail = ttsErrorToString(errorCode) + Log.e("TTSListener", "TTSListener: onError for $utteranceId, code: $errorCode ($errorDetail)") + handleTtsError(utteranceId, errorDetail) + } + private fun handleTtsError(utteranceId: String?, errorMessage: String) { + val requestDetails = synthesisQueue.remove(utteranceId) + val sourceSocket = utteranceContexts.remove(utteranceId) + if (utteranceId != null && requestDetails != null && sourceSocket != null) { + if (!canceledRequests.remove(requestDetails.starRequestId)) { + val detailedError = "Android TTS Error for ${requestDetails.starRequestId}: $errorMessage" + sendError(requestDetails.starRequestId, detailedError, sourceSocket) + } + } + File(cacheDir, "$utteranceId.wav").delete() + } + @Deprecated("deprecated", replaceWith = ReplaceWith("onError(utteranceId, errorCode)")) + override fun onError(utteranceId: String?) { onError(utteranceId, -1) } + private fun ttsErrorToString(errorCode: Int): String = when (errorCode) { + TextToSpeech.ERROR_SYNTHESIS -> "Synthesis error"; TextToSpeech.ERROR_SERVICE -> "Service error (TTS engine)" + TextToSpeech.ERROR_OUTPUT -> "Output error"; TextToSpeech.ERROR_NETWORK -> "Network error" + TextToSpeech.ERROR_NETWORK_TIMEOUT -> "Network timeout"; TextToSpeech.ERROR_INVALID_REQUEST -> "Invalid request" + TextToSpeech.ERROR_NOT_INSTALLED_YET -> "TTS data not installed yet"; else -> "Unknown TTS error ($errorCode)" + } + } + + private fun sendAudioData(starRequestId: String, audioFile: File, destinationSocket: WebSocket) { + val audioBytes = audioFile.readBytes() + val metadataJsonString = JSONObject().apply { put("id", starRequestId); put("extension", "wav") }.toString() + val metadataBytes = metadataJsonString.toByteArray(Charsets.UTF_8) + val metadataLength = metadataBytes.size.toShort() + val packetBuffer = ByteBuffer.allocate(2 + metadataBytes.size + audioBytes.size) + packetBuffer.order(ByteOrder.LITTLE_ENDIAN); packetBuffer.putShort(metadataLength); packetBuffer.put(metadataBytes); packetBuffer.put(audioBytes) + val combinedPacket = packetBuffer.array().toByteString(0, packetBuffer.position()) + val sent = destinationSocket.send(combinedPacket) + if (sent) logToActivity("Sent audio for $starRequestId to ${destinationSocket.request().url.host}") + else logToActivity("Failed to send audio packet for $starRequestId to ${destinationSocket.request().url.host}") + } + + private fun sendError(starRequestId: String, errorMessage: String, destinationSocket: WebSocket) { + val errorPayload = JSONObject().apply { + put("provider", providerRevision); put("id", starRequestId) + put("status", errorMessage.take(200)); put("abort", true) + }.toString() + logToFile("TX Error for $starRequestId to ${destinationSocket.request().url.host}: $errorMessage") + destinationSocket.send(errorPayload) + } + + private fun updateCombinedStatus() { + val connectedCount = connections.values.count { it.webSocket != null && it.status == "Connected" } + val totalCount = connections.size + val isAnyConnecting = connections.values.any { it.status.contains("Connecting") || it.status.contains("Reconnecting") } + val summary = if (totalCount > 0) "Connected to $connectedCount of $totalCount hosts. Voices: ${activeStarVoices.size}" + else "No hosts configured. Voices: ${activeStarVoices.size}" + val isRunning = connectedCount > 0 || isAnyConnecting + updateStatus(summary, isRunning) + } + + private fun updateStatus(newStatus: String, isRunning: Boolean) { + currentStatus = newStatus; isServiceCurrentlyRunning = isRunning + Log.i("StarProviderService", "Status Update: $newStatus, IsRunning: $isRunning") + updateNotification(newStatus); stateListeners.forEach { it.onStatusUpdate(newStatus, isRunning) } + } + + internal fun stopServiceInternal() { + isManuallyStopped = true + logToActivity("Service stop requested by MainActivity.") + connections.values.forEach { it.isManuallyStopped = true; it.handler.removeCallbacksAndMessages(null); cleanupWebSocket(it.hostUrl) } + connections.clear(); ttsEngines.values.forEach { try { it.stop() } catch (e: Exception) { /* ignore */ } } + stopForeground(STOP_FOREGROUND_REMOVE); stopSelf() + } + + override fun onDestroy() { + super.onDestroy() + isManuallyStopped = true; updateStatus("Service Stopped", false) + logToFile("Service onDestroy. Cleaning up all resources.") + ttsDiscoveryInstance?.shutdown() + ttsEngines.values.forEach { try { it.shutdown() } catch(e: Exception) { /* ignore */ } } + ttsEngines.clear(); ttsInitializedEngines.clear() + connections.values.forEach { it.handler.removeCallbacksAndMessages(null) } + connections.clear() + logToFile("--- Log session ended: ${getCurrentTimestamp()} ---", false) + stateListeners.clear(); logListeners.clear() + } + + companion object { const val EXTRA_SERVER_URLS = "com.star.provider.EXTRA_SERVER_URLS" } + private fun isTtsReady(): Boolean = ttsInitializedEngines.isNotEmpty() || activeStarVoices.isNotEmpty() + fun isRunning(): Boolean = isServiceCurrentlyRunning + fun requestCurrentStatus() { stateListeners.forEach { it.onStatusUpdate(currentStatus, isServiceCurrentlyRunning) } } + + private fun createNotificationChannel() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + val serviceChannel = NotificationChannel(CHANNEL_ID, "STAR Provider Service", NotificationManager.IMPORTANCE_LOW) + getSystemService(NotificationManager::class.java)?.createNotificationChannel(serviceChannel); + } + } + + private fun updateNotification(message: String) { + val notificationIntent = Intent(this, MainActivity::class.java) + val pendingIntentFlags = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT else PendingIntent.FLAG_UPDATE_CURRENT + val pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, pendingIntentFlags) + val notification = NotificationCompat.Builder(this, CHANNEL_ID) + .setContentTitle("STAR Provider").setContentText(message) + .setSmallIcon(R.drawable.ic_stat_name).setContentIntent(pendingIntent) + .setOngoing(true).setOnlyAlertOnce(true).build() + (getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager).notify(NOTIFICATION_ID, notification) + } + + private fun logToActivity(message: String) { Log.d("StarProviderServiceLog", message); logToFile(message); logListeners.forEach { it.onLogMessage(message) } } + + private fun initializeLogFile() { + try { + val logsDir = File(getExternalFilesDir(null), "logs"); if (!logsDir.exists()) logsDir.mkdirs() + logFile = File(logsDir, LOG_FILE_NAME); if (!logFile!!.exists()) { logFile!!.createNewFile() } + logToFile("--- Log session started: ${getCurrentTimestamp()} ---", false) + } catch (e: Exception) { Log.e("StarProviderService", "Error initializing log file", e); logFile = null } + } + + private fun getCurrentTimestamp(): String = SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.getDefault()).format(Date()) + + private fun logToFile(message: String, includeTimestamp: Boolean = true) { + if (logFile == null) initializeLogFile() + logFile?.let { file -> + try { + if (file.length() > MAX_LOG_SIZE_BYTES) { + val backupFile = File(file.parentFile, BACKUP_LOG_FILE_NAME); if (backupFile.exists()) backupFile.delete() + file.renameTo(backupFile); if (file.createNewFile()) { + FileOutputStream(file, true).bufferedWriter().use { it.append("${getCurrentTimestamp()} - Log file rotated.\n") } + } + } + FileOutputStream(file, true).bufferedWriter().use { it.append(if(includeTimestamp) "${getCurrentTimestamp()} - $message\n" else "$message\n") } + } catch (e: IOException) { Log.e("StarProviderService", "Error writing to log file", e) } + } + } +} \ No newline at end of file diff --git a/provider/android/app/src/main/java/com/star/provider/ui/theme/Color.kt b/provider/android/app/src/main/java/com/star/provider/ui/theme/Color.kt new file mode 100644 index 0000000..975c557 --- /dev/null +++ b/provider/android/app/src/main/java/com/star/provider/ui/theme/Color.kt @@ -0,0 +1,11 @@ +package com.star.provider.ui.theme + +import androidx.compose.ui.graphics.Color + +val Purple80 = Color(0xFFD0BCFF) +val PurpleGrey80 = Color(0xFFCCC2DC) +val Pink80 = Color(0xFFEFB8C8) + +val Purple40 = Color(0xFF6650a4) +val PurpleGrey40 = Color(0xFF625b71) +val Pink40 = Color(0xFF7D5260) \ No newline at end of file diff --git a/provider/android/app/src/main/java/com/star/provider/ui/theme/Theme.kt b/provider/android/app/src/main/java/com/star/provider/ui/theme/Theme.kt new file mode 100644 index 0000000..900d590 --- /dev/null +++ b/provider/android/app/src/main/java/com/star/provider/ui/theme/Theme.kt @@ -0,0 +1,58 @@ +package com.star.provider.ui.theme + +import android.app.Activity +import android.os.Build +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.platform.LocalContext + +private val DarkColorScheme = darkColorScheme( + primary = Purple80, + secondary = PurpleGrey80, + tertiary = Pink80 +) + +private val LightColorScheme = lightColorScheme( + primary = Purple40, + secondary = PurpleGrey40, + tertiary = Pink40 + + /* Other default colors to override + background = Color(0xFFFFFBFE), + surface = Color(0xFFFFFBFE), + onPrimary = Color.White, + onSecondary = Color.White, + onTertiary = Color.White, + onBackground = Color(0xFF1C1B1F), + onSurface = Color(0xFF1C1B1F), + */ +) + +@Composable +fun StarProviderTheme( + darkTheme: Boolean = isSystemInDarkTheme(), + // Dynamic color is available on Android 12+ + dynamicColor: Boolean = true, + content: @Composable () -> Unit +) { + val colorScheme = when { + dynamicColor && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S -> { + val context = LocalContext.current + if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context) + } + + darkTheme -> DarkColorScheme + else -> LightColorScheme + } + + MaterialTheme( + colorScheme = colorScheme, + typography = Typography, + content = content + ) +} \ No newline at end of file diff --git a/provider/android/app/src/main/java/com/star/provider/ui/theme/Type.kt b/provider/android/app/src/main/java/com/star/provider/ui/theme/Type.kt new file mode 100644 index 0000000..3119680 --- /dev/null +++ b/provider/android/app/src/main/java/com/star/provider/ui/theme/Type.kt @@ -0,0 +1,34 @@ +package com.star.provider.ui.theme + +import androidx.compose.material3.Typography +import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.text.font.FontFamily +import androidx.compose.ui.text.font.FontWeight +import androidx.compose.ui.unit.sp + +// Set of Material typography styles to start with +val Typography = Typography( + bodyLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 16.sp, + lineHeight = 24.sp, + letterSpacing = 0.5.sp + ) + /* Other default text styles to override + titleLarge = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Normal, + fontSize = 22.sp, + lineHeight = 28.sp, + letterSpacing = 0.sp + ), + labelSmall = TextStyle( + fontFamily = FontFamily.Default, + fontWeight = FontWeight.Medium, + fontSize = 11.sp, + lineHeight = 16.sp, + letterSpacing = 0.5.sp + ) + */ +) \ No newline at end of file diff --git a/provider/android/app/src/main/res/drawable/ic_launcher_background.xml b/provider/android/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/provider/android/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/provider/android/app/src/main/res/drawable/ic_launcher_foreground.xml b/provider/android/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/provider/android/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/provider/android/app/src/main/res/drawable/ic_stat_name.xml b/provider/android/app/src/main/res/drawable/ic_stat_name.xml new file mode 100644 index 0000000..1670c07 --- /dev/null +++ b/provider/android/app/src/main/res/drawable/ic_stat_name.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/provider/android/app/src/main/res/drawable/ic_voice_config.xml b/provider/android/app/src/main/res/drawable/ic_voice_config.xml new file mode 100644 index 0000000..1670c07 --- /dev/null +++ b/provider/android/app/src/main/res/drawable/ic_voice_config.xml @@ -0,0 +1,12 @@ + + + + + \ No newline at end of file diff --git a/provider/android/app/src/main/res/mipmap-anydpi/ic_launcher.xml b/provider/android/app/src/main/res/mipmap-anydpi/ic_launcher.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/provider/android/app/src/main/res/mipmap-anydpi/ic_launcher.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/provider/android/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml b/provider/android/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml new file mode 100644 index 0000000..6f3b755 --- /dev/null +++ b/provider/android/app/src/main/res/mipmap-anydpi/ic_launcher_round.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/provider/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp b/provider/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp new file mode 100644 index 0000000..c209e78 Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-hdpi/ic_launcher.webp differ diff --git a/provider/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp b/provider/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp new file mode 100644 index 0000000..b2dfe3d Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp differ diff --git a/provider/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp b/provider/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp new file mode 100644 index 0000000..4f0f1d6 Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-mdpi/ic_launcher.webp differ diff --git a/provider/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp b/provider/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp new file mode 100644 index 0000000..62b611d Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp differ diff --git a/provider/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp b/provider/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp new file mode 100644 index 0000000..948a307 Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-xhdpi/ic_launcher.webp differ diff --git a/provider/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp b/provider/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..1b9a695 Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp differ diff --git a/provider/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp b/provider/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp new file mode 100644 index 0000000..28d4b77 Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp differ diff --git a/provider/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp b/provider/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9287f50 Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp differ diff --git a/provider/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp b/provider/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp new file mode 100644 index 0000000..aa7d642 Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp differ diff --git a/provider/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp b/provider/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp new file mode 100644 index 0000000..9126ae3 Binary files /dev/null and b/provider/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp differ diff --git a/provider/android/app/src/main/res/values/colors.xml b/provider/android/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..f8c6127 --- /dev/null +++ b/provider/android/app/src/main/res/values/colors.xml @@ -0,0 +1,10 @@ + + + #FFBB86FC + #FF6200EE + #FF3700B3 + #FF03DAC5 + #FF018786 + #FF000000 + #FFFFFFFF + \ No newline at end of file diff --git a/provider/android/app/src/main/res/values/strings.xml b/provider/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..867e083 --- /dev/null +++ b/provider/android/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + star provider + \ No newline at end of file diff --git a/provider/android/app/src/main/res/values/themes.xml b/provider/android/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..e65b4e1 --- /dev/null +++ b/provider/android/app/src/main/res/values/themes.xml @@ -0,0 +1,5 @@ + + + +