2026-02-20-overlay
This commit is contained in:
@@ -81,6 +81,10 @@
|
||||
android:enabled="true"
|
||||
android:exported="true"
|
||||
/>
|
||||
<service
|
||||
android:name="com.intaleq_driver.trip_overlay_plugin.TripOverlayService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="specialUse" />
|
||||
<service android:name=".MyFirebaseMessagingService" android:exported="false" />
|
||||
<service android:name=".LocationUpdatesService" android:exported="false"
|
||||
android:foregroundServiceType="location" />
|
||||
@@ -95,6 +99,19 @@
|
||||
<!-- <service
|
||||
android:name="com.phan_tech.flutter_overlay_apps.OverlayService"
|
||||
android:exported="false" /> -->
|
||||
<service
|
||||
android:name="com.trip_overlay.TripOverlayService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="specialUse"
|
||||
android:stopWithTask="false" />
|
||||
|
||||
<receiver
|
||||
android:name="com.trip_overlay.TripOverlayReceiver"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="com.trip_overlay.SHOW_OVERLAY" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
<service android:name="flutter.overlay.window.flutter_overlay_window.OverlayService"
|
||||
android:exported="false" android:foregroundServiceType="specialUse" />
|
||||
<!-- خدمة overlay الخاصة بمكتبة flutter_overlay_window -->
|
||||
|
||||
@@ -19,10 +19,14 @@ import kotlin.concurrent.schedule
|
||||
class MainActivity : FlutterFragmentActivity() {
|
||||
private val SECURITY_CHANNEL = "com.intaleq_driver/security"
|
||||
private val APP_CONTROL_CHANNEL = "com.intaleq_driver/app_control"
|
||||
private var appControlChannel: MethodChannel? = null
|
||||
|
||||
override fun configureFlutterEngine(flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
|
||||
appControlChannel =
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, APP_CONTROL_CHANNEL)
|
||||
|
||||
// Channel for security checks (isRooted)
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, SECURITY_CHANNEL)
|
||||
.setMethodCallHandler { call, result ->
|
||||
@@ -33,68 +37,64 @@ class MainActivity : FlutterFragmentActivity() {
|
||||
}
|
||||
|
||||
// Channel for app control (bringing to foreground)
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, APP_CONTROL_CHANNEL)
|
||||
.setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"bringToForeground" -> {
|
||||
Log.d("MainActivity", "Received bringToForeground request")
|
||||
val intent =
|
||||
Intent(this, MainActivity::class.java).apply {
|
||||
action = Intent.ACTION_MAIN
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
)
|
||||
}
|
||||
try {
|
||||
startActivity(intent)
|
||||
Log.d(
|
||||
"MainActivity",
|
||||
"App brought to foreground successfully with flags: ${intent.flags}"
|
||||
)
|
||||
result.success(true)
|
||||
} catch (e: Exception) {
|
||||
Log.e(
|
||||
"MainActivity",
|
||||
"Error bringing app to foreground: ${e.message}",
|
||||
e
|
||||
)
|
||||
result.error(
|
||||
"ACTIVITY_START_FAILED",
|
||||
e.message,
|
||||
e.stackTraceToString()
|
||||
appControlChannel?.setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"bringToForeground" -> {
|
||||
val intent =
|
||||
Intent(this, MainActivity::class.java).apply {
|
||||
action = Intent.ACTION_MAIN
|
||||
addCategory(Intent.CATEGORY_LAUNCHER)
|
||||
addFlags(
|
||||
Intent.FLAG_ACTIVITY_NEW_TASK or
|
||||
Intent.FLAG_ACTIVITY_CLEAR_TOP or
|
||||
Intent.FLAG_ACTIVITY_SINGLE_TOP
|
||||
)
|
||||
}
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
try {
|
||||
startActivity(intent)
|
||||
result.success(true)
|
||||
} catch (e: Exception) {
|
||||
result.error("ACTIVITY_START_FAILED", e.message, e.stackTraceToString())
|
||||
}
|
||||
}
|
||||
else -> result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
Log.d("MainActivity", "MainActivity onCreate")
|
||||
if (isDeviceCompromised()) {
|
||||
showSecurityWarningDialog()
|
||||
}
|
||||
// ✅ فحص هل التطبيق فتح بسبب زر "قبول" في النافذة
|
||||
checkIntentForOverlayAccept(intent)
|
||||
}
|
||||
|
||||
override fun onNewIntent(intent: Intent) {
|
||||
super.onNewIntent(intent)
|
||||
setIntent(intent)
|
||||
Log.d("MainActivity", "Received new intent: ${intent.action}, flags: ${intent.flags}")
|
||||
// ✅ فحص النية (Intent) عند فتح التطبيق من الخلفية
|
||||
checkIntentForOverlayAccept(intent)
|
||||
}
|
||||
|
||||
// 🔥 هذه الدالة السحرية التي تلتقط زر القبول وترسله للتطبيق الرئيسي 🔥
|
||||
private fun checkIntentForOverlayAccept(intent: Intent) {
|
||||
val acceptedTripId = intent.getStringExtra("acceptedTripId")
|
||||
if (acceptedTripId != null) {
|
||||
Log.d("MainActivity", "✅ Trip accepted via Native Intent: $acceptedTripId")
|
||||
appControlChannel?.invokeMethod("onOverlayTripAccepted", acceptedTripId)
|
||||
intent.removeExtra("acceptedTripId") // مسح النية لكي لا تتكرر
|
||||
}
|
||||
}
|
||||
|
||||
// --- بقية كود الحماية الخاص بك ---
|
||||
private fun isDeviceCompromised(): Boolean {
|
||||
return try {
|
||||
val isRootedByRootBeer = RootBeer(this).isRooted
|
||||
Log.d("MainActivity", "Root check result: $isRootedByRootBeer")
|
||||
isRootedByRootBeer
|
||||
} catch (e: Exception) {
|
||||
Log.e("MainActivity", "Security check error: ${e.message}", e)
|
||||
true // Fail-safe: assume compromised if check fails
|
||||
true
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,9 +141,7 @@ class MainActivity : FlutterFragmentActivity() {
|
||||
private fun clearAppDataAndExit() {
|
||||
try {
|
||||
Runtime.getRuntime().exec("pm clear $packageName")
|
||||
Log.d("MainActivity", "Cleared app data via package manager")
|
||||
} catch (e: Exception) {
|
||||
Log.e("MainActivity", "Error clearing app data: ${e.message}", e)
|
||||
clearCache()
|
||||
clearAppData()
|
||||
}
|
||||
@@ -154,21 +152,14 @@ class MainActivity : FlutterFragmentActivity() {
|
||||
private fun clearCache() {
|
||||
deleteDir(cacheDir)
|
||||
deleteDir(externalCacheDir)
|
||||
Log.d("MainActivity", "Cleared cache directories")
|
||||
}
|
||||
|
||||
private fun clearAppData() {
|
||||
// Be careful with this, it deletes all app data.
|
||||
// deleteDir(applicationContext.dataDir)
|
||||
Log.d("MainActivity", "App data clearing skipped (commented out)")
|
||||
}
|
||||
private fun clearAppData() {}
|
||||
|
||||
private fun deleteDir(dir: File?): Boolean {
|
||||
if (dir != null && dir.isDirectory) {
|
||||
dir.list()?.forEach { deleteDir(File(dir, it)) }
|
||||
}
|
||||
val deleted = dir?.delete() ?: false
|
||||
Log.d("MainActivity", "Deleted directory ${dir?.path}: $deleted")
|
||||
return deleted
|
||||
return dir?.delete() ?: false
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user