diff --git a/src/.idea/deploymentTargetDropDown.xml b/src/.idea/deploymentTargetDropDown.xml index f0276b9..8234aff 100644 --- a/src/.idea/deploymentTargetDropDown.xml +++ b/src/.idea/deploymentTargetDropDown.xml @@ -12,6 +12,6 @@ - + \ No newline at end of file diff --git a/src/app/release/app-release.apk b/src/app/release/app-release.apk index 180ffaf..5bf9946 100644 Binary files a/src/app/release/app-release.apk and b/src/app/release/app-release.apk differ diff --git a/src/app/src/main/java/com/xfarrow/locatemydevice/MainActivity.java b/src/app/src/main/java/com/xfarrow/locatemydevice/MainActivity.java index bd567ce..033a5c3 100644 --- a/src/app/src/main/java/com/xfarrow/locatemydevice/MainActivity.java +++ b/src/app/src/main/java/com/xfarrow/locatemydevice/MainActivity.java @@ -10,6 +10,7 @@ import androidx.core.app.ActivityCompat; import android.Manifest; import android.content.Intent; import android.content.pm.PackageManager; +import android.os.Build; import android.os.Bundle; import android.util.Log; import android.view.Menu; @@ -40,12 +41,29 @@ public class MainActivity extends AppCompatActivity { new String[]{Manifest.permission.SEND_SMS}, Utils.PERMISSION_SMS_SEND); } + + if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { + + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, + Utils.PERMISSION_ACCESS_COARSE_LOCATION); + } + if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, Utils.PERMISSION_ACCESS_FINE_LOCATION); } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) { + if(ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_BACKGROUND_LOCATION) != PackageManager.PERMISSION_GRANTED) { + ActivityCompat.requestPermissions(this, + new String[]{Manifest.permission.ACCESS_BACKGROUND_LOCATION}, + Utils.PERMISSION_ACCESS_BACKGROUND_LOCATION); + } + } + } @Override diff --git a/src/app/src/main/java/com/xfarrow/locatemydevice/SmsHandler.java b/src/app/src/main/java/com/xfarrow/locatemydevice/SmsHandler.java index 2355cc4..f4134b4 100644 --- a/src/app/src/main/java/com/xfarrow/locatemydevice/SmsHandler.java +++ b/src/app/src/main/java/com/xfarrow/locatemydevice/SmsHandler.java @@ -22,6 +22,7 @@ import androidx.annotation.NonNull; import androidx.annotation.RequiresApi; import androidx.core.app.ActivityCompat; +import java.security.cert.CertPathValidatorException; import java.util.List; import java.util.function.Consumer; import java.util.regex.Matcher; @@ -86,7 +87,7 @@ public class SmsHandler { } // API 31 and above - if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ locationManager.getCurrentLocation(LocationManager.FUSED_PROVIDER, null, context.getMainExecutor(), new Consumer() { @Override public void accept(Location location) { @@ -112,17 +113,29 @@ public class SmsHandler { else if(providedOption.equals(Utils.CELLULAR_INFO_OPTION)) { TelephonyManager telephony = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); + StringBuilder resultSms = new StringBuilder(); - resultSms.append("Towers in range:"); + resultSms.append("Network country: "); + String country = telephony.getNetworkCountryIso(); + resultSms.append(Utils.getCountryNameByIso(country)).append("\n\n"); + List availableTowersInRange = telephony.getAllCellInfo(); + resultSms.append("Towers in range: "); + if(availableTowersInRange.size() == 0) { + resultSms.append("none or location is off."); + } + for(CellInfo tower : availableTowersInRange){ resultSms.append("\n\n"); + if(tower.isRegistered()){ resultSms.append("[Connected to this tower]\n"); } if (tower instanceof CellInfoWcdma) { resultSms.append("Radio Type: WCDMA\n"); + resultSms.append("Strength: "); + resultSms.append(((CellInfoWcdma)tower).getCellSignalStrength().getLevel()).append("/4\n"); resultSms.append("CID: ").append(((CellInfoWcdma) tower).getCellIdentity().getCid()).append("\n"); resultSms.append("LAC: ").append(((CellInfoWcdma) tower).getCellIdentity().getLac()).append("\n"); resultSms.append("MCC: ").append(((CellInfoWcdma) tower).getCellIdentity().getMccString()).append("\n"); @@ -130,6 +143,8 @@ public class SmsHandler { } else if (tower instanceof CellInfoGsm) { resultSms.append("Radio Type: GSM\n"); + resultSms.append("Strength: "); + resultSms.append(((CellInfoGsm)tower).getCellSignalStrength().getLevel()).append("/4\n"); resultSms.append("CID: ").append(((CellInfoGsm) tower).getCellIdentity().getCid()).append("\n"); resultSms.append("LAC: ").append(((CellInfoGsm) tower).getCellIdentity().getLac()).append("\n"); resultSms.append("MCC: ").append(((CellInfoGsm) tower).getCellIdentity().getMccString()).append("\n"); @@ -137,6 +152,8 @@ public class SmsHandler { } else if (tower instanceof CellInfoLte) { resultSms.append("Radio Type: LTE\n"); + resultSms.append("Strength: "); + resultSms.append(((CellInfoLte)tower).getCellSignalStrength().getLevel()).append("/4\n"); resultSms.append("CI: ").append(((CellInfoLte) tower).getCellIdentity().getCi()).append("\n"); resultSms.append("TAC: ").append(((CellInfoLte) tower).getCellIdentity().getTac()).append("\n"); resultSms.append("MCC: ").append(((CellInfoLte) tower).getCellIdentity().getMccString()).append("\n"); @@ -144,6 +161,8 @@ public class SmsHandler { } else if (tower instanceof CellInfoCdma) { resultSms.append("Radio Type: CDMA\n"); + resultSms.append("Strength: "); + resultSms.append(((CellInfoCdma)tower).getCellSignalStrength().getLevel()).append("/4\n"); resultSms.append("Latitude: ").append(((CellInfoCdma) tower).getCellIdentity().getLatitude()).append("\n"); resultSms.append("Longitude: ").append(((CellInfoCdma) tower).getCellIdentity().getLongitude()).append("\n"); resultSms.append("Network ID: ").append(((CellInfoCdma) tower).getCellIdentity().getNetworkId()).append("\n"); 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 2f188ef..6967ac3 100644 --- a/src/app/src/main/java/com/xfarrow/locatemydevice/Utils.java +++ b/src/app/src/main/java/com/xfarrow/locatemydevice/Utils.java @@ -1,10 +1,15 @@ package com.xfarrow.locatemydevice; +import java.util.Arrays; +import java.util.Locale; + public class Utils { public static final int PERMISSION_SMS_RECEIVE = 100; public static final int PERMISSION_SMS_SEND = 101; public static final int PERMISSION_ACCESS_FINE_LOCATION = 102; + public static final int PERMISSION_ACCESS_COARSE_LOCATION = 103; + public static final int PERMISSION_ACCESS_BACKGROUND_LOCATION = 104; public static final String LOCATE_OPTION = "locate"; @@ -14,4 +19,9 @@ public class Utils { return "https://www.openstreetmap.org/?mlat=" + latitude + "&mlon=" + longitude; } + public static String getCountryNameByIso(String iso){ + Locale locale = new Locale("", iso); + return locale.getDisplayCountry(); + } + }