Skip to content

Commit 6222b99

Browse files
authored
Merge pull request #28 from maeddin/27_redundant_activity
Replaces `Activity` with `Context`
2 parents cdf0f35 + 882ebdd commit 6222b99

File tree

1 file changed

+13
-28
lines changed

1 file changed

+13
-28
lines changed

android/src/main/kotlin/com/w3conext/jailbreak_root_detection/JailbreakRootDetectionPlugin.kt

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.w3conext.jailbreak_root_detection
22

3-
import android.app.Activity
3+
import android.content.Context
44
import com.anish.trust_fall.emulator.EmulatorCheck
55
import com.anish.trust_fall.externalstorage.ExternalStorageCheck
66
import com.anish.trust_fall.rooted.RootedCheck
@@ -10,8 +10,6 @@ import com.w3conext.jailbreak_root_detection.devmode.DevMode
1010
import com.w3conext.jailbreak_root_detection.frida.AntiFridaChecker
1111
import com.w3conext.jailbreak_root_detection.magisk.MagiskChecker
1212
import io.flutter.embedding.engine.plugins.FlutterPlugin
13-
import io.flutter.embedding.engine.plugins.activity.ActivityAware
14-
import io.flutter.embedding.engine.plugins.activity.ActivityPluginBinding
1513
import io.flutter.plugin.common.MethodCall
1614
import io.flutter.plugin.common.MethodChannel
1715
import io.flutter.plugin.common.MethodChannel.MethodCallHandler
@@ -22,17 +20,18 @@ import kotlinx.coroutines.Job
2220
import kotlinx.coroutines.launch
2321

2422
/** JailbreakRootDetectionPlugin */
25-
class JailbreakRootDetectionPlugin : FlutterPlugin, MethodCallHandler, ActivityAware {
23+
class JailbreakRootDetectionPlugin : FlutterPlugin, MethodCallHandler {
2624

2725
/// The MethodChannel that will the communication between Flutter and native Android
2826
///
2927
/// This local reference serves to register the plugin with the Flutter Engine and unregister it
3028
/// when the Flutter Engine is detached from the Activity
3129
private lateinit var channel: MethodChannel
3230

33-
private var activity: Activity? = null
31+
private lateinit var appContext: Context
3432

3533
override fun onAttachedToEngine(flutterPluginBinding: FlutterPlugin.FlutterPluginBinding) {
34+
appContext = flutterPluginBinding.applicationContext
3635
channel = MethodChannel(flutterPluginBinding.binaryMessenger, "jailbreak_root_detection")
3736
channel.setMethodCallHandler(this)
3837
}
@@ -43,11 +42,11 @@ class JailbreakRootDetectionPlugin : FlutterPlugin, MethodCallHandler, ActivityA
4342
"isJailBroken" -> processJailBroken(result)
4443
"isRealDevice" -> result.success(!EmulatorCheck.isEmulator)
4544
"isOnExternalStorage" -> result.success(
46-
ExternalStorageCheck.isOnExternalStorage(activity)
45+
ExternalStorageCheck.isOnExternalStorage(appContext)
4746
)
4847

49-
"isDevMode" -> result.success(DevMode.isDevMode(activity))
50-
"isDebugged" -> result.success(Debugger.isDebugged(activity))
48+
"isDevMode" -> result.success(DevMode.isDevMode(appContext))
49+
"isDebugged" -> result.success(Debugger.isDebugged(appContext))
5150
else -> result.notImplemented()
5251
}
5352
}
@@ -56,40 +55,26 @@ class JailbreakRootDetectionPlugin : FlutterPlugin, MethodCallHandler, ActivityA
5655
channel.setMethodCallHandler(null)
5756
}
5857

59-
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
60-
activity = binding.activity
61-
}
62-
63-
override fun onDetachedFromActivityForConfigChanges() {}
64-
65-
override fun onReattachedToActivityForConfigChanges(binding: ActivityPluginBinding) {
66-
activity = binding.activity
67-
}
68-
69-
override fun onDetachedFromActivity() {
70-
activity = null
71-
}
72-
7358
private fun processCheckIssues(result: Result) {
7459
val scope = CoroutineScope(Job() + Dispatchers.Default)
7560
scope.launch {
7661

77-
QLog.LOGGING_LEVEL = QLog.NONE;
62+
QLog.LOGGING_LEVEL = QLog.NONE
7863

7964
val issues = mutableListOf<String>()
80-
if (RootedCheck.isJailBroken(activity)) {
65+
if (RootedCheck.isJailBroken(appContext)) {
8166
issues.add("jailbreak")
8267
}
8368

8469
if (AntiFridaChecker.checkFrida()) {
8570
issues.add("fridaFound")
8671
}
8772

88-
if (Debugger.isDebugged(activity)) {
73+
if (Debugger.isDebugged(appContext)) {
8974
issues.add("debugged")
9075
}
9176

92-
if (DevMode.isDevMode(activity)) {
77+
if (DevMode.isDevMode(appContext)) {
9378
issues.add("devMode")
9479
}
9580

@@ -101,7 +86,7 @@ class JailbreakRootDetectionPlugin : FlutterPlugin, MethodCallHandler, ActivityA
10186
issues.add("notRealDevice")
10287
}
10388

104-
if (ExternalStorageCheck.isOnExternalStorage(activity)) {
89+
if (ExternalStorageCheck.isOnExternalStorage(appContext)) {
10590
issues.add("onExternalStorage")
10691
}
10792

@@ -115,7 +100,7 @@ class JailbreakRootDetectionPlugin : FlutterPlugin, MethodCallHandler, ActivityA
115100

116101
QLog.LOGGING_LEVEL = QLog.NONE;
117102

118-
val isRootBeer = RootedCheck.isJailBroken(activity)
103+
val isRootBeer = RootedCheck.isJailBroken(appContext)
119104
val isFrida = AntiFridaChecker.checkFrida()
120105
val isMagisk = MagiskChecker.isInstalled()
121106
val isRooted = isRootBeer || isFrida || isMagisk

0 commit comments

Comments
 (0)