init
This commit is contained in:
commit
a4c68ca9e2
76 changed files with 2737 additions and 0 deletions
2
android/app/.gitignore
vendored
Normal file
2
android/app/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
/build
|
||||
google-services.json
|
||||
103
android/app/build.gradle.kts
Normal file
103
android/app/build.gradle.kts
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
plugins {
|
||||
alias(libs.plugins.androidApplication)
|
||||
alias(libs.plugins.jetbrainsKotlinAndroid)
|
||||
alias(libs.plugins.googleServices)
|
||||
alias(libs.plugins.serialization)
|
||||
}
|
||||
|
||||
// custom properties
|
||||
val applicationIdArgument = project.findProperty("applicationId")?.toString()
|
||||
val applicationVersionCodeArgument = project.findProperty("versionCode")?.toString()?.toIntOrNull()
|
||||
val baseUrlArgument = System.getenv("PNS_BASE_URL") ?: "http://127.0.0.1:8080/"
|
||||
|
||||
android {
|
||||
namespace = applicationIdArgument ?: "org.fnives.android.servernotifications"
|
||||
compileSdk = 34
|
||||
|
||||
defaultConfig {
|
||||
applicationId = applicationIdArgument ?: "org.fnives.android.servernotifications"
|
||||
minSdk = 29
|
||||
targetSdk = 34
|
||||
versionCode = applicationVersionCodeArgument ?: 1
|
||||
versionName = "1.0"
|
||||
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
}
|
||||
|
||||
buildConfigField("String", "BASE_URL", "\"$baseUrlArgument\"")
|
||||
}
|
||||
|
||||
signingConfigs {
|
||||
with(maybeCreate("debug")) {
|
||||
storeFile = file("debug.keystore")
|
||||
storePassword = "android"
|
||||
keyAlias = "androiddebugkey"
|
||||
keyPassword = "android"
|
||||
}
|
||||
with(maybeCreate("release")) {
|
||||
storeFile = file(System.getenv("PNS_KEYSTORE") ?: "debug.keystore")
|
||||
keyAlias = System.getenv("PNS_KEY") ?: ""
|
||||
keyPassword = System.getenv("PNS_KEY_PASS") ?: ""
|
||||
storePassword = System.getenv("PNS_PASS") ?: ""
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
signingConfig = signingConfigs.getByName("release")
|
||||
isMinifyEnabled = true
|
||||
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
|
||||
buildConfig = true
|
||||
}
|
||||
composeOptions {
|
||||
kotlinCompilerExtensionVersion = "1.5.1"
|
||||
}
|
||||
packaging {
|
||||
resources {
|
||||
excludes += "/META-INF/{AL2.0,LGPL2.1}"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.lifecycle.runtime.ktx)
|
||||
implementation(libs.androidx.activity.compose)
|
||||
implementation(platform(libs.androidx.compose.bom))
|
||||
implementation(libs.androidx.ui)
|
||||
implementation(libs.androidx.ui.graphics)
|
||||
implementation(libs.androidx.ui.tooling.preview)
|
||||
implementation(libs.androidx.material3)
|
||||
implementation(libs.androidx.fragment)
|
||||
implementation(platform(libs.firebase.bom))
|
||||
implementation(libs.firebase.messaging)
|
||||
implementation(libs.serialization.json)
|
||||
|
||||
testImplementation(libs.junit)
|
||||
|
||||
androidTestImplementation(libs.androidx.junit)
|
||||
androidTestImplementation(libs.androidx.espresso.core)
|
||||
androidTestImplementation(platform(libs.androidx.compose.bom))
|
||||
androidTestImplementation(libs.androidx.ui.test.junit4)
|
||||
|
||||
debugImplementation(libs.androidx.ui.tooling)
|
||||
debugImplementation(libs.androidx.ui.test.manifest)
|
||||
}
|
||||
BIN
android/app/debug.keystore
Normal file
BIN
android/app/debug.keystore
Normal file
Binary file not shown.
21
android/app/proguard-rules.pro
vendored
Normal file
21
android/app/proguard-rules.pro
vendored
Normal file
|
|
@ -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
|
||||
|
|
@ -0,0 +1,24 @@
|
|||
package org.fnives.android.servernotifications
|
||||
|
||||
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("org.fnives.android.servernotifications", appContext.packageName)
|
||||
}
|
||||
}
|
||||
39
android/app/src/main/AndroidManifest.xml
Normal file
39
android/app/src/main/AndroidManifest.xml
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
<?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.INTERNET" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:dataExtractionRules="@xml/data_extraction_rules"
|
||||
android:fullBackupContent="@xml/backup_rules"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.ServerNotifications"
|
||||
android:usesCleartextTraffic="true"
|
||||
tools:targetApi="31">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleInstance"
|
||||
android:theme="@style/Theme.ServerNotifications">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name=".FirebaseMessages"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.google.firebase.MESSAGING_EVENT" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
|
@ -0,0 +1,155 @@
|
|||
package org.fnives.android.servernotifications
|
||||
|
||||
import android.app.NotificationChannel
|
||||
import android.app.NotificationManager
|
||||
import android.app.PendingIntent
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.util.Log
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import com.google.firebase.messaging.FirebaseMessagingService
|
||||
import com.google.firebase.messaging.RemoteMessage
|
||||
import java.time.Instant
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import org.fnives.android.servernotifications.message.DecryptMessage
|
||||
import org.fnives.android.servernotifications.message.EncryptedMessage
|
||||
import org.fnives.android.servernotifications.message.Message
|
||||
import org.fnives.android.servernotifications.message.MessageStorage
|
||||
import org.fnives.android.servernotifications.message.Priority
|
||||
import org.fnives.android.servernotifications.message.Priority.High
|
||||
import org.fnives.android.servernotifications.message.Priority.Low
|
||||
import org.fnives.android.servernotifications.message.Priority.Medium
|
||||
import org.fnives.android.servernotifications.message.Priority.Undefined
|
||||
import org.fnives.android.servernotifications.message.PriorityOf
|
||||
|
||||
class FirebaseMessages : FirebaseMessagingService() {
|
||||
|
||||
private val decryptMessage by lazy { DecryptMessage(this) }
|
||||
private val messageStorage by lazy { MessageStorage(this) }
|
||||
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
|
||||
|
||||
override fun onNewToken(token: String) {
|
||||
super.onNewToken(token)
|
||||
showNotification(
|
||||
Message(
|
||||
priority = High,
|
||||
serviceName = "PN Token has changed!",
|
||||
timestamp = Instant.now(),
|
||||
message = "",
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
override fun onMessageSent(msgId: String) {
|
||||
super.onMessageSent(msgId)
|
||||
}
|
||||
|
||||
override fun onMessageReceived(remoteMessage: RemoteMessage) {
|
||||
super.onMessageReceived(remoteMessage)
|
||||
println("received message")
|
||||
val sessionKey = remoteMessage.data["session_key"]
|
||||
val iv = remoteMessage.data["iv"]
|
||||
val messageData = remoteMessage.data["message"]
|
||||
val priority = PriorityOf(remoteMessage.data["priority"])
|
||||
val serviceName = remoteMessage.data["service"] ?: "Undefined"
|
||||
|
||||
val encryptedMessage = EncryptedMessage(
|
||||
iv = iv ?: return log("IV not found in message"),
|
||||
sessionKey = sessionKey ?: return log("SessionKey not found in message"),
|
||||
data = messageData ?: return log("MessageData not found in message"),
|
||||
)
|
||||
|
||||
coroutineScope.launch {
|
||||
val decrypted = decryptMessage.decrypt(encryptedMessage) ?: return@launch
|
||||
val message = Message(
|
||||
message = decrypted,
|
||||
priority = priority,
|
||||
serviceName = serviceName,
|
||||
timestamp = Instant.now()
|
||||
)
|
||||
messageStorage.addMessage(message)
|
||||
showNotification(message)
|
||||
}
|
||||
}
|
||||
|
||||
private fun showNotification(message: Message) {
|
||||
val importance = when (message.priority) {
|
||||
High -> NotificationCompat.PRIORITY_HIGH
|
||||
Medium -> NotificationCompat.PRIORITY_DEFAULT
|
||||
Low -> NotificationCompat.PRIORITY_LOW
|
||||
Undefined -> NotificationCompat.PRIORITY_DEFAULT
|
||||
}
|
||||
showNotification(
|
||||
importance = importance,
|
||||
channelId = message.priority.getChannelId(),
|
||||
title = "${message.priority.iconText()} ${message.serviceName}",
|
||||
id = message.hashCode()
|
||||
)
|
||||
}
|
||||
|
||||
private fun Priority.getChannelId(): String {
|
||||
val importance = when (this) {
|
||||
High -> NotificationManager.IMPORTANCE_HIGH
|
||||
Medium -> NotificationManager.IMPORTANCE_DEFAULT
|
||||
Low -> NotificationManager.IMPORTANCE_LOW
|
||||
Undefined -> NotificationManager.IMPORTANCE_DEFAULT
|
||||
}
|
||||
createChannel(
|
||||
name = name,
|
||||
description = "$name priority status updates from server",
|
||||
importance = importance,
|
||||
id = name
|
||||
)
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
private fun showNotification(
|
||||
importance: Int, title: String, channelId: String, id: Int,
|
||||
intent: Intent = Intent(this, MainActivity::class.java),
|
||||
) {
|
||||
val builder = NotificationCompat.Builder(this, channelId)
|
||||
.setSmallIcon(R.drawable.ic_server)
|
||||
.setContentTitle(title)
|
||||
.setPriority(importance)
|
||||
.setContentIntent(
|
||||
PendingIntent.getActivity(
|
||||
this, 0, intent, PendingIntent.FLAG_ONE_SHOT or PendingIntent.FLAG_IMMUTABLE
|
||||
)
|
||||
)
|
||||
.setAutoCancel(true)
|
||||
|
||||
if (ContextCompat.checkSelfPermission(
|
||||
this,
|
||||
android.Manifest.permission.POST_NOTIFICATIONS
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
) {
|
||||
NotificationManagerCompat.from(this).notify(id, builder.build())
|
||||
}
|
||||
}
|
||||
|
||||
private fun createChannel(
|
||||
name: String,
|
||||
description: String,
|
||||
id: String,
|
||||
importance: Int = NotificationManager.IMPORTANCE_DEFAULT
|
||||
) {
|
||||
val channel = NotificationChannel(id, name, importance).apply {
|
||||
this.description = description
|
||||
}
|
||||
val notificationManager =
|
||||
getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notificationManager.createNotificationChannel(channel)
|
||||
}
|
||||
|
||||
private fun log(message: String) {
|
||||
Log.d("FirebaseMessages", message)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,249 @@
|
|||
package org.fnives.android.servernotifications
|
||||
|
||||
import android.Manifest
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.widget.Space
|
||||
import androidx.activity.ComponentActivity
|
||||
import androidx.activity.compose.BackHandler
|
||||
import androidx.activity.compose.setContent
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.height
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.foundation.text.KeyboardActions
|
||||
import androidx.compose.foundation.text.KeyboardOptions
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.LocalTextStyle
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
import androidx.compose.material3.TextField
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.rememberCoroutineScope
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.input.ImeAction
|
||||
import androidx.compose.ui.text.input.KeyboardCapitalization
|
||||
import androidx.compose.ui.unit.dp
|
||||
import androidx.core.app.ActivityCompat
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
import java.util.Locale
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.launch
|
||||
import org.fnives.android.servernotifications.message.MessageStorage
|
||||
import org.fnives.android.servernotifications.message.Priority
|
||||
import org.fnives.android.servernotifications.message.Priority.High
|
||||
import org.fnives.android.servernotifications.message.Priority.Low
|
||||
import org.fnives.android.servernotifications.message.Priority.Medium
|
||||
import org.fnives.android.servernotifications.message.Priority.Undefined
|
||||
import org.fnives.android.servernotifications.token.TokenWebView
|
||||
import org.fnives.android.servernotifications.ui.theme.ServerNotificationsTheme
|
||||
import org.fnives.android.servernotifications.url.UrlStorage
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
|
||||
private val grantedEventFlow = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
|
||||
val notificationPermission = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
Manifest.permission.POST_NOTIFICATIONS
|
||||
} else {
|
||||
null
|
||||
}
|
||||
private val grantedFlow = grantedEventFlow.onStart { emit(Unit) }
|
||||
.map {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
ActivityCompat.checkSelfPermission(
|
||||
this,
|
||||
notificationPermission!!
|
||||
) == PackageManager.PERMISSION_GRANTED
|
||||
} else {
|
||||
true
|
||||
}
|
||||
}
|
||||
private val requestPermissionLauncher = registerForActivityResult(
|
||||
ActivityResultContracts.RequestPermission(),
|
||||
) { _: Boolean ->
|
||||
println(grantedEventFlow.tryEmit(Unit))
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
val messageStorage = MessageStorage(this)
|
||||
val urlStorage = UrlStorage(this)
|
||||
val formatter = DateTimeFormatter.ofPattern("MMM d yyyy hh:mm a")
|
||||
.withLocale(Locale.getDefault())
|
||||
.withZone(ZoneId.of("UTC"))
|
||||
setContent {
|
||||
ServerNotificationsTheme {
|
||||
Surface(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
color = MaterialTheme.colorScheme.background
|
||||
) {
|
||||
var navigationState by remember { mutableStateOf(Navigation.Home) }
|
||||
BackHandler(navigationState != Navigation.Home) {
|
||||
navigationState = Navigation.Home
|
||||
}
|
||||
|
||||
when (navigationState) {
|
||||
Navigation.Administration -> {
|
||||
TokenWebView(url = urlStorage.current)
|
||||
}
|
||||
|
||||
Navigation.Home -> {
|
||||
val grantedState by grantedFlow.collectAsState(initial = null)
|
||||
if (grantedState == true) {
|
||||
val scope = rememberCoroutineScope()
|
||||
Column {
|
||||
AdministrationNotice(
|
||||
onShowRegistration = {
|
||||
navigationState = Navigation.Administration
|
||||
},
|
||||
onShowChangeUrl = {
|
||||
navigationState = Navigation.ChangeURL
|
||||
},
|
||||
onClearLogs = { scope.launch { messageStorage.clear() } })
|
||||
Logs(messageStorage, formatter)
|
||||
}
|
||||
} else if (grantedState == false) {
|
||||
NoPermission()
|
||||
}
|
||||
}
|
||||
|
||||
Navigation.ChangeURL -> {
|
||||
ChangeURL(urlStorage)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun NoPermission() {
|
||||
Box(modifier = Modifier.fillMaxSize()) {
|
||||
Button(
|
||||
modifier = Modifier.align(Alignment.Center),
|
||||
onClick = {
|
||||
requestPermissionLauncher.launch(notificationPermission)
|
||||
}) {
|
||||
Text(text = "Grant notification permission")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun AdministrationNotice(
|
||||
onShowRegistration: () -> Unit,
|
||||
onShowChangeUrl: () -> Unit,
|
||||
onClearLogs: () -> Unit,
|
||||
) {
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
.padding(16.dp), Arrangement.Center
|
||||
) {
|
||||
Row {
|
||||
Button(
|
||||
onClick = { onShowRegistration() },
|
||||
) {
|
||||
Text(text = "Administration")
|
||||
}
|
||||
Spacer(modifier = Modifier.width(16.dp))
|
||||
Button(
|
||||
onClick = { onShowChangeUrl() },
|
||||
) {
|
||||
Text(text = "Change URL")
|
||||
}
|
||||
}
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Button(
|
||||
onClick = { onClearLogs() }) {
|
||||
Text(text = "Clear logs")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Logs(messageStorage: MessageStorage, formatter: DateTimeFormatter) {
|
||||
val messages by messageStorage.messages.collectAsState(initial = listOf())
|
||||
LazyColumn {
|
||||
messages.forEach {
|
||||
item {
|
||||
Text(
|
||||
modifier = Modifier.padding(horizontal = 24.dp, vertical = 4.dp),
|
||||
text = "${it.priority.iconText()} ${it.serviceName}: ${it.message} at ${
|
||||
formatter.format(
|
||||
it.timestamp
|
||||
)
|
||||
}"
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@Composable
|
||||
fun ChangeURL(urlStorage: UrlStorage) {
|
||||
val current by urlStorage.currentUrl.collectAsState(initial = "")
|
||||
val options by urlStorage.urlOptions.collectAsState(initial = emptySet())
|
||||
var overwrite by remember { mutableStateOf("") }
|
||||
val keyboardOptions = remember{KeyboardOptions.Default.copy(capitalization = KeyboardCapitalization.None, imeAction = ImeAction.Done)}
|
||||
Column {
|
||||
Text(text = "Current", style = MaterialTheme.typography.labelMedium)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
Text(text = current, style = MaterialTheme.typography.bodyLarge)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(text = "Overwrite", style = MaterialTheme.typography.labelMedium)
|
||||
Spacer(modifier = Modifier.height(4.dp))
|
||||
TextField(
|
||||
overwrite,
|
||||
textStyle = MaterialTheme.typography.bodyLarge,
|
||||
onValueChange = { overwrite = it },
|
||||
keyboardActions = KeyboardActions(onDone = {
|
||||
urlStorage.selectedUrl(overwrite)
|
||||
defaultKeyboardAction(ImeAction.Done)
|
||||
}),
|
||||
keyboardOptions = keyboardOptions
|
||||
)
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
Text(text = "Recent", style = MaterialTheme.typography.labelMedium)
|
||||
options.forEach {
|
||||
Button(onClick = {
|
||||
urlStorage.selectedUrl(it)
|
||||
}) {
|
||||
Text(text = it, style = MaterialTheme.typography.bodyMedium)
|
||||
}
|
||||
Spacer(modifier = Modifier.height(8.dp))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Priority.iconText(): String {
|
||||
return when (this) {
|
||||
High -> "\uD83D\uDEA8"
|
||||
Medium -> "⚠\uFE0F"
|
||||
Low -> "ℹ\uFE0F"
|
||||
Undefined -> "\uD83E\uDD14"
|
||||
}
|
||||
}
|
||||
|
||||
enum class Navigation {
|
||||
Administration, Home, ChangeURL
|
||||
}
|
||||
|
|
@ -0,0 +1,102 @@
|
|||
package org.fnives.android.servernotifications.message
|
||||
|
||||
import android.content.Context
|
||||
import org.fnives.android.servernotifications.BuildConfig
|
||||
import java.io.File
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.security.KeyFactory
|
||||
import java.security.KeyPair
|
||||
import java.security.KeyPairGenerator
|
||||
import java.security.spec.PKCS8EncodedKeySpec
|
||||
import java.security.spec.X509EncodedKeySpec
|
||||
import javax.crypto.Cipher
|
||||
import javax.crypto.spec.IvParameterSpec
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
import kotlin.io.encoding.Base64
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
|
||||
|
||||
interface DecryptMessage {
|
||||
|
||||
fun decrypt(message: EncryptedMessage): String?
|
||||
}
|
||||
|
||||
fun DecryptMessage(context: Context): DecryptMessage {
|
||||
return DecryptMessageImpl(getKeyPair(context))
|
||||
}
|
||||
|
||||
fun getKeyPair(context: Context): KeyPair {
|
||||
val publicKeyFile = File(context.filesDir, "key.pub")
|
||||
val privateKeyFile = File(context.filesDir, "key.rsa")
|
||||
val publicKeyBytes = if (publicKeyFile.exists()) publicKeyFile.readBytes() else ByteArray(0)
|
||||
val privateKeyBytes = if (privateKeyFile.exists()) privateKeyFile.readBytes() else ByteArray(0)
|
||||
|
||||
val keyPair: KeyPair
|
||||
if (publicKeyBytes.isEmpty() || privateKeyBytes.isEmpty()) {
|
||||
keyPair = DecryptMessageImpl.generateKeyPair()
|
||||
publicKeyFile.writeBytes(keyPair.public.encoded)
|
||||
privateKeyFile.writeBytes(keyPair.private.encoded)
|
||||
} else {
|
||||
val publicKey =
|
||||
KeyFactory.getInstance("RSA").generatePublic(X509EncodedKeySpec(publicKeyBytes))
|
||||
val privateKey =
|
||||
KeyFactory.getInstance("RSA").generatePrivate(PKCS8EncodedKeySpec(privateKeyBytes))
|
||||
|
||||
keyPair = KeyPair(publicKey, privateKey)
|
||||
}
|
||||
|
||||
return keyPair
|
||||
}
|
||||
|
||||
class DecryptMessageImpl(private val keyPair: KeyPair) : DecryptMessage {
|
||||
|
||||
//from Crypto.PublicKey import RSA
|
||||
//from Crypto.Cipher import AES, PKCS1_OAEP
|
||||
//
|
||||
//private_key = RSA.import_key(open("private.pem").read())
|
||||
//
|
||||
//with open("encrypted_data.bin", "rb") as f:
|
||||
// enc_session_key = f.read(private_key.size_in_bytes())
|
||||
// nonce = f.read(16)
|
||||
// tag = f.read(16)
|
||||
// ciphertext = f.read()
|
||||
//
|
||||
//# Decrypt the session key with the private RSA key
|
||||
//cipher_rsa = PKCS1_OAEP.new(private_key)
|
||||
//session_key = cipher_rsa.decrypt(enc_session_key)
|
||||
//
|
||||
//# Decrypt the data with the AES session key
|
||||
//cipher_aes = AES.new(session_key, AES.MODE_EAX, nonce)
|
||||
//data = cipher_aes.decrypt_and_verify(ciphertext, tag)
|
||||
//print(data.decode("utf-8"))
|
||||
@OptIn(ExperimentalEncodingApi::class)
|
||||
override fun decrypt(message: EncryptedMessage): String? {
|
||||
try {
|
||||
val privateKey = keyPair.private
|
||||
val rsaCipher = Cipher.getInstance("RSA/NONE/OAEPPadding")
|
||||
rsaCipher.init(Cipher.DECRYPT_MODE, privateKey)
|
||||
val sessionKey = rsaCipher.doFinal(Base64.decode(message.sessionKey))
|
||||
val iv = rsaCipher.doFinal(Base64.decode(message.iv))
|
||||
|
||||
val cipher = Cipher.getInstance("AES/CBC/PKCS7Padding")
|
||||
val aesKey = SecretKeySpec(sessionKey, "AES")
|
||||
cipher.init(Cipher.DECRYPT_MODE, aesKey, IvParameterSpec(iv))
|
||||
val decryptedByteArray = cipher.doFinal(Base64.decode(message.data))
|
||||
return decryptedByteArray.toString(StandardCharsets.UTF_8)
|
||||
} catch(e: Throwable) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
fun generateKeyPair(): KeyPair {
|
||||
val kpg = KeyPairGenerator.getInstance("RSA")
|
||||
kpg.initialize(2048)
|
||||
return kpg.genKeyPair()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,7 @@
|
|||
package org.fnives.android.servernotifications.message
|
||||
|
||||
data class EncryptedMessage(
|
||||
val iv: String,
|
||||
val data: String,
|
||||
val sessionKey: String
|
||||
)
|
||||
|
|
@ -0,0 +1,78 @@
|
|||
package org.fnives.android.servernotifications.message
|
||||
|
||||
import androidx.annotation.Keep
|
||||
import com.google.firebase.BuildConfig
|
||||
import java.time.Instant
|
||||
import kotlinx.serialization.KSerializer
|
||||
import kotlinx.serialization.SerialName
|
||||
import kotlinx.serialization.Serializable
|
||||
import kotlinx.serialization.descriptors.PrimitiveKind
|
||||
import kotlinx.serialization.descriptors.PrimitiveSerialDescriptor
|
||||
import kotlinx.serialization.descriptors.SerialDescriptor
|
||||
import kotlinx.serialization.encodeToString
|
||||
import kotlinx.serialization.encoding.Decoder
|
||||
import kotlinx.serialization.encoding.Encoder
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
@Serializable
|
||||
data class Message(
|
||||
@SerialName("message")
|
||||
val message: String,
|
||||
@SerialName("priority")
|
||||
val priority: Priority,
|
||||
@SerialName("service")
|
||||
val serviceName: String,
|
||||
@SerialName("time")
|
||||
@Serializable(InstantSerializer::class)
|
||||
val timestamp: Instant
|
||||
)
|
||||
|
||||
@Keep
|
||||
enum class Priority {
|
||||
High, Medium, Low, Undefined
|
||||
}
|
||||
|
||||
@Suppress("FunctionName")
|
||||
fun PriorityOf(priority: String?): Priority {
|
||||
return Priority.entries.firstOrNull { it.name.equals(priority, ignoreCase = true) }
|
||||
?: Priority.Undefined
|
||||
}
|
||||
|
||||
object InstantSerializer : KSerializer<Instant> {
|
||||
override val descriptor: SerialDescriptor = PrimitiveSerialDescriptor("java.time.Instant", PrimitiveKind.STRING)
|
||||
override fun serialize(encoder: Encoder, value: Instant) = encoder.encodeString(value.toString())
|
||||
override fun deserialize(decoder: Decoder): Instant = Instant.parse(decoder.decodeString())
|
||||
}
|
||||
|
||||
interface Converter {
|
||||
|
||||
fun serialize(message: Message): String?
|
||||
fun deserialize(message: String): Message?
|
||||
}
|
||||
|
||||
fun Converter(): Converter {
|
||||
return SerializerConverter()
|
||||
}
|
||||
|
||||
class SerializerConverter : Converter {
|
||||
override fun serialize(message: Message): String? =
|
||||
safeJson {
|
||||
Json.encodeToString(message)
|
||||
}
|
||||
|
||||
override fun deserialize(message: String): Message? =
|
||||
safeJson {
|
||||
Json.decodeFromString<Message>(message)
|
||||
}
|
||||
|
||||
private inline fun <T> safeJson(action: () -> T): T? {
|
||||
return try {
|
||||
action()
|
||||
} catch (parsingException: Throwable) {
|
||||
if (BuildConfig.DEBUG) {
|
||||
parsingException.printStackTrace()
|
||||
}
|
||||
null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package org.fnives.android.servernotifications.message
|
||||
|
||||
import android.content.Context
|
||||
import java.io.File
|
||||
import kotlin.coroutines.CoroutineContext
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.sync.Mutex
|
||||
import kotlinx.coroutines.sync.withLock
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
fun MessageStorage(context: Context): MessageStorage {
|
||||
return MessageStorage(
|
||||
limit = 100,
|
||||
file = File(context.filesDir, "logs"),
|
||||
converter = Converter(),
|
||||
)
|
||||
}
|
||||
|
||||
class MessageStorage(
|
||||
private val limit: Int,
|
||||
private val file: File,
|
||||
private val converter: Converter,
|
||||
private val context: CoroutineContext = Dispatchers.IO
|
||||
) {
|
||||
init {
|
||||
require(limit > 0)
|
||||
}
|
||||
|
||||
// DO NOT DO THIS: use database in prod
|
||||
val messages = writeEvent.onStart { emit(Unit) }.map {
|
||||
fileMutex.withLock {
|
||||
if (file.exists()) {
|
||||
file.readLines()
|
||||
.reversed()
|
||||
.mapNotNull(converter::deserialize)
|
||||
} else {
|
||||
listOf()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
suspend fun addMessage(message: Message) {
|
||||
val serializedMessage = converter.serialize(message) ?: return
|
||||
withContext(context) {
|
||||
fileMutex.withLock {
|
||||
val lines = if (file.exists()) file.readLines() else listOf()
|
||||
val current = lines.takeLast(limit - 1)
|
||||
val allLogs = current + serializedMessage
|
||||
file.writeText(allLogs.joinToString("\n"))
|
||||
}
|
||||
}
|
||||
writeEvent.tryEmit(Unit)
|
||||
}
|
||||
|
||||
suspend fun clear() {
|
||||
withContext(context) {
|
||||
fileMutex.withLock {
|
||||
file.delete()
|
||||
}
|
||||
}
|
||||
writeEvent.tryEmit(Unit)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val fileMutex = Mutex()
|
||||
private val writeEvent = MutableSharedFlow<Unit>(extraBufferCapacity = 1)
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,107 @@
|
|||
package org.fnives.android.servernotifications.token
|
||||
|
||||
import android.R.attr.capitalize
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.os.Build
|
||||
import android.view.ViewGroup
|
||||
import android.view.ViewGroup.LayoutParams.MATCH_PARENT
|
||||
import android.webkit.JavascriptInterface
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
import androidx.annotation.Keep
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.CircularProgressIndicator
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.mutableStateOf
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.runtime.setValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.text.capitalize
|
||||
import androidx.compose.ui.viewinterop.AndroidView
|
||||
import com.google.firebase.messaging.FirebaseMessaging
|
||||
import java.util.Locale
|
||||
import java.util.concurrent.CountDownLatch
|
||||
import kotlin.io.encoding.Base64
|
||||
import kotlin.io.encoding.ExperimentalEncodingApi
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import org.fnives.android.servernotifications.message.getKeyPair
|
||||
|
||||
|
||||
@SuppressLint("SetJavaScriptEnabled")
|
||||
@Composable
|
||||
fun TokenWebView(url: String) {
|
||||
var showLoading by remember(url) { mutableStateOf(true) }
|
||||
LaunchedEffect(url) {
|
||||
// can't be bothered for a real loading indicator
|
||||
delay(5000L)
|
||||
showLoading = false
|
||||
}
|
||||
Box(Modifier.fillMaxSize()) {
|
||||
AndroidView(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
factory = { context ->
|
||||
WebView(context).apply {
|
||||
setBackgroundColor(0)
|
||||
layoutParams = ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT)
|
||||
settings.javaScriptEnabled = true
|
||||
webViewClient = WebViewClient()
|
||||
addJavascriptInterface(ReadTokenInterface(context), "Android")
|
||||
|
||||
settings.loadWithOverviewMode = true
|
||||
settings.useWideViewPort = true
|
||||
settings.setSupportZoom(true)
|
||||
}
|
||||
},
|
||||
update = { webView ->
|
||||
webView.loadUrl(url)
|
||||
}
|
||||
)
|
||||
if (showLoading) {
|
||||
CircularProgressIndicator(modifier = Modifier.align(Alignment.Center))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Keep
|
||||
class ReadTokenInterface(private val context: Context) {
|
||||
|
||||
@OptIn(ExperimentalEncodingApi::class)
|
||||
@JavascriptInterface
|
||||
fun publicKey(): String {
|
||||
val publicKey = getKeyPair(context).public.encoded
|
||||
return Base64.encode(publicKey)
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun messagingToken(): String {
|
||||
val latch = CountDownLatch(1)
|
||||
var token: String? = null
|
||||
FirebaseMessaging.getInstance().token.addOnSuccessListener {
|
||||
token = it
|
||||
latch.countDown()
|
||||
}
|
||||
latch.await()
|
||||
return token!!
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
fun deviceName(): String {
|
||||
val manufacturer = Build.MANUFACTURER
|
||||
val model = Build.MODEL
|
||||
|
||||
return if (model.startsWith(manufacturer)) {
|
||||
model
|
||||
} else {
|
||||
"$manufacturer $model"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
package org.fnives.android.servernotifications.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)
|
||||
|
|
@ -0,0 +1,73 @@
|
|||
package org.fnives.android.servernotifications.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.runtime.SideEffect
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.toArgb
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalView
|
||||
import androidx.core.view.WindowCompat
|
||||
|
||||
private val DarkColorScheme = darkColorScheme(
|
||||
primary = Purple80,
|
||||
secondary = PurpleGrey80,
|
||||
tertiary = Pink80,
|
||||
surface = Color(0xFF2a2a2a),
|
||||
)
|
||||
|
||||
private val LightColorScheme = lightColorScheme(
|
||||
primary = Purple40,
|
||||
secondary = PurpleGrey40,
|
||||
tertiary = Pink40,
|
||||
surface = Color(0xFFEaEaEa),
|
||||
|
||||
/* 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 ServerNotificationsTheme(
|
||||
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
|
||||
}
|
||||
val view = LocalView.current
|
||||
if (!view.isInEditMode) {
|
||||
SideEffect {
|
||||
val window = (view.context as Activity).window
|
||||
window.statusBarColor = colorScheme.surface.toArgb()
|
||||
WindowCompat.getInsetsController(window, view).isAppearanceLightStatusBars = !darkTheme
|
||||
}
|
||||
}
|
||||
|
||||
MaterialTheme(
|
||||
colorScheme = colorScheme,
|
||||
typography = Typography,
|
||||
content = content
|
||||
)
|
||||
}
|
||||
|
|
@ -0,0 +1,34 @@
|
|||
package org.fnives.android.servernotifications.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
|
||||
)
|
||||
*/
|
||||
)
|
||||
|
|
@ -0,0 +1,39 @@
|
|||
package org.fnives.android.servernotifications.url
|
||||
|
||||
import android.content.Context
|
||||
import android.content.SharedPreferences
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import org.fnives.android.servernotifications.BuildConfig
|
||||
|
||||
fun UrlStorage(context: Context): UrlStorage {
|
||||
val sharedPref = context.getSharedPreferences("url_storage", Context.MODE_PRIVATE)
|
||||
return UrlStorage(sharedPref)
|
||||
}
|
||||
|
||||
class UrlStorage(private val sharedPref: SharedPreferences) {
|
||||
// DO NOT DO THIS: listen to the sharedPref or use DataStore
|
||||
private val update = MutableSharedFlow<Unit>(extraBufferCapacity = 1, replay = 1).apply {
|
||||
tryEmit(Unit)
|
||||
}
|
||||
private var _current get() = sharedPref.getString("current", null) ?: BuildConfig.BASE_URL
|
||||
set(value) {
|
||||
sharedPref.edit().putString("current", value).apply()
|
||||
}
|
||||
val currentUrl: Flow<String> = update.map {_current }
|
||||
val current: String get() = _current
|
||||
private var _urlOptions get() = sharedPref.getStringSet("all", null) ?: setOf(BuildConfig.BASE_URL)
|
||||
set(value) {
|
||||
sharedPref.edit().putStringSet("all", value).apply()
|
||||
}
|
||||
val urlOptions: Flow<Set<String>> = update.map {_urlOptions }
|
||||
|
||||
fun selectedUrl(url: String) {
|
||||
_current = url
|
||||
_urlOptions = _urlOptions + url
|
||||
update.tryEmit(Unit)
|
||||
}
|
||||
}
|
||||
10
android/app/src/main/res/drawable/ic_launcher_background.xml
Normal file
10
android/app/src/main/res/drawable/ic_launcher_background.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:viewportWidth="108"
|
||||
android:viewportHeight="108">
|
||||
<path
|
||||
android:fillColor="#2a2a2a"
|
||||
android:pathData="M0,0h108v108h-108z" />
|
||||
</vector>
|
||||
18
android/app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
18
android/app/src/main/res/drawable/ic_launcher_foreground.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:tint="#FF6650a4"
|
||||
android:viewportWidth="48"
|
||||
android:viewportHeight="48">
|
||||
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M0,15H17 c-0.55,0 -1,0.45 -1,1v6c0,0.55 0.45,1 1,1h16c0.55,0 1,-0.45 1,-1v-6c0,-0.55 -0.45,-1 -1,-1z
|
||||
M19,21 c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z" />
|
||||
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M0,25H17 c-0.55,0 -1,0.45 -1,1v6c0,0.55 0.45,1 1,1h16c0.55,0 1,-0.45 1,-1v-6c0,-0.55 -0.45,-1 -1,-1z
|
||||
M19,31 c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z" />
|
||||
|
||||
</vector>
|
||||
18
android/app/src/main/res/drawable/ic_server.xml
Normal file
18
android/app/src/main/res/drawable/ic_server.xml
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="108dp"
|
||||
android:height="108dp"
|
||||
android:tint="#FF6650a4"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24">
|
||||
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M0,2H4 c-0.55,0 -1,0.45 -1,1v6c0,0.55 0.45,1 1,1h16c0.55,0 1,-0.45 1,-1v-6c0,-0.55 -0.45,-1 -1,-1z
|
||||
M6,8 c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z" />
|
||||
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M0,13H4 c-0.55,0 -1,0.45 -1,1v6c0,0.55 0.45,1 1,1h16c0.55,0 1,-0.45 1,-1v-6c0,-0.55 -0.45,-1 -1,-1z
|
||||
M6,18 c-1.1,0 -2,-0.9 -2,-2s0.9,-2 2,-2 2,0.9 2,2 -0.9,2 -2,2z" />
|
||||
|
||||
</vector>
|
||||
6
android/app/src/main/res/mipmap-anydpi/ic_launcher.xml
Normal file
6
android/app/src/main/res/mipmap-anydpi/ic_launcher.xml
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<background android:drawable="@drawable/ic_launcher_background" />
|
||||
<foreground android:drawable="@drawable/ic_launcher_foreground" />
|
||||
<monochrome android:drawable="@drawable/ic_launcher_foreground" />
|
||||
</adaptive-icon>
|
||||
10
android/app/src/main/res/values/colors.xml
Normal file
10
android/app/src/main/res/values/colors.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<color name="purple_200">#FFBB86FC</color>
|
||||
<color name="purple_500">#FF6200EE</color>
|
||||
<color name="purple_700">#FF3700B3</color>
|
||||
<color name="teal_200">#FF03DAC5</color>
|
||||
<color name="teal_700">#FF018786</color>
|
||||
<color name="black">#FF000000</color>
|
||||
<color name="white">#FFFFFFFF</color>
|
||||
</resources>
|
||||
3
android/app/src/main/res/values/strings.xml
Normal file
3
android/app/src/main/res/values/strings.xml
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name">Server Notifications</string>
|
||||
</resources>
|
||||
10
android/app/src/main/res/values/themes.xml
Normal file
10
android/app/src/main/res/values/themes.xml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="Theme.ServerNotifications" parent="android:Theme.Material.NoActionBar" >
|
||||
<item name="android:background">#2a2a2a</item>
|
||||
<item name="android:windowBackground">#2a2a2a</item>
|
||||
<item name="android:statusBarColor">#2a2a2a</item>
|
||||
<item name="android:windowLightStatusBar">false</item>
|
||||
</style>
|
||||
</resources>
|
||||
13
android/app/src/main/res/xml/backup_rules.xml
Normal file
13
android/app/src/main/res/xml/backup_rules.xml
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample backup rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/guide/topics/data/autobackup
|
||||
for details.
|
||||
Note: This file is ignored for devices older that API 31
|
||||
See https://developer.android.com/about/versions/12/backup-restore
|
||||
-->
|
||||
<full-backup-content>
|
||||
<!--
|
||||
<include domain="sharedpref" path="."/>
|
||||
<exclude domain="sharedpref" path="device.xml"/>
|
||||
-->
|
||||
</full-backup-content>
|
||||
19
android/app/src/main/res/xml/data_extraction_rules.xml
Normal file
19
android/app/src/main/res/xml/data_extraction_rules.xml
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
Sample data extraction rules file; uncomment and customize as necessary.
|
||||
See https://developer.android.com/about/versions/12/backup-restore#xml-changes
|
||||
for details.
|
||||
-->
|
||||
<data-extraction-rules>
|
||||
<cloud-backup>
|
||||
<!-- TODO: Use <include> and <exclude> to control what is backed up.
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
-->
|
||||
</cloud-backup>
|
||||
<!--
|
||||
<device-transfer>
|
||||
<include .../>
|
||||
<exclude .../>
|
||||
</device-transfer>
|
||||
-->
|
||||
</data-extraction-rules>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package org.fnives.android.servernotifications
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.*
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
*
|
||||
* See [testing documentation](http://d.android.com/tools/testing).
|
||||
*/
|
||||
class ExampleUnitTest {
|
||||
@Test
|
||||
fun addition_isCorrect() {
|
||||
assertEquals(4, 2 + 2)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue