Skip to content

Commit fc4d486

Browse files
committed
feat(pigeon): switch to pigeon
- Android native uses pigeon - iOS native uses pigeon Signed-off-by: Denis Dobanda <[email protected]>
1 parent 1b8fedf commit fc4d486

19 files changed

+649
-261
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ and ios. Please refer to readme to participate in native development
6363
Please use the latest Flutter Version. Use the provided example project to test
6464
or bug report any existing or new features.
6565

66+
Use Pigeon to update interfaces between flutter and native libraries:
67+
`dart run pigeon --input lib/src/pigeon.dart`
68+
6669
## Submitting changes
6770

6871
Before submitting your changes as a pull request, please make sure to format

android/src/main/kotlin/com/example/flutter_security_toolkit/FlutterSecurityToolkitPlugin.kt

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Autogenerated from Pigeon (v22.6.4), do not edit directly.
2+
// See also: https://pub.dev/packages/pigeon
3+
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")
4+
5+
6+
import android.util.Log
7+
import io.flutter.plugin.common.BasicMessageChannel
8+
import io.flutter.plugin.common.BinaryMessenger
9+
import io.flutter.plugin.common.MessageCodec
10+
import io.flutter.plugin.common.StandardMessageCodec
11+
import java.io.ByteArrayOutputStream
12+
import java.nio.ByteBuffer
13+
14+
private fun wrapResult(result: Any?): List<Any?> {
15+
return listOf(result)
16+
}
17+
18+
private fun wrapError(exception: Throwable): List<Any?> {
19+
return if (exception is FlutterError) {
20+
listOf(
21+
exception.code,
22+
exception.message,
23+
exception.details
24+
)
25+
} else {
26+
listOf(
27+
exception.javaClass.simpleName,
28+
exception.toString(),
29+
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
30+
)
31+
}
32+
}
33+
34+
/**
35+
* Error class for passing custom error details to Flutter via a thrown PlatformException.
36+
* @property code The error code.
37+
* @property message The error message.
38+
* @property details The error details. Must be a datatype supported by the api codec.
39+
*/
40+
class FlutterError (
41+
val code: String,
42+
override val message: String? = null,
43+
val details: Any? = null
44+
) : Throwable()
45+
private open class ThreatCenterApiPigeonCodec : StandardMessageCodec() {
46+
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
47+
return super.readValueOfType(type, buffer)
48+
}
49+
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
50+
super.writeValue(stream, value)
51+
}
52+
}
53+
54+
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
55+
interface ThreatCenterApi {
56+
fun areRootPrivilegesDetected(): Boolean
57+
fun areHooksDetected(): Boolean
58+
fun isSimulatorDetected(): Boolean
59+
60+
companion object {
61+
/** The codec used by ThreatCenterApi. */
62+
val codec: MessageCodec<Any?> by lazy {
63+
ThreatCenterApiPigeonCodec()
64+
}
65+
/** Sets up an instance of `ThreatCenterApi` to handle messages through the `binaryMessenger`. */
66+
@JvmOverloads
67+
fun setUp(binaryMessenger: BinaryMessenger, api: ThreatCenterApi?, messageChannelSuffix: String = "") {
68+
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
69+
run {
70+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_security_toolkit.ThreatCenterApi.areRootPrivilegesDetected$separatedMessageChannelSuffix", codec)
71+
if (api != null) {
72+
channel.setMessageHandler { _, reply ->
73+
val wrapped: List<Any?> = try {
74+
listOf(api.areRootPrivilegesDetected())
75+
} catch (exception: Throwable) {
76+
wrapError(exception)
77+
}
78+
reply.reply(wrapped)
79+
}
80+
} else {
81+
channel.setMessageHandler(null)
82+
}
83+
}
84+
run {
85+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_security_toolkit.ThreatCenterApi.areHooksDetected$separatedMessageChannelSuffix", codec)
86+
if (api != null) {
87+
channel.setMessageHandler { _, reply ->
88+
val wrapped: List<Any?> = try {
89+
listOf(api.areHooksDetected())
90+
} catch (exception: Throwable) {
91+
wrapError(exception)
92+
}
93+
reply.reply(wrapped)
94+
}
95+
} else {
96+
channel.setMessageHandler(null)
97+
}
98+
}
99+
run {
100+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_security_toolkit.ThreatCenterApi.isSimulatorDetected$separatedMessageChannelSuffix", codec)
101+
if (api != null) {
102+
channel.setMessageHandler { _, reply ->
103+
val wrapped: List<Any?> = try {
104+
listOf(api.isSimulatorDetected())
105+
} catch (exception: Throwable) {
106+
wrapError(exception)
107+
}
108+
reply.reply(wrapped)
109+
}
110+
} else {
111+
channel.setMessageHandler(null)
112+
}
113+
}
114+
}
115+
}
116+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// Autogenerated from Pigeon (v22.6.4), do not edit directly.
2+
// See also: https://pub.dev/packages/pigeon
3+
@file:Suppress("UNCHECKED_CAST", "ArrayInDataClass")
4+
5+
6+
import android.util.Log
7+
import io.flutter.plugin.common.BasicMessageChannel
8+
import io.flutter.plugin.common.BinaryMessenger
9+
import io.flutter.plugin.common.MessageCodec
10+
import io.flutter.plugin.common.StandardMessageCodec
11+
import java.io.ByteArrayOutputStream
12+
import java.nio.ByteBuffer
13+
14+
private fun wrapResult(result: Any?): List<Any?> {
15+
return listOf(result)
16+
}
17+
18+
private fun wrapError(exception: Throwable): List<Any?> {
19+
return if (exception is FlutterError) {
20+
listOf(
21+
exception.code,
22+
exception.message,
23+
exception.details
24+
)
25+
} else {
26+
listOf(
27+
exception.javaClass.simpleName,
28+
exception.toString(),
29+
"Cause: " + exception.cause + ", Stacktrace: " + Log.getStackTraceString(exception)
30+
)
31+
}
32+
}
33+
34+
/**
35+
* Error class for passing custom error details to Flutter via a thrown PlatformException.
36+
* @property code The error code.
37+
* @property message The error message.
38+
* @property details The error details. Must be a datatype supported by the api codec.
39+
*/
40+
class FlutterError (
41+
val code: String,
42+
override val message: String? = null,
43+
val details: Any? = null
44+
) : Throwable()
45+
private open class ThreatCenterApiPigeonCodec : StandardMessageCodec() {
46+
override fun readValueOfType(type: Byte, buffer: ByteBuffer): Any? {
47+
return super.readValueOfType(type, buffer)
48+
}
49+
override fun writeValue(stream: ByteArrayOutputStream, value: Any?) {
50+
super.writeValue(stream, value)
51+
}
52+
}
53+
54+
/** Generated interface from Pigeon that represents a handler of messages from Flutter. */
55+
interface ThreatCenterApi {
56+
fun areRootPrivilegesDetected(): Boolean
57+
fun areHooksDetected(): Boolean
58+
fun isSimulatorDetected(): Boolean
59+
60+
companion object {
61+
/** The codec used by ThreatCenterApi. */
62+
val codec: MessageCodec<Any?> by lazy {
63+
ThreatCenterApiPigeonCodec()
64+
}
65+
/** Sets up an instance of `ThreatCenterApi` to handle messages through the `binaryMessenger`. */
66+
@JvmOverloads
67+
fun setUp(binaryMessenger: BinaryMessenger, api: ThreatCenterApi?, messageChannelSuffix: String = "") {
68+
val separatedMessageChannelSuffix = if (messageChannelSuffix.isNotEmpty()) ".$messageChannelSuffix" else ""
69+
run {
70+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_security_toolkit.ThreatCenterApi.areRootPrivilegesDetected$separatedMessageChannelSuffix", codec)
71+
if (api != null) {
72+
channel.setMessageHandler { _, reply ->
73+
val wrapped: List<Any?> = try {
74+
listOf(api.areRootPrivilegesDetected())
75+
} catch (exception: Throwable) {
76+
wrapError(exception)
77+
}
78+
reply.reply(wrapped)
79+
}
80+
} else {
81+
channel.setMessageHandler(null)
82+
}
83+
}
84+
run {
85+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_security_toolkit.ThreatCenterApi.areHooksDetected$separatedMessageChannelSuffix", codec)
86+
if (api != null) {
87+
channel.setMessageHandler { _, reply ->
88+
val wrapped: List<Any?> = try {
89+
listOf(api.areHooksDetected())
90+
} catch (exception: Throwable) {
91+
wrapError(exception)
92+
}
93+
reply.reply(wrapped)
94+
}
95+
} else {
96+
channel.setMessageHandler(null)
97+
}
98+
}
99+
run {
100+
val channel = BasicMessageChannel<Any?>(binaryMessenger, "dev.flutter.pigeon.flutter_security_toolkit.ThreatCenterApi.isSimulatorDetected$separatedMessageChannelSuffix", codec)
101+
if (api != null) {
102+
channel.setMessageHandler { _, reply ->
103+
val wrapped: List<Any?> = try {
104+
listOf(api.isSimulatorDetected())
105+
} catch (exception: Throwable) {
106+
wrapError(exception)
107+
}
108+
reply.reply(wrapped)
109+
}
110+
} else {
111+
channel.setMessageHandler(null)
112+
}
113+
}
114+
}
115+
}
116+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
2+
package com.exxeta.security_toolkit
3+
4+
import ThreatCenterApi
5+
import com.exxeta.securitytoolkit.ThreatDetectionCenter
6+
import io.flutter.embedding.engine.plugins.FlutterPlugin
7+
8+
class ThreatCenterApiImpl : FlutterPlugin, ThreatCenterApi {
9+
private lateinit var threatDetectionCenter: ThreatDetectionCenter
10+
11+
override fun onAttachedToEngine(binding: FlutterPlugin.FlutterPluginBinding) {
12+
threatDetectionCenter = ThreatDetectionCenter(binding.applicationContext)
13+
ThreatCenterApi.setUp(binding.binaryMessenger, this)
14+
}
15+
16+
override fun onDetachedFromEngine(binding: FlutterPlugin.FlutterPluginBinding) {
17+
ThreatCenterApi.setUp(binding.binaryMessenger, null)
18+
}
19+
20+
// MARK: - ThreatCenterApi
21+
22+
override fun areRootPrivilegesDetected(): Boolean {
23+
return threatDetectionCenter.areRootPrivilegesDetected
24+
}
25+
26+
override fun areHooksDetected(): Boolean {
27+
return threatDetectionCenter.areHooksDetected
28+
}
29+
30+
override fun isSimulatorDetected(): Boolean {
31+
return threatDetectionCenter.isSimulatorDetected
32+
}
33+
}

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- Flutter (1.0.0)
3-
- flutter_security_toolkit (1.0.1):
3+
- flutter_security_toolkit (1.0.2):
44
- Flutter
55
- SecurityToolkit (~> 1.0)
66
- integration_test (0.0.1):
@@ -26,7 +26,7 @@ EXTERNAL SOURCES:
2626

2727
SPEC CHECKSUMS:
2828
Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7
29-
flutter_security_toolkit: 73412e795f89286c565f7f91b76b2c4c610c953a
29+
flutter_security_toolkit: 82972aec2bbed79dc6b22fac76aed57419e24c73
3030
integration_test: ce0a3ffa1de96d1a89ca0ac26fca7ea18a749ef4
3131
SecurityToolkit: 51927d4723e634bddb83a4d16e86940b344fa6a4
3232

0 commit comments

Comments
 (0)