25-3/12/1
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'dart:ui';
|
||||
@@ -235,7 +236,7 @@ class SecurityHelper {
|
||||
// debugPrint("Bundle ID: $bundleId"); // Print the bundle ID
|
||||
|
||||
// Check for security risks and potentially show a warning
|
||||
if (isJailBroken || isNotTrust || !isRealDevice || isTampered) {
|
||||
if (isJailBroken || isRealDevice == false || isTampered) {
|
||||
// print("security_warning".tr); //using easy_localization
|
||||
// Use a more robust approach to show a warning, like a dialog:
|
||||
_showSecurityWarning();
|
||||
@@ -249,30 +250,89 @@ class SecurityHelper {
|
||||
exit(0); // This will terminate the app. Be VERY careful with this.
|
||||
}
|
||||
|
||||
// static void _showSecurityWarning() {
|
||||
// // Show a dialog, navigate to an error screen, etc.
|
||||
// // Example using Get.dialog (if you use GetX):
|
||||
//
|
||||
// Get.dialog(
|
||||
// AlertDialog(
|
||||
// title: Text("Security Warning".tr), // Or use localized string
|
||||
// content: Text(
|
||||
// "Potential security risks detected. The application may not function correctly."
|
||||
// .tr), //Or use localized string
|
||||
// actions: [
|
||||
// TextButton(
|
||||
// onPressed: () async {
|
||||
// await storage.deleteAll();
|
||||
// await box.erase();
|
||||
// Get.back(); // Close the dialog
|
||||
// // Or, if you really must, exit the app (but give the user a chance!)
|
||||
// exit(0);
|
||||
// },
|
||||
// child: Text("OK"), // Or use a localized string
|
||||
// ),
|
||||
// ],
|
||||
// ),
|
||||
// barrierDismissible: false, // Prevent closing by tapping outside
|
||||
// );
|
||||
// }
|
||||
static void _showSecurityWarning() {
|
||||
// Show a dialog, navigate to an error screen, etc.
|
||||
// Example using Get.dialog (if you use GetX):
|
||||
// Use an RxInt to track the remaining seconds. This is the KEY!
|
||||
RxInt secondsRemaining = 10.obs;
|
||||
|
||||
Get.dialog(
|
||||
AlertDialog(
|
||||
title: Text("Security Warning".tr), // Or use localized string
|
||||
content: Text(
|
||||
"Potential security risks detected. The application may not function correctly."
|
||||
.tr), //Or use localized string
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
await storage.deleteAll();
|
||||
await box.erase();
|
||||
Get.back(); // Close the dialog
|
||||
// Or, if you really must, exit the app (but give the user a chance!)
|
||||
exit(0);
|
||||
},
|
||||
child: Text("OK"), // Or use a localized string
|
||||
),
|
||||
],
|
||||
CupertinoAlertDialog(
|
||||
title: Text("Security Warning".tr),
|
||||
content: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Obx(() => Text(
|
||||
"Potential security risks detected. The application will close in @seconds seconds."
|
||||
.trParams({
|
||||
// Use trParams for placeholders
|
||||
'seconds': secondsRemaining.value.toString(),
|
||||
}),
|
||||
// Wrap the Text widget in Obx
|
||||
)),
|
||||
SizedBox(height: 24), // More spacing before the progress bar
|
||||
Obx(() => SizedBox(
|
||||
width: double.infinity, // Make progress bar full width
|
||||
child: CupertinoActivityIndicator(
|
||||
// in case of loading
|
||||
radius: 15,
|
||||
animating: true,
|
||||
))),
|
||||
SizedBox(height: 8),
|
||||
Obx(() => ClipRRect(
|
||||
borderRadius: BorderRadius.circular(8), // Rounded corners
|
||||
child: LinearProgressIndicator(
|
||||
value: secondsRemaining.value / 10,
|
||||
backgroundColor: Colors.grey.shade300, // Lighter background
|
||||
valueColor: AlwaysStoppedAnimation<Color>(
|
||||
CupertinoColors.systemRed), // iOS-style red
|
||||
minHeight: 8, // Slightly thicker progress bar
|
||||
),
|
||||
)),
|
||||
],
|
||||
),
|
||||
),
|
||||
barrierDismissible: false, // Prevent closing by tapping outside
|
||||
barrierDismissible: false,
|
||||
);
|
||||
|
||||
Timer.periodic(Duration(seconds: 1), (timer) {
|
||||
secondsRemaining.value--;
|
||||
if (secondsRemaining.value <= 0) {
|
||||
timer.cancel();
|
||||
// Get.back();
|
||||
_clearDataAndExit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
static Future<void> _clearDataAndExit() async {
|
||||
await storage.deleteAll();
|
||||
await box.erase();
|
||||
exit(0); // Exit the app
|
||||
print('exit');
|
||||
}
|
||||
}
|
||||
|
||||
46
lib/controller/functions/security_checks.dart
Normal file
46
lib/controller/functions/security_checks.dart
Normal file
@@ -0,0 +1,46 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:get/get.dart';
|
||||
|
||||
class SecurityChecks {
|
||||
static const platform = MethodChannel(
|
||||
'com.sefer_driver/security'); // Choose a unique channel name
|
||||
|
||||
static Future<bool> isDeviceCompromised() async {
|
||||
try {
|
||||
final bool result = await platform
|
||||
.invokeMethod('isNativeRooted'); // Invoke the native method
|
||||
return result;
|
||||
} on PlatformException catch (e) {
|
||||
print("Failed to check security status: ${e.message}");
|
||||
return true; // Treat platform errors as a compromised device (for safety)
|
||||
}
|
||||
}
|
||||
|
||||
static isDeviceRootedFromNative(BuildContext context) async {
|
||||
bool compromised = await isDeviceCompromised();
|
||||
if (compromised) {
|
||||
showDialog(
|
||||
barrierDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => AlertDialog(
|
||||
title: Text("Security Warning".tr),
|
||||
content: Text(
|
||||
"Your device appears to be compromised. The app will now close."
|
||||
.tr),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
SystemNavigator.pop(); // Close the app
|
||||
},
|
||||
child: Text("OK"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
} else {
|
||||
// Continue with normal app flow
|
||||
print("Device is secure.");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user