Skip to content

Commit

Permalink
Fixed : Ignore wifi state check when user has enabled localhost option
Browse files Browse the repository at this point in the history
  • Loading branch information
umer0586 committed Dec 2, 2022
1 parent a5df9c0 commit 2c29019
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 10 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
minSdk 21
targetSdk 31
multiDexEnabled true
versionCode 12
versionName "2.2.2"
versionCode 13
versionName "2.2.3"


}
Expand Down
27 changes: 20 additions & 7 deletions app/src/main/java/github/umer0586/fragments/ServerFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import github.umer0586.sensorserver.ServerInfo;
import github.umer0586.service.SensorService;
import github.umer0586.service.ServiceBindHelper;
import github.umer0586.setting.AppSettings;
import github.umer0586.util.UIUtil;


Expand All @@ -42,6 +43,7 @@ public class ServerFragment extends Fragment

private SensorService sensorService;
private ServiceBindHelper serviceBindHelper;
private AppSettings appSettings;

// Button at center to start/stop server
private MaterialButton startButton;
Expand Down Expand Up @@ -75,6 +77,8 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
pulseAnimation = view.findViewById(R.id.loading_animation);
cardView = view.findViewById(R.id.card_view);

appSettings = new AppSettings(getContext());

serviceBindHelper = new ServiceBindHelper(
getContext(),
this,
Expand Down Expand Up @@ -115,17 +119,26 @@ private void startServer()
Log.d(TAG, "startServer() called");

WifiManager wifiManager = (WifiManager) getContext().getApplicationContext().getSystemService(getContext().WIFI_SERVICE);

// TODO: ignore wifi check when user has enabled adb option
if(!wifiManager.isWifiEnabled())

//If user has enabled local-host option (for adb) then don't check wifi state
if(appSettings.isLocalHostOptionEnable())
{
Intent intent = new Intent(getContext(), SensorService.class);
ContextCompat.startForegroundService(getContext(),intent);
}
//If user has not enabled local-host option then check if wifi is enabled
else if(wifiManager.isWifiEnabled())
{
Intent intent = new Intent(getContext(), SensorService.class);
ContextCompat.startForegroundService(getContext(),intent);
}

else
{
showMessage("Please enable Wi-Fi");
return;
}

serviceBindHelper.bindToService();
Intent intent = new Intent(getContext(), SensorService.class);
ContextCompat.startForegroundService(getContext(),intent);


}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public int onStartCommand(Intent intent, int flags, int startId)

String ipAddress = null;

// is "local host" switch in enable
// if "local host" switch in enable
// no need to check for wifi network
if(appSettings.isLocalHostOptionEnable())
ipAddress = "127.0.0.1"; // use loopback address
Expand Down

0 comments on commit 2c29019

Please sign in to comment.