sdk final

This commit is contained in:
robin
2026-03-05 16:53:59 +08:00
parent a10f3f3740
commit 491ade1bc3
44 changed files with 1595 additions and 960 deletions

View File

@@ -22,6 +22,7 @@ class TrustAPPHttpDnsPlugin : FlutterPlugin, MethodCallHandler {
private var appId: String? = null
private var secretKey: String? = null
private var apiUrl: String? = null
private var primaryServiceHost: String? = null
private var backupServiceHost: String? = null
private var servicePort: Int? = null
@@ -63,9 +64,11 @@ class TrustAPPHttpDnsPlugin : FlutterPlugin, MethodCallHandler {
return
}
val apiUrlArg = (args["apiUrl"] as? String)?.trim()
val primaryHostArg = (args["primaryServiceHost"] as? String)?.trim()
if (primaryHostArg.isNullOrBlank()) {
Log.i("TrustAPPHttpDns", "initialize missing primaryServiceHost")
if (apiUrlArg.isNullOrBlank() && primaryHostArg.isNullOrBlank()) {
Log.i("TrustAPPHttpDns", "initialize missing both apiUrl and primaryServiceHost")
result.success(false)
return
}
@@ -81,13 +84,14 @@ class TrustAPPHttpDnsPlugin : FlutterPlugin, MethodCallHandler {
appId = parsedAppId
secretKey = secret
apiUrl = apiUrlArg
primaryServiceHost = primaryHostArg
backupServiceHost = backup?.trim()?.takeIf { it.isNotEmpty() }
servicePort = if (port != null && port > 0) port else null
Log.i(
"TrustAPPHttpDns",
"initialize appId=$appId, primaryServiceHost=$primaryServiceHost, backupServiceHost=$backupServiceHost, servicePort=$servicePort"
"initialize appId=$appId, apiUrl=$apiUrl, primaryServiceHost=$primaryServiceHost, backupServiceHost=$backupServiceHost, servicePort=$servicePort"
)
result.success(true)
}
@@ -190,25 +194,39 @@ class TrustAPPHttpDnsPlugin : FlutterPlugin, MethodCallHandler {
}
try {
builder.javaClass.getMethod("setPrimaryServiceHost", String::class.java)
.invoke(builder, primaryServiceHost)
hostConfigApplied = true
} catch (t: Throwable) {
Log.w("TrustAPPHttpDns", "setPrimaryServiceHost failed: ${t.message}")
}
try {
backupServiceHost?.let {
builder.javaClass.getMethod("setBackupServiceHost", String::class.java)
.invoke(builder, it)
if (!apiUrl.isNullOrBlank()) {
try {
builder.javaClass.getMethod("setServiceUrl", String::class.java)
.invoke(builder, apiUrl)
hostConfigApplied = true
} catch (t: Throwable) {
Log.w("TrustAPPHttpDns", "setServiceUrl failed: ${t.message}")
}
} else {
try {
builder.javaClass.getMethod("setPrimaryServiceHost", String::class.java)
.invoke(builder, primaryServiceHost)
hostConfigApplied = true
} catch (t: Throwable) {
Log.w("TrustAPPHttpDns", "setPrimaryServiceHost failed: ${t.message}")
}
try {
backupServiceHost?.let {
builder.javaClass.getMethod("setBackupServiceHost", String::class.java)
.invoke(builder, it)
}
} catch (_: Throwable) {
}
try {
servicePort?.let {
builder.javaClass.getMethod("setServicePort", Int::class.javaPrimitiveType)
.invoke(builder, it)
}
} catch (_: Throwable) {
}
}
} catch (_: Throwable) {
}
try {
servicePort?.let {
builder.javaClass.getMethod("setServicePort", Int::class.javaPrimitiveType)
.invoke(builder, it)
}
} catch (_: Throwable) {
} catch (e: Exception) {
Log.w("TrustAPPHttpDns", "Host configuration failed: ${e.message}")
}
try {