WiGLE WiFi Wardriving FOSS v2.63版本的 MD5 值为:20a157bff1dec2e81d8268d404e15cb5
以下内容为反编译后的 DBResultActivity.java 源代码,内容仅作参考
package net.wigle.wigleandroid;
import android.app.Activity;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.DatabaseUtils;
import android.location.Address;
import android.location.Location;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Parcelable;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.TreeMap;
import net.wigle.wigleandroid.background.AbstractApiRequest;
import net.wigle.wigleandroid.background.ApiDownloader;
import net.wigle.wigleandroid.background.ApiListener;
import net.wigle.wigleandroid.background.DownloadHandler;
import net.wigle.wigleandroid.background.QueryThread;
import net.wigle.wigleandroid.model.ConcurrentLinkedHashMap;
import net.wigle.wigleandroid.model.LatLng;
import net.wigle.wigleandroid.model.Network;
import net.wigle.wigleandroid.model.NetworkType;
import net.wigle.wigleandroid.model.QueryArgs;
import net.wigle.wigleandroid.ui.SetNetworkListAdapter;
import net.wigle.wigleandroid.ui.WiGLEToast;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class DBResultActivity extends AppCompatActivity {
private static final String API_BSSID_PARAM = "netid";
private static final String API_LAT1_PARAM = "latrange1";
private static final String API_LAT2_PARAM = "latrange2";
private static final String API_LON1_PARAM = "longrange1";
private static final String API_LON2_PARAM = "longrange2";
private static final String API_SSIDLIKE_PARAM = "ssidlike";
private static final String API_SSID_PARAM = "ssid";
private static final int DEFAULT_ZOOM = 18;
private static final int LIMIT = 50;
private static final int MENU_RETURN = 12;
private static final int MSG_PARSE_FAILED = 500;
private static final int MSG_QUERY_DONE = 2;
private static final int MSG_QUERY_EMPTY = 3;
private static final int MSG_SEARCH_DONE = 100;
private static final int MSG_SEARCH_FAILED = 400;
private static final String NETID_KEY = "netid";
private static final String RESULT_LIST_KEY = "results";
private static final String SSID_KEY = "ssid";
private SetNetworkListAdapter listAdapter;
private static final Double LOCAL_RANGE = Double.valueOf(0.1d);
private static final Double ONLINE_RANGE = Double.valueOf(0.001d);
private static final String TRILAT_KEY = "trilat";
private static final String TRILON_KEY = "trilong";
private static final String ENCRYPTION_KEY = "encryption";
private static final String CHANNEL_KEY = "channel";
private static final String[] ALL_NET_KEYS = {TRILAT_KEY, TRILON_KEY, "ssid", "netid", ENCRYPTION_KEY, CHANNEL_KEY};
private final List<Network> resultList = new ArrayList();
private final ConcurrentLinkedHashMap<LatLng, Integer> obsMap = new ConcurrentLinkedHashMap<>();
private void setupMap(LatLng latLng, Bundle bundle) {
}
@Override
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
ActionBar supportActionBar = getSupportActionBar();
if (supportActionBar != null) {
supportActionBar.setDisplayHomeAsUpEnabled(true);
}
MainActivity.setLocale(this);
setContentView(R.layout.dbresult);
setVolumeControlStream(3);
setupList();
QueryArgs queryArgs = ListFragment.lameStatic.queryArgs;
MainActivity.info("queryArgs: " + queryArgs);
TextView textView = (TextView) findViewById(R.id.dbstatus);
if (queryArgs != null) {
textView.setText(getString(R.string.status_working));
Address address = queryArgs.getAddress();
LatLng latLng = MappingFragment.DEFAULT_POINT;
if (address != null) {
latLng = new LatLng(address.getLatitude(), address.getLongitude());
}
setupMap(latLng, bundle);
if (queryArgs.searchWiGLE()) {
setupWiGLEQuery(queryArgs, this, findViewById(16908290));
return;
} else {
setupQuery(queryArgs);
return;
}
}
textView.setText(getString(R.string.status_fail) + "...");
}
private void setupList() {
this.listAdapter = new SetNetworkListAdapter(this, R.layout.row);
ListFragment.setupListAdapter((ListView) findViewById(R.id.dblist), MainActivity.getMainActivity(), this.listAdapter, true);
}
private void setupQuery(QueryArgs queryArgs) {
boolean z;
final Address address = queryArgs.getAddress();
final Handler handler = new Handler() {
@Override
public void handleMessage(Message message) {
TextView textView = (TextView) DBResultActivity.this.findViewById(R.id.dbstatus);
boolean z2 = true;
if (message.what == 2) {
textView.setText(DBResultActivity.this.getString(R.string.status_success));
DBResultActivity.this.listAdapter.clear();
for (Network network : DBResultActivity.this.resultList) {
DBResultActivity.this.listAdapter.add(network);
if (address == null && z2) {
MainActivity.info("set center: " + MappingFragment.getCenter(DBResultActivity.this, network.getLatLng(), null) + " network: " + network.getSsid() + " point: " + network.getLatLng());
z2 = false;
}
}
DBResultActivity.this.resultList.clear();
} else if (message.what == 3) {
textView.setText(DBResultActivity.this.getString(R.string.search_empty));
DBResultActivity.this.listAdapter.clear();
WiGLEToast.showOverActivity(this, R.string.app_name, DBResultActivity.this.getString(R.string.search_empty), 1);
}
}
};
String ssid = queryArgs.getSSID();
String bssid = queryArgs.getBSSID();
String str = "SELECT bssid,lastlat,lastlon FROM network WHERE 1=1 ";
if (ssid == null || "".equals(ssid)) {
z = false;
} else {
str = "SELECT bssid,lastlat,lastlon FROM network WHERE 1=1 AND ssid like " + DatabaseUtils.sqlEscapeString(ssid);
z = true;
}
if (bssid != null && !"".equals(bssid)) {
str = str + " AND bssid like " + DatabaseUtils.sqlEscapeString(bssid);
z = true;
}
if (address != null) {
double latitude = address.getLatitude();
double longitude = address.getLongitude();
StringBuilder append = new StringBuilder().append(str).append(" AND lastlat > '");
Double d = LOCAL_RANGE;
str = append.append(latitude - d.doubleValue()).append("' AND lastlat < '").append(latitude + d.doubleValue()).append("'").toString() + " AND lastlon > '" + (longitude - d.doubleValue()) + "' AND lastlon < '" + (longitude + d.doubleValue()) + "'";
}
if (z) {
str = str + " LIMIT 50";
}
String str2 = str;
final TreeMap treeMap = new TreeMap();
final float[] fArr = new float[1];
final long[] jArr = new long[1];
ListFragment.lameStatic.dbHelper.addToQueue(new QueryThread.Request(str2, new QueryThread.ResultHandler() {
@Override
public boolean handleRow(Cursor cursor) {
String string = cursor.getString(0);
float f = cursor.getFloat(1);
float f2 = cursor.getFloat(2);
long[] jArr2 = jArr;
jArr2[0] = jArr2[0] + 1;
Address address2 = address;
if (address2 == null) {
treeMap.put(Float.valueOf((float) jArr2[0]), string);
} else {
Location.distanceBetween(f, f2, address2.getLatitude(), address.getLongitude(), fArr);
float f3 = fArr[0];
if (treeMap.size() <= 50) {
DBResultActivity.putWithBackoff(treeMap, string, f3);
} else {
Float f4 = (Float) treeMap.lastKey();
if (f3 < f4.floatValue()) {
treeMap.remove(f4);
DBResultActivity.putWithBackoff(treeMap, string, f3);
}
}
}
return true;
}
@Override
public void complete() {
if (treeMap.values().size() > 0) {
for (String str3 : treeMap.values()) {
Network network = ListFragment.lameStatic.dbHelper.getNetwork(str3);
DBResultActivity.this.resultList.add(network);
LatLng latLng = network.getLatLng();
if (latLng != null) {
DBResultActivity.this.obsMap.put(latLng, 0);
}
}
handler.sendEmptyMessage(2);
return;
}
handler.sendEmptyMessage(3);
}
}));
}
private void setupWiGLEQuery(QueryArgs queryArgs, AppCompatActivity appCompatActivity, View view) {
String str = "";
if (queryArgs.getSSID() != null && !queryArgs.getSSID().isEmpty()) {
if (queryArgs.getSSID().contains("%") || queryArgs.getSSID().contains("_")) {
str = "ssidlike=" + URLEncoder.encode(queryArgs.getSSID());
} else {
str = "ssid=" + URLEncoder.encode(queryArgs.getSSID());
}
}
if (queryArgs.getBSSID() != null && !queryArgs.getBSSID().isEmpty()) {
if (!str.isEmpty()) {
str = str + "&";
}
str = str + "netid=" + queryArgs.getBSSID();
}
Address address = queryArgs.getAddress();
if (address != null) {
if (!str.isEmpty()) {
str = str + "&";
}
double latitude = address.getLatitude();
double longitude = address.getLongitude();
StringBuilder append = new StringBuilder().append(str).append("latrange1=");
Double d = ONLINE_RANGE;
str = ((append.append(latitude - d.doubleValue()).append("&").toString() + "latrange2=" + (latitude + d.doubleValue()) + "&") + "longrange1=" + (longitude - d.doubleValue()) + "&") + "longrange2=" + (longitude + d.doubleValue());
}
String str2 = str;
final NetsDownloadHandler netsDownloadHandler = new NetsDownloadHandler(view, appCompatActivity.getPackageName(), getResources(), this.listAdapter, this.obsMap, this);
try {
new ApiDownloader(appCompatActivity, ListFragment.lameStatic.dbHelper, "search-cache-" + str2 + ".json", "https://api.wigle.net/api/v2/network/search?" + str2, false, true, true, AbstractApiRequest.REQUEST_GET, new ApiListener() {
@Override
public void requestComplete(JSONObject jSONObject, boolean z) {
DBResultActivity.this.handleNets(jSONObject, netsDownloadHandler);
}
}).startDownload(getSupportFragmentManager().findFragmentById(R.id.net_list));
} catch (WiGLEAuthException e) {
MainActivity.warn("Authentication error on news load (should not happen)", e);
}
}
public void handleNets(JSONObject jSONObject, Handler handler) {
String[] strArr;
MainActivity.info("handleNets");
if (jSONObject == null) {
MainActivity.info("handleNets null json, returning");
return;
}
Bundle bundle = new Bundle();
Message message = new Message();
try {
JSONArray jSONArray = jSONObject.getJSONArray(RESULT_LIST_KEY);
if (jSONArray != null && jSONArray.length() != 0) {
ArrayList<? extends Parcelable> arrayList = new ArrayList<>(jSONArray.length());
for (int i = 0; i < jSONArray.length(); i++) {
JSONObject jSONObject2 = jSONArray.getJSONObject(i);
Bundle bundle2 = new Bundle();
for (String str : ALL_NET_KEYS) {
bundle2.putString(str, jSONObject2.getString(str));
}
arrayList.add(bundle2);
}
bundle.putParcelableArrayList(RESULT_LIST_KEY, arrayList);
message.setData(bundle);
message.what = 100;
handler.sendMessage(message);
return;
}
message.what = 500;
handler.sendMessage(message);
MainActivity.error("empty results");
} catch (JSONException e) {
message.what = 500;
handler.sendMessage(message);
MainActivity.error("json error parsing: " + jSONObject, e);
} catch (Exception e2) {
message.what = MSG_SEARCH_FAILED;
handler.sendMessage(message);
MainActivity.error("search error: " + e2, e2);
}
}
public static void putWithBackoff(TreeMap<Float, String> treeMap, String str, float f) {
String put = treeMap.put(Float.valueOf(f), str);
for (int i = 0; put != null && i < 1000; i++) {
f += 1.0E-4f;
put = treeMap.put(Float.valueOf(f), put);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
menu.add(0, 12, 0, getString(R.string.menu_return)).setIcon(17301541);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() != 12) {
return false;
}
finish();
return true;
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onResume() {
super.onResume();
}
@Override
public void onPause() {
super.onPause();
}
@Override
public void onSaveInstanceState(Bundle bundle) {
super.onSaveInstanceState(bundle);
}
@Override
public void onLowMemory() {
super.onLowMemory();
}
public static final class NetsDownloadHandler extends DownloadHandler {
private final Activity activityContext;
private final ConcurrentLinkedHashMap<LatLng, Integer> obsMap;
private final SetNetworkListAdapter resultList;
private NetsDownloadHandler(View view, String str, Resources resources, SetNetworkListAdapter setNetworkListAdapter, ConcurrentLinkedHashMap<LatLng, Integer> concurrentLinkedHashMap, Activity activity) {
super(view, null, str, resources);
this.resultList = setNetworkListAdapter;
this.obsMap = concurrentLinkedHashMap;
this.activityContext = activity;
}
@Override
public void handleMessage(Message message) {
ArrayList parcelableArrayList = message.getData().getParcelableArrayList(DBResultActivity.RESULT_LIST_KEY);
MainActivity.info("handleMessage. results: " + parcelableArrayList);
TextView textView = (TextView) this.activityContext.findViewById(R.id.dbstatus);
boolean z = true;
if (message.what == 100 && parcelableArrayList != null) {
this.resultList.clear();
Iterator it = parcelableArrayList.iterator();
while (it.hasNext()) {
Parcelable parcelable = (Parcelable) it.next();
if (parcelable instanceof Bundle) {
Bundle bundle = (Bundle) parcelable;
Network network = new Network(bundle.getString("netid"), bundle.getString("ssid"), Integer.parseInt(bundle.getString(DBResultActivity.CHANNEL_KEY)), "[" + bundle.getString(DBResultActivity.ENCRYPTION_KEY).toUpperCase() + " SEARCH]", 0, NetworkType.WIFI);
network.setLatLng(new LatLng(Double.parseDouble(bundle.getString(DBResultActivity.TRILAT_KEY)), Double.parseDouble(bundle.getString(DBResultActivity.TRILON_KEY))));
if (z) {
z = false;
}
this.resultList.add(network);
LatLng latLng = network.getLatLng();
if (latLng != null) {
this.obsMap.put(latLng, 0);
}
}
}
if (textView != null) {
textView.setText(this.activityContext.getString(R.string.status_success));
}
} else if (message.what == DBResultActivity.MSG_SEARCH_FAILED) {
if (textView != null) {
textView.setText(this.activityContext.getString(R.string.search_failed));
}
Activity activity = this.activityContext;
WiGLEToast.showOverActivity(activity, R.string.app_name, activity.getString(R.string.search_failed), 1);
} else if (message.what == 500) {
if (textView != null) {
textView.setText(this.activityContext.getString(R.string.search_empty));
}
Activity activity2 = this.activityContext;
WiGLEToast.showOverActivity(activity2, R.string.app_name, activity2.getString(R.string.search_empty), 1);
}
}
}
}