Fix Gson serialization escaping HTML characters issue and lint problems.
Gson default enable HTML escaping when serialize object into
Json string. It would make the account key looks like:
BHdGSdGR6khQV5kaiNBWgQ\u003d\u003d (base64.encode())
After turning off the HTML escaping, it looks like:
BJxRDeh6k6mkRvOvxyLgCQ== (base64.encode())
This change also resolve Kotlin list problems.
Test: go/ml-fp-dp-tool with NearbyFastPairProviderSimulatorApp
Bug: 214015364
Ignore-AOSP-First: nearby_not_in_aosp_yet
Change-Id: Iadcd0258d03a55acc2a5518191dd559788aa4841
diff --git a/nearby/tests/multidevices/clients/test_service/fastpair_seeker_data_provider/shared/android/nearby/fastpair/seeker/FastPairTestDataCache.kt b/nearby/tests/multidevices/clients/test_service/fastpair_seeker_data_provider/shared/android/nearby/fastpair/seeker/FastPairTestDataCache.kt
index 80ca855..be94031 100644
--- a/nearby/tests/multidevices/clients/test_service/fastpair_seeker_data_provider/shared/android/nearby/fastpair/seeker/FastPairTestDataCache.kt
+++ b/nearby/tests/multidevices/clients/test_service/fastpair_seeker_data_provider/shared/android/nearby/fastpair/seeker/FastPairTestDataCache.kt
@@ -21,12 +21,12 @@
import android.nearby.FastPairDeviceMetadata
import android.nearby.FastPairDiscoveryItem
import com.google.common.io.BaseEncoding
-import com.google.gson.Gson
+import com.google.gson.GsonBuilder
import com.google.gson.annotations.SerializedName
/** Manage a cache of Fast Pair test data for testing. */
class FastPairTestDataCache {
- private val gson = Gson()
+ private val gson = GsonBuilder().disableHtmlEscaping().create()
private val accountKeyDeviceMetadataList = mutableListOf<FastPairAccountKeyDeviceMetadata>()
private val antispoofKeyDeviceMetadataDataMap =
mutableMapOf<String, FastPairAntispoofKeyDeviceMetadataData>()
@@ -71,13 +71,13 @@
@SerializedName("account_key") val accountKey: String?,
@SerializedName("sha256_account_key_public_address") val accountKeyPublicAddress: String?,
@SerializedName("fast_pair_device_metadata") val deviceMeta: FastPairDeviceMetadataData?,
- @SerializedName("fast_pair_discovery_item") val discoveryItem: FastPairDiscoveryItemData?,
+ @SerializedName("fast_pair_discovery_item") val discoveryItem: FastPairDiscoveryItemData?
) {
constructor(meta: FastPairAccountKeyDeviceMetadata) : this(
accountKey = meta.deviceAccountKey?.base64Encode(),
accountKeyPublicAddress = meta.sha256DeviceAccountKeyPublicAddress?.base64Encode(),
deviceMeta = meta.fastPairDeviceMetadata?.let { FastPairDeviceMetadataData(it) },
- discoveryItem = meta.fastPairDiscoveryItem?.let { FastPairDiscoveryItemData(it) },
+ discoveryItem = meta.fastPairDiscoveryItem?.let { FastPairDiscoveryItemData(it) }
)
fun toFastPairAccountKeyDeviceMetadata(): FastPairAccountKeyDeviceMetadata {
@@ -92,7 +92,7 @@
data class FastPairAntispoofKeyDeviceMetadataData(
@SerializedName("anti_spoofing_public_key_str") val antispoofPublicKey: String?,
- @SerializedName("fast_pair_device_metadata") val deviceMeta: FastPairDeviceMetadataData?,
+ @SerializedName("fast_pair_device_metadata") val deviceMeta: FastPairDeviceMetadataData?
) {
fun toFastPairAntispoofKeyDeviceMetadata(): FastPairAntispoofKeyDeviceMetadata {
return FastPairAntispoofKeyDeviceMetadata.Builder()
@@ -135,7 +135,7 @@
@SerializedName("unable_to_connect_description") val unableToConnectDescription: String?,
@SerializedName("unable_to_connect_title") val unableToConnectTitle: String?,
@SerializedName("update_companion_app_description") val updateCompAppDes: String?,
- @SerializedName("wait_launch_companion_app_description") val waitLaunchCompApp: String?,
+ @SerializedName("wait_launch_companion_app_description") val waitLaunchCompApp: String?
) {
constructor(meta: FastPairDeviceMetadata) : this(
assistantSetupHalfSheet = meta.assistantSetupHalfSheet,
@@ -170,7 +170,7 @@
unableToConnectDescription = meta.unableToConnectDescription,
unableToConnectTitle = meta.unableToConnectTitle,
updateCompAppDes = meta.updateCompanionAppDescription,
- waitLaunchCompApp = meta.waitLaunchCompanionAppDescription,
+ waitLaunchCompApp = meta.waitLaunchCompanionAppDescription
)
fun toFastPairDeviceMetadata(): FastPairDeviceMetadata {
@@ -242,7 +242,7 @@
@SerializedName("title") val title: String?,
@SerializedName("trigger_id") val triggerId: String?,
@SerializedName("tx_power") val txPower: Int,
- @SerializedName("type") val type: Int,
+ @SerializedName("type") val type: Int
) {
constructor(item: FastPairDiscoveryItem) : this(
actionUrl = item.actionUrl,
@@ -274,7 +274,7 @@
title = item.title,
triggerId = item.triggerId,
txPower = item.txPower,
- type = item.type,
+ type = item.type
)
fun toFastPairDiscoveryItem(): FastPairDiscoveryItem {