Permalink
Browse files

sd card install, new nets since upload, improve startup time, cdma ce…

…ll tower

info
  • Loading branch information...
1 parent eb1adb8 commit 122f89e7346dc1b94b3f71903ddb736c640665f5 @bobzilladev bobzilladev committed Jan 9, 2011
View
@@ -2,7 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.wigle.wigleandroid"
android:versionCode="32"
- android:versionName="1.32">
+ android:versionName="1.32"
+ android:installLocation="auto">
<application android:icon="@drawable/wiglewifi" android:label="@string/app_name" android:debuggable="false">
<activity android:name=".MainActivity" android:label="@string/app_name"
android:theme="@android:style/Theme.NoTitleBar"
@@ -87,7 +88,7 @@
android:normalScreens="true"
android:largeScreens="true"
/>
-<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="4" />
+<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="8" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
View
3 TODO
@@ -20,6 +20,9 @@ show new networks since last upload
--- done ---
* 1.32
Added setting to use english or metric units
+Added "New Nets Since Upload" to Dashboard
+Improved startup time by delaying location count query
+Allow installation on SD card
* 1.30
Fix binding of app to service, should help stay alive when in background
View
@@ -10,4 +10,4 @@
# Indicates whether an apk should be generated for each density.
split.density=false
# Project target.
-target=android-4
+target=android-8
View
@@ -51,6 +51,13 @@
android:textSize="24sp"
/>
+ <TextView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:id="@+id/newNetsSinceUpload"
+ android:textSize="24sp"
+ />
+
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
@@ -76,6 +76,9 @@ private void updateUI() {
tv = (TextView) findViewById( R.id.currnets );
tv.setText( "Visible Nets: " + ListActivity.lameStatic.currNets );
+ tv = (TextView) findViewById( R.id.newNetsSinceUpload );
+ tv.setText( "New Nets Since Upload: " + newNetsSinceUpload() );
+
updateDist( R.id.rundist, ListActivity.PREF_DISTANCE_RUN, "Run Distance: " );
updateDist( R.id.totaldist, ListActivity.PREF_DISTANCE_TOTAL, "Total Distance: " );
updateDist( R.id.prevrundist, ListActivity.PREF_DISTANCE_PREV_RUN, "Previous Run: " );
@@ -88,7 +91,7 @@ private void updateUI() {
tv = (TextView) findViewById( R.id.dbLocs );
tv.setText( "DB Locations: " + ListActivity.lameStatic.dbLocs );
-
+
tv = (TextView) findViewById( R.id.gpsstatus );
Location location = ListActivity.lameStatic.location;
String gpsStatus = "No Location!";
@@ -98,6 +101,16 @@ private void updateUI() {
tv.setText( "Loc: " + gpsStatus );
}
+ private long newNetsSinceUpload() {
+ final SharedPreferences prefs = this.getSharedPreferences( ListActivity.SHARED_PREFS, 0 );
+ final long uploaded = prefs.getLong( ListActivity.PREF_DB_MARKER, 0L );
+ long newSinceUpload = ListActivity.lameStatic.dbLocs - uploaded;
+ if ( newSinceUpload < 0 ) {
+ newSinceUpload = 0;
+ }
+ return newSinceUpload;
+ }
+
private void updateDist( final int id, final String pref, final String title ) {
final SharedPreferences prefs = this.getSharedPreferences( ListActivity.SHARED_PREFS, 0 );
@@ -775,6 +775,7 @@ public long getNewNetworkCount() {
public long getNetworkCount() {
return networkCount.get();
}
+
private void getNetworkCountFromDB() {
networkCount.set( getCountFromDB( NETWORK_TABLE ) );
}
@@ -783,9 +784,27 @@ public long getLocationCount() {
return locationCount.get();
}
- /** careful with threading on this one */
- public void getLocationCountFromDB() {
- locationCount.set( getCountFromDB( LOCATION_TABLE ) );
+ private void getLocationCountFromDB() {
+ final long count = getCountFromDB( LOCATION_TABLE );
+ locationCount.set( count );
+ setupMaxidDebug( count );
+ }
+
+ private void setupMaxidDebug( final long locCount ) {
+ final SharedPreferences prefs = context.getSharedPreferences( ListActivity.SHARED_PREFS, 0 );
+ final long maxid = prefs.getLong( ListActivity.PREF_DB_MARKER, -1L );
+ final Editor edit = prefs.edit();
+ edit.putLong( ListActivity.PREF_MAX_DB, locCount );
+
+ if ( maxid == -1L ) {
+ if ( locCount > 0 ) {
+ // there is no preference set, yet there are locations, this is likely
+ // a developer testing a new install on an old db, so set the pref.
+ ListActivity.info( "setting db marker to: " + locCount );
+ edit.putLong( ListActivity.PREF_DB_MARKER, locCount );
+ }
+ }
+ edit.commit();
}
private long getCountFromDB( final String table ) {
@@ -25,6 +25,7 @@
import net.wigle.wigleandroid.listener.BatteryLevelReceiver;
import net.wigle.wigleandroid.listener.GPSListener;
import net.wigle.wigleandroid.listener.PhoneState;
+import net.wigle.wigleandroid.listener.PhoneStateFactory;
import net.wigle.wigleandroid.listener.WifiReceiver;
import org.andnav.osm.util.GeoPoint;
@@ -269,8 +270,6 @@ public void onCreate( final Bundle savedInstanceState ) {
setupService();
info( "setupDatabase" );
setupDatabase();
- info( "setupMaxidDebug" );
- setupMaxidDebug();
info( "setupUploadButton" );
setupUploadButton();
info( "setupList" );
@@ -968,9 +967,10 @@ private void setupSound() {
TelephonyManager tele = (TelephonyManager) getSystemService( TELEPHONY_SERVICE );
if ( tele != null && state.phoneState == null ) {
- state.phoneState = new PhoneState();
+ state.phoneState = PhoneStateFactory.createPhoneState();
+ final int signal_strengths = 256;
tele.listen( state.phoneState, PhoneStateListener.LISTEN_SERVICE_STATE
- | PhoneStateListener.LISTEN_CALL_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTH );
+ | PhoneStateListener.LISTEN_CALL_STATE | PhoneStateListener.LISTEN_SIGNAL_STRENGTH | signal_strengths );
}
setupMuteButton();
@@ -1253,26 +1253,5 @@ public static boolean hasSD() {
ListActivity.info( "no sd card apparently: " + ex, ex );
}
return sdCard != null && sdCard.exists() && sdCard.isDirectory() && sdCard.canRead() && sdCard.canWrite();
- }
-
- private void setupMaxidDebug() {
- final SharedPreferences prefs = ListActivity.this.getSharedPreferences( SHARED_PREFS, 0 );
- final long maxid = prefs.getLong( PREF_DB_MARKER, -1L );
- // load up the local value
- state.dbHelper.getLocationCountFromDB();
- final long loccount = state.dbHelper.getLocationCount();
-
- final Editor edit = prefs.edit();
- edit.putLong( PREF_MAX_DB, loccount );
-
- if ( maxid == -1L ) {
- if ( loccount > 0 ) {
- // there is no preference set, yet there are locations, this is likely
- // a developer testing a new install on an old db, so set the pref.
- info( "setting db marker to: " + loccount );
- edit.putLong( PREF_DB_MARKER, loccount );
- }
- }
- edit.commit();
- }
+ }
}
@@ -1,6 +1,31 @@
package net.wigle.wigleandroid;
+import java.util.HashMap;
+import java.util.Map;
+
public enum NetworkType {
- WIFI,
- GSM
+ WIFI("W"),
+ GSM("G"),
+ CDMA("C");
+
+ public static Map<String,NetworkType> types = new HashMap<String,NetworkType>();
+
+ static {
+ for( NetworkType type : NetworkType.values() ) {
+ types.put( type.getCode(), type );
+ }
+ }
+
+ private final String code;
+ private NetworkType(final String code) {
+ this.code = code;
+ }
+
+ public String getCode() {
+ return code;
+ }
+
+ public static NetworkType typeForCode(final String code) {
+ return types.get(code);
+ }
}
@@ -9,7 +9,7 @@
public class PhoneState extends PhoneStateListener {
private boolean isPhoneActive = false;
- private int strength = 0;
+ protected int strength = 0;
private ServiceState serviceState;
@Override
@@ -42,8 +42,11 @@ public void onSignalStrengthChanged(final int asu) {
}
@Override
- public void onCellLocationChanged(CellLocation cellLoc){
- if ( cellLoc instanceof GsmCellLocation) {
+ public void onCellLocationChanged(CellLocation cellLoc){
+ if ( cellLoc.getClass().getSimpleName().equals("CdmaCellLocation") ) {
+ ListActivity.info("cell location changed: cdma: " + cellLoc);
+ }
+ else if ( cellLoc instanceof GsmCellLocation) {
GsmCellLocation gsmCell = (GsmCellLocation) cellLoc;
ListActivity.info("cell location changed: gsm Cid: " + gsmCell.getCid());
ListActivity.info("cell location changed: gsm Lac: " + gsmCell.getLac());
@@ -0,0 +1,21 @@
+package net.wigle.wigleandroid.listener;
+
+import android.telephony.SignalStrength;
+
+public final class PhoneState7 extends PhoneState {
+ @Override
+ public void onSignalStrengthsChanged (SignalStrength signalStrength) {
+ // ListActivity.info("signalStrength: " + signalStrength);
+ if (signalStrength.isGsm()) {
+ strength = signalStrength.getGsmSignalStrength();
+ }
+ else {
+ strength = signalStrength.getCdmaDbm();
+ }
+ }
+
+ @Override
+ public void onSignalStrengthChanged(final int asu) {
+ // do nothing
+ }
+}
@@ -0,0 +1,17 @@
+package net.wigle.wigleandroid.listener;
+
+import net.wigle.wigleandroid.ListActivity;
+
+public final class PhoneStateFactory {
+ private PhoneStateFactory() {}
+
+ public static PhoneState createPhoneState() {
+ try {
+ Class.forName("android.telephony.SignalStrength");
+ return new PhoneState7();
+ } catch (Exception ex) {
+ ListActivity.info("Using original PhoneState");
+ }
+ return new PhoneState();
+ }
+}
@@ -357,45 +357,54 @@ else if ( somethingAdded && playRun ) {
private void recordCellInfo(final Location location) {
TelephonyManager tele = (TelephonyManager) listActivity.getSystemService( Context.TELEPHONY_SERVICE );
if ( tele != null ) {
+ String bssid = null;
+ NetworkType type = null;
+
CellLocation cellLocation = tele.getCellLocation();
- if ( cellLocation instanceof GsmCellLocation ) {
+ if ( cellLocation.getClass().getSimpleName().equals("CdmaCellLocation") ) {
+ try {
+ final int systemId = (Integer) cellLocation.getClass().getMethod("getSystemId").invoke(cellLocation);
+ final int networkId = (Integer) cellLocation.getClass().getMethod("getNetworkId").invoke(cellLocation);
+ final int baseStationId = (Integer) cellLocation.getClass().getMethod("getBaseStationId").invoke(cellLocation);
+ bssid = systemId + "_" + networkId + "_" + baseStationId;
+ type = NetworkType.CDMA;
+ }
+ catch ( Exception ex ) {
+ ListActivity.error("cdma reflection exception: " + ex);
+ }
+ }
+ else if ( cellLocation instanceof GsmCellLocation ) {
GsmCellLocation gsmCellLocation = (GsmCellLocation) cellLocation;
- //dbHelper.recordCellInfo(location, gsmCellLocation)
- PhoneState phoneState = listActivity.getPhoneState();
+ bssid = tele.getNetworkOperator() + "_" + gsmCellLocation.getLac() + "_" + gsmCellLocation.getCid();
+ type = NetworkType.CDMA;
+ }
+
+ if ( bssid != null ) {
+ final String ssid = tele.getNetworkOperatorName();
+ final String capabilities = tele.getNetworkCountryIso();
+
int strength = 0;
-// String operatorAlphaLong = "";
+ PhoneState phoneState = listActivity.getPhoneState();
if (phoneState != null) {
strength = phoneState.getStrength();
-// ServiceState serviceState = phoneState.getServiceState();
-// // ListActivity.info( "serviceState: " + serviceState );
-// if ( serviceState != null ) {
-// operatorAlphaLong = serviceState.getOperatorAlphaLong();
-// }
}
- if (false){
- ListActivity.info( "----------------" );
- ListActivity.info( "lac: " + gsmCellLocation.getLac() );
- ListActivity.info( "cid: " + gsmCellLocation.getCid() );
- ListActivity.info( "operator: " + tele.getNetworkOperator() );
- ListActivity.info( "operator iso: " + tele.getNetworkCountryIso() );
- ListActivity.info( "operator name: " + tele.getNetworkOperatorName() );
+ if ( false ) {
+ ListActivity.info( "bssid: " + bssid );
ListActivity.info( "strength: " + strength );
+ ListActivity.info( "ssid: " + ssid );
+ ListActivity.info( "capabilities: " + capabilities );
ListActivity.info( "location: " + location );
}
-
- final String bssid = Integer.toHexString( Integer.parseInt( tele.getNetworkOperator() ) )
- + "_" + Integer.toHexString( gsmCellLocation.getLac() )
- + "_" + Integer.toHexString( gsmCellLocation.getCid() );
- final String ssid = tele.getNetworkOperatorName();
-
+
final CacheMap<String,Network> networkCache = ListActivity.getNetworkCache();
Network network = networkCache.get( bssid );
if ( network == null ) {
- network = new Network( bssid, ssid, 0, "", strength, NetworkType.GSM );
+ network = new Network( bssid, ssid, 0, capabilities, strength, type );
networkCache.put( network.getBssid(), network );
}
+ //dbHelper.recordCellInfo(location, gsmCellLocation)
}
}
}

0 comments on commit 122f89e

Please sign in to comment.