From 058241c9180c5e9a0a256e8e22865c329ffb2f0f Mon Sep 17 00:00:00 2001
From: Alessandro Ferro <49845537+xfarrow@users.noreply.github.com>
Date: Fri, 30 Sep 2022 09:31:00 +0200
Subject: [PATCH] Added options "wifi-enable" and "wifi-disable"
---
src/app/src/main/AndroidManifest.xml | 3 +-
.../xfarrow/locatemydevice/SmsHandler.java | 63 ++++++++++++++-----
.../com/xfarrow/locatemydevice/Utils.java | 2 +
3 files changed, 50 insertions(+), 18 deletions(-)
diff --git a/src/app/src/main/AndroidManifest.xml b/src/app/src/main/AndroidManifest.xml
index b23efec..ac5506c 100644
--- a/src/app/src/main/AndroidManifest.xml
+++ b/src/app/src/main/AndroidManifest.xml
@@ -11,6 +11,7 @@
+
+ tools:targetApi="30">
= Build.VERSION_CODES.O_MR1) {
+ responseSms.append("Location is off. Unable to execute command.");
+ Utils.sendSms(smsManager, responseSms.toString(), sender);
+ return;
+ }
+
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
responseSms.append("Wifi enabled: ");
- if(!wifiManager.isWifiEnabled()){
+ if (!wifiManager.isWifiEnabled()) {
responseSms.append("No");
- }
- else{
- responseSms.append("Yes\n");
-
- WifiInfo wifiInfo = wifiManager.getConnectionInfo();
- String ssid = (wifiInfo.getSSID().equals(WifiManager.UNKNOWN_SSID))?
- "Not connected or unknown" : wifiInfo.getSSID();
-
- responseSms.append("SSID: ").append(ssid).append("\n");
- responseSms.append("BSSID: ").append(wifiInfo.getBSSID()).append("\n");
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
- responseSms.append("Strength: ").append(wifiManager.calculateSignalLevel(wifiInfo.getRssi()))
- .append("/").append(wifiManager.getMaxSignalLevel()).append("\n");
- }
+ Utils.sendSms(smsManager, responseSms.toString(), sender);
+ return;
}
+ responseSms.append("Yes\n");
+ WifiInfo wifiInfo = wifiManager.getConnectionInfo();
+ String ssid = (wifiInfo.getSSID().equals(WifiManager.UNKNOWN_SSID)) ?
+ "Not connected or unknown" : wifiInfo.getSSID();
+ String bssid = (wifiInfo.getBSSID().equals("02:00:00:00:00:00")) ?
+ "Not connected or unknown" : wifiInfo.getBSSID();
+ responseSms.append("SSID: ").append(ssid).append("\n");
+ responseSms.append("BSSID: ").append(bssid).append("\n");
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
+ responseSms.append("Strength: ").append(wifiManager.calculateSignalLevel(wifiInfo.getRssi()))
+ .append("/").append(wifiManager.getMaxSignalLevel()).append("\n");
+ }
responseSms.append("\nNearby networks:");
List scanResults = wifiManager.getScanResults();
- for(ScanResult scanResult : scanResults){
+ for (ScanResult scanResult : scanResults) {
responseSms.append("\n");
responseSms.append("SSID: ").append(scanResult.SSID).append("\n");
responseSms.append("BSSID: ").append(scanResult.BSSID).append("\n");
@@ -269,5 +280,23 @@ public class SmsHandler {
}
Utils.sendSms(smsManager, responseSms.toString(), sender);
}
+
+ // wifi-enabled OR wifi-disabled
+ else if(providedOption.contains(Utils.WIFI_OPTION) && (providedOption.contains(Utils.WIFI_ENABLE_SUBOPTION)
+ || providedOption.contains(Utils.WIFI_DISABLE_SUBOPTION))){
+
+ StringBuilder responseSms = new StringBuilder();
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q){
+ responseSms.append("Your device does not support this option.");
+ Utils.sendSms(smsManager, responseSms.toString(), sender);
+ return;
+ }
+
+ WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
+ wifiManager.setWifiEnabled(providedOption.contains(Utils.WIFI_ENABLE_SUBOPTION));
+ responseSms.append("Command executed");
+ Utils.sendSms(smsManager, responseSms.toString(), sender);
+ }
+
}
}
diff --git a/src/app/src/main/java/com/xfarrow/locatemydevice/Utils.java b/src/app/src/main/java/com/xfarrow/locatemydevice/Utils.java
index 8750176..c7c8268 100644
--- a/src/app/src/main/java/com/xfarrow/locatemydevice/Utils.java
+++ b/src/app/src/main/java/com/xfarrow/locatemydevice/Utils.java
@@ -17,6 +17,8 @@ public class Utils {
public static final String BATTERY_OPTION = "battery";
public static final String CALL_ME_OPTION = "callme";
public static final String WIFI_OPTION = "wifi";
+ public static final String WIFI_ENABLE_SUBOPTION = "-enable";
+ public static final String WIFI_DISABLE_SUBOPTION = "-disable";
public static String getCountryNameByIso(String iso){
Locale locale = new Locale("", iso);