Verified Commit 3178ca28 by agilob

Map downloader will use only enabled online servs.

* Improve logging in radiocell request task
parent 144910e9
Pipeline #777151 failed with stage
......@@ -14,7 +14,7 @@ import org.badcoders.aimsicd.utils.TinyDB;
import java.lang.ref.WeakReference;
@ReportsCrashes(
formUri = "http://agilob.net/projects/aimsicd/reporter.php",
formUri = "https://www.agilob.net/projects/aimsicd/reporter.php",
httpMethod = HttpSender.Method.POST
)
public class MyApplication extends Application {
......@@ -22,8 +22,6 @@ public class MyApplication extends Application {
public static final String NOTIFICATION_STOP = "com.SecUpwN.MyApplication.stop";
public static final String TRACKING_CHANGE = "com.SecUpwN.MyApplication.trackingChange";
private static final String TAG = "MyApplication";
private WeakReference<Aimsicd> mMainActivity = new WeakReference<>(null);
private ServiceBroadcastReceiver mReceiver;
......
......@@ -21,12 +21,14 @@ import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.IBinder;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.telephony.TelephonyManager;
import android.util.Log;
......@@ -146,7 +148,9 @@ public class MapViewFragment extends Fragment {
ScaleBarOverlay myScaleBarOverlay = new ScaleBarOverlay(mMap);
MyLocationNewOverlay mMyLocationOverlay = new MyLocationNewOverlay(mContext, gpsMyLocationProvider, mMap);
MyLocationNewOverlay mMyLocationOverlay = new MyLocationNewOverlay(mContext,
gpsMyLocationProvider,
mMap);
mMyLocationOverlay.setDrawAccuracyEnabled(true);
mMyLocationOverlay.enableMyLocation();
......@@ -282,19 +286,14 @@ public class MapViewFragment extends Fragment {
Log.d(TAG, "Using last known location");
loc = new GeoPoint(lastLoc.getLatitudeInDegrees(),
lastLoc.getLongitudeInDegrees());
mMap.getController().setZoom(INITIAL_ZOOM);
mMap.getController().animateTo(new GeoPoint(loc.getLatitude(),
loc.getLongitude()));
} else {
Log.d(TAG, "Using default location");
//Use MCC to move camera to an approximate location near Countries Capital
loc = defaultLoc;
mMap.getController().setZoom(INITIAL_ZOOM);
mMap.getController().animateTo(new GeoPoint(loc.getLatitude(),
loc.getLongitude()));
}
mMap.getController().setZoom(INITIAL_ZOOM);
mMap.getController().animateTo(new GeoPoint(loc.getLatitude(),
loc.getLongitude()));
}
}
if(mCellTowerGridMarkerClusterer != null) {
......@@ -367,10 +366,23 @@ public class MapViewFragment extends Fragment {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
boolean isOpenCellIdServiceEnabled = prefs.getBoolean("remote_service_opencellid_enabled",
false);
boolean isRadioCellServiceEnabled = prefs.getBoolean("remote_service_radiocell_enabled",
true);
if(isOpenCellIdServiceEnabled == false
&& isRadioCellServiceEnabled == false) {
Toast.makeText(mContext, "You must enable at least one remote service!",
Toast.LENGTH_SHORT).show();
return false;
}
boolean hasNetworkConnection = NetworkUtil.isInternetConnectionAvailable(mContext);
if(item.getItemId() == R.id.get_opencellid) {
if(!hasNetworkConnection) {// if no internet connection leave method
if(item.getItemId() == R.id.download_cell_data) {
if(hasNetworkConnection == false) {// if no internet connection leave method
Toast.makeText(mContext, R.string.please_enable_network_connectivity,
Toast.LENGTH_LONG).show();
return false;
......@@ -384,20 +396,26 @@ public class MapViewFragment extends Fragment {
cell.setLat(mMap.getMapCenter().getLatitude());
cell.setLon(mMap.getMapCenter().getLongitude());
RadioCellDownloadTask rcdt = new RadioCellDownloadTask(mContext,
mDbAdapter);
rcdt.execute(cell);
if(isOpenCellIdServiceEnabled) {
Log.d(TAG, "Using OCID data on user request");
OpenCellIdDownloadTask ocidt = new OpenCellIdDownloadTask(mContext,
mDbAdapter);
ocidt.execute(cell);
}
if(isRadioCellServiceEnabled) {
Log.d(TAG, "Using RadioCell data on user request");
RadioCellDownloadTask rcdt = new RadioCellDownloadTask(mContext,
mDbAdapter);
rcdt.execute(cell);
}
OpenCellIdDownloadTask ocidt = new OpenCellIdDownloadTask(mContext,
mDbAdapter);
ocidt.execute(cell);
return true;
//if any of them is enabled...
return (isOpenCellIdServiceEnabled || isRadioCellServiceEnabled);
} else {
return super.onOptionsItemSelected(item);
}
}
/**
* Service Connection to bind the activity to the service <p> This seem to setup the connection
* and animates the map window movement to the last known location.
......
......@@ -35,7 +35,6 @@ public class MarkerData {
return "000";
if(mcc.length() >= 3)
return mcc;
return ("000" + mcc).substring(mcc.length());
}
......
......@@ -21,6 +21,7 @@ import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.preference.PreferenceManager;
import android.util.Log;
import android.widget.Toast;
import com.github.kevinsawicki.http.HttpRequest;
......@@ -41,6 +42,8 @@ import java.util.List;
public class RadioCellDownloadTask extends AsyncTask<Cell, Integer, Integer> {
private static final String TAG = "RadioCelDownTask";
private Context mContext;
private AimsicdDbAdapter mDbAdapter;
......@@ -62,8 +65,10 @@ public class RadioCellDownloadTask extends AsyncTask<Cell, Integer, Integer> {
code = request.code();
this.body = request.body();
} catch(RuntimeException re) {
Log.e(TAG, "RunTimeException: " + re.getMessage(), re);
return -1000;
}
Log.d(TAG, "HTTP status code: " + code);
return code;
}
......@@ -80,6 +85,7 @@ public class RadioCellDownloadTask extends AsyncTask<Cell, Integer, Integer> {
Cell cellModel;
List<Cell> cells = new ArrayList<>();
Log.d(TAG, "Downloaded " + size + " cells");
for(int i = 0; i < size; i++) {
cellModel = RadioCellHelper.getCellFromJson(jsonArr.get(i).getAsJsonObject());
cells.add(cellModel);
......@@ -100,6 +106,7 @@ public class RadioCellDownloadTask extends AsyncTask<Cell, Integer, Integer> {
Cell cell;
for(int i = 0; i < cells.size(); i++) {
cell = cells.get(i);
Log.v(TAG, "Updating cell " + cell.getCellId());
//String db_src, String rat, int mcc, int mnc, int lac,
//int cid, int psc, String lat, String lon, int isGpsExact,
//int avg_range, int avg_signal, int samples, String time_first,
......@@ -127,7 +134,7 @@ public class RadioCellDownloadTask extends AsyncTask<Cell, Integer, Integer> {
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(mContext, mContext.getString(
R.string.unknown_problem_connecting_to_online_resource_encountered),
R.string.unknown_problem_connecting_to_online_resource_encountered) + " " + result,
Toast.LENGTH_SHORT).show();
}
......@@ -165,7 +172,7 @@ public class RadioCellDownloadTask extends AsyncTask<Cell, Integer, Integer> {
String uri = "http://radiocells.org/api/get_cells_api?"
// + cellParameter
+ boundParameter;
Log.d(TAG, "Sending request: " + uri);
return uri;
}
......
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/get_opencellid"
<item android:id="@+id/download_cell_data"
android:icon="@drawable/ic_action_download"
android:title="@string/get_opencellid"
android:showAsAction="ifRoom"/>
......
......@@ -111,7 +111,7 @@
<string name="pref_ocid_requestkey_summary">Request API key for OpenCellID data access</string>
<string name="samples_label">Samples: </string>
<string name="samples_label">Samples:</string>
<string name="open_cell_id_label">OpenCellID Data</string>
<!-- Database Viewer -->
......@@ -199,9 +199,9 @@
<string name="stopped_tracking_femtocell">: Stopped tracking FemtoCell connections.</string>
<string name="alert_femtocell_tracking_detected">ALERT: FemtoCell Tracking Detected!</string>
<string name="refreshing_every">Refreshing every</string>
<string name="refreshing_now">Refreshing now</string>
<string name="refreshing_now">Refreshing now...</string>
<string name="seconds">seconds.</string>
<string name="contacting_online_resources_for_data">Contacting online resources for data\nThis may take up to a minute.</string>
<string name="contacting_online_resources_for_data">Contacting online resources for data...\nThis may take up to a minute.</string>
<string name="unable_to_determine_last_location">Unable to determine your last location.\nEnable Location Services and try again.</string>
<string name="no_tracked_locations_found">No tracked locations found to show on map.</string>
<string name="no_data_for_publishing">No data for publishing available.</string>
......
......@@ -41,9 +41,9 @@
<string name="MWI" translatable="false">MWI</string>
<string name="FLASH" translatable="false">FLASH</string>
<string name="WAPPUSH" translatable="false">WAPPUSH</string>
<string name="auto_upload_to_radiocell" translatable="false">auto_upload_to_radiocell</string>
<string name="remote_service_opencellid_enabled" translatable="false">remote_service_opencellid_enabled</string>
<string name="remote_service_radiocell_enabled" translatable="false">remote_service_radiocell_enabled</string>
<string name="auto_upload_to_radiocell" translatable="false">auto_upload_to_radiocell</string>
<!-- Are we tracking cells right now? -->
<string name="tracking_state" translatable="false">tracking_state</string>
......
......@@ -3,4 +3,4 @@ cp bad_cell_detector/build/outputs/apk/bad_cell_detector-release*.*.apk /home/ag
cd /home/agilob/Projects/fdroid
./fdroid update
./fdroid publish
rsync -a -e 'ssh -p 3022' --progress repo/* fdroid@agilob.net:~
rsync -a -e 'ssh -p 3022' --progress repo fdroid@agilob.net:~
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment