Skip to content

Commit

Permalink
Merge branch 'main' into zh
Browse files Browse the repository at this point in the history
  • Loading branch information
rksh authored Nov 7, 2024
2 parents 827ea2a + 75f6b86 commit 8905955
Show file tree
Hide file tree
Showing 49 changed files with 489 additions and 67 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ jobs:

steps:
- uses: actions/checkout@v3
- name: set up JDK 11
- name: set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '11'
java-version: '17'
distribution: 'temurin'
cache: gradle
- name: Update API KEY from Secrets
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.android.tools.build:gradle:8.1.1'
}
}
plugins {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
4 changes: 3 additions & 1 deletion wiglewifiwardriving/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ android {
vectorDrawables.useSupportLibrary = true
multiDexEnabled true
}
buildFeatures {
buildConfig = true
}

buildTypes {
release {
Expand All @@ -27,7 +30,6 @@ android {
excludes += ['META-INF/ASL2.0', 'META-INF/LICENSE', 'META-INF/NOTICE', 'META-INF/NOTICE.txt', 'META-INF/LICENSE.txt', 'META-INF/MANIFEST.MF']
}
}

}

configurations {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public void run() {
@Override
public void onClick( final DialogInterface dialog, final int which ) {
try {
dialog.dismiss();
}
catch ( Exception ex ) {
if (null != dialog) {
dialog.dismiss();
}
} catch ( Exception ex ) {
// guess it wasn't there anyways
Logging.info( "exception dismissing alert dialog: " + ex );
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2426,7 +2426,10 @@ public void checkStorage() {
iseDlgBuilder.setMessage(external?R.string.no_external_space_message:R.string.no_internal_space_message)
.setTitle(external?R.string.no_external_space_title:R.string.no_internal_space_title)
.setCancelable(true)
.setPositiveButton(R.string.ok, (dialog, which) -> dialog.dismiss());
.setPositiveButton(R.string.ok, (dialog, which) -> {
if (null != dialog) {
dialog.dismiss();
}});
final Dialog dialog = iseDlgBuilder.create();
if (!isFinishing()) {
dialog.show();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ private void setupMapView(final View view, final LatLng oldCenter, final int old
@Override
public Tile getTile(int x, int y, int zoom) {
if (!checkTileExists(x, y, zoom)) {
return null;
return NO_TILE;
}

final Long since = prefs.getLong(PreferenceKeys.PREF_SHOW_DISCOVERED_SINCE, 2001);
Expand Down Expand Up @@ -402,7 +402,11 @@ public Tile getTile(int x, int y, int zoom) {

try {
final byte[] data = downloadData(new URL(s), userAgent, authToken);
return new Tile(providerTileRes, providerTileRes, data);
if (data.length > 0) {
return new Tile(providerTileRes, providerTileRes, data);
} else {
return null;
}
} catch (MalformedURLException e) {
throw new AssertionError(e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;

import android.annotation.SuppressLint;
import android.app.Dialog;
Expand All @@ -28,6 +30,8 @@
import androidx.annotation.NonNull;
import androidx.fragment.app.DialogFragment;
import androidx.appcompat.app.ActionBar;
import androidx.fragment.app.FragmentActivity;

import android.text.ClipboardManager;
import android.text.InputType;
import android.view.LayoutInflater;
Expand All @@ -52,25 +56,32 @@
import com.google.android.material.textfield.TextInputEditText;
import com.google.gson.Gson;

import net.wigle.wigleandroid.background.KmlSurveyWriter;
import net.wigle.wigleandroid.background.PooledQueryExecutor;
import net.wigle.wigleandroid.db.DatabaseHelper;
import net.wigle.wigleandroid.listener.WiFiScanUpdater;
import net.wigle.wigleandroid.model.ConcurrentLinkedHashMap;
import net.wigle.wigleandroid.model.MccMncRecord;
import net.wigle.wigleandroid.model.Network;
import net.wigle.wigleandroid.model.NetworkType;
import net.wigle.wigleandroid.model.OUI;
import net.wigle.wigleandroid.model.Observation;
import net.wigle.wigleandroid.ui.NetworkListUtil;
import net.wigle.wigleandroid.ui.ScreenChildActivity;
import net.wigle.wigleandroid.ui.ThemeUtil;
import net.wigle.wigleandroid.ui.WiGLEConfirmationDialog;
import net.wigle.wigleandroid.util.Logging;
import net.wigle.wigleandroid.util.PreferenceKeys;

@SuppressWarnings("deprecation")
public class NetworkActivity extends ScreenChildActivity implements DialogListener {
public class NetworkActivity extends ScreenChildActivity implements DialogListener, WiFiScanUpdater {
private static final int MENU_RETURN = 11;
private static final int MENU_COPY = 12;
private static final int NON_CRYPTO_DIALOG = 130;

private static final int SITE_SURVEY_DIALOG = 131;


private static final int MSG_OBS_UPDATE = 1;
private static final int MSG_OBS_DONE = 2;

Expand All @@ -81,6 +92,7 @@ public class NetworkActivity extends ScreenChildActivity implements DialogListen
private int observations = 0;
private boolean isDbResult = false;
private final ConcurrentLinkedHashMap<LatLng, Integer> obsMap = new ConcurrentLinkedHashMap<>(512);
private final ConcurrentLinkedHashMap<LatLng, Observation> localObsMap = new ConcurrentLinkedHashMap<>(1024);
private NumberFormat numberFormat;

// used for shutting extraneous activities down on an error
Expand Down Expand Up @@ -370,6 +382,10 @@ public void handleMessage( final Message msg ) {
googleMap.addMarker(new MarkerOptions().position(estCentroid));
}
Logging.info("observation count: " + count);
if ( NetworkType.WIFI.equals(network.getType()) ) {
View v = findViewById(R.id.survey);
v.setVisibility(View.VISIBLE);
}
});
}
}
Expand Down Expand Up @@ -426,6 +442,32 @@ private LatLng computeBasicLocation(ConcurrentLinkedHashMap<LatLng, Integer> obs
return new LatLng(trilateratedLatitude, trilateratedLongitude);
}

private LatLng computeObservationLocation(ConcurrentLinkedHashMap<LatLng, Observation> obsMap) {
double latSum = 0.0;
double lonSum = 0.0;
double weightSum = 0.0;
for (Map.Entry<LatLng, Observation> obs : obsMap.entrySet()) {
if (null != obs.getKey()) {
float cleanSignal = cleanSignal((float) obs.getValue().getRssi());
final double latV = obs.getKey().latitude;
final double lonV = obs.getKey().longitude;
if (Math.abs(latV) > 0.01d && Math.abs(lonV) > 0.01d) { // 0 GPS-coord check
cleanSignal *= cleanSignal;
latSum += (obs.getKey().latitude * cleanSignal);
lonSum += (obs.getKey().longitude * cleanSignal);
weightSum += cleanSignal;
}
}
}
double trilateratedLatitude = 0;
double trilateratedLongitude = 0;
if (weightSum > 0) {
trilateratedLatitude = latSum / weightSum;
trilateratedLongitude = lonSum / weightSum;
}
return new LatLng(trilateratedLatitude, trilateratedLongitude);
}

private int computeZoom(ConcurrentLinkedHashMap<LatLng, Integer> obsMap, final LatLng centroid) {
float maxDist = 0f;
for (Map.Entry<LatLng, Integer> obs : obsMap.entrySet()) {
Expand Down Expand Up @@ -535,7 +577,6 @@ private void setupButtons( final Network network, final SharedPreferences prefs
disableLogMacButton.setEnabled(false);
}


hideMacButton.setOnClickListener(buttonView -> {
// add a display-exclude row fot MAC
if (network.getBssid() != null) {
Expand Down Expand Up @@ -564,6 +605,32 @@ private void setupButtons( final Network network, final SharedPreferences prefs
}
disableLogMacButton.setEnabled(false);
});

final Button startSurveyButton = findViewById(R.id.start_survey);
final Button endSurveyButton = findViewById(R.id.end_survey);
MainActivity.State state = MainActivity.getStaticState();
startSurveyButton.setOnClickListener(buttonView -> {
final FragmentActivity fa = this;
//TDDO: disabled until obsMap DB load complete?
if (null != fa) {
final String message = String.format(getString(R.string.confirm_survey),
getString(R.string.end_survey), getString(R.string.nonstop));
WiGLEConfirmationDialog.createConfirmation(fa, message,
R.id.nav_data, SITE_SURVEY_DIALOG);
}
});
endSurveyButton.setOnClickListener(buttonView -> {
startSurveyButton.setVisibility(View.VISIBLE);
endSurveyButton.setVisibility(View.GONE);
if (null != state) {
state.wifiReceiver.unregisterWiFiScanUpdater();
KmlSurveyWriter kmlWriter = new KmlSurveyWriter((FragmentActivity) MainActivity.getMainActivity(), ListFragment.lameStatic.dbHelper,
"KmlSurveyWriter", true, network.getBssid(), localObsMap.values());
kmlWriter.start();
//TODO: do we want the obsMap back?
}
});

}
}

Expand Down Expand Up @@ -610,6 +677,22 @@ public void handleDialog(final int dialogId) {
case NON_CRYPTO_DIALOG:
connectToNetwork( null );
break;
case SITE_SURVEY_DIALOG:
MainActivity.State state = MainActivity.getStaticState();
final Button startSurveyButton = findViewById(R.id.start_survey);
final Button endSurveyButton = findViewById(R.id.end_survey);
if (null != state) {
startSurveyButton.setVisibility(View.GONE);
endSurveyButton.setVisibility(View.VISIBLE);
obsMap.clear();
final String[] currentList = new String[]{network.getBssid()};
final Set<String> registerSet = new HashSet<>(Arrays.asList(currentList));
state.wifiReceiver.registerWiFiScanUpdater(this, registerSet);
mapView.getMapAsync(googleMap -> {
googleMap.clear();
});
}
break;
default:
Logging.warn("Network unhandled dialogId: " + dialogId);
}
Expand Down Expand Up @@ -641,6 +724,26 @@ private void connectToNetwork( final String password ) {
}
}

@Override
public void handleWiFiSeen(String bssid, Integer rssi, Location location) {
LatLng latest = new LatLng(location.getLatitude(), location.getLongitude());
localObsMap.put(latest, new Observation(rssi, location.getLatitude(), location.getLongitude(), location.getAltitude()));
final LatLng estCentroid = computeObservationLocation(localObsMap);
final int zoomLevel = computeZoom(obsMap, estCentroid);
mapView.getMapAsync(googleMap -> {
if (network.getLatLng() == null) {
final CameraPosition cameraPosition = new CameraPosition.Builder()
.target(latest).zoom(zoomLevel).build();
googleMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
BitmapDescriptor obsIcon = NetworkListUtil.getSignalBitmap(
getApplicationContext(), rssi);
googleMap.addMarker(new MarkerOptions().icon(obsIcon)
.position(latest).zIndex(rssi));
Logging.info("survey observation added");
});
}

public static class CryptoDialog extends DialogFragment {
public static CryptoDialog newInstance(final Network network) {
final CryptoDialog frag = new CryptoDialog();
Expand Down Expand Up @@ -764,4 +867,5 @@ public boolean onOptionsItemSelected( final MenuItem item ) {
}
return false;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -183,27 +183,27 @@ public static String getApiToken(SharedPreferences prefs) {
try {
final KeyStore keyStore = getKeyStore();

KeyStore.PrivateKeyEntry privateKeyEntry;

KeyStore.PrivateKeyEntry privateKeyEntry = null;
// prefer v2 key -> v1 key -> v0 key, nada as applicable
int versionThreshold = android.os.Build.VERSION_CODES.M;
if (keyStore.containsAlias(KEYSTORE_WIGLE_CREDS_KEY_V2)) {
//DEBUG: MainActivity.info("Using v2: " + KEYSTORE_WIGLE_CREDS_KEY_V2);
return getApiTokenVersion2(prefs);
} else if (keyStore.containsAlias(KEYSTORE_WIGLE_CREDS_KEY_V1)) {
privateKeyEntry = (KeyStore.PrivateKeyEntry)
keyStore.getEntry(KEYSTORE_WIGLE_CREDS_KEY_V1, null);
} else if (keyStore.containsAlias(KEYSTORE_WIGLE_CREDS_KEY_V0)) {
privateKeyEntry = (KeyStore.PrivateKeyEntry)
keyStore.getEntry(KEYSTORE_WIGLE_CREDS_KEY_V0, null);
versionThreshold = Build.VERSION_CODES.JELLY_BEAN_MR2;
} else {
Logging.warn("[TOKEN] Compatible build, but no key set: " +
android.os.Build.VERSION.SDK_INT + " - returning plaintext.");
return prefs.getString(PreferenceKeys.PREF_TOKEN, "");
if (null != keyStore) {
if (keyStore.containsAlias(KEYSTORE_WIGLE_CREDS_KEY_V2)) {
//DEBUG: MainActivity.info("Using v2: " + KEYSTORE_WIGLE_CREDS_KEY_V2);
return getApiTokenVersion2(prefs);
} else if (keyStore.containsAlias(KEYSTORE_WIGLE_CREDS_KEY_V1)) {
privateKeyEntry = (KeyStore.PrivateKeyEntry)
keyStore.getEntry(KEYSTORE_WIGLE_CREDS_KEY_V1, null);
} else if (keyStore.containsAlias(KEYSTORE_WIGLE_CREDS_KEY_V0)) {
privateKeyEntry = (KeyStore.PrivateKeyEntry)
keyStore.getEntry(KEYSTORE_WIGLE_CREDS_KEY_V0, null);
versionThreshold = Build.VERSION_CODES.JELLY_BEAN_MR2;
} else {
Logging.warn("[TOKEN] Compatible build, but no key set: " +
android.os.Build.VERSION.SDK_INT + " - returning plaintext.");
return prefs.getString(PreferenceKeys.PREF_TOKEN, "");
}
}


if (null != privateKeyEntry) {
String encodedCypherText = prefs.getString(PreferenceKeys.PREF_TOKEN, "");
if (!encodedCypherText.isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,9 @@ public void handleMessage( final Message msg ) {
if (dialog != null) {
try {
//DEBUG: Logging.info("fragment from dialog: " + dialog);
dialog.dismiss();
if (null != dialog && dialog.isVisible()) {
dialog.dismiss();
}
} catch ( Exception ex ) {
// you can't dismiss what isn't there
Logging.error( "exception dismissing fm dialog: " + ex );
Expand Down Expand Up @@ -326,7 +328,9 @@ public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog ad = builder.create();
ad.setButton( DialogInterface.BUTTON_POSITIVE, "OK", (dialog, which) -> {
try {
dialog.dismiss();
if (null != dialog) {
dialog.dismiss();
}
} catch ( Exception ex ) {
// guess it wasn't there anyways
Logging.info( "exception dismissing alert dialog: " + ex );
Expand Down
Loading

0 comments on commit 8905955

Please sign in to comment.