Skip to content

Commit e8e3769

Browse files
committed
added toEvenLog() code place holder to be made working
Need some code cleanup and fixes to be working...
1 parent ade43f3 commit e8e3769

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java

+69
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import android.database.sqlite.SQLiteDatabase;
1616
import android.database.sqlite.SQLiteException;
1717
import android.database.sqlite.SQLiteOpenHelper;
18+
import android.os.Vibrator;
1819
import android.util.Log;
1920
import android.util.SparseArray;
2021
import java.io.File;
@@ -136,6 +137,7 @@ public class AIMSICDDbAdapter extends SQLiteOpenHelper{
136137
private final String[] mTables;
137138
private SQLiteDatabase mDb;
138139
private final Context mContext;
140+
//private static Context context; // Added by E:V:A for toEventLog()
139141

140142
public AIMSICDDbAdapter(Context context) {
141143
super(context, DB_NAME, null, 1);
@@ -2179,6 +2181,8 @@ public void insertDetectionFlags(int code,
21792181
* Issues: [ ] ALL events should be logged!!
21802182
* [ ] To avoid repeated copies, only check last DB entries
21812183
* [ ] Before inserting event, check that LAC/CID are not "-1".
2184+
* [ ] Any related notifications are better put here as well, right?
2185+
* [ ]
21822186
*
21832187
* Notes: a) Table item order:
21842188
*
@@ -2250,6 +2254,71 @@ public void insertEventLog(String time,
22502254
}
22512255
}
22522256

2257+
/*
2258+
// Defining a new simpler version of insertEventLog:
2259+
public void toEventLog(int DF_id, String DF_desc){
2260+
// TODO: What to use here...
2261+
//private static Context context;
2262+
//mContext = context;
2263+
//this.context = context;
2264+
Cell cell; //TODO is this enough?
2265+
2266+
String time = MiscUtils.getCurrentTimeStamp(); // time
2267+
int lac = cell.getLAC(); // LAC
2268+
int cid = cell.getCID(); // CID
2269+
int psc = cell.getPSC(); // PSC [UMTS,LTE]
2270+
String gpsd_lat = String.valueOf(cell.getLat());// gpsd_lat
2271+
String gpsd_lon = String.valueOf(cell.getLon());// gpsd_lon
2272+
int gpsd_accu = (int)cell.getAccuracy(); // gpsd_accu
2273+
2274+
// skip CID/LAC of "-1" (due to crappy API, Roaming or Air-Plane Mode)
2275+
if (cid != -1 || lac != -1) {
2276+
// Check if LAST entry is the same!
2277+
String query = String.format(
2278+
"SELECT * from EventLog WHERE _id=(SELECT max(_id) from EventLog) AND CID=%d AND LAC=%d AND PSC=%d AND DF_id=%d",
2279+
cid, lac, psc, DF_id);
2280+
Cursor cursor = mDb.rawQuery(query,null);
2281+
2282+
// WARNING: By skipping duplicate events, we might be missing counts of Type-0 SMS etc.
2283+
boolean insertData = true;
2284+
if (cursor.getCount() > 0) { insertData = false; }
2285+
cursor.close();
2286+
2287+
if(insertData){
2288+
ContentValues eventLog = new ContentValues();
2289+
2290+
eventLog.put("time", time ); // time
2291+
eventLog.put("LAC", lac ); // LAC
2292+
eventLog.put("CID", cid ); // CID
2293+
eventLog.put("PSC", psc ); // PSC [UMTS,LTE]
2294+
eventLog.put("gpsd_lat", gpsd_lat ); // gpsd_lat
2295+
eventLog.put("gpsd_lon", gpsd_lon ); // gpsd_lon
2296+
eventLog.put("gpsd_accu", gpsd_accu ); // gpsd_accu
2297+
eventLog.put("DF_id", DF_id); // DF_id
2298+
eventLog.put("DF_description", DF_desc); // DF_desc
2299+
2300+
mDb.insert("EventLog", null, eventLog);
2301+
Log.i(TAG, mTAG + ":insertEventLog(): Added New Event: id=" +DF_id+ " time=" +time+ " cid=" +cid);
2302+
// TODO: Insert notification sound and vibration here.
2303+
// Short 100 ms Vibration
2304+
//Vibrator v = (Vibrator) this.context.getSystemService(Context.VIBRATOR_SERVICE);
2305+
//v.vibrate(100); // Vibrate for 100 ms
2306+
2307+
// Short sound:
2308+
// TODO see issue #15
2309+
2310+
} else {
2311+
// TODO This may need to be removed as it may spam the logcat buffer...
2312+
//Log.v(TAG, mTAG + ":insertEventLog(): Skipped inserting duplicate event");
2313+
}
2314+
}
2315+
// TODO This may need to be removed as it may spam the logcat buffer...
2316+
//Log.v(TAG, mTAG + ":insertEventLog(): Skipped inserting bad CID/LAC data");
2317+
}
2318+
*/
2319+
2320+
2321+
22532322
/**
22542323
* Description: Inserts BTS Sector Type data into the SectorType table
22552324
*

0 commit comments

Comments
 (0)