Skip to content

Improve code quality - fix security and performance issues, better error handling #613

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

Merged
merged 31 commits into from
Sep 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
29beff5
close input buffer
agilob Sep 19, 2015
19c3805
fix floating point comparsion
agilob Sep 19, 2015
ec66705
fix context of logs in AIMSICD and DebugLogs
agilob Sep 19, 2015
c6f3f75
DebugLog - code compliant with java code guidelines
agilob Sep 19, 2015
ab4ace7
fix double comparsion statement in mapviewer
agilob Sep 19, 2015
cb7c6ba
change generic exception to IOexception
agilob Sep 19, 2015
e6c2646
general code cleanup in requesttask
agilob Sep 19, 2015
7286433
removed a lot of crap from AIMSICDDbAdapter
agilob Sep 19, 2015
879105d
add missing exception logging in AIMSICDDbAdapter
agilob Sep 19, 2015
7bd4c9b
general code cleanup in aboutfragment
agilob Sep 19, 2015
ec00e16
code cleanup in AtCommandFragment
agilob Sep 19, 2015
7b3ad44
better stack printing in atcommandfragment
agilob Sep 19, 2015
f468f11
remove unused code, fix exception handling in samsungmulticlient
agilob Sep 19, 2015
b5730b0
AccelerometerMonitor: Runnable().run should never be called directly
agilob Sep 19, 2015
f1b63fe
celltracker.java: removed unused code and fixed double comparision st…
agilob Sep 19, 2015
11cf2b4
locationtracker.java fix double comparsion
agilob Sep 19, 2015
1e7ab59
one more double comparsion in locationtracker
agilob Sep 19, 2015
8ba54da
AdvancedUserActivity: new translation strings
agilob Sep 19, 2015
d84034f
add missing new translation strings
agilob Sep 19, 2015
5f2e776
smsdetector- fix potential NPEs, decrease stack
agilob Sep 19, 2015
a2c0894
properly log exception in cell.java
agilob Sep 19, 2015
b2a4e1a
add exception logging in chilprocess.java
agilob Sep 19, 2015
fb307f0
removed unused code from device.java improve logging
agilob Sep 19, 2015
3cbf475
fix potential runtimexception (i had once) in AimsicdService
agilob Sep 19, 2015
4189b27
fix double comp. statement in helpers.java
agilob Sep 19, 2015
545a77f
log exceptions in miscutils
agilob Sep 19, 2015
7616124
fix potential NPE in status.java
agilob Sep 19, 2015
e54ceb5
add and improve logging to statuspropertiesrefl
agilob Sep 19, 2015
d29b559
tinydb: remove unused code
agilob Sep 19, 2015
ee33ad7
add logger to truncatedlocation
agilob Sep 19, 2015
7bb5e74
add logger to ttyprivfile
agilob Sep 19, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 67 additions & 87 deletions app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java

Large diffs are not rendered by default.

45 changes: 22 additions & 23 deletions app/src/main/java/com/SecUpwN/AIMSICD/activities/DebugLogs.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,9 @@
*
*/


public class DebugLogs extends BaseActivity {

private static final String TAG = "AIMSICD";
private static final String mTAG = "DebugLogs";
private static final String TAG = "DebugLogs";

private LogUpdaterThread logUpdater = null;
private boolean updateLogs = true;
Expand All @@ -73,7 +71,6 @@ public class DebugLogs extends BaseActivity {
private Button btnClear = null;
private Button btnCopy = null;
private Button btnStop = null;
//private Button btnRadio = null;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -86,7 +83,6 @@ public void onCreate(Bundle savedInstanceState) {
btnClear = (Button) findViewById(R.id.btnClear);
btnStop = (Button) findViewById(R.id.btnStopLogs);
btnCopy = (Button) findViewById(R.id.btnCopy);
//btnRadio = (Button) findViewById(R.id.btnRadio);

runOnUiThread(new Runnable() {
@Override
Expand All @@ -100,9 +96,8 @@ public void run() {
public void onClick(View view) {
try {
clearLogs();
//Log.d("DebugLogs", "Logcat clearing disabled!");
} catch (Exception e) {
Log.e(TAG, mTAG + ": Error clearing logs", e);
} catch (IOException e) {
Log.e(TAG, "Error clearing logs", e);
}
}
});
Expand Down Expand Up @@ -161,12 +156,10 @@ protected void onResume() {

private void startLogging() {
updateLogs = true;
try {
logUpdater = new LogUpdaterThread();
logUpdater.start();
} catch (Exception e) {
Log.e(TAG, mTAG + ": Error starting log updater thread", e);
}

logUpdater = new LogUpdaterThread();
logUpdater.start();

btnStop.setText(getString(R.string.btn_stop_logs));
}

Expand Down Expand Up @@ -218,7 +211,7 @@ public void run() {
intent.putExtra(Intent.EXTRA_TEXT, log);
startActivity(Intent.createChooser(intent, "Send Error Log"));
} catch (IOException e) {
Log.e(TAG, mTAG + ": Error reading logs", e);
Log.w(TAG, "Error reading logs", e);
}
}
}.start();
Expand Down Expand Up @@ -280,8 +273,10 @@ private String runProcess(String command) throws IOException {
*/
private String runProcess(String[] command) throws IOException {
Process process = null;
if (command.length == 1) process = Runtime.getRuntime().exec(command[0]);
else Runtime.getRuntime().exec(command);
if (command.length == 1)
process = Runtime.getRuntime().exec(command[0]);
else
Runtime.getRuntime().exec(command);

BufferedReader bufferedReader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
Expand All @@ -292,6 +287,7 @@ private String runProcess(String[] command) throws IOException {
log.append(line);
log.append("\n");
}
bufferedReader.close();
return log.toString();
}

Expand All @@ -306,8 +302,8 @@ private void clearLogs() throws IOException {
public void run() {
try {
Runtime.getRuntime().exec("logcat -c -b main -b system -b radio -b events");
} catch (Exception e) {
Log.e(TAG, mTAG + ": Error clearing logs", e);
} catch (IOException e) {
Log.e(TAG, "Error clearing logs", e);
}

runOnUiThread(new Runnable() {
Expand All @@ -325,7 +321,6 @@ class LogUpdaterThread extends Thread {
public void run() {
while (updateLogs) {
try {
//Log.d("log_thread", "running");
final String logs = getLogs();
if (!logs.equals(logView.getText().toString())) {
runOnUiThread(new Runnable() {
Expand All @@ -345,10 +340,14 @@ public void run() {
}
});
}
} catch (Exception e) {
Log.e(TAG, mTAG + ": Error updating logs", e);
} catch (IOException e) {
Log.w(TAG, "Error updating logs", e);
}
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
Log.w(TAG, "Thread was interrupted", e);
}
try { Thread.sleep(1000); } catch (Exception e) {}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,13 +263,13 @@ private void setupMapType(int mapType) {
// as they are redundant (hybrid) and broken (satellite).
switch (mapType) {
case 0:
mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE); //setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
break;
case 1:
mMap.setTileSource(TileSourceFactory.CYCLEMAP); //.setMapType(GoogleMap.MAP_TYPE_TERRAIN);
mMap.setTileSource(TileSourceFactory.CYCLEMAP);
break;
default:
mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE); //setMapType(GoogleMap.MAP_TYPE_NORMAL);
mMap.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
break;
}
}
Expand Down Expand Up @@ -392,11 +392,9 @@ private void loadEntries() {
new AsyncTask<Void,Void,GeoPoint>() {
@Override
protected GeoPoint doInBackground(Void... voids) {
final int SIGNAL_SIZE_RATIO = 15; // A scale factor to draw BTS Signal circles
int signal;

mCellTowerGridMarkerClusterer.getItems().clear();
// loadOpenCellIDMarkers();

//New function only gets bts from DBe_import by sim network
loadOcidMarkersByNetwork();
Expand All @@ -407,9 +405,8 @@ protected GeoPoint doInBackground(Void... voids) {
try {
// Grab cell data from CELL_TABLE (cellinfo) --> DBi_bts
c = mDbHelper.getCellData();

}catch(IllegalStateException ix) {
Log.e(TAG, ix.getMessage(), ix);
} catch(IllegalStateException ix) {
Log.e(TAG, "Problem getting data from CELL_TABLE", ix);
}

/*
Expand All @@ -425,32 +422,35 @@ protected GeoPoint doInBackground(Void... voids) {
final int mnc = c.getInt(c.getColumnIndex(DBTableColumnIds.DBI_BTS_MNC)); // MNC
final double dlat = c.getDouble(c.getColumnIndex(DBTableColumnIds.DBI_BTS_LAT)); // Lat
final double dlng = c.getDouble(c.getColumnIndex(DBTableColumnIds.DBI_BTS_LON)); // Lon
if (dlat == 0.0 && dlng == 0.0) {

if (Double.doubleToRawLongBits(dlat) == 0
&& Double.doubleToRawLongBits(dlng) == 0) {
continue;
}
//TODO this (signal) is not in DBi_bts
signal = 1;//c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_AVG_SIGNAL)); // signal
// TODO this (signal) is not in DBi_bts
signal = 1;
//c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_AVG_SIGNAL)); // signal
// In case of missing or negative signal, set a default fake signal,
// so that we can still draw signal circles. ?
if (signal <= 0) {
signal = 20;
}
//if (signal <= 0) {
// signal = 20;
//}

if ((dlat != 0.0) || (dlng != 0.0)) {
if (Double.doubleToRawLongBits(dlat) != 0
|| Double.doubleToRawLongBits(dlng) != 0) {
loc = new GeoPoint(dlat, dlng);


CellTowerMarker ovm = new CellTowerMarker(mContext, mMap,
"Cell ID: " + cellID,
"", loc,
new MarkerData(
"" + cellID,
"" + loc.getLatitude(),
"" + loc.getLongitude(),
"" + lac,
"" + mcc,
"" + mnc,
"", false)
"Cell ID: " + cellID,
"", loc,
new MarkerData(
String.valueOf(cellID),
String.valueOf(loc.getLatitude()),
String.valueOf(loc.getLongitude()),
String.valueOf(lac),
String.valueOf(mcc),
String.valueOf(mnc),
"", false)
);
// The pin of our current position
ovm.setIcon(getResources().getDrawable(R.drawable.ic_map_pin_blue));
Expand Down Expand Up @@ -482,10 +482,14 @@ public void run() {
c.close();
}
// plot neighbouring cells
while (mAimsicdService == null) try {
if (isCancelled()) return null;
Thread.sleep(100);
} catch (Exception e) {}
while (mAimsicdService == null)
try {
if (isCancelled())
return null;
Thread.sleep(100);
} catch (InterruptedException e) {
Log.w(TAG, "thread interrupted", e);
}
List<Cell> nc = mAimsicdService.getCellTracker().updateNeighbouringCells();
for (Cell cell : nc) {
if (isCancelled()) return null;
Expand All @@ -495,13 +499,13 @@ public void run() {
getString(R.string.cell_id_label) + cell.getCID(),
"", loc,
new MarkerData(
"" + cell.getCID(),
"" + loc.getLatitude(),
"" + loc.getLongitude(),
"" + cell.getLAC(),
"" + cell.getMCC(),
"" + cell.getMNC(),
"", false));
String.valueOf(cell.getCID()),
String.valueOf(loc.getLatitude()),
String.valueOf(loc.getLongitude()),
String.valueOf(cell.getLAC()),
String.valueOf(cell.getMCC()),
String.valueOf(cell.getMNC()),
"", false));

// The pin of other BTS
ovm.setIcon(getResources().getDrawable(R.drawable.ic_map_pin_orange));
Expand All @@ -526,7 +530,8 @@ public void run() {
*/
@Override
protected void onPostExecute(GeoPoint defaultLoc) {
if (loc != null && (loc.getLatitude() != 0.0 && loc.getLongitude() != 0.0)) {
if (loc != null && (Double.doubleToRawLongBits(loc.getLatitude()) != 0
&& Double.doubleToRawLongBits(loc.getLongitude()) != 0)) {
mMap.getController().setZoom(16);
mMap.getController().animateTo(new GeoPoint(loc.getLatitude(), loc.getLongitude()));
} else {
Expand Down Expand Up @@ -567,7 +572,7 @@ private void loadOcidMarkersByNetwork() {
int imnc =0;
if (networkOperator != null) {
imcc = Integer.parseInt(networkOperator.substring(0, 3));
imnc =Integer.parseInt(networkOperator.substring(3));
imnc = Integer.parseInt(networkOperator.substring(3));
}
// DBe_import tower pins.
Drawable cellTowerMarkerIcon = getResources().getDrawable(R.drawable.ic_map_pin_green);
Expand All @@ -577,36 +582,35 @@ private void loadOcidMarkersByNetwork() {
if (c.moveToFirst()) {
do {
// CellID,Lac,Mcc,Mnc,Lat,Lng,AvgSigStr,Samples
final int cellID = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_CID)); // CellID
final int lac = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_LAC)); // Lac
final int mcc = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_MCC)); // Mcc
final int mnc = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_MNC)); // Mnc
final double dlat = Double.parseDouble(c.getString(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_GPS_LAT))); // Lat
final double dlng = Double.parseDouble(c.getString(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_GPS_LON))); // Lon
final GeoPoint location = new GeoPoint(dlat, dlng); //
final int cellID = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_CID));
final int lac = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_LAC));
final int mcc = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_MCC));
final int mnc = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_MNC));
final double dlat = Double.parseDouble(c.getString(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_GPS_LAT)));
final double dlng = Double.parseDouble(c.getString(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_GPS_LON)));
final GeoPoint location = new GeoPoint(dlat, dlng);
//where is c.getString(6)AvgSigStr
final int samples = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_SAMPLES)); //Samples
final int samples = c.getInt(c.getColumnIndex(DBTableColumnIds.DBE_IMPORT_SAMPLES));
// Add map marker for CellID
CellTowerMarker ovm = new CellTowerMarker(mContext, mMap,
"Cell ID: " + cellID,
"", location,
new MarkerData(
"" + cellID,
"" + location.getLatitude(),
"" + location.getLongitude(),
"" + lac,
"" + mcc,
"" + mnc,
"" + samples,
false));
String.valueOf(cellID),
String.valueOf(location.getLatitude()),
String.valueOf(location.getLongitude()),
String.valueOf(lac),
String.valueOf(mcc),
String.valueOf(mnc),
String.valueOf(samples),
false));

ovm.setIcon(cellTowerMarkerIcon);
items.add(ovm);
} while (c.moveToNext());
}
c.close();


mCellTowerGridMarkerClusterer.addAll(items);
}
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
Expand All @@ -619,8 +623,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin

public void setRefreshActionButtonState(final boolean refreshing) {
if (mOptionsMenu != null) {
final MenuItem refreshItem = mOptionsMenu
.findItem(R.id.get_opencellid);
final MenuItem refreshItem = mOptionsMenu.findItem(R.id.get_opencellid);
if (refreshItem != null) {
if (refreshing) {
refreshItem.setActionView(R.layout.actionbar_indeterminate_progress);
Expand All @@ -641,7 +644,7 @@ public void onStop() {
public void onStart() {
super.onStart();
((AppAIMSICD) getApplication()).attach(this);
if( TinyDB.getInstance().getBoolean(TinyDbKeys.FINISHED_LOAD_IN_MAP)) {
if(TinyDB.getInstance().getBoolean(TinyDbKeys.FINISHED_LOAD_IN_MAP)) {
setRefreshActionButtonState(false);
}
}
Expand Down
Loading