Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
188 righe
5.9 KiB
188 righe
5.9 KiB
import 'dart:convert'; |
|
import 'dart:io'; |
|
|
|
import 'package:device_info_plus/device_info_plus.dart'; |
|
import 'package:flutter/cupertino.dart'; |
|
import 'package:flutter/material.dart'; |
|
import 'package:flutter/services.dart'; |
|
import 'package:idrocap/private/constant/globals.dart'; |
|
import 'package:idrocap/private/model/user_access.dart'; |
|
import 'package:root_jailbreak_sniffer/rjsniffer.dart'; |
|
import 'package:shared_preferences/shared_preferences.dart'; |
|
import 'package:url_launcher/url_launcher.dart'; |
|
import 'package:encrypt/encrypt.dart'; |
|
import 'package:encrypt/encrypt.dart' as encrypt; |
|
import '../private/constant/globals.dart' as globals; |
|
|
|
class Utility { |
|
/* static Future<void> avviaIndicazione(String latitudine, String longitudine, |
|
String locationDatalatitude, String locationDatalongitude) async { |
|
var url_go = "https://www.google.com/maps/dir/?api=1&origin=" + |
|
locationDatalatitude + |
|
"," + |
|
locationDatalongitude + |
|
"&destination=" + |
|
latitudine + |
|
"," + |
|
longitudine + |
|
"&travelmode=walking"; |
|
print(url_go); |
|
|
|
var url = Uri.parse(url_go); |
|
if (!await launchUrl(url, mode: LaunchMode.inAppWebView)) { |
|
throw 'Could not launch $url'; |
|
} |
|
} */ |
|
|
|
static Future<void> viewToMaps( |
|
String latitudine, |
|
String longitudine, |
|
) async { |
|
var url_go = "https://www.google.com/maps?q=" + latitudine + "," + longitudine; |
|
|
|
var url = Uri.parse(url_go); |
|
if (!await launchUrl(url, mode: LaunchMode.inAppWebView)) { |
|
throw 'Could not launch $url'; |
|
} |
|
} |
|
|
|
static Future<void> makePhoneCall(String phoneNumber) async { |
|
final Uri launchUri = Uri( |
|
scheme: 'tel', |
|
path: phoneNumber, |
|
); |
|
await launchUrl(launchUri); |
|
} |
|
|
|
static Future<void> makeEmail(String email) async { |
|
final Uri launchUri = Uri( |
|
scheme: 'mailto', |
|
path: email, |
|
); |
|
await launchUrl(launchUri); |
|
} |
|
|
|
static void logout(BuildContext context) async { |
|
globals.userAccess.token = ""; |
|
globals.userAccess = new UserAccess(); |
|
globals.headers = null; |
|
|
|
try { |
|
Navigator.of(context).pushNamedAndRemoveUntil('login', (Route<dynamic> route) => false); |
|
return; |
|
} catch (e) { |
|
return; |
|
} |
|
} |
|
|
|
dialogAlert(BuildContext context) { |
|
return showDialog<void>( |
|
barrierDismissible: false, |
|
context: context, |
|
builder: (BuildContext contextd) { |
|
return CupertinoAlertDialog( |
|
title: Text('Attenzione'), |
|
content: Text("Per poter continuare ad utilizzare il servizio effettuare di nuovo l'accesso al sistema"), |
|
actions: <Widget>[ |
|
TextButton( |
|
style: TextButton.styleFrom( |
|
textStyle: Theme.of(context).textTheme.labelLarge, |
|
), |
|
child: const Text('ok'), |
|
onPressed: () { |
|
Navigator.of(contextd).pop(); |
|
logout(context); |
|
}, |
|
), |
|
], |
|
); |
|
}, |
|
); |
|
} |
|
|
|
// encrypt data |
|
String decryptWithAES(String keyBase64, String iv, String encryptedBase64) { |
|
final keyBytes = base64.decode(keyBase64); |
|
final ivBytes = utf8.encode(iv); |
|
final encryptedData = encrypt.Encrypted(base64.decode(encryptedBase64)); |
|
|
|
final encrypter = encrypt.Encrypter(encrypt.AES(encrypt.Key(keyBytes), mode: encrypt.AESMode.cbc)); |
|
|
|
final decrypted = encrypter.decrypt(encryptedData, iv: encrypt.IV(ivBytes)); |
|
return decrypted; |
|
} |
|
|
|
String encryptWithAES(String keyBase64, String iv, String plainText) { |
|
final keyBytes = base64.decode(keyBase64); |
|
final ivBytes = utf8.encode(iv); |
|
|
|
final encrypter = encrypt.Encrypter(encrypt.AES(encrypt.Key(keyBytes), mode: encrypt.AESMode.cbc)); |
|
|
|
final encrypted = encrypter.encrypt(plainText, iv: encrypt.IV(ivBytes)); |
|
return base64.encode(encrypted.bytes); |
|
} |
|
|
|
getSniffer() async { |
|
globals.amICompromised = await Rjsniffer.amICompromised() ?? false; //Detect JailBreak and Root |
|
|
|
globals.amIDebugged = await Rjsniffer.amIDebugged() ?? false; //Detect being Debugged |
|
|
|
if (Platform.isAndroid) { |
|
checkIfEmulator(); |
|
} |
|
} |
|
|
|
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); |
|
void checkIfEmulator() async { |
|
globals.amIEmulator = await isEmulator(); |
|
|
|
// print("Is emulator: ${globals.amIEmulator}"); |
|
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; |
|
/* print("Fingerprint: ${androidInfo.fingerprint}"); |
|
print("Model: ${androidInfo.model}"); |
|
print("Manufacturer: ${androidInfo.manufacturer}"); |
|
print("Brand: ${androidInfo.brand}"); |
|
print("Device: ${androidInfo.device}"); |
|
print("Product: ${androidInfo.product}"); */ |
|
} |
|
|
|
Future<bool> isEmulator() async { |
|
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin(); |
|
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo; |
|
bool ritornoRisposta = false; |
|
|
|
bool isFingerprintGeneric = androidInfo.fingerprint.startsWith('generic'); |
|
bool isModelEmulator = androidInfo.model.contains('Emulator'); |
|
bool isManufacturerGenymotion = androidInfo.manufacturer.contains('Genymotion'); |
|
bool isBrandAndDeviceGeneric = androidInfo.brand.startsWith('generic') && androidInfo.device.startsWith('generic'); |
|
bool isProductGoogleSdk = androidInfo.product == 'google_sdk'; |
|
|
|
if (isFingerprintGeneric) { |
|
ritornoRisposta = true; |
|
} |
|
if (isModelEmulator) { |
|
ritornoRisposta = true; |
|
} |
|
if (isManufacturerGenymotion) { |
|
ritornoRisposta = true; |
|
} |
|
if (isBrandAndDeviceGeneric) { |
|
ritornoRisposta = true; |
|
} |
|
if (isProductGoogleSdk) { |
|
ritornoRisposta = true; |
|
} |
|
|
|
return ritornoRisposta; |
|
} |
|
|
|
void checkDevice(BuildContext context) { |
|
if (globals.amICompromised || globals.amIDebugged || globals.amIEmulator) |
|
ScaffoldMessenger.of(context).showSnackBar( |
|
SnackBar( |
|
content: Text("Attenzione! L\'app non può essere eseguita su questo dispositivo."), |
|
backgroundColor: Colors.red, |
|
), |
|
); |
|
} |
|
}
|
|
|