diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java index 6346d41a96fec1a4cd5bd5401457240c1a12a516..d9efb25cae1d0bafb0879d458e9bbd6a5cd0f52f 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java @@ -466,11 +466,11 @@ public class AIMSICDDbAdapter { /** * Returns Cell Information for contribution to the OpenCellID Project * - * Function: Seem to Return a list of all rows where OCID_SUBMITTED is not 1. + * Function: Return a list of all rows which were not submitted to OpenCellID Project */ public Cursor getOPCIDSubmitData() { return mDb.query( CELL_TABLE, - new String[]{ "Lng", "Lat", "Mcc", "Mnc", "Lac", "CellID", "Signal", "Timestamp", + new String[]{"Mcc", "Mnc", "Lac", "CellID", "Lng", "Lat", "Signal", "Timestamp", "Accuracy", "Speed", "Direction", "NetworkType"}, "OCID_SUBMITTED <> 1", null, null, null, null ); @@ -642,7 +642,7 @@ public class AIMSICDDbAdapter { */ public boolean prepareOpenCellUploadData() { boolean result; - // Q: Where is this? + // Q: Where is this? // A: It is wherever your device has mounted its SDCard. // For example: /data/media/0/AIMSICD/OpenCellID File dir = new File(FOLDER + "OpenCellID/"); @@ -655,30 +655,39 @@ public class AIMSICDDbAdapter { File file = new File(dir, "aimsicd-ocid-data.csv"); try { - result = file.createNewFile(); - if (!result) { - return false; - } - CSVWriter csvWrite = new CSVWriter(new FileWriter(file)); - open(); - Cursor c = getOPCIDSubmitData(); + open(); // open Database + Cursor c = getOPCIDSubmitData(); // get data not submitted yet + + if(c.getCount() > 0) { // check if we have something to upload + + if (!file.exists()) { + result = file.createNewFile(); + if (!result) { + return false; + } - csvWrite.writeNext("mcc,mnc,lac,cellid,lon,lat,signal,measured_at,rating,speed,direction,act"); - String[] rowData = new String[c.getColumnCount()]; - int size = c.getColumnCount(); - AIMSICD.mProgressBar.setProgress(0); - AIMSICD.mProgressBar.setMax(size); - while (c.moveToNext()) { - for (int i = 0; i < size; i++) { - rowData[i] = c.getString(i); - AIMSICD.mProgressBar.setProgress(i); } - csvWrite.writeNext(rowData); - } - csvWrite.close(); - c.close(); - return true; + CSVWriter csvWrite = new CSVWriter(new FileWriter(file)); + + csvWrite.writeNext("mcc,mnc,lac,cellid,lon,lat,signal,measured_at,rating,speed,direction,act"); + String[] rowData = new String[c.getColumnCount()]; + int size = c.getColumnCount(); + AIMSICD.mProgressBar.setProgress(0); + AIMSICD.mProgressBar.setMax(size); + while (c.moveToNext()) { + for (int i = 0; i < size; i++) { + rowData[i] = c.getString(i); + AIMSICD.mProgressBar.setProgress(i); + } + csvWrite.writeNext(rowData); + } + + csvWrite.close(); + c.close(); + return true; + } + return false; } catch (Exception e) { Log.e(TAG, "Error creating OpenCellID Upload Data: " + e); return false; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java index 96cc1c8fb967f5da835b7b8328f71f4392b8b65d..36962e5779fb9487acd25b6bce5a36bd80cedbc5 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java @@ -37,6 +37,7 @@ import com.SecUpwN.AIMSICD.utils.DeviceApi17; import com.SecUpwN.AIMSICD.utils.Helpers; import com.SecUpwN.AIMSICD.utils.Icon; import com.SecUpwN.AIMSICD.utils.Status; +import com.SecUpwN.AIMSICD.utils.RequestTask; import org.apache.http.HttpResponse; import org.apache.http.StatusLine; @@ -1011,6 +1012,8 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi // TODO: Do we need to re-insert this CID somewhere? (Probably not? --E:V:A) mCellIdNotInOpenDb = true; setNotification(); + // Request uploading here? + new RequestTask(context, com.SecUpwN.AIMSICD.utils.RequestTask.DBE_UPLOAD_REQUEST).execute(""); // no string needed for csv based upload } else { mCellIdNotInOpenDb = false; } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java index 6983a379a2c8aa2da4a76ee507654cb9995c09c9..197bb987a3379804a4c270d69547962c104400b2 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java @@ -83,7 +83,7 @@ public class RequestTask extends AsyncTask<String, Integer, String> { public static final char DBE_DOWNLOAD_REQUEST = 1; // OCID download request from "APPLICATION" drawer title public static final char DBE_DOWNLOAD_REQUEST_FROM_MAP = 2; // OCID download request from "Antenna Map Viewer" - //public static final char DBE_UPLOAD_REQUEST = 3; // TODO: OCID upload request from "APPLICATION" drawer title + public static final char DBE_UPLOAD_REQUEST = 6; // TODO: OCID upload request from "APPLICATION" drawer title public static final char BACKUP_DATABASE = 3; public static final char RESTORE_DATABASE = 4; public static final char CELL_LOOKUP = 5; // TODO: "All Current Cell Details (ACD)" @@ -105,7 +105,7 @@ public class RequestTask extends AsyncTask<String, Integer, String> { // We need to create a separate case for UPLOADING to DBe (OCID, MLS etc) switch (mType) { -/* + // UPLOADING !! case DBE_UPLOAD_REQUEST: // OCID upload request from "APPLICATION" drawer title try { @@ -144,21 +144,26 @@ public class RequestTask extends AsyncTask<String, Integer, String> { publishProgress(60,100); httppost.setEntity(bArrEntity); response = httpclient.execute(httppost); + publishProgress(80,100); if (response!= null) { Log.i("AIMSICD", "OCID Upload Response: " + response.getStatusLine().getStatusCode() + " - " - + response.getStatusLine()); - mDbAdapter.ocidProcessed(); + + response.getStatusLine() + " - " + response.getEntity().getContent().toString()); + if (response.getStatusLine().getStatusCode() == org.apache.http.HttpStatus.SC_OK) + mDbAdapter.ocidProcessed(); // Update only if status code was OK publishProgress(95,100); } } + return "Successful"; } + return null; } catch (Exception e) { Log.i("AIMSICD", "Upload OpenCellID data - " + e.getMessage()); + return null; } -*/ + // DOWNLOADING... case DBE_DOWNLOAD_REQUEST: // OCID download request from "APPLICATION" drawer title case DBE_DOWNLOAD_REQUEST_FROM_MAP: // OCID download request from "Antenna Map Viewer"