mirror of
https://github.com/lone-cloud/prism-android
synced 2026-06-03 11:03:10 -07:00
fix manual app addition regression, v1 release
This commit is contained in:
parent
624ce20ef4
commit
a84619c7dc
4 changed files with 17 additions and 6 deletions
2
VERSION
2
VERSION
|
|
@ -1 +1 @@
|
||||||
0.5.0
|
1.0.0
|
||||||
|
|
|
||||||
|
|
@ -169,13 +169,13 @@ class PrismPreferences(private val context: Context) :
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setVapidPrivateKey(connectorToken: String, privateKey: String) {
|
fun setVapidPrivateKey(connectorToken: String, privateKey: String) {
|
||||||
securePreferences.edit { putString("vapid_private_$connectorToken", privateKey) }
|
securePreferences.edit(commit = true) { putString("vapid_private_$connectorToken", privateKey) }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getVapidPrivateKey(connectorToken: String): String? = securePreferences.getString("vapid_private_$connectorToken", null)
|
fun getVapidPrivateKey(connectorToken: String): String? = securePreferences.getString("vapid_private_$connectorToken", null)
|
||||||
|
|
||||||
fun removeVapidPrivateKey(connectorToken: String) {
|
fun removeVapidPrivateKey(connectorToken: String) {
|
||||||
securePreferences.edit { remove("vapid_private_$connectorToken") }
|
securePreferences.edit(commit = true) { remove("vapid_private_$connectorToken") }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun addPendingChannelDeletion(channelId: String) {
|
fun addPendingChannelDeletion(channelId: String) {
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,7 @@ class MainViewModel(
|
||||||
|
|
||||||
val descriptionParts = mutableListOf("target:$targetPackageName")
|
val descriptionParts = mutableListOf("target:$targetPackageName")
|
||||||
description?.takeIf { it.isNotBlank() }?.let { descriptionParts.add(it) }
|
description?.takeIf { it.isNotBlank() }?.let { descriptionParts.add(it) }
|
||||||
|
descriptionParts.add("${DescriptionParser.VAPID_PRIVATE_KEY_PREFIX}${vapidKeys.privateKey}")
|
||||||
val fullDescription = descriptionParts.joinToString("|")
|
val fullDescription = descriptionParts.joinToString("|")
|
||||||
|
|
||||||
val keyStore = EncryptionKeyStore(app)
|
val keyStore = EncryptionKeyStore(app)
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,8 @@ class ManualAppRegistrationHandler(private val context: Context) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.d(TAG, "Auto-registering manual app '${app.title}' with Prism server")
|
Log.d(TAG, "Auto-registering manual app '${app.title}' with Prism server")
|
||||||
val vapidPrivateKey = PrismPreferences(context).getVapidPrivateKey(app.connectorToken)
|
val vapidPrivateKey = DescriptionParser.extractValue(app.description, DescriptionParser.VAPID_PRIVATE_KEY_PREFIX)
|
||||||
?: DescriptionParser.extractValue(app.description, DescriptionParser.VAPID_PRIVATE_KEY_PREFIX)
|
?: PrismPreferences(context).getVapidPrivateKey(app.connectorToken)
|
||||||
|
|
||||||
if (vapidPrivateKey.isNullOrBlank()) {
|
if (vapidPrivateKey.isNullOrBlank()) {
|
||||||
handleFailure(
|
handleFailure(
|
||||||
|
|
@ -113,8 +113,10 @@ class ManualAppRegistrationHandler(private val context: Context) {
|
||||||
|
|
||||||
val preferences = PrismPreferences(context)
|
val preferences = PrismPreferences(context)
|
||||||
val isInitialPendingRegistration = preferences.isPendingManualToken(connectorToken)
|
val isInitialPendingRegistration = preferences.isPendingManualToken(connectorToken)
|
||||||
|
val isLikelyNewManualApp = isLikelyNewManualApp(connectorToken)
|
||||||
|
val shouldRollback = isInitialPendingRegistration || isLikelyNewManualApp
|
||||||
|
|
||||||
if (isInitialPendingRegistration) {
|
if (shouldRollback) {
|
||||||
Log.w(TAG, "Rolling back pending manual app '$appTitle' after registration failure")
|
Log.w(TAG, "Rolling back pending manual app '$appTitle' after registration failure")
|
||||||
rollback(connectorToken)
|
rollback(connectorToken)
|
||||||
}
|
}
|
||||||
|
|
@ -133,6 +135,14 @@ class ManualAppRegistrationHandler(private val context: Context) {
|
||||||
sendUiAction(context, UiActions.RefreshRegistrations)
|
sendUiAction(context, UiActions.RefreshRegistrations)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isLikelyNewManualApp(connectorToken: String): Boolean {
|
||||||
|
val app = DatabaseFactory.getDb(context)
|
||||||
|
.listApps()
|
||||||
|
.find { it.connectorToken == connectorToken }
|
||||||
|
?: return false
|
||||||
|
return DescriptionParser.isManualApp(app.description) && app.endpoint.isNullOrBlank()
|
||||||
|
}
|
||||||
|
|
||||||
private fun rollback(connectorToken: String) {
|
private fun rollback(connectorToken: String) {
|
||||||
val db = DatabaseFactory.getDb(context)
|
val db = DatabaseFactory.getDb(context)
|
||||||
val app = db.listApps().find { it.connectorToken == connectorToken }
|
val app = db.listApps().find { it.connectorToken == connectorToken }
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue