Added wifi option (beta)

This commit is contained in:
Alessandro Ferro 2022-09-29 23:11:53 +02:00
parent 2406ed411d
commit 2c23b000e9
2 changed files with 38 additions and 1 deletions

View File

@ -11,6 +11,9 @@ import android.location.Location;
import android.location.LocationListener; import android.location.LocationListener;
import android.location.LocationManager; import android.location.LocationManager;
import android.net.Uri; import android.net.Uri;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.os.Build; import android.os.Build;
import android.telephony.CellInfo; import android.telephony.CellInfo;
@ -51,7 +54,9 @@ public class SmsHandler {
+ "|" + "|"
+ Utils.BATTERY_OPTION + Utils.BATTERY_OPTION
+ "|" + "|"
+ Utils.CALL_ME_OPTION; + Utils.CALL_ME_OPTION
+ "|"
+ Utils.WIFI_OPTION;
Pattern pattern = Pattern.compile(regexToMatch); Pattern pattern = Pattern.compile(regexToMatch);
Matcher matcher = pattern.matcher(message); Matcher matcher = pattern.matcher(message);
@ -229,5 +234,36 @@ public class SmsHandler {
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent); context.startActivity(intent);
} }
else if(providedOption.equals(Utils.WIFI_OPTION)){
StringBuilder responseSms = new StringBuilder();
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
responseSms.append("Wifi enabled: ");
if(!wifiManager.isWifiEnabled()){
responseSms.append("No");
}
else{
responseSms.append("Yes\n");
WifiInfo wifiInfo = wifiManager.getConnectionInfo();
responseSms.append("SSID: ").append(wifiInfo.getSSID()).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");
}
}
responseSms.append("\nNearby networks:");
List<ScanResult> scanResults = wifiManager.getScanResults();
for(ScanResult scanResult : scanResults){
responseSms.append("\n");
responseSms.append("SSID: ").append(scanResult.SSID).append("\n");
responseSms.append("BSSID: ").append(scanResult.BSSID).append("\n");
responseSms.append("Security: ").append(scanResult.capabilities).append("\n");
}
Utils.sendSms(smsManager, responseSms.toString(), sender);
}
} }
} }

View File

@ -16,6 +16,7 @@ public class Utils {
public static final String CELLULAR_INFO_OPTION = "cellinfo"; public static final String CELLULAR_INFO_OPTION = "cellinfo";
public static final String BATTERY_OPTION = "battery"; public static final String BATTERY_OPTION = "battery";
public static final String CALL_ME_OPTION = "callme"; public static final String CALL_ME_OPTION = "callme";
public static final String WIFI_OPTION = "wifi";
public static String getCountryNameByIso(String iso){ public static String getCountryNameByIso(String iso){
Locale locale = new Locale("", iso); Locale locale = new Locale("", iso);