-
Notifications
You must be signed in to change notification settings - Fork 210
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[ENH/FIX] Search clean-up #717
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,6 +144,8 @@ public final class DatabaseHelper extends Thread { | |
private static final String LOCATED_NETS_QUERY_STEM = " FROM " + DatabaseHelper.NETWORK_TABLE | ||
+ " WHERE bestlat != 0.0 AND bestlon != 0.0 AND instr(bssid, '_') <= 0"; | ||
|
||
public static final String SEARCH_NETWORKS = "SELECT bssid,lastlat,lastlon FROM " + NETWORK_TABLE + " WHERE 1=1 "; | ||
//TODO: should search use best[lat|lon] instead of last? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe any time we only show a single location it should be the 'best' one. It's newer, back in the day we didn't have best. |
||
|
||
private static final String LOCATED_WIFI_QUERY_STEM = " FROM " + DatabaseHelper.NETWORK_TABLE | ||
+ " WHERE bestlat != 0.0 AND bestlon != 0.0 AND " + NetworkFilter.WIFI.getFilter() | ||
|
@@ -1348,7 +1350,7 @@ public Network getNetwork( final String bssid ) { | |
try { | ||
checkDB(); | ||
final String[] args = new String[]{ bssid }; | ||
cursor = db.rawQuery("select ssid,frequency,capabilities,type,lastlat,lastlon,bestlat,bestlon,rcois,mfgrid,service FROM " | ||
cursor = db.rawQuery("select ssid,frequency,capabilities,type,lastlat,lastlon,bestlat,bestlon,rcois,mfgrid,service,bestlevel,lasttime FROM " | ||
+ NETWORK_TABLE | ||
+ " WHERE bssid = ?", args); | ||
if ( cursor.getCount() > 0 ) { | ||
|
@@ -1363,23 +1365,26 @@ public Network getNetwork( final String bssid ) { | |
final String rcois = cursor.getString(8); | ||
final int mfgridInt = cursor.getInt(9); | ||
final String service = cursor.getString(10); | ||
final int level = cursor.getInt(11); | ||
final long lastTime = cursor.getLong(12); | ||
|
||
Integer mfgrid = null; | ||
if (mfgridInt != 0) mfgrid = mfgridInt; | ||
List<String> serviceUUIDs = service.isEmpty() ? null : | ||
new ArrayList<>(Arrays.asList(service.split(" "))); | ||
|
||
final NetworkType type = NetworkType.typeForCode( cursor.getString(3) ); | ||
retval = new Network( bssid, ssid, frequency, capabilities, 0, type, serviceUUIDs, mfgrid ); | ||
retval = new Network( bssid, ssid, frequency, capabilities, level, type, serviceUUIDs, mfgrid, lastTime ); | ||
if (bestlat != 0 && bestlon != 0) { | ||
retval.setLatLng( new LatLng(bestlat, bestlon) ); | ||
} | ||
else { | ||
} else { | ||
retval.setLatLng( new LatLng(lastlat, lastlon) ); | ||
} | ||
if (!rcois.isEmpty()) { | ||
retval.setRcois(rcois); | ||
} | ||
|
||
|
||
MainActivity.getNetworkCache().put( bssid, retval ); | ||
} | ||
} catch (DBException ex ) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,7 @@ public final class Network implements ClusterItem { | |
|
||
private int frequency; | ||
private int level; | ||
private Long lastTime; | ||
private Integer channel; | ||
private LatLng geoPoint; | ||
private boolean isNew; | ||
|
@@ -119,33 +120,36 @@ public enum NetworkBand { | |
*/ | ||
public Network( final ScanResult scanResult ) { | ||
this( scanResult.BSSID, scanResult.SSID, scanResult.frequency, scanResult.capabilities, | ||
scanResult.level, NetworkType.WIFI, null, null, null); | ||
scanResult.level, NetworkType.WIFI, null, null, null, null); | ||
} | ||
public Network( final String bssid, final String ssid, final int frequency, final String capabilities, | ||
final int level, final NetworkType type) { | ||
this(bssid, ssid, frequency, capabilities, level, type, null, null, null); | ||
this(bssid, ssid, frequency, capabilities, level, type, null, null, null, null); | ||
} | ||
|
||
public Network( final String bssid, final String ssid, final int frequency, final String capabilities, | ||
final int level, final NetworkType type, final List<String> bleServiceUuid16s, Integer bleMfgrId) { | ||
this(bssid, ssid, frequency, capabilities, level, type, bleServiceUuid16s, bleMfgrId, null); | ||
final int level, final NetworkType type, final List<String> bleServiceUuid16s, Integer bleMfgrId, final Long lastTime) { | ||
this(bssid, ssid, frequency, capabilities, level, type, bleServiceUuid16s, bleMfgrId, null, lastTime); | ||
} | ||
|
||
// for WiFiSearchResponse | ||
public Network( final String bssid, final String ssid, final int frequency, final String capabilities, | ||
final int level, final NetworkType type, final LatLng latLng ) { | ||
this(bssid, ssid, frequency, capabilities, level, type, null, null, latLng); | ||
this(bssid, ssid, frequency, capabilities, level, type, null, null, latLng, null); | ||
} | ||
|
||
private Network( final String bssid, final String ssid, final int frequency, final String capabilities, | ||
private Network(final String bssid, final String ssid, final int frequency, final String capabilities, | ||
final int level, final NetworkType type, final List<String> bleServiceUuid16s, Integer bleMfgrId, | ||
final LatLng latLng ) { | ||
final LatLng latLng, final Long lastTime ) { | ||
this.bssid = ( bssid == null ) ? "" : bssid.toLowerCase(Locale.US); | ||
this.ssid = ( ssid == null ) ? "" : ssid; | ||
this.frequency = frequency; | ||
this.capabilities = ( capabilities == null ) ? "" : capabilities; | ||
this.level = level; | ||
this.type = type; | ||
if (null != lastTime && lastTime > 0L) { | ||
this.lastTime = lastTime; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. HACK: Since the scheme is not-null, empty is resulting in zeros - I'd rather leave last null. |
||
if (bleMfgrId != null) this.bleMfgrId = bleMfgrId; | ||
if (NetworkType.WIFI.equals(this.type)) { | ||
this.channel = channelForWiFiFrequencyMhz(frequency); | ||
|
@@ -263,6 +267,10 @@ public String getRcoisOrBlank() { | |
return result == null ? "" : result; | ||
} | ||
|
||
public Long getLastTime() { | ||
return lastTime; | ||
} | ||
|
||
public void setRcois(final String concatenatedRcois) { | ||
this.concatenatedRcois = concatenatedRcois; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import android.graphics.Canvas; | ||
import android.graphics.Color; | ||
import android.graphics.drawable.Drawable; | ||
import android.provider.Settings; | ||
import android.text.format.DateFormat; | ||
|
||
import androidx.annotation.ColorInt; | ||
import androidx.annotation.DrawableRes; | ||
|
@@ -33,6 +33,16 @@ | |
* Common utility methods for the network list | ||
*/ | ||
public class NetworkListUtil { | ||
//ALIBI: while this means you need a restart to get new date/time formats, dynamic calls for each refresh would be heavy. | ||
private static final Locale l = Locale.getDefault(); | ||
private static final String timePattern = DateFormat.getBestDateTimePattern(l, "h:mm:ss a"); | ||
private static final String timePattern24 = DateFormat.getBestDateTimePattern(l, "H:mm:ss"); | ||
private static final String dateTimePattern = DateFormat.getBestDateTimePattern(l, "yyyy-MM-dd h:mm:ss a"); | ||
private static final String dateTimePattern24 = DateFormat.getBestDateTimePattern(l, "yyyy-MM-dd H:mm:ss"); | ||
private static final SimpleDateFormat timeFormatter = new SimpleDateFormat(timePattern, l); | ||
private static final SimpleDateFormat dateTimeFormatter = new SimpleDateFormat(dateTimePattern, l); | ||
private static final SimpleDateFormat timeFormatter24 = new SimpleDateFormat(timePattern24, l); | ||
private static final SimpleDateFormat dateTimeFormatter24 = new SimpleDateFormat(dateTimePattern24, l); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we were building these dynamically each time before, which seems silly. OTOH, now we're stuck building two instances we'll never use (over the entire app) because static initialization doesn't have access to Context we need to discriminate between 24 and 12 hour time preference. |
||
//color by signal strength | ||
private static final int COLOR_1 = Color.rgb(0, 255, 0); | ||
|
@@ -51,19 +61,26 @@ public class NetworkListUtil { | |
private static final int COLOR_6A = Color.argb(128, 255, 85, 0); | ||
private static final int COLOR_7A = Color.argb(128, 255, 0, 0); | ||
|
||
public static String getConstructionTime(final SimpleDateFormat format, final Network network) { | ||
return format.format(new Date(network.getConstructionTime())); | ||
} | ||
|
||
public static SimpleDateFormat getConstructionTimeFormater(final Context context) { | ||
final int value = Settings.System.getInt(context.getContentResolver(), Settings.System.TIME_12_24, -1); | ||
SimpleDateFormat format; | ||
if (value == 24) { | ||
format = new SimpleDateFormat("H:mm:ss", Locale.getDefault()); | ||
public static String getTime(@NonNull final Network network, final boolean historical, @NonNull final Context context) { | ||
final Long last = network.getLastTime(); | ||
if (null == last) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if lasttime is null then use construction time There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This has a practical problem - if |
||
if (historical) { | ||
//ALIBI: if this is a historical/non-live view, we don't want construction times. | ||
return ""; | ||
} | ||
if (DateFormat.is24HourFormat(context)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. they made a utility method for us |
||
return timeFormatter24.format(new Date(network.getConstructionTime())); | ||
} else { | ||
return timeFormatter.format(new Date(network.getConstructionTime())); | ||
} | ||
// SOMEDAY (SDK26+: return Instant.ofEpochSecond(network.getConstructionTime()).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(timePattern)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this would be great, but it's Android SDK 26+ so we'll use it when we get forced another two versions forward. |
||
} | ||
if (DateFormat.is24HourFormat(context)) { | ||
return dateTimeFormatter24.format(new Date(network.getLastTime())); | ||
} else { | ||
format = new SimpleDateFormat("h:mm:ss a", Locale.getDefault()); | ||
return dateTimeFormatter.format(new Date(network.getLastTime())); | ||
} | ||
return format; | ||
// SOMEDAY (SDK 26+): return Instant.ofEpochSecond(network.getConstructionTime()).atZone(ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern(timePattern)); | ||
} | ||
|
||
public static int getSignalColor(final int level, final boolean alpha) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe this whole method should move to DatabaseHelper, not just the query string?