Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/ handle connect wifi error state #1189

Merged
merged 28 commits into from
Aug 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
58408e8
handle connect wifi error state
ghassenbenzahra123 Jun 21, 2024
6b5c0f2
change filename to undercase
ghassenbenzahra123 Jun 22, 2024
befcf4f
add mawaqit box v2 connect wifi new method
ghassenbenzahra123 Jun 26, 2024
dc256b0
handle new box connect status
ghassenbenzahra123 Jul 3, 2024
89f53ae
programaticaly add fine location permission
ghassenbenzahra123 Jul 3, 2024
198d7fe
add await to scan access points
ghassenbenzahra123 Jul 4, 2024
9064c84
fix auto scan access points & focus exit & unique ssids
ghassenbenzahra123 Jul 8, 2024
f88d06a
init state wifi notifier
ghassenbenzahra123 Jul 9, 2024
3890097
add delay & retry on empty list
ghassenbenzahra123 Jul 9, 2024
9e1a896
Revert "add delay & retry on empty list"
ghassenbenzahra123 Jul 9, 2024
bc2f74c
fix permission on startup
ghassenbenzahra123 Jul 9, 2024
d024ee9
Merge branch 'main' into fix/handle-failed-wifi-connect
YassinNouh21 Jul 9, 2024
9c34a3d
Revert "fix permission on startup"
ghassenbenzahra123 Jul 10, 2024
3575492
Merge branch 'fix/handle-failed-wifi-connect' of https://github.com/m…
ghassenbenzahra123 Jul 10, 2024
86261bc
recall getscanned results on empty array
ghassenbenzahra123 Jul 10, 2024
323fc36
refactor wifi scan method
ghassenbenzahra123 Jul 11, 2024
b5131be
add permission on timezone
ghassenbenzahra123 Jul 11, 2024
eade0cc
fix enable state on off tv
ghassenbenzahra123 Jul 15, 2024
96fb3ad
change toast package to handle duration
ghassenbenzahra123 Jul 15, 2024
6c0027d
fix circular progress indicator
ghassenbenzahra123 Jul 16, 2024
121cb5f
format files
ghassenbenzahra123 Jul 16, 2024
ca90905
refactor ux onboarding
ghassenbenzahra123 Jul 19, 2024
182834e
fix ux issues
ghassenbenzahra123 Jul 24, 2024
4c57eb1
force unfocus textsearchfield
ghassenbenzahra123 Jul 24, 2024
cf765d2
switch willpopscope to keyboard detect
ghassenbenzahra123 Jul 25, 2024
2f82d95
fix top padding
ghassenbenzahra123 Aug 2, 2024
357ca4d
format files & restore root check status
ghassenbenzahra123 Aug 7, 2024
31a1444
Merge branch 'main' into fix/handle-failed-wifi-connect
ghassenbenzahra123 Aug 7, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ android {

defaultConfig {
applicationId "com.mawaqit.androidtv"
minSdkVersion 19
minSdkVersion 21
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
Expand Down
109 changes: 105 additions & 4 deletions android/app/src/main/kotlin/com/flyweb/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ import java.io.IOException
import android.app.KeyguardManager
import android.os.AsyncTask
import android.util.Log
import android.net.wifi.WifiConfiguration
import android.net.wifi.WifiManager
import android.net.ConnectivityManager

class MainActivity : FlutterActivity() {
private lateinit var mAdminComponentName: ComponentName
Expand All @@ -47,6 +50,11 @@ class MainActivity : FlutterActivity() {
"checkRoot" -> result.success(checkRoot())
"toggleBoxScreenOff" -> toggleBoxScreenOff(call, result)
"toggleBoxScreenOn" -> toggleBoxScreenOn(call, result)
"connectToNetworkWPA" -> connectToNetworkWPA(call, result)
"addLocationPermission" -> addLocationPermission(call, result)
"grantFineLocationPermission" -> grantFineLocationPermission(call, result)
"sendDownArrowEvent" -> sendDownArrowEvent(call, result)
"sendTabKeyEvent" -> sendTabKeyEvent(call, result)
"clearAppData" -> {
val isSuccess = clearDataRestart()
result.success(isSuccess)
Expand Down Expand Up @@ -98,6 +106,15 @@ class MainActivity : FlutterActivity() {
}
}
}
private fun addLocationPermission(call: MethodCall, result: MethodChannel.Result) {
AsyncTask.execute {
try {
executeCommand(listOf("settings put secure location_mode 3"), result)
} catch (e: Exception) {
handleCommandException(e, result)
}
}
}

private fun isPackageInstalled(packageName: String?): Boolean {
val packageManager = applicationContext.packageManager
Expand Down Expand Up @@ -125,10 +142,55 @@ class MainActivity : FlutterActivity() {
}
}
}
fun connectToNetworkWPA(call: MethodCall, result: MethodChannel.Result) {
AsyncTask.execute {
try {
val networkSSID = call.argument<String>("ssid")
val password = call.argument<String>("password")
ghassenbenzahra123 marked this conversation as resolved.
Show resolved Hide resolved
val conf = WifiConfiguration().apply {
SSID = "\"$networkSSID\""
status = WifiConfiguration.Status.ENABLED
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.TKIP)
allowedGroupCiphers.set(WifiConfiguration.GroupCipher.CCMP)
allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.TKIP)
allowedPairwiseCiphers.set(WifiConfiguration.PairwiseCipher.CCMP)
if (password.isNullOrEmpty()) {
allowedKeyManagement.set(WifiConfiguration.KeyMgmt.NONE)
} else {
preSharedKey = "\"$password\""
allowedKeyManagement.set(WifiConfiguration.KeyMgmt.WPA_PSK)
}
}

Log.d("connectToNetworkWPA", "Connecting to SSID: ${conf.SSID}")

val wifiManager = applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
val networkId = wifiManager.addNetwork(conf)
wifiManager.disconnect()
wifiManager.enableNetwork(networkId, true)
wifiManager.reconnect()

// Wait for the connection to be established
var connectionAttempts = 0
while (wifiManager.getConnectionInfo().networkId == -1 && connectionAttempts < 3) {
Thread.sleep(500)
connectionAttempts++
}
ghassenbenzahra123 marked this conversation as resolved.
Show resolved Hide resolved

val wifiInfo = wifiManager.getConnectionInfo()
if (wifiInfo.networkId != -1) {
Log.d("connectToNetworkWPA", "Connected to network:")
result.success(true)
} else {
Log.e("connectToNetworkWPA", "Failed to connect to network")
result.success(false)
}
} catch (ex: Exception) {
Log.e("connectToNetworkWPA", "Error connecting to network", ex)
result.error("exception", ex.message, ex)
}
}
}

private fun clearDataRestart(): Boolean {
return try {
Expand All @@ -145,8 +207,6 @@ class MainActivity : FlutterActivity() {
}
}



private fun toggleBoxScreenOff(call: MethodCall, result: MethodChannel.Result) {
AsyncTask.execute {
try {
Expand All @@ -161,6 +221,19 @@ class MainActivity : FlutterActivity() {
}
}
}
private fun grantFineLocationPermission(call: MethodCall, result: MethodChannel.Result) {
AsyncTask.execute {
try {
val commands = listOf(
"pm grant com.mawaqit.androidtv android.permission.ACCESS_FINE_LOCATION",

)
executeCommand(commands, result) // Lock the device
} catch (e: Exception) {
handleCommandException(e, result)
}
}
}

private fun toggleBoxScreenOn(call: MethodCall, result: MethodChannel.Result) {
AsyncTask.execute {
Expand All @@ -177,6 +250,31 @@ class MainActivity : FlutterActivity() {
}
}
}
private fun sendDownArrowEvent(call: MethodCall, result: MethodChannel.Result) {
AsyncTask.execute {
try {
val commands = listOf(
"input keyevent 20"
)
executeCommand(commands, result)
} catch (e: Exception) {
handleCommandException(e, result)
}
}
}
private fun sendTabKeyEvent(call: MethodCall, result: MethodChannel.Result) {
AsyncTask.execute {
try {
val commands = listOf(
"input keyevent 61"
)
executeCommand(commands, result)
} catch (e: Exception) {
handleCommandException(e, result)
}
}
}




Expand All @@ -202,7 +300,7 @@ class MainActivity : FlutterActivity() {
val exitCode = suProcess.waitFor()
Log.d("SU_COMMAND", "Exit code: $exitCode")

if (exitCode != 0) {
if (exitCode != 0 || output.contains("Connection failed")) {
Log.e("SU_COMMAND", "Command failed with exit code $exitCode.")
result.success(false)
} else {
Expand All @@ -215,7 +313,10 @@ class MainActivity : FlutterActivity() {
}
}



private fun handleCommandException(e: Exception, result: MethodChannel.Result) {
result.error("Exception", "An exception occurred: $e", null)
}
}
}

2 changes: 1 addition & 1 deletion lib/src/pages/WifiSelectorScreen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:mawaqit/const/resource.dart';
import 'package:mawaqit/src/pages/onBoarding/widgets/Wifi_selector_widget.dart';
import 'package:mawaqit/src/pages/onBoarding/widgets/wifi_selector_widget.dart';
import 'package:mawaqit/src/pages/onBoarding/widgets/onboarding_timezone_selector.dart';
import 'package:mawaqit/src/widgets/ScreenWithAnimation.dart';

Expand Down
12 changes: 7 additions & 5 deletions lib/src/pages/onBoarding/OnBoardingScreen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import '../../../i18n/l10n.dart';
import '../../helpers/LocaleHelper.dart';
import '../../state_management/on_boarding/on_boarding_notifier.dart';
import '../../widgets/mawaqit_back_icon_button.dart';
import 'widgets/Wifi_selector_widget.dart';
import 'widgets/wifi_selector_widget.dart';
import 'widgets/onboarding_screen_type.dart';

class OnBoardingItem {
Expand All @@ -32,7 +32,7 @@ class OnBoardingItem {
final bool enablePreviousButton;
final bool skipPage;
final bool Function()? skip;

late FocusNode skipButtonFocusNode;
OnBoardingItem({
required this.animation,
this.widget,
Expand All @@ -56,7 +56,7 @@ class _OnBoardingScreenState extends riverpod.ConsumerState<OnBoardingScreen> {
final sharedPref = SharedPref();
int currentScreen = 0;
bool _rootStatus = false;

late FocusNode skipButtonFocusNode = FocusNode();
late List<OnBoardingItem> onBoardingItems = [
OnBoardingItem(
animation: 'language',
Expand Down Expand Up @@ -145,12 +145,12 @@ class _OnBoardingScreenState extends riverpod.ConsumerState<OnBoardingScreen> {
),
OnBoardingItem(
animation: 'settings',
widget: OnBoardingTimeZoneSelector(onSelect: () => nextPage(2)),
widget: OnBoardingTimeZoneSelector(onSelect: () => nextPage(2), focusNode: skipButtonFocusNode),
enablePreviousButton: true,
skipPage: true),
OnBoardingItem(
animation: 'settings',
widget: OnBoardingWifiSelector(onSelect: () => nextPage(3)),
widget: OnBoardingWifiSelector(onSelect: () => nextPage(3), focusNode: skipButtonFocusNode),
enablePreviousButton: true,
skipPage: true),
OnBoardingItem(
Expand Down Expand Up @@ -294,12 +294,14 @@ class _OnBoardingScreenState extends riverpod.ConsumerState<OnBoardingScreen> {
),
if (activePage.enableNextButton)
MawaqitIconButton(
focusNode: skipButtonFocusNode,
icon: Icons.arrow_forward_rounded,
label: S.of(context).next,
onPressed: () => nextPage(currentScreen + 1),
),
if (activePage.skipPage)
MawaqitIconButton(
focusNode: skipButtonFocusNode,
icon: Icons.arrow_forward_rounded,
label: S.of(context).skip,
onPressed: () => nextPage(currentScreen + 1),
Expand Down
Loading
Loading