perf: bridge objects

- bridge oneway methods
- scope sync
This commit is contained in:
rhunk
2024-01-16 00:01:37 +01:00
parent 0994b8f36d
commit 8c71e4af27
16 changed files with 232 additions and 187 deletions

View File

@ -13,7 +13,7 @@ interface BridgeInterface {
/**
* broadcast a log message
*/
void broadcastLog(String tag, String level, String message);
oneway void broadcastLog(String tag, String level, String message);
/**
* Execute a file operation
@ -36,7 +36,7 @@ interface BridgeInterface {
/**
* Enqueue a download
*/
void enqueueDownload(in Intent intent, DownloadCallback callback);
oneway void enqueueDownload(in Intent intent, DownloadCallback callback);
/**
* Get rules for a given user or conversation
@ -56,7 +56,7 @@ interface BridgeInterface {
*
* @param type rule type (MessagingRuleType)
*/
void setRule(String uuid, String type, boolean state);
oneway void setRule(String uuid, String type, boolean state);
/**
* Sync groups and friends
@ -66,12 +66,12 @@ interface BridgeInterface {
/**
* Trigger sync for an id
*/
void triggerSync(String scope, String id);
oneway void triggerSync(String scope, String id);
/**
* Pass all groups and friends to be able to add them to the database
* @param groups list of groups (MessagingGroupInfo as json string)
* @param friends list of friends (MessagingFriendInfo as json string)
* @param groups list of groups (MessagingGroupInfo as parcelable)
* @param friends list of friends (MessagingFriendInfo as parcelable)
*/
oneway void passGroupsAndFriends(in List<String> groups, in List<String> friends);
@ -81,11 +81,11 @@ interface BridgeInterface {
MessageLoggerInterface getMessageLogger();
void registerMessagingBridge(MessagingBridge bridge);
oneway void registerMessagingBridge(MessagingBridge bridge);
void openSettingsOverlay();
oneway void openSettingsOverlay();
void closeSettingsOverlay();
oneway void closeSettingsOverlay();
void registerConfigStateListener(in ConfigStateListener listener);
oneway void registerConfigStateListener(in ConfigStateListener listener);
}

View File

@ -8,11 +8,11 @@ interface IScripting {
@nullable String getScriptContent(String path);
void registerIPCListener(String channel, String eventName, IPCListener listener);
oneway void registerIPCListener(String channel, String eventName, IPCListener listener);
void sendIPCMessage(String channel, String eventName, in String[] args);
oneway void sendIPCMessage(String channel, String eventName, in String[] args);
@nullable String configTransaction(String module, String action, @nullable String key, @nullable String value, boolean save);
void registerAutoReloadListener(in AutoReloadListener listener);
oneway void registerAutoReloadListener(in AutoReloadListener listener);
}

View File

@ -33,7 +33,7 @@ class ModConfig(
private fun load() {
root = createRootConfig()
wasPresent = file.isFileExists()
if (!file.isFileExists()) {
if (!wasPresent) {
writeConfig()
return
}

View File

@ -1,7 +1,8 @@
package me.rhunk.snapenhance.common.data
import android.os.Parcelable
import kotlinx.parcelize.Parcelize
import me.rhunk.snapenhance.common.config.FeatureNotice
import me.rhunk.snapenhance.common.util.SerializableDataObject
import kotlin.time.Duration.Companion.hours
@ -52,12 +53,12 @@ enum class MessagingRuleType(
}
}
@Parcelize
data class FriendStreaks(
val userId: String,
val notify: Boolean,
val notify: Boolean = true,
val expirationTimestamp: Long,
val length: Int
) : SerializableDataObject() {
): Parcelable {
fun hoursLeft() = (expirationTimestamp - System.currentTimeMillis()) / 1000 / 60 / 60
fun isAboutToExpire(expireHours: Int) = (expirationTimestamp - System.currentTimeMillis()).let {
@ -65,20 +66,22 @@ data class FriendStreaks(
}
}
@Parcelize
data class MessagingGroupInfo(
val conversationId: String,
val name: String,
val participantsCount: Int
) : SerializableDataObject()
): Parcelable
@Parcelize
data class MessagingFriendInfo(
val userId: String,
val displayName: String?,
val mutableUsername: String,
val bitmojiId: String?,
val selfieId: String?
) : SerializableDataObject()
val selfieId: String?,
var streaks: FriendStreaks?,
): Parcelable
class StoryData(
val url: String,
@ -86,4 +89,4 @@ class StoryData(
val createdAt: Long,
val key: ByteArray?,
val iv: ByteArray?
) : SerializableDataObject()
)

View File

@ -3,7 +3,6 @@ package me.rhunk.snapenhance.common.database.impl
import android.annotation.SuppressLint
import android.database.Cursor
import me.rhunk.snapenhance.common.database.DatabaseObject
import me.rhunk.snapenhance.common.util.SerializableDataObject
import me.rhunk.snapenhance.common.util.ktx.getInteger
import me.rhunk.snapenhance.common.util.ktx.getLong
import me.rhunk.snapenhance.common.util.ktx.getStringOrNull
@ -33,7 +32,7 @@ data class FriendInfo(
var usernameForSorting: String? = null,
var friendLinkType: Int = 0,
var postViewEmoji: String? = null,
) : DatabaseObject, SerializableDataObject() {
) : DatabaseObject {
val mutableUsername get() = username?.split("|")?.last()
val firstCreatedUsername get() = username?.split("|")?.first()

View File

@ -0,0 +1,33 @@
package me.rhunk.snapenhance.common.util
import android.os.Parcelable
import kotlinx.parcelize.parcelableCreator
import kotlin.io.encoding.Base64
import kotlin.io.encoding.ExperimentalEncodingApi
@OptIn(ExperimentalEncodingApi::class)
fun Parcelable.toSerialized(): String? {
val parcel = android.os.Parcel.obtain()
return try {
writeToParcel(parcel, 0)
parcel.marshall()?.let {
Base64.encode(it)
}
} finally {
parcel.recycle()
}
}
@OptIn(ExperimentalEncodingApi::class)
inline fun <reified T : Parcelable> toParcelable(serialized: String): T? {
val parcel = android.os.Parcel.obtain()
return try {
Base64.decode(serialized).let {
parcel.unmarshall(it, 0, it.size)
}
parcel.setDataPosition(0)
parcelableCreator<T>().createFromParcel(parcel)
} finally {
parcel.recycle()
}
}

View File

@ -1,22 +0,0 @@
package me.rhunk.snapenhance.common.util
import com.google.gson.Gson
import com.google.gson.GsonBuilder
open class SerializableDataObject {
companion object {
val gson: Gson = GsonBuilder().create()
inline fun <reified T : SerializableDataObject> fromJson(json: String): T {
return gson.fromJson(json, T::class.java)
}
inline fun <reified T : SerializableDataObject> fromJson(json: String, type: Class<T>): T {
return gson.fromJson(json, type)
}
}
fun toJson(): String {
return gson.toJson(this)
}
}