Initial commit du projet Flutter
This commit is contained in:
44
android/app/build.gradle.kts
Normal file
44
android/app/build.gradle.kts
Normal file
@@ -0,0 +1,44 @@
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("kotlin-android")
|
||||
// The Flutter Gradle Plugin must be applied after the Android and Kotlin Gradle plugins.
|
||||
id("dev.flutter.flutter-gradle-plugin")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "com.example.wtpe"
|
||||
compileSdk = flutter.compileSdkVersion
|
||||
ndkVersion ="27.0.12077973"
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
kotlinOptions {
|
||||
jvmTarget = JavaVersion.VERSION_11.toString()
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
|
||||
applicationId = "com.example.wtpe"
|
||||
// You can update the following values to match your application needs.
|
||||
// For more information, see: https://flutter.dev/to/review-gradle-config.
|
||||
minSdk = flutter.minSdkVersion
|
||||
targetSdk = flutter.targetSdkVersion
|
||||
versionCode = flutter.versionCode
|
||||
versionName = flutter.versionName
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig = signingConfigs.getByName("debug")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
flutter {
|
||||
source = "../.."
|
||||
}
|
||||
7
android/app/src/debug/AndroidManifest.xml
Normal file
7
android/app/src/debug/AndroidManifest.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
60
android/app/src/main/AndroidManifest.xml
Normal file
60
android/app/src/main/AndroidManifest.xml
Normal file
@@ -0,0 +1,60 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
package="com.example.wtpe">
|
||||
|
||||
<!-- Permissions nécessaires pour l'application -->
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
|
||||
<!-- Fusion des deux <queries> -->
|
||||
<queries>
|
||||
<package android:name="com.whatsapp" />
|
||||
<package android:name="com.whatsapp.w4b" />
|
||||
<intent>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<data android:scheme="https" />
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.settings.WIFI_SETTINGS" />
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.settings.SETTINGS" />
|
||||
</intent>
|
||||
<intent>
|
||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
||||
<data android:mimeType="text/plain"/>
|
||||
</intent>
|
||||
</queries>
|
||||
|
||||
<application
|
||||
android:label="wtpe"
|
||||
android:name="${applicationName}"
|
||||
android:testOnly="true"
|
||||
android:icon="@mipmap/ic_launcher">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true"
|
||||
android:launchMode="singleTop"
|
||||
android:theme="@style/LaunchTheme"
|
||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
|
||||
<meta-data
|
||||
android:name="io.flutter.embedding.android.NormalTheme"
|
||||
android:resource="@style/NormalTheme" />
|
||||
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<meta-data
|
||||
android:name="flutterEmbedding"
|
||||
android:value="2" />
|
||||
</application>
|
||||
</manifest>
|
||||
25
android/app/src/main/kotlin/com/example/wtpe/BootReceiver.kt
Normal file
25
android/app/src/main/kotlin/com/example/wtpe/BootReceiver.kt
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.example.wtpe
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
|
||||
class BootReceiver : BroadcastReceiver() {
|
||||
|
||||
override fun onReceive(context: Context, intent: Intent) {
|
||||
if (Intent.ACTION_BOOT_COMPLETED == intent.action ||
|
||||
"android.intent.action.QUICKBOOT_POWERON" == intent.action) {
|
||||
|
||||
Log.d("BootReceiver", "WTPE - Démarrage détecté, lancement de l'application")
|
||||
|
||||
val startIntent = Intent(context, MainActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP)
|
||||
}
|
||||
|
||||
context.startActivity(startIntent)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.example.wtpe
|
||||
|
||||
import android.app.admin.DeviceAdminReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.util.Log
|
||||
|
||||
class DeviceAdminReceiver : DeviceAdminReceiver() {
|
||||
|
||||
override fun onEnabled(context: Context, intent: Intent) {
|
||||
super.onEnabled(context, intent)
|
||||
Log.d("DeviceAdmin", "WTPE Device Admin activé")
|
||||
}
|
||||
|
||||
override fun onDisabled(context: Context, intent: Intent) {
|
||||
super.onDisabled(context, intent)
|
||||
Log.d("DeviceAdmin", "WTPE Device Admin désactivé")
|
||||
}
|
||||
|
||||
override fun onLockTaskModeEntering(context: Context, intent: Intent, pkg: String) {
|
||||
super.onLockTaskModeEntering(context, intent, pkg)
|
||||
Log.d("DeviceAdmin", "WTPE - Entrée en mode Lock Task: $pkg")
|
||||
}
|
||||
|
||||
override fun onLockTaskModeExiting(context: Context, intent: Intent) {
|
||||
super.onLockTaskModeExiting(context, intent)
|
||||
Log.d("DeviceAdmin", "WTPE - Sortie du mode Lock Task")
|
||||
}
|
||||
}
|
||||
617
android/app/src/main/kotlin/com/example/wtpe/MainActivity.kt
Normal file
617
android/app/src/main/kotlin/com/example/wtpe/MainActivity.kt
Normal file
@@ -0,0 +1,617 @@
|
||||
package com.example.wtpe
|
||||
|
||||
import android.app.ActivityManager
|
||||
import android.app.admin.DevicePolicyManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager
|
||||
import android.graphics.PixelFormat
|
||||
import android.net.Uri
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.view.Gravity
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.view.WindowManager.LayoutParams
|
||||
import androidx.annotation.NonNull
|
||||
import io.flutter.embedding.android.FlutterActivity
|
||||
import io.flutter.embedding.engine.FlutterEngine
|
||||
import io.flutter.plugin.common.MethodChannel
|
||||
|
||||
class MainActivity : FlutterActivity() {
|
||||
private val CHANNEL = "com.wortis.agent/settings"
|
||||
private val KIOSK_CHANNEL = "kiosk_mode"
|
||||
|
||||
private lateinit var devicePolicyManager: DevicePolicyManager
|
||||
private lateinit var compName: ComponentName
|
||||
private var overlayView: View? = null
|
||||
private var isKioskModeActive = true
|
||||
|
||||
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
|
||||
super.configureFlutterEngine(flutterEngine)
|
||||
|
||||
devicePolicyManager = getSystemService(Context.DEVICE_POLICY_SERVICE) as DevicePolicyManager
|
||||
compName = ComponentName(this, DeviceAdminReceiver::class.java)
|
||||
|
||||
// Configuration du mode kiosque au démarrage
|
||||
enableKioskMode()
|
||||
|
||||
// Ajoutez cette méthode au canal CHANNEL dans configureFlutterEngine :
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
// ... vos autres méthodes ...
|
||||
|
||||
"forceRestartKiosk" -> {
|
||||
// Méthode pour forcer le retour en mode kiosque
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
enableAdvancedKioskMode()
|
||||
} else {
|
||||
enableKioskMode()
|
||||
}
|
||||
result.success("Kiosk mode restarted")
|
||||
}
|
||||
|
||||
else -> {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Canal principal pour les paramètres système
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, CHANNEL).setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"openWifiSettings" -> {
|
||||
openWifiSettings()
|
||||
result.success("WiFi settings opened")
|
||||
}
|
||||
"openSettings" -> {
|
||||
openSettings()
|
||||
result.success("Settings opened")
|
||||
}
|
||||
// ============= AJOUTER CES MÉTHODES =============
|
||||
"enableKioskMode" -> {
|
||||
enableKioskMode()
|
||||
result.success("Kiosk mode enabled")
|
||||
}
|
||||
"exitKioskMode" -> {
|
||||
exitKioskMode()
|
||||
result.success("Kiosk mode disabled")
|
||||
}
|
||||
// ============= FIN AJOUT =============
|
||||
"setBrightness" -> {
|
||||
val brightness = call.argument<Double>("brightness") ?: 0.5
|
||||
setBrightness(brightness.toFloat())
|
||||
result.success("Brightness set to ${(brightness * 100).toInt()}%")
|
||||
}
|
||||
"getSystemBrightness" -> {
|
||||
val brightness = getSystemBrightness()
|
||||
result.success(brightness.toDouble())
|
||||
}
|
||||
"openWhatsApp" -> {
|
||||
val opened = openWhatsApp()
|
||||
if (opened) {
|
||||
result.success("WhatsApp opened")
|
||||
} else {
|
||||
result.error("WHATSAPP_ERROR", "WhatsApp not installed or error opening", null)
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Canal pour le mode kiosque avancé
|
||||
MethodChannel(flutterEngine.dartExecutor.binaryMessenger, KIOSK_CHANNEL).setMethodCallHandler { call, result ->
|
||||
when (call.method) {
|
||||
"enableKioskMode" -> {
|
||||
enableAdvancedKioskMode()
|
||||
result.success(null)
|
||||
}
|
||||
"disableKioskMode" -> {
|
||||
disableAdvancedKioskMode()
|
||||
result.success(null)
|
||||
}
|
||||
"isDeviceOwner" -> {
|
||||
result.success(devicePolicyManager.isDeviceOwnerApp(packageName))
|
||||
}
|
||||
"requestDeviceAdmin" -> {
|
||||
requestDeviceAdmin()
|
||||
result.success(null)
|
||||
}
|
||||
"hideNavigationBar" -> {
|
||||
hideSystemUI()
|
||||
result.success(null)
|
||||
}
|
||||
"enableStatusBarExpansion" -> {
|
||||
enableStatusBarExpansion(call.argument<Boolean>("enable") ?: false)
|
||||
result.success(null)
|
||||
}
|
||||
"preventStatusBarExpansion" -> {
|
||||
preventStatusBarExpansion()
|
||||
result.success(null)
|
||||
}
|
||||
"exitKioskMode" -> {
|
||||
exitKioskMode()
|
||||
result.success("Kiosk mode disabled")
|
||||
}
|
||||
else -> {
|
||||
result.notImplemented()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
// Configuration de la fenêtre pour le mode kiosque avancé
|
||||
window.setFlags(
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN or
|
||||
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
|
||||
WindowManager.LayoutParams.FLAG_SECURE,
|
||||
WindowManager.LayoutParams.FLAG_FULLSCREEN or
|
||||
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS or
|
||||
WindowManager.LayoutParams.FLAG_SECURE
|
||||
)
|
||||
|
||||
// Masquer immédiatement tous les éléments système
|
||||
hideSystemUI()
|
||||
preventStatusBarExpansion()
|
||||
|
||||
// Créer un overlay pour bloquer les gestes système
|
||||
createSystemOverlay()
|
||||
|
||||
// Activer le mode kiosque avancé si on est Device Owner
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
enableAdvancedKioskMode()
|
||||
} else {
|
||||
enableKioskMode()
|
||||
}
|
||||
}
|
||||
|
||||
// Modifiez onResume pour réactiver automatiquement le mode kiosque :
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
|
||||
// Délai pour permettre à l'utilisateur de revenir depuis les paramètres
|
||||
android.os.Handler(android.os.Looper.getMainLooper()).postDelayed({
|
||||
if (isKioskModeActive) {
|
||||
hideSystemUI()
|
||||
preventStatusBarExpansion()
|
||||
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
// Vérifier si on doit relancer le Lock Task
|
||||
val activityManager = getSystemService(Context.ACTIVITY_SERVICE) as ActivityManager
|
||||
if (!activityManager.isInLockTaskMode) {
|
||||
enableAdvancedKioskMode()
|
||||
android.util.Log.d("MainActivity", "Lock Task réactivé depuis onResume")
|
||||
}
|
||||
} else {
|
||||
enableKioskMode()
|
||||
}
|
||||
}
|
||||
}, 1000) // Délai de 1 seconde
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
super.onWindowFocusChanged(hasFocus)
|
||||
if (hasFocus && isKioskModeActive) {
|
||||
hideSystemUI()
|
||||
}
|
||||
}
|
||||
|
||||
private fun createSystemOverlay() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
try {
|
||||
if (Settings.canDrawOverlays(this)) {
|
||||
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
|
||||
// Créer un overlay invisible au-dessus de la barre de statut
|
||||
overlayView = View(this)
|
||||
overlayView?.setBackgroundColor(android.graphics.Color.TRANSPARENT)
|
||||
|
||||
val layoutParams = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
LayoutParams(
|
||||
LayoutParams.MATCH_PARENT,
|
||||
getStatusBarHeight(),
|
||||
LayoutParams.TYPE_APPLICATION_OVERLAY,
|
||||
LayoutParams.FLAG_NOT_TOUCHABLE or
|
||||
LayoutParams.FLAG_LAYOUT_IN_SCREEN or
|
||||
LayoutParams.FLAG_FULLSCREEN,
|
||||
PixelFormat.TRANSLUCENT
|
||||
)
|
||||
} else {
|
||||
LayoutParams(
|
||||
LayoutParams.MATCH_PARENT,
|
||||
getStatusBarHeight(),
|
||||
LayoutParams.TYPE_SYSTEM_OVERLAY,
|
||||
LayoutParams.FLAG_NOT_TOUCHABLE or
|
||||
LayoutParams.FLAG_LAYOUT_IN_SCREEN or
|
||||
LayoutParams.FLAG_FULLSCREEN,
|
||||
PixelFormat.TRANSLUCENT
|
||||
)
|
||||
}
|
||||
|
||||
layoutParams.gravity = Gravity.TOP
|
||||
windowManager.addView(overlayView, layoutParams)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun getStatusBarHeight(): Int {
|
||||
var result = 0
|
||||
val resourceId = resources.getIdentifier("status_bar_height", "dimen", "android")
|
||||
if (resourceId > 0) {
|
||||
result = resources.getDimensionPixelSize(resourceId)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
private fun hideSystemUI() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
window.decorView.systemUiVisibility = (
|
||||
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LOW_PROFILE
|
||||
or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
)
|
||||
}
|
||||
|
||||
// Configuration supplémentaire pour Android 11+
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
window.setDecorFitsSystemWindows(false)
|
||||
}
|
||||
|
||||
// Masquer les barres système
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
window.statusBarColor = android.graphics.Color.TRANSPARENT
|
||||
window.navigationBarColor = android.graphics.Color.TRANSPARENT
|
||||
}
|
||||
}
|
||||
|
||||
private fun enableKioskMode() {
|
||||
try {
|
||||
isKioskModeActive = true
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
window.decorView.systemUiVisibility = (
|
||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
)
|
||||
}
|
||||
|
||||
// Empêcher l'extinction de l'écran
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
||||
// Masquer la barre de navigation pour les écrans avec encoche
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
window.attributes.layoutInDisplayCutoutMode =
|
||||
WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun enableAdvancedKioskMode() {
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
try {
|
||||
isKioskModeActive = true
|
||||
val packages = arrayOf(packageName)
|
||||
devicePolicyManager.setLockTaskPackages(compName, packages)
|
||||
startLockTask()
|
||||
|
||||
// Désactiver la barre de statut si Device Owner
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
devicePolicyManager.setStatusBarDisabled(compName, true)
|
||||
}
|
||||
|
||||
// Appliquer aussi les configurations de base
|
||||
enableKioskMode()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
// Fallback vers le mode kiosque de base
|
||||
enableKioskMode()
|
||||
}
|
||||
} else {
|
||||
// Si pas Device Owner, utiliser le mode kiosque de base
|
||||
enableKioskMode()
|
||||
}
|
||||
}
|
||||
|
||||
private fun disableAdvancedKioskMode() {
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
try {
|
||||
stopLockTask()
|
||||
|
||||
// Réactiver la barre de statut
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
devicePolicyManager.setStatusBarDisabled(compName, false)
|
||||
}
|
||||
|
||||
exitKioskMode()
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
exitKioskMode()
|
||||
}
|
||||
} else {
|
||||
exitKioskMode()
|
||||
}
|
||||
}
|
||||
|
||||
private fun exitKioskMode() {
|
||||
try {
|
||||
isKioskModeActive = false
|
||||
|
||||
// Restaurer l'UI normale
|
||||
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE
|
||||
|
||||
// Permettre l'extinction automatique de l'écran
|
||||
window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun setBrightness(brightness: Float) {
|
||||
try {
|
||||
runOnUiThread {
|
||||
val layoutParams = window.attributes
|
||||
layoutParams.screenBrightness = brightness.coerceIn(0.0f, 1.0f)
|
||||
window.attributes = layoutParams
|
||||
}
|
||||
|
||||
// Log pour debug
|
||||
android.util.Log.d("MainActivity", "Luminosité réglée à: ${(brightness * 100).toInt()}%")
|
||||
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MainActivity", "Erreur réglage luminosité: ${e.message}")
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
private fun getSystemBrightness(): Float {
|
||||
return try {
|
||||
val currentBrightness = window.attributes.screenBrightness
|
||||
if (currentBrightness >= 0) {
|
||||
android.util.Log.d("MainActivity", "Luminosité actuelle: ${(currentBrightness * 100).toInt()}%")
|
||||
currentBrightness
|
||||
} else {
|
||||
0.5f
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MainActivity", "Erreur lecture luminosité: ${e.message}")
|
||||
0.5f
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun openWhatsApp(): Boolean {
|
||||
return try {
|
||||
// Sortir du Lock Task si on est Device Owner
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
try {
|
||||
stopLockTask()
|
||||
android.util.Log.d("MainActivity", "Lock Task arrêté pour WhatsApp")
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MainActivity", "Erreur arrêt Lock Task: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
// Désactiver le mode kiosque temporairement
|
||||
exitKioskMode()
|
||||
|
||||
val packageManager = packageManager
|
||||
|
||||
// Essayer WhatsApp Business EN PREMIER
|
||||
var intent = packageManager.getLaunchIntentForPackage("com.whatsapp.w4b")
|
||||
|
||||
if (intent != null) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
startActivity(intent)
|
||||
android.util.Log.d("MainActivity", "WhatsApp Business ouvert")
|
||||
return true
|
||||
}
|
||||
|
||||
// Fallback vers WhatsApp normal
|
||||
intent = packageManager.getLaunchIntentForPackage("com.whatsapp")
|
||||
if (intent != null) {
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
startActivity(intent)
|
||||
android.util.Log.d("MainActivity", "WhatsApp normal ouvert")
|
||||
return true
|
||||
}
|
||||
|
||||
// Si aucun WhatsApp installé, ouvrir le Play Store pour WhatsApp Business
|
||||
try {
|
||||
val playStoreIntent = Intent(Intent.ACTION_VIEW).apply {
|
||||
data = Uri.parse("market://details?id=com.whatsapp.w4b")
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
startActivity(playStoreIntent)
|
||||
return true
|
||||
} catch (e: Exception) {
|
||||
val webIntent = Intent(Intent.ACTION_VIEW).apply {
|
||||
data = Uri.parse("https://play.google.com/store/apps/details?id=com.whatsapp.w4b")
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
startActivity(webIntent)
|
||||
return true
|
||||
}
|
||||
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MainActivity", "Erreur ouverture WhatsApp: ${e.message}")
|
||||
e.printStackTrace()
|
||||
// Réactiver le mode kiosque en cas d'erreur
|
||||
enableKioskMode()
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun openWifiSettings() {
|
||||
try {
|
||||
// Sortir du Lock Task si on est Device Owner
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
try {
|
||||
stopLockTask()
|
||||
android.util.Log.d("MainActivity", "Lock Task arrêté pour WiFi")
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MainActivity", "Erreur arrêt Lock Task: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
// Désactiver le mode kiosque temporairement
|
||||
exitKioskMode()
|
||||
|
||||
// Essayer d'ouvrir directement les paramètres WiFi
|
||||
val intent = Intent(Settings.ACTION_WIFI_SETTINGS).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
}
|
||||
startActivity(intent)
|
||||
|
||||
android.util.Log.d("MainActivity", "Paramètres WiFi ouverts")
|
||||
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MainActivity", "Erreur ouverture WiFi: ${e.message}")
|
||||
e.printStackTrace()
|
||||
// Fallback vers les paramètres généraux
|
||||
openSettings()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun openSettings() {
|
||||
try {
|
||||
// Sortir du Lock Task si on est Device Owner
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
try {
|
||||
stopLockTask()
|
||||
} catch (e: Exception) {
|
||||
android.util.Log.e("MainActivity", "Erreur arrêt Lock Task: ${e.message}")
|
||||
}
|
||||
}
|
||||
|
||||
// Désactiver le mode kiosque temporairement
|
||||
exitKioskMode()
|
||||
|
||||
val intent = Intent(Settings.ACTION_SETTINGS).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
}
|
||||
startActivity(intent)
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
// Réactiver le mode kiosque en cas d'erreur
|
||||
enableKioskMode()
|
||||
}
|
||||
}
|
||||
|
||||
private fun requestDeviceAdmin() {
|
||||
val intent = Intent(DevicePolicyManager.ACTION_ADD_DEVICE_ADMIN).apply {
|
||||
putExtra(DevicePolicyManager.EXTRA_DEVICE_ADMIN, compName)
|
||||
putExtra(DevicePolicyManager.EXTRA_ADD_EXPLANATION,
|
||||
"Cette application nécessite des privilèges d'administrateur pour fonctionner en mode kiosque.")
|
||||
}
|
||||
startActivityForResult(intent, 1)
|
||||
}
|
||||
|
||||
private fun preventStatusBarExpansion() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
try {
|
||||
// Empêcher l'expansion de la barre de statut
|
||||
val service = getSystemService(Context.STATUS_BAR_SERVICE)
|
||||
val statusbarManager = Class.forName("android.app.StatusBarManager")
|
||||
val expand = statusbarManager.getMethod("collapsePanels")
|
||||
expand.invoke(service)
|
||||
|
||||
// Désactiver les notifications pour cette app si Device Owner
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
devicePolicyManager.setStatusBarDisabled(compName, true)
|
||||
}
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun enableStatusBarExpansion(enable: Boolean) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
try {
|
||||
devicePolicyManager.setStatusBarDisabled(compName, !enable)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated("Deprecated in Java")
|
||||
override fun onBackPressed() {
|
||||
// Désactiver le bouton retour en mode kiosque uniquement
|
||||
if (isKioskModeActive) {
|
||||
// Permettre le bouton retour pour la navigation dans l'app en mode kiosque avancé
|
||||
if (devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
super.onBackPressed()
|
||||
}
|
||||
// Sinon, ne rien faire pour empêcher la sortie
|
||||
} else {
|
||||
// Permettre la navigation normale quand pas en mode kiosque
|
||||
super.onBackPressed()
|
||||
}
|
||||
}
|
||||
|
||||
override fun onUserLeaveHint() {
|
||||
super.onUserLeaveHint()
|
||||
// Ne forcer le retour que si en mode kiosque
|
||||
if (isKioskModeActive) {
|
||||
try {
|
||||
val intent = Intent(this, MainActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
}
|
||||
startActivity(intent)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
super.onPause()
|
||||
// Ramener immédiatement l'app au premier plan en mode kiosque avancé seulement
|
||||
if (isKioskModeActive && devicePolicyManager.isDeviceOwnerApp(packageName)) {
|
||||
val intent = Intent(this, MainActivity::class.java).apply {
|
||||
addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT)
|
||||
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
|
||||
}
|
||||
startActivity(intent)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroy() {
|
||||
super.onDestroy()
|
||||
// Supprimer l'overlay si il existe
|
||||
if (overlayView != null) {
|
||||
try {
|
||||
val windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
|
||||
windowManager.removeView(overlayView)
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
12
android/app/src/main/res/drawable-v21/launch_background.xml
Normal file
12
android/app/src/main/res/drawable-v21/launch_background.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Modify this file to customize your launch splash screen -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="?android:colorBackground" />
|
||||
|
||||
<!-- You can insert your own image assets here -->
|
||||
<!-- <item>
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:src="@mipmap/launch_image" />
|
||||
</item> -->
|
||||
</layer-list>
|
||||
12
android/app/src/main/res/drawable/launch_background.xml
Normal file
12
android/app/src/main/res/drawable/launch_background.xml
Normal file
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Modify this file to customize your launch splash screen -->
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item android:drawable="@android:color/white" />
|
||||
|
||||
<!-- You can insert your own image assets here -->
|
||||
<!-- <item>
|
||||
<bitmap
|
||||
android:gravity="center"
|
||||
android:src="@mipmap/launch_image" />
|
||||
</item> -->
|
||||
</layer-list>
|
||||
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 544 B |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 442 B |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 721 B |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.0 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.4 KiB |
18
android/app/src/main/res/values-night/styles.xml
Normal file
18
android/app/src/main/res/values-night/styles.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is on -->
|
||||
<style name="LaunchTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||
<!-- Show a splash screen on the activity. Automatically removed when
|
||||
the Flutter engine draws its first frame -->
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
Flutter UI initializes, as well as behind your Flutter UI while its
|
||||
running.
|
||||
|
||||
This Theme is only used starting with V2 of Flutter's Android embedding. -->
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Black.NoTitleBar">
|
||||
<item name="android:windowBackground">?android:colorBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
18
android/app/src/main/res/values/styles.xml
Normal file
18
android/app/src/main/res/values/styles.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<!-- Theme applied to the Android Window while the process is starting when the OS's Dark Mode setting is off -->
|
||||
<style name="LaunchTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||
<!-- Show a splash screen on the activity. Automatically removed when
|
||||
the Flutter engine draws its first frame -->
|
||||
<item name="android:windowBackground">@drawable/launch_background</item>
|
||||
</style>
|
||||
<!-- Theme applied to the Android Window as soon as the process has started.
|
||||
This theme determines the color of the Android Window while your
|
||||
Flutter UI initializes, as well as behind your Flutter UI while its
|
||||
running.
|
||||
|
||||
This Theme is only used starting with V2 of Flutter's Android embedding. -->
|
||||
<style name="NormalTheme" parent="@android:style/Theme.Light.NoTitleBar">
|
||||
<item name="android:windowBackground">?android:colorBackground</item>
|
||||
</style>
|
||||
</resources>
|
||||
14
android/app/src/main/res/xml/device_admin.xml
Normal file
14
android/app/src/main/res/xml/device_admin.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<device-admin xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<uses-policies>
|
||||
<limit-password />
|
||||
<watch-login />
|
||||
<reset-password />
|
||||
<force-lock />
|
||||
<wipe-data />
|
||||
<expire-password />
|
||||
<encrypted-storage />
|
||||
<disable-camera />
|
||||
<disable-keyguard />
|
||||
</uses-policies>
|
||||
</device-admin>
|
||||
7
android/app/src/profile/AndroidManifest.xml
Normal file
7
android/app/src/profile/AndroidManifest.xml
Normal file
@@ -0,0 +1,7 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<!-- The INTERNET permission is required for development. Specifically,
|
||||
the Flutter tool needs it to communicate with the running application
|
||||
to allow setting breakpoints, to provide hot reload, etc.
|
||||
-->
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
</manifest>
|
||||
Reference in New Issue
Block a user