From 4f52d86802177b97ba98d86640e3b02050ee79ac Mon Sep 17 00:00:00 2001 From: Lars Grefer <github@larsgrefer.de> Date: Tue, 8 Dec 2015 12:53:33 +0100 Subject: [PATCH 1/6] add dependency --- app/build.gradle | 1 + build.gradle | 1 + 2 files changed, 2 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 993588c0..3891c9bc 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -125,6 +125,7 @@ dependencies { compile 'org.apache.commons:commons-lang3:3.3.2' compile 'com.google.code.gson:gson:2.2.4' compile 'com.github.kaichunlin.transition:core:0.9.2' + compile 'io.freefair.android-util:logging:1.1.0' //debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1' //releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1' } diff --git a/build.gradle b/build.gradle index a4063289..14ee0ac7 100644 --- a/build.gradle +++ b/build.gradle @@ -12,5 +12,6 @@ buildscript { allprojects { repositories { mavenCentral() + maven { url "https://jitpack.io" } } } -- GitLab From fd100505ab257940899633cbc2f60c0d3c9b18f1 Mon Sep 17 00:00:00 2001 From: Lars Grefer <github@larsgrefer.de> Date: Tue, 8 Dec 2015 13:07:33 +0100 Subject: [PATCH 2/6] use logger in Activities --- .../AIMSICD/activities/BaseActivity.java | 18 ++++++------- .../activities/CreditsRollActivity.java | 1 - .../SecUpwN/AIMSICD/activities/DebugLogs.java | 17 +++++++----- .../AIMSICD/activities/MapViewerOsmDroid.java | 22 ++++++++------- .../activities/OpenCellIdActivity.java | 27 ++++++++++--------- 5 files changed, 46 insertions(+), 39 deletions(-) diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/activities/BaseActivity.java b/app/src/main/java/com/SecUpwN/AIMSICD/activities/BaseActivity.java index ce0104eb..2e0efe7e 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/activities/BaseActivity.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/activities/BaseActivity.java @@ -10,25 +10,25 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.SharedPreferences; -import android.support.v4.app.FragmentActivity; import android.support.v4.content.LocalBroadcastManager; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import com.SecUpwN.AIMSICD.R; import com.SecUpwN.AIMSICD.service.AimsicdService; import com.SecUpwN.AIMSICD.utils.Icon; import com.SecUpwN.AIMSICD.utils.Status; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Base activity class, handles code that is shared between all activities * * @author Tor Henning Ueland */ public class BaseActivity extends AppCompatActivity { - private static final String TAG = "AIMSICD"; - private static final String mTAG = "BaseActivity"; - + //TODO: @Inject + private final Logger log = AndroidLogger.forClass(BaseActivity.class); /** * Triggered when GUI is opened @@ -36,7 +36,7 @@ public class BaseActivity extends AppCompatActivity { @Override protected void onResume() { super.onResume(); - Log.d(TAG, mTAG + ": StatusWatcher starting watching"); + log.debug("StatusWatcher starting watching"); LocalBroadcastManager.getInstance(this).registerReceiver(mMessageReceiver, new IntentFilter("StatusChange")); updateIcon(this); @@ -48,8 +48,8 @@ public class BaseActivity extends AppCompatActivity { private BroadcastReceiver mMessageReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { - Log.d(TAG, mTAG + ": StatusWatcher received status change to " + Status.getStatus().name()+", updating icon"); - updateIcon(context); + log.debug("StatusWatcher received status change to " + Status.getStatus().name() + ", updating icon"); + updateIcon(context); } }; @@ -72,7 +72,7 @@ public class BaseActivity extends AppCompatActivity { @Override protected void onPause() { super.onPause(); - Log.d(TAG, mTAG + ": StatusWatcher stopped watching"); + log.debug("StatusWatcher stopped watching"); LocalBroadcastManager.getInstance(this).unregisterReceiver(mMessageReceiver); } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/activities/CreditsRollActivity.java b/app/src/main/java/com/SecUpwN/AIMSICD/activities/CreditsRollActivity.java index efeecc4e..5507bfb6 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/activities/CreditsRollActivity.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/activities/CreditsRollActivity.java @@ -17,7 +17,6 @@ package com.SecUpwN.AIMSICD.activities; -import android.app.Activity; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/activities/DebugLogs.java b/app/src/main/java/com/SecUpwN/AIMSICD/activities/DebugLogs.java index 98332f6c..80dc6de4 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/activities/DebugLogs.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/activities/DebugLogs.java @@ -10,7 +10,6 @@ import android.content.ClipboardManager; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NavUtils; -import android.util.Log; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -25,6 +24,9 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: This class is providing for the Debug log feature in the swipe menu. * It reads the last 500 lines from the Logcat ring buffers: main and radio. @@ -61,7 +63,8 @@ import java.io.InputStreamReader; public class DebugLogs extends BaseActivity { - private static final String TAG = "DebugLogs"; + //TODO: @Inject + private final Logger log = AndroidLogger.forClass(DebugLogs.class); private LogUpdaterThread logUpdater = null; private boolean updateLogs = true; @@ -97,7 +100,7 @@ public class DebugLogs extends BaseActivity { try { clearLogs(); } catch (IOException e) { - Log.e(TAG, "Error clearing logs", e); + log.error("Error clearing logs", e); } } }); @@ -211,7 +214,7 @@ public class DebugLogs extends BaseActivity { intent.putExtra(Intent.EXTRA_TEXT, log); startActivity(Intent.createChooser(intent, "Send Error Log")); } catch (IOException e) { - Log.w(TAG, "Error reading logs", e); + log.warn("Error reading logs", e); } } }.start(); @@ -303,7 +306,7 @@ public class DebugLogs extends BaseActivity { try { Runtime.getRuntime().exec("logcat -c -b main -b system -b radio -b events"); } catch (IOException e) { - Log.e(TAG, "Error clearing logs", e); + log.error("Error clearing logs", e); } runOnUiThread(new Runnable() { @@ -341,12 +344,12 @@ public class DebugLogs extends BaseActivity { }); } } catch (IOException e) { - Log.w(TAG, "Error updating logs", e); + log.warn("Error updating logs", e); } try { Thread.sleep(1000); } catch (InterruptedException e) { - Log.w(TAG, "Thread was interrupted", e); + log.warn("Thread was interrupted", e); } } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java b/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java index 9447634e..85fd76d7 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java @@ -24,7 +24,6 @@ import android.telephony.CellInfo; import android.telephony.PhoneStateListener; import android.telephony.ServiceState; import android.telephony.TelephonyManager; -import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; @@ -57,6 +56,9 @@ import org.osmdroid.views.overlay.mylocation.MyLocationNewOverlay; import java.util.LinkedList; import java.util.List; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: TODO: add details * <p/> @@ -88,7 +90,7 @@ import java.util.List; public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPreferenceChangeListener { - private final String TAG = "AIMSICD_MapViewer"; + private final Logger log = AndroidLogger.forClass(MapViewerOsmDroid.class); public static final String updateOpenCellIDMarkers = "update_open_cell_markers"; private MapView mMap; @@ -123,7 +125,7 @@ public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPre */ @Override public void onCreate(Bundle savedInstanceState) { - Log.i(TAG, "Starting MapViewer"); + log.info("Starting MapViewer"); super.onCreate(savedInstanceState); mContext = this; @@ -207,7 +209,7 @@ public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPre public void onReceive(Context context, Intent intent) { loadEntries(); if (BuildConfig.DEBUG && mCellTowerGridMarkerClusterer != null && mCellTowerGridMarkerClusterer.getItems() != null) { - Log.v(TAG, "mMessageReceiver CellTowerMarkers.invalidate() markers.size():" + mCellTowerGridMarkerClusterer.getItems().size()); + log.verbose("mMessageReceiver CellTowerMarkers.invalidate() markers.size():" + mCellTowerGridMarkerClusterer.getItems().size()); } } @@ -238,7 +240,7 @@ public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPre @Override public void onServiceDisconnected(ComponentName arg0) { - Log.e(TAG, "Service Disconnected"); + log.error("Service Disconnected"); mBound = false; } }; @@ -400,7 +402,7 @@ public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPre // Grab cell data from CELL_TABLE (cellinfo) --> DBi_bts c = mDbHelper.getCellData(); } catch (IllegalStateException ix) { - Log.e(TAG, "Problem getting data from CELL_TABLE", ix); + log.error("Problem getting data from CELL_TABLE", ix); } /* @@ -469,7 +471,7 @@ public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPre double[] d = mDbHelper.getDefaultLocation(mcc); ret = new GeoPoint(d[0], d[1]); } catch (Exception e) { - Log.e("map", "Error getting default location!", e); + log.error("Error getting default location!", e); } } if (c != null) { @@ -482,7 +484,7 @@ public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPre return null; Thread.sleep(100); } catch (InterruptedException e) { - Log.w(TAG, "thread interrupted", e); + log.warn("thread interrupted", e); } List<Cell> nc = mAimsicdService.getCellTracker().updateNeighbouringCells(); for (Cell cell : nc) { @@ -505,7 +507,7 @@ public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPre ovm.setIcon(getResources().getDrawable(R.drawable.ic_map_pin_orange)); items.add(ovm); } catch (Exception e) { - Log.e("map", "Error plotting neighbouring cells", e); + log.error("Error plotting neighbouring cells", e); } } @@ -549,7 +551,7 @@ public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPre } if (mCellTowerGridMarkerClusterer != null) { if (BuildConfig.DEBUG && mCellTowerGridMarkerClusterer.getItems() != null) { - Log.v(TAG, "CellTowerMarkers.invalidate() markers.size():" + mCellTowerGridMarkerClusterer.getItems().size()); + log.verbose("CellTowerMarkers.invalidate() markers.size():" + mCellTowerGridMarkerClusterer.getItems().size()); } //Drawing markers of cell tower immediately as possible mCellTowerGridMarkerClusterer.invalidate(); diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/activities/OpenCellIdActivity.java b/app/src/main/java/com/SecUpwN/AIMSICD/activities/OpenCellIdActivity.java index b11dc25c..dd5b1f83 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/activities/OpenCellIdActivity.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/activities/OpenCellIdActivity.java @@ -9,7 +9,6 @@ import android.app.ProgressDialog; import android.content.SharedPreferences; import android.os.AsyncTask; import android.os.Bundle; -import android.util.Log; import android.view.View; import com.SecUpwN.AIMSICD.AppAIMSICD; @@ -23,6 +22,9 @@ import com.squareup.okhttp.Response; import java.io.IOException; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: Popup toast messages asking if user wants to download new API key * to access OpenCellId services and data. @@ -37,7 +39,8 @@ import java.io.IOException; */ public class OpenCellIdActivity extends BaseActivity { private SharedPreferences prefs; - private static final String TAG = "OpenCellIdActivity"; + //TODO: @Inject + private final Logger log = AndroidLogger.forClass(OpenCellIdActivity.class); private ProgressDialog pd; //TODO: @Inject @@ -77,7 +80,7 @@ public class OpenCellIdActivity extends BaseActivity { try { return requestNewOCIDKey(); } catch (final IOException e) { - Log.w(TAG, "Error getting new OCID-API", e); + log.warn("Error getting new OCID-API", e); /** * In case response from OCID takes more time and user pressed back or anything else, @@ -164,38 +167,38 @@ public class OpenCellIdActivity extends BaseActivity { String htmlResponse = response.body().string(); // For debugging HTTP server response and codes - Log.d(TAG, "Response Html=" + htmlResponse + " Response Code=" + String.valueOf(responseCode)); + log.debug("Response Html=" + htmlResponse + " Response Code=" + String.valueOf(responseCode)); if (responseCode == 200) { - Log.d(TAG, "OCID Code 1: Cell Not found: " + htmlResponse); + log.debug("OCID Code 1: Cell Not found: " + htmlResponse); return htmlResponse; } else if (responseCode == 401) { - Log.d(TAG, "OCID Code 2: Invalid API Key! :" + htmlResponse); + log.debug("OCID Code 2: Invalid API Key! :" + htmlResponse); return htmlResponse; } else if(responseCode == 400){ - Log.d(TAG, "OCID Code 3: Invalid input data: " + htmlResponse); + log.debug("OCID Code 3: Invalid input data: " + htmlResponse); return "Bad Request"; // For making a toast! } else if (responseCode == 403) { - Log.d(TAG, "OCID Code 4: Your API key must be white listed: " + htmlResponse); + log.debug("OCID Code 4: Your API key must be white listed: " + htmlResponse); return "Bad Request"; // For making a toast! } else if(responseCode == 500){ - Log.d(TAG, "OCID Code 5: Remote internal server error: " + htmlResponse); + log.debug("OCID Code 5: Remote internal server error: " + htmlResponse); return "Bad Request"; // For making a toast! } else if (responseCode == 503) { - Log.d(TAG, "OCID Code 6: Reached 24hr API key request limit: " + htmlResponse); + log.debug("OCID Code 6: Reached 24hr API key request limit: " + htmlResponse); return htmlResponse; } else if(responseCode == 429){ - Log.d(TAG, "OCID Code 7: Exceeded daily request limit (1000) for your API key: " + htmlResponse); + log.debug("OCID Code 7: Exceeded daily request limit (1000) for your API key: " + htmlResponse); return htmlResponse; } else { - Log.e(TAG, "OCID Returned Unknown Response: " + responseCode); + log.debug("OCID Returned Unknown Response: " + responseCode); return null; } } -- GitLab From a4f1b0980eeb53e7df1d87f9dd7e3522e975c743 Mon Sep 17 00:00:00 2001 From: Lars Grefer <github@larsgrefer.de> Date: Tue, 8 Dec 2015 13:45:03 +0100 Subject: [PATCH 3/6] add missing comment --- .../java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java b/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java index 85fd76d7..26e6bbb4 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/activities/MapViewerOsmDroid.java @@ -90,6 +90,7 @@ import io.freefair.android.util.logging.Logger; public final class MapViewerOsmDroid extends BaseActivity implements OnSharedPreferenceChangeListener { + //TODO: @Inject private final Logger log = AndroidLogger.forClass(MapViewerOsmDroid.class); public static final String updateOpenCellIDMarkers = "update_open_cell_markers"; -- GitLab From 252e306a12e3fdc8f5510870a8a708c8d9093bce Mon Sep 17 00:00:00 2001 From: Lars Grefer <github@larsgrefer.de> Date: Tue, 8 Dec 2015 14:11:48 +0100 Subject: [PATCH 4/6] more logging --- .../AIMSICD/adapters/AIMSICDDbAdapter.java | 99 ++++++++++--------- .../AIMSICD/fragments/AboutFragment.java | 9 +- .../AIMSICD/fragments/AtCommandFragment.java | 28 +++--- .../AIMSICD/fragments/DeviceFragment.java | 8 +- .../SecUpwN/AIMSICD/receiver/SmsReceiver.java | 15 +-- 5 files changed, 85 insertions(+), 74 deletions(-) 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 3015767d..9db95a70 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/adapters/AIMSICDDbAdapter.java @@ -10,7 +10,6 @@ import android.database.sqlite.SQLiteException; import android.database.sqlite.SQLiteOpenHelper; import android.os.Vibrator; import android.preference.PreferenceManager; -import android.util.Log; import android.util.SparseArray; import com.SecUpwN.AIMSICD.AIMSICD; @@ -36,6 +35,8 @@ import java.util.List; import au.com.bytecode.opencsv.CSVReader; import au.com.bytecode.opencsv.CSVWriter; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; /** * Description: @@ -132,7 +133,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { // TODO: This should be implemented as a SharedPreference... private static final Boolean MONO_DB_DUMP = true; // Also back-up DB with one monolithic dump file? - private static final String TAG = "AIMSICDDbAdapter"; + private final Logger log = AndroidLogger.forClass(AIMSICDDbAdapter.class); private static final String DB_NAME = "aimsicd.db"; private String[] mTables; @@ -195,10 +196,10 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { this.getReadableDatabase(); try { copyDataBase(); - Log.i(TAG, "Database created"); + log.info( "Database created"); return true; } catch (IOException e) { - Log.e(TAG, "Error creating database", e); + log.error( "Error creating database", e); throw new Error("Error copying database", e); } @@ -216,10 +217,10 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { SQLiteDatabase checkDB = null; try { - Log.i(TAG, "Checking for db first install this will throw an error on install and is normal"); + log.info( "Checking for db first install this will throw an error on install and is normal"); checkDB = SQLiteDatabase.openDatabase(mDatabasePath, null, SQLiteDatabase.OPEN_READONLY); } catch (SQLiteException e) { - Log.e(TAG, "database not yet created", e); + log.error( "database not yet created", e); } if (checkDB != null) { @@ -287,7 +288,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { * @return result of deleting that CID */ public int deleteCell(int cellId) { - Log.i(TAG, "Deleted CID: " + cellId); + log.info( "Deleted CID: " + cellId); // TODO Instead we need to delete this cell from DBi_measure, since: // we are using foreign_key enforced DB, that doesn't allow you to // remove Dbi_bts without corresponding DBi_measures that uses them. @@ -386,14 +387,14 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { while (bts_cursor.moveToNext()) { // 1=LAC, 8=Accuracy, 11=Time if (cell.getLAC() != bts_cursor.getInt(bts_cursor.getColumnIndex("LAC"))) { - Log.i(TAG, "ALERT: Changing LAC on CID: " + cell.getCID() + log.info( "ALERT: Changing LAC on CID: " + cell.getCID() + " LAC(API): " + cell.getLAC() + " LAC(DBi): " + bts_cursor.getInt(bts_cursor.getColumnIndex("LAC"))); bts_cursor.close(); return false; } else { - Log.v(TAG, "LAC checked - no change on CID:" + cell.getCID() + log.verbose( "LAC checked - no change on CID:" + cell.getCID() + " LAC(API): " + cell.getLAC() + " LAC(DBi): " + bts_cursor.getInt(bts_cursor.getColumnIndex("LAC"))); } @@ -527,7 +528,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { csvWrite.writeNext("mcc,mnc,lac,cellid,lon,lat,signal,measured_at,rating"); int size = c.getCount(); - Log.d(TAG, "OCID UPLOAD: row count = " + size); + log.debug( "OCID UPLOAD: row count = " + size); while (c.moveToNext()) { csvWrite.writeNext( @@ -550,7 +551,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { c.close(); return false; } catch (Exception e) { - Log.e(TAG, "prepareOpenCellUploadData(): Error creating OpenCellID Upload Data: ", e); + log.error( "prepareOpenCellUploadData(): Error creating OpenCellID Upload Data: ", e); return false; } } @@ -642,7 +643,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { if (!csvCellID.isEmpty()) { int lines = csvCellID.size(); - Log.i(TAG, "UpdateOpenCellID: OCID CSV size (lines): " + lines); + log.info( "UpdateOpenCellID: OCID CSV size (lines): " + lines); // TODO: WHAT IS THIS DOING?? (Why is it needed?) // This counts how many CIDs we have in DBe_import @@ -715,14 +716,14 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { ); } AIMSICD.mProgressBar.setProgress(4); - Log.d(TAG, "PopulateDBeImport(): inserted " + rowCounter + " cells."); + log.debug( "PopulateDBeImport(): inserted " + rowCounter + " cells."); } } else { - Log.e(TAG, "Opencellid.csv file does not exist!"); + log.error( "Opencellid.csv file does not exist!"); } return true; } catch (Exception e) { - Log.e(TAG, "Error parsing OpenCellID data: " + e.getMessage()); + log.error( "Error parsing OpenCellID data: " + e.getMessage()); return false; } finally { try { @@ -780,7 +781,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { records.get(i)[4] // lon ); } catch (Exception ee) { - Log.e(TAG, "RestoreDB: Error in insertDefaultLocation()", ee); + log.error( "RestoreDB: Error in insertDefaultLocation()", ee); } break; @@ -836,7 +837,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { 0 //Integer.parseInt(records.get(i)[16]) // TODO: rej_cause ); } catch (Exception ee) { - Log.e(TAG, "RestoreDB: Error in insertDBeImport()", ee); + log.error( "RestoreDB: Error in insertDBeImport()", ee); } break; @@ -857,7 +858,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { Double.parseDouble(records.get(i)[12]) // lon ); } catch (Exception ee) { - Log.e(TAG, "RestoreDB: Error in insertBTS()", ee); + log.error( "RestoreDB: Error in insertBTS()", ee); } break; @@ -889,7 +890,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { //records.get(i)[23].toString() // TODO: con_state ); } catch (Exception ee) { - Log.e(TAG, "RestoreDB: Error in insertDbiMeasure()", ee); + log.error( "RestoreDB: Error in insertDbiMeasure()", ee); } break; @@ -957,10 +958,10 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { } } } - Log.i(TAG, "RestoreDB() Finished"); + log.info( "RestoreDB() Finished"); return true; } catch (Exception e) { - Log.e(TAG, "RestoreDB() Error", e); + log.error( "RestoreDB() Error", e); return false; } finally { AIMSICD.mProgressBar.setProgress(0); @@ -1008,13 +1009,13 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { String execString = "/system/xbin/sqlite3 " + aimdir + "aimsicd.db '.backup " + file + "'"; try { - Log.i(TAG, "DumpDB() Attempting to dump DB to: " + file + "\nUsing: \"" + execString + "\"\n"); + log.info( "DumpDB() Attempting to dump DB to: " + file + "\nUsing: \"" + execString + "\"\n"); CMDProcessor.runSuCommand(execString); // We need SU for this... AIMSICD.mProgressBar.setProgress(2); } catch (Exception e) { - Log.e(TAG, "DumpDB() Failed to export DB dump file: ", e); + log.error( "DumpDB() Failed to export DB dump file: ", e); } - Log.i(TAG, "DumpDB() Dumped internal database to: " + aimdir + file); + log.info( "DumpDB() Dumped internal database to: " + aimdir + file); AIMSICD.mProgressBar.setProgress(0); } @@ -1038,7 +1039,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { } return true; } catch (Exception ioe) { - Log.e(TAG, "BackupDB() Error: ", ioe); + log.error( "BackupDB() Error: ", ioe); return false; } } @@ -1054,20 +1055,20 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { * @param tableName String representing table name to export */ private void backup(String tableName) { - Log.i(TAG, "Database Backup: " + DB_NAME); + log.info( "Database Backup: " + DB_NAME); File dir = new File(mExternalFilesDirPath); if (!dir.exists()) { if (!dir.mkdirs()) { - Log.e(TAG, "Backup(): Cannot create directory structure to " + dir.getAbsolutePath()); + log.error( "Backup(): Cannot create directory structure to " + dir.getAbsolutePath()); } } // We should probably add some more error handling here. File file = new File(dir, "aimsicd-" + tableName + ".csv"); try { - Log.i(TAG, "Backup(): Backup file was created? " + file.createNewFile()); + log.info( "Backup(): Backup file was created? " + file.createNewFile()); CSVWriter csvWrite = new CSVWriter(new FileWriter(file)); - Log.d(TAG, "DB backup() tableName: " + tableName); + log.debug( "DB backup() tableName: " + tableName); Cursor c = mDb.rawQuery("SELECT * FROM " + tableName, new String[0]); @@ -1085,9 +1086,9 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { c.close(); } catch (Exception e) { - Log.e(TAG, "Error exporting table: " + tableName, e); + log.error( "Error exporting table: " + tableName, e); } - Log.i(TAG, "Backup(): Successfully exported DB table to: " + file); + log.info( "Backup(): Successfully exported DB table to: " + file); } @@ -1155,7 +1156,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { //=== DELETE bad cells from BTS data //============================================================= - Log.d(TAG, "CheckDBe() Attempting to delete bad import data from DBe_import table..."); + log.debug( "CheckDBe() Attempting to delete bad import data from DBe_import table..."); // =========== samples =========== sqlQuery = "DELETE FROM DBe_import WHERE samples < 1"; @@ -1195,7 +1196,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { mDb.execSQL(sqlQuery); // SELECT count(*) from DBe_import; - Log.i(TAG, "CheckDBe() Deleted BTS entries from DBe_import table with bad LAC/CID..."); + log.info("CheckDBe() Deleted BTS entries from DBe_import table with bad LAC/CID..."); //============================================================= //=== UPDATE "rej_cause" in BTS data (DBe_import) @@ -1240,7 +1241,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { */ public void cleanseCellStrengthTables(long maxTime) { - Log.d(TAG, "CleanseCellStrengthTables(): Cleaning DBi_measure WHERE time < " + maxTime); + log.debug("CleanseCellStrengthTables(): Cleaning DBi_measure WHERE time < " + maxTime); //TODO Change "time" to INTEGER in DB -- currently not working String query = String.format( @@ -1301,7 +1302,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { mDb.delete("SmsData", "_id=" + deleteme, null); return true; } catch (Exception ee) { - Log.i(TAG, mTAG + ": Deleting SMS data failed", ee); + log.info(mTAG + ": Deleting SMS data failed", ee); } return false; } @@ -1312,7 +1313,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { mDb.delete("DetectionStrings", "det_str='" + deleteme + "'", null); return true; } catch (Exception ee) { - Log.i(TAG, "Deleting detection string failed", ee); + log.info("Deleting detection string failed", ee); } return false; @@ -1350,14 +1351,14 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { cursor.close(); if (exists) { - Log.i(TAG, "Detection String already in Database"); + log.info("Detection String already in Database"); } else { try { mDb.insert("DetectionStrings", null, newString); - Log.i(TAG, "New detection string added."); + log.info("New detection string added."); return true; } catch (Exception ee) { - Log.i(TAG, "Adding detection string Failed! ", ee); + log.info("Adding detection string Failed! ", ee); } } return false; @@ -1753,7 +1754,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { mDb.insert("DBi_bts", null, values); - Log.i(TAG, "DBi_bts was populated."); + log.info("DBi_bts was populated."); } else { // If cell is already in the DB, update it to last time seen and @@ -1776,7 +1777,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { // update (String table, ContentValues values, String whereClause, String[] whereArgs) mDb.update("DBi_bts", values, "CID=?", new String[]{Integer.toString(cell.getCID())}); - Log.i(TAG, "DBi_bts updated: CID=" + cell.getCID() + " LAC=" + cell.getLAC()); + log.info("DBi_bts updated: CID=" + cell.getCID() + " LAC=" + cell.getLAC()); } // TODO: This doesn't make sense, if it's in DBi_bts it IS part of DBi_measure! @@ -1810,7 +1811,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { dbiMeasure.put("isNeighbour", 0); mDb.insert("DBi_measure", null, dbiMeasure); - Log.i(TAG, "DBi_measure inserted bts_id=" + cell.getCID()); // TODO: NO!! + log.info("DBi_measure inserted bts_id=" + cell.getCID()); // TODO: NO!! } else { // Updating DBi_measure tables if already exists. @@ -1859,7 +1860,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { //dbiMeasure.put("AvgEcNo",AvgEcNo); // TODO: I need to check this... mDb.update("DBi_measure", dbiMeasure, "bts_id=?", new String[]{Integer.toString(cell.getCID())}); - Log.i(TAG, "DBi_measure updated bts_id=" + cell.getCID()); + log.info("DBi_measure updated bts_id=" + cell.getCID()); } @@ -1905,7 +1906,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { // has changed. At the moment this is only PSC, since we don't have the others... // ======================================================================= mDb.update("DBi_bts", btsValues, "CID=?", new String[]{Integer.toString(cid)}); - Log.i(TAG, "Warning: Physical cell data in DBi_bts has changed! CID=" + cid); + log.info("Warning: Physical cell data in DBi_bts has changed! CID=" + cid); } } @@ -2114,10 +2115,10 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { eventLog.put("DF_description", DF_description); mDb.insert("EventLog", null, eventLog); - Log.i(TAG, "InsertEventLog(): Insert detection event into EventLog table with CID=" + cid); + log.info("InsertEventLog(): Insert detection event into EventLog table with CID=" + cid); } else { // TODO This may need to be removed as it may spam the logcat buffer... - Log.v(TAG, "InsertEventLog(): Skipped inserting duplicate event into EventLog table with CID=" + cid); + log.verbose("InsertEventLog(): Skipped inserting duplicate event into EventLog table with CID=" + cid); } } } @@ -2165,7 +2166,7 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { eventLog.put("DF_description", DF_desc); // DF_desc mDb.insert("EventLog", null, eventLog); - Log.i(TAG, "ToEventLog(): Added new event: id=" + DF_id + " time=" + time + " cid=" + cid); + log.info("ToEventLog(): Added new event: id=" + DF_id + " time=" + time + " cid=" + cid); // Short 100 ms Vibration // TODO not elegant solution, vibrator invocation should be moved somewhere else imho @@ -2184,11 +2185,11 @@ public final class AIMSICDDbAdapter extends SQLiteOpenHelper { } // else { // TODO This may need to be removed as it may spam the logcat buffer... - //Log.v(TAG, mTAG + ":toEventLog(): Skipped inserting duplicate event"); + //log.verbose(mTAG + ":toEventLog(): Skipped inserting duplicate event"); // } } // TODO This may need to be removed as it may spam the logcat buffer... - //Log.v(TAG, mTAG + ":insertEventLog(): Skipped inserting bad CID/LAC data"); + //log.verbose(mTAG + ":insertEventLog(): Skipped inserting bad CID/LAC data"); } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/AboutFragment.java b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/AboutFragment.java index fe48c185..69cf14a8 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/AboutFragment.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/AboutFragment.java @@ -16,7 +16,6 @@ import android.support.annotation.DrawableRes; import android.support.annotation.StringRes; import android.support.v4.app.Fragment; import android.support.v7.app.AlertDialog; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -27,9 +26,13 @@ import com.SecUpwN.AIMSICD.BuildConfig; import com.SecUpwN.AIMSICD.R; import com.SecUpwN.AIMSICD.activities.CreditsRollActivity; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + public class AboutFragment extends Fragment { - private static final String TAG = "Aboutfragment"; + //TODO: @Inject + private final Logger log = AndroidLogger.forClass(AboutFragment.class); private Context mContext; private Button btncredits; @@ -50,7 +53,7 @@ public class AboutFragment extends Fragment { } catch (PackageManager.NameNotFoundException e) { //Woops something went wrong?? // so what do we do then? // YES!! LOG THE EXCEPTION ~agilob - Log.e(TAG, "Something went wrong", e); + log.error("Something went wrong", e); version = ""; } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/AtCommandFragment.java b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/AtCommandFragment.java index bf3da281..6f302f99 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/AtCommandFragment.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/AtCommandFragment.java @@ -13,7 +13,6 @@ import android.os.Looper; import android.os.Message; import android.support.v4.app.Fragment; import android.text.Editable; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -38,6 +37,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: This is the AT Command Interface or AT Command Processor (ATCoP) that @@ -70,7 +72,7 @@ import java.util.List; */ public class AtCommandFragment extends Fragment { - private static final String TAG = "AtCommandFrag"; + private final Logger log = AndroidLogger.forClass(AtCommandFragment.class); //Return value constants private static final int SERIAL_INIT_OK = 100; @@ -215,7 +217,7 @@ public class AtCommandFragment extends Fragment { public void onClick(View v) { if (mAtCommand.getText() != null) { String command = mAtCommand.getText().toString(); - Log.i(TAG, "AT Command Detected: " + command); + log.info("AT Command Detected: " + command); executeAT(); } } @@ -276,7 +278,7 @@ public class AtCommandFragment extends Fragment { mSerialDevices.add(mSerialDevice); } } catch (StringIndexOutOfBoundsException e) { - Log.w(TAG, e.getMessage()); + log.warn(e.getMessage()); // ignore, move on } @@ -334,7 +336,7 @@ public class AtCommandFragment extends Fragment { } } catch (Exception e) { - Log.e(TAG, "InitSerialDevice ", e); + log.error("InitSerialDevice ", e); } if (!mSerialDevices.isEmpty()) { @@ -379,7 +381,7 @@ public class AtCommandFragment extends Fragment { // We need a device-type check here, perhaps: gsm.version.ril-impl. Editable cmd = mAtCommand.getText(); if (cmd != null && cmd.length() != 0) { - Log.d(TAG, "ExecuteAT: attempting to send: " + cmd.toString()); + log.debug("ExecuteAT: attempting to send: " + cmd.toString()); if (getSerialDevice() != null) { mCommandTerminal.send(cmd.toString(), new Handler(Looper.getMainLooper()) { @@ -422,26 +424,26 @@ public class AtCommandFragment extends Fragment { cmd.wait(mTimeout); } } catch (InterruptedException e) { - Log.e(TAG, e.getMessage()); + log.error(e.getMessage()); } } if (!cmd.isExecuting() && !cmd.isFinished()) { Exception e = new Exception(); if (!shell.isExecuting && !shell.isReading) { - Log.w(TAG, "Waiting for a command to be executed in a shell that is not executing and not reading! \n\n Command: " + cmd.getCommand()); + log.warn("Waiting for a command to be executed in a shell that is not executing and not reading! \n\n Command: " + cmd.getCommand()); e.setStackTrace(Thread.currentThread().getStackTrace()); - Log.e(TAG, e.getMessage(), e); + log.error(e.getMessage(), e); } else if (shell.isExecuting && !shell.isReading) { - Log.e(TAG, "Waiting for a command to be executed in a shell that is executing but not reading! \n\n Command: " + cmd.getCommand()); + log.error("Waiting for a command to be executed in a shell that is executing but not reading! \n\n Command: " + cmd.getCommand()); e.setStackTrace(Thread.currentThread().getStackTrace()); - Log.e(TAG, e.getMessage(), e); + log.error(e.getMessage(), e); } else { - Log.e(TAG, "Waiting for a command to be executed in a shell that is not reading! \n\n Command: " + cmd.getCommand()); + log.error("Waiting for a command to be executed in a shell that is not reading! \n\n Command: " + cmd.getCommand()); e.setStackTrace(Thread.currentThread().getStackTrace()); - Log.e(TAG, e.getMessage(), e); + log.error(e.getMessage(), e); } } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DeviceFragment.java b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DeviceFragment.java index 016d1986..f675bd59 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DeviceFragment.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/fragments/DeviceFragment.java @@ -16,7 +16,6 @@ import android.os.Bundle; import android.os.IBinder; import android.support.v4.app.Fragment; import android.telephony.TelephonyManager; -import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -29,9 +28,12 @@ import com.SecUpwN.AIMSICD.utils.Helpers; import com.SecUpwN.AIMSICD.widget.HighlightTextView; import com.kaichunlin.transition.animation.AnimationManager; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + public class DeviceFragment extends Fragment { - private final String TAG = "AIMSICD"; + private final Logger log = AndroidLogger.forClass(DeviceFragment.class); private View mView; @@ -103,7 +105,7 @@ public class DeviceFragment extends Fragment { @Override public void onServiceDisconnected(ComponentName arg0) { - Log.e(TAG, "Service Disconnected"); + log.error("Service Disconnected"); mBound = false; } }; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/receiver/SmsReceiver.java b/app/src/main/java/com/SecUpwN/AIMSICD/receiver/SmsReceiver.java index ef532aff..d1180a67 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/receiver/SmsReceiver.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/receiver/SmsReceiver.java @@ -10,13 +10,15 @@ import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.telephony.SmsMessage; -import android.util.Log; import com.SecUpwN.AIMSICD.service.CellTracker; import java.util.ArrayList; import java.util.List; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: The SMS receiver class that handles the SMS PDU data @@ -67,6 +69,8 @@ import java.util.List; */ public class SmsReceiver extends BroadcastReceiver { + private final Logger log = AndroidLogger.forClass(SmsReceiver.class); + public void onReceive(Context context, Intent intent) { try { final Bundle bundle = intent.getExtras(); @@ -87,7 +91,7 @@ public class SmsReceiver extends BroadcastReceiver { } full_pdu_string = sb.toString(); } catch (Exception err) { - Log.e("SmsReceiver", "Exception PDU smsReceiver" + err); + log.error("Exception PDU smsReceiver" + err); } // We may also need to consider catching WAP PUSH SMS messages @@ -97,8 +101,7 @@ public class SmsReceiver extends BroadcastReceiver { //int mms = firstByte & 0x4; // 4 = 0000 0100 (bit 3) //int sri = firstByte & 0x10; // 16 = 0001 0000 (bit 5) int pID = smsPdu[1] & 0xc0; // 192 = 1100 0000 - Log.i("AIMSICD_SmsReceiver", "PDU Data: firstByte: " + firstByte + - " TP-MTI: " + mti + " TP-PID: " + pID); + log.info("PDU Data: firstByte: " + firstByte + " TP-MTI: " + mti + " TP-PID: " + pID); // Need checking! --EVA if (pID == 0x40 && mti == 0) { messages.add(SmsMessage.createFromPdu((byte[]) pdu)); @@ -116,14 +119,14 @@ public class SmsReceiver extends BroadcastReceiver { smsData.putString("message", sms.getMessageBody()); smsIntent.putExtras(smsData); context.sendBroadcast(smsIntent); - Log.i("AIMSICD_SmsReceiver", "Type-0 SMS received! Sender: " + log.info("Type-0 SMS received! Sender: " + sms.getOriginatingAddress() + " Message: " + sms.getMessageBody()); } } } } catch (NullPointerException npe) { - Log.e("SmsReceiver", "Exception smsReceiver" + npe); + log.error("Exception smsReceiver", npe); } } -- GitLab From fc82b51b4fedb2e27c8dac33325ba8e9246c06b2 Mon Sep 17 00:00:00 2001 From: Lars Grefer <github@larsgrefer.de> Date: Tue, 8 Dec 2015 15:32:43 +0100 Subject: [PATCH 5/6] adjust Logging in Services --- .../AIMSICD/service/AimsicdService.java | 15 ++++--- .../SecUpwN/AIMSICD/service/CellTracker.java | 44 ++++++++++--------- .../AIMSICD/service/LocationTracker.java | 18 ++++---- .../service/SignalStrengthTracker.java | 31 +++++++------ 4 files changed, 57 insertions(+), 51 deletions(-) diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/service/AimsicdService.java b/app/src/main/java/com/SecUpwN/AIMSICD/service/AimsicdService.java index 99be4b48..6bc55ee8 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/AimsicdService.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/AimsicdService.java @@ -35,7 +35,6 @@ import android.os.Binder; import android.os.Bundle; import android.os.Handler; import android.os.IBinder; -import android.util.Log; import android.view.WindowManager; import com.SecUpwN.AIMSICD.R; @@ -44,6 +43,9 @@ import com.SecUpwN.AIMSICD.smsdetection.SmsDetector; import com.SecUpwN.AIMSICD.utils.Cell; import com.SecUpwN.AIMSICD.utils.GeoLocation; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: This starts the (background?) AIMSICD service to check for SMS and track * cells with or without GPS enabled. @@ -51,7 +53,8 @@ import com.SecUpwN.AIMSICD.utils.GeoLocation; */ public class AimsicdService extends Service { - private static final String TAG = "AimsicdService"; + //TODO: @Inject + private final Logger log = AndroidLogger.forClass(AimsicdService.class); // /data/data/com.SecUpwN.AIMSICD/shared_prefs/com.SecUpwN.AIMSICD_preferences.xml public static final String SHARED_PREFERENCES_BASENAME = "com.SecUpwN.AIMSICD_preferences"; @@ -119,7 +122,7 @@ public class AimsicdService extends Service { mRilExecutor = new RilExecutor(this); mCellTracker = new CellTracker(this, signalStrengthTracker); - Log.i(TAG, "Service launched successfully."); + log.info("Service launched successfully."); } @Override @@ -138,7 +141,7 @@ public class AimsicdService extends Service { if (SmsDetector.getSmsDetectionState()) { smsdetector.stopSmsDetection(); } - Log.i(TAG, "Service destroyed."); + log.info("Service destroyed."); } public GeoLocation lastKnownLocation() { @@ -189,7 +192,7 @@ public class AimsicdService extends Service { public void startSmsTracking() { if(!isSmsTracking()) { - Log.i(TAG, "Sms Detection Thread Started"); + log.info("Sms Detection Thread Started"); smsdetector = new SmsDetector(this); smsdetector.startSmsDetection(); } @@ -198,7 +201,7 @@ public class AimsicdService extends Service { public void stopSmsTracking() { if(isSmsTracking()) { smsdetector.stopSmsDetection(); - Log.i(TAG, "Sms Detection Thread Stopped"); + log.info("Sms Detection Thread Stopped"); } } 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 042573f1..a123433a 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/CellTracker.java @@ -26,7 +26,6 @@ import android.telephony.SignalStrength; import android.telephony.TelephonyManager; import android.telephony.cdma.CdmaCellLocation; import android.telephony.gsm.GsmCellLocation; -import android.util.Log; import com.SecUpwN.AIMSICD.AIMSICD; import com.SecUpwN.AIMSICD.BuildConfig; @@ -45,6 +44,9 @@ import java.util.List; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: Class to handle tracking of cell information * @@ -83,7 +85,7 @@ import java.util.concurrent.TimeUnit; public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeListener{ - private static final String TAG = "CellTracker"; + private final Logger log = AndroidLogger.forClass(CellTracker.class); public static Cell mMonitorCell; public static String OCID_API_KEY = null; // see getOcidKey() @@ -355,7 +357,7 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi //if nclp = true then check for neighboringCellInfo if (neighboringCellInfo != null && neighboringCellInfo.size() == 0 && nclp) { - Log.i(TAG, "NeighbouringCellInfo is empty: start polling..."); + log.info("NeighbouringCellInfo is empty: start polling..."); // Try to poll the neighboring cells for a few seconds neighboringCellBlockingQueue = new LinkedBlockingQueue<>(100); // TODO What is this ?? @@ -376,14 +378,14 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi // TODO: Consider removing ?? for (int i = 0; i < 10 && neighboringCellInfo.size() == 0; i++) { try { - Log.d(TAG, "NeighbouringCellInfo empty: trying " + i); + log.debug("NeighbouringCellInfo empty: trying " + i); NeighboringCellInfo info = neighboringCellBlockingQueue.poll(1, TimeUnit.SECONDS); if (info == null) { neighboringCellInfo = tm.getNeighboringCellInfo(); if(neighboringCellInfo != null) if (neighboringCellInfo.size() > 0) { // Can we think of a better log message here? - Log.d(TAG, "NeighbouringCellInfo found on " + i + " try. (time based)"); + log.debug("NeighbouringCellInfo found on " + i + " try. (time based)"); break; } else { continue; @@ -405,11 +407,11 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi //commented because I got NPE here // TODO: Who are you?? --EVA - //Log.d(TAG, mTAG + ": neighbouringCellInfo size: " + neighboringCellInfo.size()); + //log.debug(mTAG + ": neighbouringCellInfo size: " + neighboringCellInfo.size()); // Add NC list to DBi_measure:nc_list for (NeighboringCellInfo neighbourCell : neighboringCellInfo) { - Log.i(TAG, "NeighbouringCellInfo -" + + log.info("NeighbouringCellInfo -" + " LAC:" + neighbourCell.getLac() + " CID:" + neighbourCell.getCid() + " PSC:" + neighbourCell.getPsc() + @@ -460,7 +462,7 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi * */ public void checkForNeighbourCount(CellLocation location){ - Log.i(TAG, "CheckForNeighbourCount()"); + log.info("CheckForNeighbourCount()"); Integer ncls = 0; // NC list size if(tm != null && tm.getNeighboringCellInfo() != null) // See # 383 @@ -468,20 +470,20 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi Boolean nclp = tinydb.getBoolean("nc_list_present"); // NC list present? (default is false) if (ncls > 0) { - Log.d(TAG, "NeighbouringCellInfo size: " + ncls ); + log.debug("NeighbouringCellInfo size: " + ncls ); if (!nclp) { - Log.d(TAG, "Setting nc_list_present to: true"); + log.debug("Setting nc_list_present to: true"); tinydb.putBoolean("nc_list_present", true); } } else if (ncls == 0 && nclp) { // Detection 7a - Log.i(TAG, "ALERT: No neighboring cells detected for CID: " + mDevice.mCell.getCID()); + log.info("ALERT: No neighboring cells detected for CID: " + mDevice.mCell.getCID()); vibrate(100, Status.Type.MEDIUM); dbHelper.toEventLog(4,"No neighboring cells detected"); // (DF_id, DF_desc) } else { // Todo: remove cid string when working. - Log.d(TAG, "NC list not supported by AOS on this device. Nothing to do."); - Log.d(TAG, ": Setting nc_list_present to: false"); + log.debug("NC list not supported by AOS on this device. Nothing to do."); + log.debug(": Setting nc_list_present to: false"); tinydb.putBoolean("nc_list_present", false); } } @@ -568,7 +570,7 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi if (!dbHelper.openCellExists(mMonitorCell.getCID())) { dbHelper.toEventLog(2, "CID not in DBe_import"); - Log.i(TAG, "ALERT: Connected to unknown CID not in DBe_import: " + mMonitorCell.getCID()); + log.info("ALERT: Connected to unknown CID not in DBe_import: " + mMonitorCell.getCID()); vibrate(100, Status.Type.MEDIUM); mCellIdNotInOpenDb = true; @@ -618,7 +620,7 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi return; } - Log.i(TAG, "NeighbouringCellInfo empty - event based polling succeeded!"); + log.info("NeighbouringCellInfo empty - event based polling succeeded!"); tm.listen(phoneStatelistener, PhoneStateListener.LISTEN_NONE); if(neighboringCellInfo == null) neighboringCellInfo = new ArrayList<>(); @@ -1131,7 +1133,7 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi mTrackingFemtocell = true; mPhoneStateListener = new PhoneStateListener() { public void onServiceStateChanged(ServiceState s) { - Log.d(TAG, context.getString(R.string.service_state_changed)); + log.debug(context.getString(R.string.service_state_changed)); getServiceStateInfo(s); } }; @@ -1148,7 +1150,7 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi tm.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); mTrackingFemtocell = false; setNotification(); - Log.v(TAG, context.getString(R.string.stopped_tracking_femtocell)); + log.verbose(context.getString(R.string.stopped_tracking_femtocell)); } } @@ -1196,11 +1198,11 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi return !((networkID < FEMTO_NID_MIN) || (networkID >= FEMTO_NID_MAX)); } else { - Log.v(TAG, "Cell location info is null."); + log.verbose("Cell location info is null."); return false; } } else { - Log.v(TAG, "Telephony Manager is null."); + log.verbose("Telephony Manager is null."); return false; } } @@ -1219,11 +1221,11 @@ public class CellTracker implements SharedPreferences.OnSharedPreferenceChangeLi int FEMTO_NID_MIN = 0xfa; return !((networkID < FEMTO_NID_MIN) || (networkID >= FEMTO_NID_MAX)); } else { - Log.v(TAG, "Cell location info is null."); + log.verbose("Cell location info is null."); return false; } } else { - Log.v(TAG, "Telephony Manager is null."); + log.verbose("Telephony Manager is null."); return false; } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/service/LocationTracker.java b/app/src/main/java/com/SecUpwN/AIMSICD/service/LocationTracker.java index 7a8fc905..051b5079 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/LocationTracker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/LocationTracker.java @@ -13,7 +13,6 @@ import android.location.LocationListener; import android.location.LocationManager; import android.os.Build; import android.os.Bundle; -import android.util.Log; import com.SecUpwN.AIMSICD.R; import com.SecUpwN.AIMSICD.adapters.AIMSICDDbAdapter; @@ -21,12 +20,15 @@ import com.SecUpwN.AIMSICD.utils.Cell; import com.SecUpwN.AIMSICD.utils.GeoLocation; import com.SecUpwN.AIMSICD.utils.TruncatedLocation; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Class to handle GPS location tracking */ public final class LocationTracker { - private static final String TAG = "LocationTracker"; + private final Logger log = AndroidLogger.forClass(LocationTracker.class); // how long with no movement detected, before we assume we are not moving public static final long MOVEMENT_THRESHOLD_MS = 20 * 1000; @@ -59,21 +61,21 @@ public final class LocationTracker { lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, GPS_MIN_UPDATE_TIME, GPS_MIN_UPDATE_DISTANCE, mLocationListener); } catch (IllegalArgumentException e) { - Log.d(TAG, "GPS location provider doesnt exist"); + log.debug("GPS location provider doesnt exist"); } try { lm.requestLocationUpdates(LocationManager.PASSIVE_PROVIDER, GPS_MIN_UPDATE_TIME, GPS_MIN_UPDATE_DISTANCE, mLocationListener); } catch (IllegalArgumentException e) { - Log.d(TAG, "Passive location provider doesnt exist"); + log.debug("Passive location provider doesnt exist"); } try { lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, GPS_MIN_UPDATE_TIME, GPS_MIN_UPDATE_DISTANCE, mLocationListener); } catch (IllegalArgumentException e) { - Log.d(TAG, "Network location provider doesnt exist"); + log.debug("Network location provider doesnt exist"); } } @@ -126,21 +128,21 @@ public final class LocationTracker { try { Cell cell = context.getCell(); if (cell != null) { - Log.d("location", "Looking up MCC " + cell.getMCC()); + log.debug("Looking up MCC " + cell.getMCC()); double[] defLoc = mDbHelper.getDefaultLocation(cell.getMCC()); loc = GeoLocation.fromDegrees(defLoc[0], defLoc[1]); } } catch (Exception e) { - Log.e("location", "Unable to get location from MCC", e); + log.error("Unable to get location from MCC", e); } } } } if (loc != null) - Log.i("location", "Last known location " + loc.toString()); + log.info("Last known location " + loc.toString()); return loc; } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/service/SignalStrengthTracker.java b/app/src/main/java/com/SecUpwN/AIMSICD/service/SignalStrengthTracker.java index c7a2abde..58f1867d 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/SignalStrengthTracker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/SignalStrengthTracker.java @@ -6,12 +6,14 @@ package com.SecUpwN.AIMSICD.service; import android.content.Context; -import android.util.Log; import com.SecUpwN.AIMSICD.adapters.AIMSICDDbAdapter; import java.util.HashMap; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: Class that calculates cell signal strength averages and decides if a * given cell + strength appears to be mysteriously (low or high). @@ -72,7 +74,7 @@ import java.util.HashMap; * * ChangeLog * - * 20150703 E:V:A Changed log TAG to use only TAG for Log.i() and mTAG for Log.d/e/v() + * 20150703 E:V:A Changed log TAG to use only TAG for log.info() and mTAG for log.debug/e/v() * 20150717 E:V:A Added back mTAG's and added comments * 20150719 E:V:A Added comments * @@ -80,8 +82,7 @@ import java.util.HashMap; */ public class SignalStrengthTracker { - private static final String TAG = "AIMSICD"; - private static final String mTAG = "SignalStrengthTracker"; + private final Logger log = AndroidLogger.forClass(SignalStrengthTracker.class); private static int sleepTimeBetweenSignalRegistration = 60; // [seconds] private static int minimumIdleTime = 30; // [seconds] @@ -119,17 +120,15 @@ public class SignalStrengthTracker { // TODO: We probably need to convert this into seconds for easy use in DB long now = System.currentTimeMillis(); // [ms] - if(deviceIsMoving()) { - Log.i(TAG, mTAG + - ": Ignored signal sample for CID: " + cellID + - " due to device movement. Waiting for " + ((minimumIdleTime*1000) - (now - lastMovementDetected)) + " ms."); + if (deviceIsMoving()) { + log.info("Ignored signal sample for CID: " + cellID + + " due to device movement. Waiting for " + ((minimumIdleTime * 1000) - (now - lastMovementDetected)) + " ms."); return; } if( now - (sleepTimeBetweenSignalRegistration*1000) > lastRegistrationTime) { long diff = now - lastRegistrationTime; - Log.i(TAG, mTAG + - ": Scheduling signal strength calculation from CID: " + cellID + + log.info("Scheduling signal strength calculation from CID: " + cellID + " @ " + signalStrength + " dBm. Last registration was " + diff + "ms ago."); lastRegistrationTime = now; @@ -138,7 +137,7 @@ public class SignalStrengthTracker { } if( now - (sleepTimeBetweenCleanup*1000) > lastCleanupTime) { - Log.i(TAG, mTAG + ": Removing old signal strength entries from DB."); + log.info("Removing old signal strength entries from DB."); // cleanupOldData();// // TODO cleanupOldData() need to change query as now time is a string value @@ -173,7 +172,7 @@ public class SignalStrengthTracker { // If moving, return false if(deviceIsMoving()) { - Log.i(TAG, mTAG + ": Cannot check signal strength for CID: " + cellID + " because of device movements."); + log.info("Cannot check signal strength for CID: " + cellID + " because of device movements."); return false; } @@ -182,12 +181,12 @@ public class SignalStrengthTracker { // Cached? if(averageSignalCache.get(cellID) != null) { storedAvg = averageSignalCache.get(cellID); - Log.d(TAG, mTAG + ": Cached average SS for CID: " + cellID + " is: " + storedAvg); + log.debug("Cached average SS for CID: " + cellID + " is: " + storedAvg); } else { // Not cached, check DB storedAvg = mDbHelper.getAverageSignalStrength(cellID); // DBi_measure:rx_signal averageSignalCache.put(cellID, storedAvg); - Log.d(TAG, mTAG + ": Average SS in DB for CID: " + cellID + " is: " + storedAvg); + log.debug("Average SS in DB for CID: " + cellID + " is: " + storedAvg); } boolean result; @@ -196,13 +195,13 @@ public class SignalStrengthTracker { } else { result = signalStrength - storedAvg > mysteriousSignalDifference; } - Log.d(TAG, mTAG + ": Signal Strength mystery check for CID: " + cellID + + log.debug("Signal Strength mystery check for CID: " + cellID + " is " + result + ", avg:" + storedAvg + ", this signal: " + signalStrength); return result; } public void onSensorChanged() { - //Log.d(TAG, "We are moving..."); + //log.debug(TAG, "We are moving..."); lastMovementDetected = System.currentTimeMillis(); } } -- GitLab From fde2b918b753c5febb921b2a983e4275264c39da Mon Sep 17 00:00:00 2001 From: Lars Grefer <github@larsgrefer.de> Date: Tue, 8 Dec 2015 16:47:00 +0100 Subject: [PATCH 6/6] even more logging --- .../java/com/SecUpwN/AIMSICD/AIMSICD.java | 27 ++++--- .../java/com/SecUpwN/AIMSICD/AppAIMSICD.java | 39 +++++----- .../receiver/BootCompletedReceiver.java | 8 +- .../AIMSICD/rilexecutor/RilExecutor.java | 18 +++-- .../SamsungMulticlientRilExecutor.java | 74 ++++++++++--------- .../service/SignalStrengthTracker.java | 2 +- .../smsdetection/AdvancedUserActivity.java | 15 ++-- .../smsdetection/AdvancedUserSmsActivity.java | 19 +++-- .../AIMSICD/smsdetection/SmsDetector.java | 36 ++++----- .../SecUpwN/AIMSICD/utils/CMDProcessor.java | 7 +- .../SecUpwN/AIMSICD/utils/ChildProcess.java | 19 ++--- .../SecUpwN/AIMSICD/utils/CommandResult.java | 14 ++-- .../com/SecUpwN/AIMSICD/utils/Device.java | 20 ++--- .../SecUpwN/AIMSICD/utils/DeviceApi17.java | 11 ++- .../SecUpwN/AIMSICD/utils/DeviceApi18.java | 16 ++-- .../com/SecUpwN/AIMSICD/utils/Helpers.java | 22 +++--- .../com/SecUpwN/AIMSICD/utils/MiscUtils.java | 10 ++- .../SecUpwN/AIMSICD/utils/OemCommands.java | 12 +-- .../SecUpwN/AIMSICD/utils/RequestTask.java | 34 +++++---- .../utils/SystemPropertiesReflection.java | 18 +++-- .../AIMSICD/utils/TruncatedLocation.java | 8 +- .../utils/atcmd/AtCommandTerminal.java | 9 ++- .../AIMSICD/utils/atcmd/TtyPrivFile.java | 6 +- .../AIMSICD/utils/atcmd/TtyStream.java | 11 ++- 24 files changed, 247 insertions(+), 208 deletions(-) diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java b/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java index a5e92d88..beefa510 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/AIMSICD.java @@ -22,7 +22,9 @@ import android.support.v7.app.ActionBarDrawerToggle; import android.support.v4.widget.DrawerLayout; import android.support.v7.app.ActionBar; import android.telephony.TelephonyManager; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -74,7 +76,8 @@ import java.util.List; */ public class AIMSICD extends BaseActivity implements AsyncResponse { - private final String TAG = "AIMSICD"; + //TODO: @Inject + private final Logger log = AndroidLogger.forClass(AIMSICD.class); private final Context mContext = this; private boolean mBound; @@ -327,7 +330,7 @@ public class AIMSICD extends BaseActivity implements AsyncResponse { cell.setMCC(Integer.parseInt(networkOperator.substring(0, 3))); int mnc = Integer.parseInt(networkOperator.substring(3)); cell.setMNC(Integer.parseInt(networkOperator.substring(3, 5))); - Log.d(TAG, "CELL:: mcc=" + mcc + " mnc=" + mnc); + log.debug("CELL:: mcc=" + mcc + " mnc=" + mnc); } @@ -415,12 +418,12 @@ public class AIMSICD extends BaseActivity implements AsyncResponse { mAimsicdService.stopSmsTracking(); } } catch (Exception ee) { - Log.w(TAG, "Exception in smstracking module: " + ee.getMessage()); + log.warn("Exception in smstracking module: " + ee.getMessage()); } if (mAimsicdService != null) mAimsicdService.onDestroy(); //Close database on Exit - Log.i(TAG, "Closing db from DrawerMenu.ID.APPLICATION.QUIT"); + log.info("Closing db from DrawerMenu.ID.APPLICATION.QUIT"); new AIMSICDDbAdapter(getApplicationContext()).close(); finish(); } @@ -438,7 +441,7 @@ public class AIMSICD extends BaseActivity implements AsyncResponse { @Override public void processFinish(float[] location) { - Log.i(TAG, "processFinish - location[0]=" + location[0] + " location[1]=" + location[1]); + log.info("processFinish - location[0]=" + location[0] + " location[1]=" + location[1]); if (Float.floatToRawIntBits(location[0]) == 0 @@ -455,7 +458,7 @@ public class AIMSICD extends BaseActivity implements AsyncResponse { if (cells != null) { if (!cells.isEmpty()) { for (Cell cell : cells) { - Log.i(TAG, "processFinish - Cell =" + cell.toString()); + log.info("processFinish - Cell =" + cell.toString()); if (cell.isValid()) { mAimsicdService.setCell(cell); Intent intent = new Intent(AimsicdService.UPDATE_DISPLAY); @@ -501,7 +504,7 @@ public class AIMSICD extends BaseActivity implements AsyncResponse { @Override public void onServiceDisconnected(ComponentName arg0) { - Log.w(TAG, "Service disconnected"); + log.warn("Service disconnected"); mBound = false; } }; @@ -621,10 +624,10 @@ public class AIMSICD extends BaseActivity implements AsyncResponse { mAimsicdService.stopSmsTracking(); } } catch (Exception ee) { - Log.e(TAG, "Error: Stopping SMS detection : " + ee.getMessage()); + log.error("Error: Stopping SMS detection : " + ee.getMessage()); } // Close database on Exit - Log.i(TAG, "Closing db from onBackPressed()"); + log.info("Closing db from onBackPressed()"); new AIMSICDDbAdapter(getApplicationContext()).close(); finish(); } @@ -637,11 +640,11 @@ public class AIMSICD extends BaseActivity implements AsyncResponse { if (root_sms && !mAimsicdService.isSmsTracking()) { mAimsicdService.startSmsTracking(); Helpers.msgShort(mContext, "SMS Detection Started"); - Log.i(TAG, "SMS Detection Thread Started"); + log.info("SMS Detection Thread Started"); } else if (!root_sms && mAimsicdService.isSmsTracking()) { mAimsicdService.stopSmsTracking(); Helpers.msgShort(mContext, "Sms Detection Stopped"); - Log.i(TAG, "SMS Detection Thread Stopped"); + log.info("SMS Detection Thread Stopped"); } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/AppAIMSICD.java b/app/src/main/java/com/SecUpwN/AIMSICD/AppAIMSICD.java index 29e4ecd5..1bb4c893 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/AppAIMSICD.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/AppAIMSICD.java @@ -8,23 +8,25 @@ package com.SecUpwN.AIMSICD; import android.app.Activity; import android.app.Application; -import android.util.Log; import android.util.SparseArray; import com.SecUpwN.AIMSICD.constants.TinyDbKeys; import com.SecUpwN.AIMSICD.utils.BaseAsyncTask; import com.SecUpwN.AIMSICD.utils.TinyDB; -import com.squareup.okhttp.Cache; import com.squareup.okhttp.OkHttpClient; -// DO NOT REMOVE BELOW COMMENTED-OUT CODE BEFORE ASKING! -//import com.squareup.leakcanary.LeakCanary; import java.util.ArrayList; import java.util.List; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + +// DO NOT REMOVE BELOW COMMENTED-OUT CODE BEFORE ASKING! +//import com.squareup.leakcanary.LeakCanary; + public class AppAIMSICD extends Application { - final static String TAG = "AIMSICD"; - final static String mTAG = "AppAIMSICD"; + + private final Logger log = AndroidLogger.forClass(AppAIMSICD.class); private OkHttpClient okHttpClient; @@ -57,9 +59,8 @@ public class AppAIMSICD extends Application { for (BaseAsyncTask<?, ?, ?> lTask : tasks) { if (lTask.equals(pTask)) { tasks.remove(lTask); - if (BuildConfig.DEBUG) { - Log.v(TAG, mTAG + ": BaseTask removed:" + pTask.toString()); - } + log.verbose("BaseTask removed:" + pTask.toString()); + break; } } @@ -74,18 +75,16 @@ public class AppAIMSICD extends Application { if (activity == null) { return; } - if (BuildConfig.DEBUG) { - Log.d(TAG, mTAG + ": BaseTask addTask activity:" + activity.getClass().getCanonicalName()); - } + + log.debug("BaseTask addTask activity:" + activity.getClass().getCanonicalName()); + int key = activity.getClass().getCanonicalName().hashCode(); List<BaseAsyncTask<?, ?, ?>> tasks = mActivityTaskMap.get(key); if (tasks == null) { tasks = new ArrayList<>(); mActivityTaskMap.put(key, tasks); } - if (BuildConfig.DEBUG) { - Log.v(TAG, mTAG + ": BaseTask added:" + pTask.toString()); - } + log.verbose("BaseTask added:" + pTask.toString()); tasks.add(pTask); } @@ -93,9 +92,8 @@ public class AppAIMSICD extends Application { if (activity == null) { return; } - if (BuildConfig.DEBUG) { - Log.d(TAG, mTAG + ": BaseTask detach:" + activity.getClass().getCanonicalName()); - } + + log.debug("BaseTask detach:" + activity.getClass().getCanonicalName()); List<BaseAsyncTask<?, ?, ?>> tasks = mActivityTaskMap.get(activity.getClass().getCanonicalName().hashCode()); if (tasks != null) { @@ -109,9 +107,8 @@ public class AppAIMSICD extends Application { if (activity == null) { return; } - if (BuildConfig.DEBUG) { - Log.d(TAG, mTAG + ": BaseTask attach:" + activity.getClass().getCanonicalName()); - } + log.debug("BaseTask attach:" + activity.getClass().getCanonicalName()); + List<BaseAsyncTask<?, ?, ?>> tasks = mActivityTaskMap.get(activity.getClass().getCanonicalName().hashCode()); if (tasks != null) { for (BaseAsyncTask<?, ?, ?> task : tasks) { diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/receiver/BootCompletedReceiver.java b/app/src/main/java/com/SecUpwN/AIMSICD/receiver/BootCompletedReceiver.java index c0151df8..da9bfad4 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/receiver/BootCompletedReceiver.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/receiver/BootCompletedReceiver.java @@ -9,13 +9,17 @@ import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import com.SecUpwN.AIMSICD.R; import com.SecUpwN.AIMSICD.service.AimsicdService; public class BootCompletedReceiver extends BroadcastReceiver { + private final Logger log = AndroidLogger.forClass(BootCompletedReceiver.class); + @Override public void onReceive(Context context, Intent intent) { SharedPreferences prefs = context.getSharedPreferences( @@ -23,7 +27,7 @@ public class BootCompletedReceiver extends BroadcastReceiver { final String AUTO_START = context.getString(R.string.pref_autostart_key); boolean mAutoStart = prefs.getBoolean(AUTO_START, false); if (mAutoStart) { - Log.i("AIMSICD", "System booted starting service."); + log.info("System booted starting service."); context.startService(new Intent(context, AimsicdService.class)); } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/RilExecutor.java b/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/RilExecutor.java index 116be495..5ed49785 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/RilExecutor.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/RilExecutor.java @@ -11,7 +11,9 @@ import android.os.Handler; import android.os.HandlerThread; import android.os.Looper; import android.os.Message; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import com.SecUpwN.AIMSICD.utils.Helpers; import com.SecUpwN.AIMSICD.utils.OemCommands; @@ -27,8 +29,8 @@ import java.util.Queue; * Class to handle Ril and Samsung MultiRil implementation. Used by the Aimsicd Service. */ public class RilExecutor { - protected static final String TAG = "AIMSICD"; - protected static final String mTAG = "RilExecutor"; + + private final Logger log = AndroidLogger.forClass(RilExecutor.class); public boolean mMultiRilCompatible; @@ -78,7 +80,7 @@ public class RilExecutor { mRilExecutorDetectResult = mRequestExecutor.detect(); if (!mRilExecutorDetectResult.available) { mMultiRilCompatible = false; - Log.e(TAG, mTAG + ": Samsung Multiclient RIL not available: " + mRilExecutorDetectResult.error); + log.error("Samsung Multiclient RIL not available: " + mRilExecutorDetectResult.error); mRequestExecutor = null; } else { mRequestExecutor.start(); @@ -144,7 +146,7 @@ public class RilExecutor { subtype, keySeqence).sendToTarget(); if (!mRequestCondvar.block(timeout)) { - Log.e(TAG, mTAG + ": request timeout"); + log.error("request timeout"); return Collections.emptyList(); } else { synchronized (mLastResponseLock) { @@ -250,15 +252,15 @@ public class RilExecutor { try { RawResult result = (RawResult) msg.obj; if (result == null) { - Log.e(TAG, mTAG + ": result is null"); + log.error("result is null"); break; } if (result.exception != null) { - Log.e(TAG, mTAG + ": ", result.exception); + log.error("", result.exception); break; } if (result.result == null) { - Log.v(TAG, mTAG + ": No need to refresh."); + log.verbose("No need to refresh"); break; } if (lastKeyStep.captureResponse) { diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/SamsungMulticlientRilExecutor.java b/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/SamsungMulticlientRilExecutor.java index e6fda833..5750066c 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/SamsungMulticlientRilExecutor.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/rilexecutor/SamsungMulticlientRilExecutor.java @@ -20,7 +20,9 @@ import android.net.LocalSocket; import android.net.LocalSocketAddress; import android.os.Message; import android.os.Parcel; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import java.io.IOException; import java.io.InputStream; @@ -40,7 +42,7 @@ import java.util.concurrent.atomic.AtomicBoolean; */ public class SamsungMulticlientRilExecutor implements OemRilExecutor { - private static final String TAG = "SamsungMulticlientRil"; + private final Logger log = AndroidLogger.forClass(SamsungMulticlientRilExecutor.class); private static final String MULTICLIENT_SOCKET = "Multiclient"; private static final int RIL_REQUEST_OEM_RAW = 59; private static final int RIL_REQUEST_OEM_STRINGS = 60; @@ -67,7 +69,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { Method method = clazz.getDeclaredMethod("get", String.class, String.class); gsmVerRilImpl = (String) method.invoke(null, "gsm.version.ril-impl", ""); } catch (Exception ignore) { - Log.d(TAG, "ignore this exception?", ignore); + log.debug("ignore this exception?", ignore); } // E:V:A comment out for debugging purposes on other non-Samsung RILS @@ -81,14 +83,14 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { try { s.connect(new LocalSocketAddress(MULTICLIENT_SOCKET)); } catch (IOException e) { - Log.w(TAG, e.getMessage()); + log.warn(e.getMessage()); return DetectResult.Unavailable( "Multiclient socket is not available\n" + "gsm.version.ril-impl = " + gsmVerRilImpl); } finally { try { s.close(); } catch (IOException e) { - Log.e(TAG, e.getMessage(), e); + log.error(e.getMessage(), e); } } @@ -98,7 +100,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { @Override public synchronized void start() { if (mThread != null) { - Log.e(TAG, "OEM raw request executor thread is running"); + log.error("OEM raw request executor thread is running"); return; } mThread = new LocalSocketThread(MULTICLIENT_SOCKET); @@ -108,7 +110,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { @Override public synchronized void stop() { if (mThread == null) { - Log.e(TAG, "OEM raw request executor thread is not running"); + log.error("OEM raw request executor thread is not running"); return; } mThread.cancel(); @@ -118,26 +120,26 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { @Override public synchronized void invokeOemRilRequestRaw(byte[] data, Message response) { if (mThread == null) { - Log.e(TAG, " OEM raw request executor thread is not running"); + log.error(" OEM raw request executor thread is not running"); return; } try { mThread.invokeOemRilRequestRaw(data, response); } catch (IOException ioe) { - Log.e(TAG, "InvokeOemRilRequestRaw() error", ioe); + log.error("InvokeOemRilRequestRaw() error", ioe); } } @Override public synchronized void invokeOemRilRequestStrings(String[] strings, Message response) { if (mThread == null) { - Log.e(TAG, "OEM raw request executor thread is not running"); + log.error("OEM raw request executor thread is not running"); return; } try { mThread.invokeOemRilRequestStrings(strings, response); } catch (IOException ioe) { - Log.e(TAG, "InvokeOemRilRequestStrings() error", ioe); + log.error("InvokeOemRilRequestStrings() error", ioe); } } @@ -162,7 +164,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { public void cancel() { if (DBG) { - Log.v(TAG, "SamsungMulticlientRil cancel()"); + log.verbose("SamsungMulticlientRil cancel()"); } synchronized (this) { mCancelRequested.set(true); @@ -175,12 +177,12 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { throws IOException { int token; if (mMessages.size() > MAX_MESSAGES) { - Log.e(TAG, "message queue is full"); + log.error("message queue is full"); return; } if (mOutputStream == null) { - Log.e(TAG, "Local write() error: not connected"); + log.error("Local write() error: not connected"); return; } @@ -191,8 +193,8 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { byte req[] = marshallRequest(token, data); if (DBG) { - Log.v(TAG, String.format("InvokeOemRilRequestRaw() token: 0x%X, header: %s, req: %s ", - token, HexDump.toHexString(getHeader(req)),HexDump.toHexString(req)) + log.verbose(String.format("InvokeOemRilRequestRaw() token: 0x%X, header: %s, req: %s ", + token, HexDump.toHexString(getHeader(req)), HexDump.toHexString(req)) ); } @@ -205,12 +207,12 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { throws IOException { int token; if (mMessages.size() > MAX_MESSAGES) { - Log.e(TAG, "Message queue is full"); + log.error("Message queue is full"); return; } if (mOutputStream == null) { - Log.e(TAG, "Local write() error: not connected"); + log.error("Local write() error: not connected"); return; } @@ -221,7 +223,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { byte[] req = marshallRequest(token, strings); if (DBG) { - Log.v(TAG, String.format("InvokeOemRilRequestStrings() token: 0x%X, header: %s, req: %s ", + log.verbose(String.format("InvokeOemRilRequestStrings() token: 0x%X, header: %s, req: %s ", token, HexDump.toHexString(getHeader(req)), HexDump.toHexString(req))); } @@ -263,7 +265,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { public synchronized void disconnect() { if (DBG) { - Log.v(TAG, "Local disconnect()"); + log.verbose("Local disconnect()"); } if (mSocket == null) { @@ -273,31 +275,31 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { try { mSocket.shutdownInput(); } catch (IOException e) { - Log.e(TAG, "Local shutdownInput() of mSocket failed", e); + log.error("Local shutdownInput() of mSocket failed", e); } try { mSocket.shutdownOutput(); } catch (IOException e) { - Log.e(TAG, "Local shutdownOutput() of mSocket failed", e); + log.error("Local shutdownOutput() of mSocket failed", e); } try { mInputStream.close(); } catch (IOException e) { - Log.e(TAG, "Local close() of mInputStream failed", e); + log.error("Local close() of mInputStream failed", e); } try { mOutputStream.close(); } catch (IOException e) { - Log.e(TAG, "Local close() of mOutputStream failed", e); + log.error("Local close() of mOutputStream failed", e); } try { mSocket.close(); } catch (IOException e) { - Log.e(TAG, "Local close() of mSocket failed", e); + log.error("Local close() of mSocket failed", e); } mSocket = null; @@ -312,7 +314,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { int endpos = 0; final byte buf[] = new byte[4096]; - Log.i(TAG, "BEGIN LocalSocketThread-Socket"); + log.info("BEGIN LocalSocketThread-Socket"); setName("MultiClientThread"); mSocket = new LocalSocket(); @@ -321,7 +323,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { mInputStream = mSocket.getInputStream(); mOutputStream = mSocket.getOutputStream(); } catch (IOException e) { - Log.e(TAG, "Connect error", e); + log.error("Connect error", e); return; } @@ -330,7 +332,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { rcvd = mInputStream.read(buf, endpos, buf.length - endpos); if (rcvd < 0) { if (DBG) { - Log.v(TAG, "EOF reached"); + log.verbose("EOF reached"); } break; } @@ -341,7 +343,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { int msgLen = (buf[0] << 24) | (buf[1] << 16) | (buf[2] << 8) | (buf[3] & 0xff); if (msgLen + 4 > buf.length) { - Log.e(TAG, "Message to big. Length: " + msgLen); + log.error("Message to big. Length: " + msgLen); endpos = 0; continue; } @@ -369,7 +371,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { Parcel p; if (DBG) { - Log.v(TAG, "Received " + length + " bytes: " + + log.verbose("Received " + length + " bytes: " + HexDump.toHexString(data, pos, length)); } @@ -381,13 +383,13 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { responseType = p.readInt(); switch (responseType) { case RESPONSE_UNSOLICITED: - Log.v(TAG, "Unsolicited response "); + log.verbose("Unsolicited response "); break; case RESPONSE_SOLICITED: processSolicited(p); break; default: - Log.v(TAG, "Invalid response type: " + responseType); + log.verbose("Invalid response type: " + responseType); break; } } finally { @@ -406,7 +408,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { int err = p.readInt(); if (DBG) { - Log.v(TAG, String.format(": processSolicited() token: 0x%X err: %d", token, err)); + log.verbose(String.format(": processSolicited() token: 0x%X err: %d", token, err)); } if (err != RIL_CLIENT_ERR_SUCCESS) { @@ -417,12 +419,12 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { stringsResponseData = p.createStringArray(); } catch (Exception ex) { - Log.e(TAG, ex.getMessage()); + log.error(ex.getMessage()); errorEx = ex; } if (token == null) { - Log.e(TAG, "token is null", errorEx); + log.error("token is null", errorEx); } else { synchronized (this) { Message m = mMessages.remove(token); @@ -440,7 +442,7 @@ public class SamsungMulticlientRilExecutor implements OemRilExecutor { m.sendToTarget(); } } else { - Log.i(TAG, "Message with token " + token + " not found"); + log.info("Message with token " + token + " not found"); } } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/service/SignalStrengthTracker.java b/app/src/main/java/com/SecUpwN/AIMSICD/service/SignalStrengthTracker.java index 58f1867d..302321bb 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/service/SignalStrengthTracker.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/service/SignalStrengthTracker.java @@ -201,7 +201,7 @@ public class SignalStrengthTracker { } public void onSensorChanged() { - //log.debug(TAG, "We are moving..."); + //log.debug("We are moving..."); lastMovementDetected = System.currentTimeMillis(); } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/AdvancedUserActivity.java b/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/AdvancedUserActivity.java index 983bab41..19f2ae37 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/AdvancedUserActivity.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/AdvancedUserActivity.java @@ -11,7 +11,6 @@ package com.SecUpwN.AIMSICD.smsdetection; import android.content.ContentValues; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.Button; @@ -26,9 +25,13 @@ import com.SecUpwN.AIMSICD.constants.DBTableColumnIds; import java.util.ArrayList; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + public class AdvancedUserActivity extends AppCompatActivity { - private static final String TAG = "AdvancedUserActivity"; + //TODO: @Inject + private final Logger log = AndroidLogger.forClass(AdvancedUserActivity.class); private ListView listViewAdv; private AIMSICDDbAdapter dbAccess; @@ -51,7 +54,7 @@ public class AdvancedUserActivity extends AppCompatActivity { try { msgItems = dbAccess.getDetectionStrings(); } catch (Exception ee) { - Log.e(TAG, "Database error", ee); + log.error("Database error", ee); msgItems = new ArrayList<>(); AdvanceUserItems advUserItems = new AdvanceUserItems(); advUserItems.setDetection_string("NO DATA"); @@ -80,7 +83,7 @@ public class AdvancedUserActivity extends AppCompatActivity { try { loadDbString(); } catch (Exception ee){ - Log.d(TAG, "Error loading db string", ee); + log.debug("Error loading db string", ee); } return false; } @@ -113,7 +116,7 @@ public class AdvancedUserActivity extends AppCompatActivity { try { loadDbString(); } catch (Exception ee) { - Log.e(TAG, ee.getMessage(), ee); + log.error(ee.getMessage(), ee); } } } @@ -130,7 +133,7 @@ public class AdvancedUserActivity extends AppCompatActivity { newmsglist = dbAccess.getDetectionStrings(); listViewAdv.setAdapter(new AdvanceUserBaseAdapter(getApplicationContext(), newmsglist)); } catch (Exception ee) { - Log.e(TAG, "<AdvanceUserItems>", ee); + log.error("<AdvanceUserItems>", ee); } } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/AdvancedUserSmsActivity.java b/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/AdvancedUserSmsActivity.java index cbfb11f5..e675d24d 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/AdvancedUserSmsActivity.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/AdvancedUserSmsActivity.java @@ -11,7 +11,6 @@ package com.SecUpwN.AIMSICD.smsdetection; import android.database.Cursor; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; -import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.ListView; @@ -23,8 +22,14 @@ import com.SecUpwN.AIMSICD.constants.DBTableColumnIds; import java.util.ArrayList; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + public class AdvancedUserSmsActivity extends AppCompatActivity { - final static String TAG ="AdvancedUserSmsActivity"; + + //TODO: @Inject + private final Logger log = AndroidLogger.forClass(AdvancedUserSmsActivity.class); + ListView listViewAdv; AIMSICDDbAdapter dbaccess; ArrayList<CapturedSmsData> msgitems; @@ -59,8 +64,8 @@ public class AdvancedUserSmsActivity extends AppCompatActivity { } smscur.close(); - }catch (Exception ee){ - Log.e(TAG, "DB ERROR>>>>" + ee.toString()); + } catch (Exception ee) { + log.error("DB ERROR", ee); } @@ -111,9 +116,9 @@ public class AdvancedUserSmsActivity extends AppCompatActivity { } smscur.close(); - listViewAdv.setAdapter(new AdvanceUserBaseSmsAdapter(getApplicationContext(),newmsglist)); - }catch (Exception ee){ - Log.e(TAG, "DB ERROR>>>>" + ee.toString()); + listViewAdv.setAdapter(new AdvanceUserBaseSmsAdapter(getApplicationContext(), newmsglist)); + } catch (Exception ee) { + log.error("DB ERROR", ee); } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/SmsDetector.java b/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/SmsDetector.java index a1530b74..685741b8 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/SmsDetector.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/smsdetection/SmsDetector.java @@ -13,7 +13,6 @@ import android.content.ServiceConnection; import android.os.IBinder; import android.support.annotation.StringRes; import android.support.v7.app.AlertDialog; -import android.util.Log; import com.SecUpwN.AIMSICD.R; import com.SecUpwN.AIMSICD.adapters.AIMSICDDbAdapter; @@ -28,6 +27,9 @@ import java.io.InputStreamReader; import java.util.ArrayList; import java.util.List; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: Detects mysterious SMS by scraping Logcat entries. * <p/> @@ -59,7 +61,7 @@ import java.util.List; */ public final class SmsDetector extends Thread { - private final static String TAG = "SmsDetector"; + private final Logger log = AndroidLogger.forClass(SmsDetector.class); private BufferedReader mLogcatReader; private AimsicdService mAIMSICDService; @@ -119,7 +121,7 @@ public final class SmsDetector extends Thread { Intent intent = new Intent(mContext, AimsicdService.class); mContext.bindService(intent, mConnection, Context.BIND_AUTO_CREATE); start(); - Log.i(TAG, "SMS detection started"); + log.info("SMS detection started"); } public void stopSmsDetection() { @@ -129,7 +131,7 @@ public final class SmsDetector extends Thread { mContext.unbindService(mConnection); mBound = false; } - Log.i(TAG, "SMS detection stopped"); + log.info("SMS detection stopped"); } @Override @@ -150,7 +152,7 @@ public final class SmsDetector extends Thread { mLogcatReader = new BufferedReader(new InputStreamReader(process.getInputStream())); } catch (InterruptedException | IOException e) { - Log.e(TAG, "Exception while initializing LogCat (time, radio, main) reader", e); + log.error("Exception while initializing LogCat (time, radio, main) reader", e); return; } @@ -230,16 +232,16 @@ public final class SmsDetector extends Thread { } } catch (IOException e) { - Log.e(TAG, "IO Exception", e); + log.error("IO Exception", e); } catch (InterruptedException e) { - Log.e(TAG, "Interrupted Exception", e); + log.error("Interrupted Exception", e); } } try { mLogcatReader.close(); } catch (IOException ee) { - Log.e(TAG, "IOE Error closing BufferedReader", ee); + log.error("IOE Error closing BufferedReader", ee); } } @@ -250,26 +252,26 @@ public final class SmsDetector extends Thread { // memory optimized and precaution for LOADED_DETECTION_STRING being not filled String[] splitDetectionString = LOADED_DETECTION_STRING == null ? null : LOADED_DETECTION_STRING.split("#"); if (splitDetectionString == null || splitDetectionString.length < 2 || splitDetectionString[0] == null || splitDetectionString[1] == null) { - Log.d(TAG, "Broken detection string: " + LOADED_DETECTION_STRING); + log.debug("Broken detection string: " + LOADED_DETECTION_STRING); // skip broken detection string continue; } if (line.contains(splitDetectionString[0])) { if ("TYPE0".equalsIgnoreCase(splitDetectionString[1])) { - Log.i(TAG, "TYPE0 detected"); + log.info("TYPE0 detected"); return TYPE0; } else if ("MWI".equalsIgnoreCase(splitDetectionString[1])) { - Log.i(TAG, "MWI detected"); + log.info("MWI detected"); return MWI; } else if ("WAPPUSH".equalsIgnoreCase(splitDetectionString[1])) { - Log.i(TAG, "WAPPUSH detected"); + log.info("WAPPUSH detected"); return WAP; } } // This is currently unused, but keeping as an example of possible data contents // else if (line.contains("BroadcastReceiver action: android.provider.Telephony.SMS_RECEIVED")) { - // Log.i(TAG, "SMS found"); + // log.info("SMS found"); // return 0; // } } @@ -304,7 +306,7 @@ public final class SmsDetector extends Thread { mDbAdapter.toEventLog(3, "Detected Type-0 SMS"); startPopUpInfo(SmsType.SILENT); } else { - Log.d(TAG, "Detected Sms already logged"); + log.debug("Detected Sms already logged"); } } @@ -336,7 +338,7 @@ public final class SmsDetector extends Thread { mDbAdapter.toEventLog(4, "Detected MWI SMS"); startPopUpInfo(SmsType.MWI); } else { - Log.d(TAG, " Detected Sms already logged"); + log.debug(" Detected Sms already logged"); } } @@ -366,7 +368,7 @@ public final class SmsDetector extends Thread { mDbAdapter.toEventLog(6, "Detected WAPPUSH SMS"); startPopUpInfo(SmsType.WAP_PUSH); } else { - Log.d(TAG, "Detected SMS already logged"); + log.debug("Detected SMS already logged"); } } @@ -439,7 +441,7 @@ public final class SmsDetector extends Thread { @Override public void onServiceDisconnected(ComponentName arg0) { - Log.i(TAG, "Disconnected SMS Detection Service"); + log.info("Disconnected SMS Detection Service"); mBound = false; } }; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/CMDProcessor.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/CMDProcessor.java index 3e643ca7..b7326eba 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/CMDProcessor.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/CMDProcessor.java @@ -21,11 +21,12 @@ package com.SecUpwN.AIMSICD.utils; -import android.util.Log; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; public final class CMDProcessor { - private static final String TAG = "CMDProcessor"; + private static final Logger log = AndroidLogger.forClass(CMDProcessor.class); public CMDProcessor() { @@ -78,7 +79,7 @@ public final class CMDProcessor { out.append(r.getStdout()); out.append(" ; "); out.append(r.getStderr()); - Log.d(TAG, "canSU() su[" + r.getExitValue() + "]: " + out); + log.debug("canSU() su[" + r.getExitValue() + "]: " + out); return r.success(); } } \ No newline at end of file diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/ChildProcess.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/ChildProcess.java index 3d3d6745..d3bde1ad 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/ChildProcess.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/ChildProcess.java @@ -21,17 +21,18 @@ package com.SecUpwN.AIMSICD.utils; -import android.util.Log; - import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + import static java.lang.System.nanoTime; public class ChildProcess { - private static final String TAG = "ChildProcess"; + private final Logger log = AndroidLogger.forClass(ChildProcess.class); private static final int PIPE_SIZE = 1024; private class ChildReader extends Thread { @@ -53,12 +54,12 @@ public class ChildProcess { mBuffer.append(s); } } catch (IOException e) { - Log.d(TAG, e.getMessage()); + log.debug(e.getMessage()); } try { mStream.close(); } catch (IOException e) { - Log.d(TAG, "cannot close stream", e); + log.debug("cannot close stream", e); } } } @@ -83,12 +84,12 @@ public class ChildProcess { off += len; } } catch (IOException e) { - Log.d(TAG, e.getMessage()); + log.debug(e.getMessage()); } try { mStream.close(); } catch (IOException e) { - Log.d(TAG, "cannot close stream", e); + log.debug("cannot close stream", e); } } } @@ -120,7 +121,7 @@ public class ChildProcess { mChildStderrReader = new ChildReader(mChildProc.getErrorStream(), mChildStderr); mChildStderrReader.start(); } catch (IOException e) { - Log.d(TAG, e.getMessage(), e); + log.debug(e.getMessage(), e); } } @@ -151,7 +152,7 @@ public class ChildProcess { mChildStdinWriter = null; } } catch (InterruptedException e) { - Log.d(TAG, e.getMessage(), e); + log.debug(e.getMessage(), e); } } return mExitValue; diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/CommandResult.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/CommandResult.java index 0d1c43ea..8ca039a9 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/CommandResult.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/CommandResult.java @@ -23,7 +23,6 @@ package com.SecUpwN.AIMSICD.utils; import android.os.Parcel; import android.os.Parcelable; -import android.util.Log; import com.SecUpwN.AIMSICD.adapters.AIMSICDDbAdapter; @@ -31,10 +30,13 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + @SuppressWarnings("AccessOfSystemProperties") public class CommandResult implements Parcelable { - private static final String TAG = "AIMSICD_CommandResult"; + private final Logger log = AndroidLogger.forClass(CommandResult.class); private long mStartTime; private int mExitValue; private String mStdout; @@ -49,7 +51,7 @@ public class CommandResult implements Parcelable { this.mStderr = stderr; this.mEndTime = endTime; - Log.d(TAG, "Time to execute: " + (mEndTime - mStartTime) + " ns (nanoseconds)"); + log.debug("Time to execute: " + (mEndTime - mStartTime) + " ns (nanoseconds)"); // this is set last so log from here checkForErrors(); } @@ -101,20 +103,20 @@ public class CommandResult implements Parcelable { errorWriter.write(lineEnding); errorWriter.write("Attempted to write to an offline cpu core (ignore me)."); } else { - errorWriter.write(TAG + " shell error detected!"); + errorWriter.write("shell error detected!"); errorWriter.write(lineEnding); errorWriter.write("CommandResult {" + this.toString() + '}'); errorWriter.write(lineEnding); } errorWriter.write(lineEnding); } catch (IOException e) { - Log.e(TAG, "Failed to write command result to error file", e); + log.error("Failed to write command result to error file", e); } finally { if (errorWriter != null) { try { errorWriter.close(); } catch (IOException ignored) { - Log.e(TAG, "Failed to close error writer", ignored); + log.error("Failed to close error writer", ignored); } } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Device.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Device.java index f0d94766..a4e97804 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Device.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Device.java @@ -11,7 +11,9 @@ import android.os.Build; import android.telephony.TelephonyManager; import android.telephony.cdma.CdmaCellLocation; import android.telephony.gsm.GsmCellLocation; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; /** * Description: TODO @@ -27,7 +29,7 @@ import android.util.Log; */ public class Device { - private final String TAG = "Device"; + private final Logger log = AndroidLogger.forClass(Device.class); public Cell mCell; private int mPhoneID = -1; @@ -84,7 +86,7 @@ public class Device { if (mCell.getMNC() == Integer.MAX_VALUE) mCell.setMNC(Integer.parseInt(tm.getNetworkOperator().substring(3, 5))); } catch (Exception e) { - Log.i(TAG, "MncMcc parse exception: ", e); + log.info("MncMcc parse exception: ", e); } } mNetName = tm.getNetworkOperatorName(); @@ -120,7 +122,7 @@ public class Device { if (mCell.getMNC() == Integer.MAX_VALUE) mCell.setMNC(Integer.valueOf(homeOperator.substring(3, 5))); } catch (Exception e) { - Log.i(TAG, "HomeOperator parse exception - " + e.getMessage(), e); + log.info("HomeOperator parse exception - " + e.getMessage(), e); } } } @@ -184,7 +186,7 @@ public class Device { } catch (Exception e) { // SIM methods can cause Exceptions on some devices mSimCountry = "N/A"; - Log.e(TAG, "GetSimCountry " + e); + log.error("GetSimCountry " + e); } if (mSimCountry.isEmpty()) { @@ -216,7 +218,7 @@ public class Device { } catch (Exception e) { // SIM methods can cause Exceptions on some devices mSimOperator = "N/A"; - Log.e(TAG, "GetSimOperator " + e.getMessage(), e); + log.error("GetSimOperator " + e.getMessage(), e); } if (mSimOperator.isEmpty()) { @@ -243,7 +245,7 @@ public class Device { mSimOperatorName = "N/A"; } } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); + log.error(e.getMessage(), e); //SIM methods can cause Exceptions on some devices mSimOperatorName = "N/A"; } @@ -274,7 +276,7 @@ public class Device { } catch (Exception e) { //Some devices don't like this method mSimSubs = "N/A"; - Log.e(TAG, "GetSimSubs "+e.getMessage(), e); + log.error("GetSimSubs "+e.getMessage(), e); } if (mSimSubs.isEmpty()) { @@ -304,7 +306,7 @@ public class Device { } catch (Exception e) { // SIM methods can cause Exceptions on some devices mSimSerial = "N/A"; - Log.e(TAG, "GetSimSerial " + e); + log.error("GetSimSerial " + e); } if (mSimSerial.isEmpty()) { diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/DeviceApi17.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/DeviceApi17.java index 2c52f172..8ae9fb12 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/DeviceApi17.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/DeviceApi17.java @@ -22,10 +22,12 @@ import android.telephony.CellSignalStrengthLte; import android.telephony.CellSignalStrengthWcdma; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; -import android.util.Log; import java.util.List; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: TODO * @@ -33,7 +35,8 @@ import java.util.List; */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public class DeviceApi17 { - public static final String TAG = "DeviceApi17"; + + private static final Logger log = AndroidLogger.forClass(DeviceApi17.class); public static void loadCellInfo(TelephonyManager tm, Device pDevice) { int lCurrentApiVersion = android.os.Build.VERSION.SDK_INT; @@ -103,7 +106,7 @@ public class DeviceApi17 { pDevice.mCell.setPSC(identityWcdma.getPsc()); } else { - Log.i(TAG, "Unknown type of cell signal! " + log.info("Unknown type of cell signal! " + "ClassName: " + info.getClass().getSimpleName() + " ToString: " + info.toString()); } @@ -112,7 +115,7 @@ public class DeviceApi17 { } } } catch (NullPointerException npe) { - Log.e(TAG, "loadCellInfo: Unable to obtain cell signal information: ", npe); + log.error("loadCellInfo: Unable to obtain cell signal information: ", npe); } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/DeviceApi18.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/DeviceApi18.java index 776e91bf..4b536825 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/DeviceApi18.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/DeviceApi18.java @@ -22,7 +22,9 @@ import android.telephony.CellSignalStrengthLte; import android.telephony.CellSignalStrengthWcdma; import android.telephony.PhoneStateListener; import android.telephony.TelephonyManager; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import java.util.List; @@ -49,8 +51,8 @@ import java.util.List; */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR2) public class DeviceApi18 { - public static final String TAG = "AIMSICD"; - public static final String mTAG = "DeviceApi18"; + + public static final Logger log = AndroidLogger.forClass(DeviceApi18.class); public static void loadCellInfo(TelephonyManager tm, Device pDevice) { int lCurrentApiVersion = android.os.Build.VERSION.SDK_INT; @@ -111,16 +113,16 @@ public class DeviceApi18 { pDevice.mCell.setPSC(identityWcdma.getPsc()); } else { - Log.i(TAG, mTAG + ": Unknown type of cell signal!" - + "\n ClassName: " + info.getClass().getSimpleName() - + "\n ToString: " + info.toString()); + log.info("Unknown type of cell signal!" + + "\n ClassName: " + info.getClass().getSimpleName() + + "\n ToString: " + info.toString()); } if (pDevice.mCell.isValid()) break; } } } catch (NullPointerException npe) { - Log.e(TAG, mTAG + ": loadCellInfo: Unable to obtain cell signal information: ", npe); + log.error("loadCellInfo: Unable to obtain cell signal information: ", npe); } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java index b40ece7d..113f8ccb 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/Helpers.java @@ -25,7 +25,9 @@ import android.content.Intent; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.text.TextUtils; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import com.SecUpwN.AIMSICD.R; import com.SecUpwN.AIMSICD.activities.MapViewerOsmDroid; @@ -75,7 +77,7 @@ import java.util.List; */ public class Helpers { - private static final String TAG = "Helpers"; + private static final Logger log = AndroidLogger.forClass(Helpers.class); private static final int CHARS_PER_LINE = 34; /** @@ -141,7 +143,7 @@ import java.util.List; return wifiInfo.isConnected() || mobileInfo.isConnected(); } } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); + log.error(e.getMessage(), e); } return false; } @@ -237,18 +239,18 @@ import java.util.List; + String.valueOf(boundingCoords[1].getLatitudeInDegrees()) + "," + String.valueOf(boundingCoords[1].getLongitudeInDegrees()); - Log.i(TAG, "OCID BBOX is set to: " + boundParameter + " with radius " + radius + " Km."); + log.info("OCID BBOX is set to: " + boundParameter + " with radius " + radius + " Km."); StringBuilder sb = new StringBuilder(); sb.append("http://www.opencellid.org/cell/getInArea?key=") .append(CellTracker.OCID_API_KEY).append("&BBOX=") .append(boundParameter); - Log.i(TAG, "OCID MCC is set to: " + cell.getMCC()); + log.info("OCID MCC is set to: " + cell.getMCC()); if (cell.getMCC() != Integer.MAX_VALUE) { sb.append("&mcc=").append(cell.getMCC()); } - Log.i(TAG, "OCID MNC is set to: " + cell.getMNC()); + log.info("OCID MNC is set to: " + cell.getMNC()); if (cell.getMNC() != Integer.MAX_VALUE) { sb.append("&mnc=").append(cell.getMNC()); } @@ -282,7 +284,7 @@ import java.util.List; if (aob.length == 0) { // WARNING: This one is very chatty! - Log.v(TAG, "invokeOemRilRequestRaw: byte-list response Length = 0"); + log.verbose("invokeOemRilRequestRaw: byte-list response Length = 0"); return Collections.emptyList(); } int lines = aob.length / CHARS_PER_LINE; @@ -294,13 +296,13 @@ import java.util.List; byteCount = 0; if (offset + byteCount >= aob.length) { - Log.e(TAG, "Unexpected EOF"); + log.error("Unexpected EOF"); break; } while (aob[offset + byteCount] != 0 && (byteCount < CHARS_PER_LINE)) { byteCount += 1; if (offset + byteCount >= aob.length) { - Log.e(TAG, "Unexpected EOF"); + log.error("Unexpected EOF"); break; } } @@ -318,7 +320,7 @@ import java.util.List; try { result = SystemPropertiesReflection.get(context, prop); } catch (IllegalArgumentException iae) { - Log.e(TAG, "Failed to get system property: " + prop, iae); + log.error("Failed to get system property: " + prop, iae); } return result == null ? def : result; } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/MiscUtils.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/MiscUtils.java index 03c43ed9..e1868c0c 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/MiscUtils.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/MiscUtils.java @@ -13,7 +13,9 @@ import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.support.v4.app.NotificationCompat; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import com.SecUpwN.AIMSICD.AIMSICD; import com.SecUpwN.AIMSICD.R; @@ -37,7 +39,7 @@ import java.util.Locale; */ public class MiscUtils { - private static final String TAG = "MiscUtils"; + private static final Logger log = AndroidLogger.forClass(MiscUtils.class); public static String setAssetsString(Context context){ BufferedReader reader = null; @@ -51,13 +53,13 @@ public class MiscUtils { rline = reader.readLine().replace("'","\\'").replace("\\n",""); } } catch (Exception ee) { - Log.e(TAG, ee.getMessage()); + log.error(ee.getMessage()); } finally { if(reader != null) { try { reader.close(); } catch (Exception ee) { - Log.e(TAG, ee.getMessage()); + log.error(ee.getMessage()); } } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/OemCommands.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/OemCommands.java index a9db8f06..53464191 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/OemCommands.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/OemCommands.java @@ -5,7 +5,8 @@ */ package com.SecUpwN.AIMSICD.utils; -import android.util.Log; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import com.SecUpwN.AIMSICD.R; @@ -22,7 +23,8 @@ import android.content.Context; */ public class OemCommands { - private static final String TAG = "AIMSICD_OemCommands"; + private static final Logger log = AndroidLogger.forClass(OemCommands.class); + public static final char OEM_SERVM_FUNCTAG = 1; public static final char OEM_SM_ACTION = 0; public static final char OEM_SM_QUERY = 1; @@ -106,7 +108,7 @@ public class OemCommands { dos.writeByte(query); return baos.toByteArray(); } catch (IOException e) { - Log.e(TAG, "", e); + log.error("", e); } return null; } @@ -128,7 +130,7 @@ public class OemCommands { dos.writeByte(modeType); return baos.toByteArray(); } catch (IOException e) { - Log.e(TAG, "", e); + log.error("", e); } return null; } @@ -151,7 +153,7 @@ public class OemCommands { dos.writeByte(query); return baos.toByteArray(); } catch (IOException e) { - Log.e(TAG, "", e); + log.error("", e); } return null; } 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 2a33bafc..a3c73471 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/RequestTask.java @@ -10,7 +10,9 @@ import android.app.AlertDialog; import android.content.Context; import android.content.Intent; import android.support.v4.content.LocalBroadcastManager; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import com.SecUpwN.AIMSICD.AIMSICD; import com.SecUpwN.AIMSICD.AppAIMSICD; @@ -98,7 +100,7 @@ public class RequestTask extends BaseAsyncTask<String, Integer, String> { public static final char RESTORE_DATABASE = 4; // Restore DB from CSV files public static final char CELL_LOOKUP = 5; // TODO: "All Current Cell Details (ACD)" - public static final String TAG = "RequestTask"; + private final Logger log = AndroidLogger.forClass(RequestTask.class); private AIMSICDDbAdapter mDbAdapter; private Context mAppContext; @@ -125,7 +127,7 @@ public class RequestTask extends BaseAsyncTask<String, Integer, String> { try { boolean prepared = mDbAdapter.prepareOpenCellUploadData(); - Log.i(TAG, "OCID upload data prepared - " + String.valueOf(prepared)); + log.info("OCID upload data prepared - " + String.valueOf(prepared)); if (prepared) { File file = new File((mAppContext.getExternalFilesDir(null) + File.separator) + "OpenCellID/aimsicd-ocid-data.csv"); publishProgress(25, 100); @@ -147,7 +149,7 @@ public class RequestTask extends BaseAsyncTask<String, Integer, String> { publishProgress(80,100); if (response!= null) { - Log.i(TAG, "OCID Upload Response: " + log.info("OCID Upload Response: " + response.code() + " - " + response.message()); if (response.code() == 200) { @@ -163,13 +165,13 @@ public class RequestTask extends BaseAsyncTask<String, Integer, String> { // all caused by httpclient.execute(httppost); } catch (UnsupportedEncodingException e) { - Log.e(TAG, "Upload OpenCellID data Exception", e); + log.error("Upload OpenCellID data Exception", e); } catch (FileNotFoundException e) { - Log.e(TAG, "Upload OpenCellID data Exception", e); + log.error("Upload OpenCellID data Exception", e); } catch (IOException e) { - Log.e(TAG, "Upload OpenCellID data Exception", e); + log.error("Upload OpenCellID data Exception", e); } catch (Exception e) { - Log.e(TAG, "Upload OpenCellID data Exception", e); + log.error("Upload OpenCellID data Exception", e); } // DOWNLOADING... @@ -186,7 +188,7 @@ public class RequestTask extends BaseAsyncTask<String, Integer, String> { dir.mkdirs(); } File file = new File(dir, OCDB_File_Name); - Log.i(TAG, "DBE_DOWNLOAD_REQUEST write to: " + dirName + OCDB_File_Name); + log.info("DBE_DOWNLOAD_REQUEST write to: " + dirName + OCDB_File_Name); Request request = new Request.Builder() .url(commandString[0]) @@ -199,22 +201,22 @@ public class RequestTask extends BaseAsyncTask<String, Integer, String> { try { String error = response.body().string(); Helpers.msgLong(mAppContext, mAppContext.getString(R.string.download_error) + " " + error); - Log.e(TAG, "Download OCID data error: " + error); + log.error("Download OCID data error: " + error); } catch (Exception e) { Helpers.msgLong(mAppContext, mAppContext.getString(R.string.download_error) + " " + e.getClass().getName() + " - " + e.getMessage()); - Log.e(TAG, "Download OCID exception: ", e); + log.error("Download OCID exception: ", e); } return "Error"; } else { // This returns "-1" for streamed response (Chunked Transfer Encoding) total = response.body().contentLength(); if (total == -1 ) { - Log.d(TAG, "doInBackground DBE_DOWNLOAD_REQUEST total not returned!"); + log.debug("doInBackground DBE_DOWNLOAD_REQUEST total not returned!"); total = 1024; // Let's set it arbitrarily to something other than "-1" } else { - Log.d(TAG, "doInBackground DBE_DOWNLOAD_REQUEST total: " + total); + log.debug("doInBackground DBE_DOWNLOAD_REQUEST total: " + total); publishProgress((int) (0.25 * total), (int)total); // Let's show something! } @@ -236,7 +238,7 @@ public class RequestTask extends BaseAsyncTask<String, Integer, String> { return "Successful"; } catch (IOException e) { - Log.w(TAG, "Problem reading data from steam", e); + log.warn("Problem reading data from steam", e); return null; } @@ -265,7 +267,7 @@ public class RequestTask extends BaseAsyncTask<String, Integer, String> { protected void onProgressUpdate(Integer... values) { super.onProgressUpdate(values); // Silence or Remove when working: - Log.v(TAG, "onProgressUpdate values[0]: " + values[0] + " values[1]: " + values[1]); + log.verbose("onProgressUpdate values[0]: " + values[0] + " values[1]: " + values[1]); AIMSICD.mProgressBar.setProgress(values[0]); AIMSICD.mProgressBar.setMax(values[1]); } @@ -395,7 +397,7 @@ public class RequestTask extends BaseAsyncTask<String, Integer, String> { private void showHideMapProgressBar(boolean pFlag) { Activity lActivity = getActivity(); if(BuildConfig.DEBUG && lActivity == null) { - Log.v(TAG, "BaseTask showHideMapProgressBar() activity is null"); + log.verbose("BaseTask showHideMapProgressBar() activity is null"); } if (lActivity != null && lActivity instanceof MapViewerOsmDroid) { ((MapViewerOsmDroid) lActivity).setRefreshActionButtonState(pFlag); diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/SystemPropertiesReflection.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/SystemPropertiesReflection.java index 077d1cc8..d12ad8c1 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/SystemPropertiesReflection.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/SystemPropertiesReflection.java @@ -18,7 +18,9 @@ package com.SecUpwN.AIMSICD.utils; import android.content.Context; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import java.io.File; import java.lang.reflect.Method; @@ -43,7 +45,7 @@ import dalvik.system.DexFile; */ public class SystemPropertiesReflection { - private static final String TAG = "SystemPropertiesRef"; + private static final Logger log = AndroidLogger.forClass(SystemPropertiesReflection.class); /** * This class cannot be instantiated @@ -80,10 +82,10 @@ public class SystemPropertiesReflection { ret = (String) get.invoke(SystemProperties, params); } catch (IllegalArgumentException iae) { - Log.e(TAG, iae.getMessage(), iae); + log.error(iae.getMessage(), iae); throw iae; } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); + log.error(e.getMessage(), e); ret = ""; } @@ -122,10 +124,10 @@ public class SystemPropertiesReflection { ret = (String) get.invoke(SystemProperties, params); } catch (IllegalArgumentException iae) { - Log.e(TAG, iae.getMessage(), iae); + log.error(iae.getMessage(), iae); throw iae; } catch (Exception e) { - Log.e(TAG, e.getMessage(), e); + log.error(e.getMessage(), e); ret = def; } @@ -165,10 +167,10 @@ public class SystemPropertiesReflection { set.invoke(SystemProperties, params); } catch (IllegalArgumentException iae) { - Log.e(TAG, iae.getMessage(), iae); + log.error(iae.getMessage(), iae); throw iae; } catch (Exception ignored) { - Log.d(TAG, ignored.getMessage(), ignored); + log.debug(ignored.getMessage(), ignored); } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/TruncatedLocation.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/TruncatedLocation.java index 9140ad6b..d8357717 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/TruncatedLocation.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/TruncatedLocation.java @@ -1,7 +1,9 @@ package com.SecUpwN.AIMSICD.utils; import android.location.Location; -import android.util.Log; + +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; import java.text.NumberFormat; import java.text.ParseException; @@ -11,7 +13,7 @@ import java.text.ParseException; */ public class TruncatedLocation extends Location { - private static final String TAG = "TruncLocation"; + private static final Logger log = AndroidLogger.forClass(TruncatedLocation.class); public TruncatedLocation(Location l) { super(l); @@ -41,7 +43,7 @@ public class TruncatedLocation extends Location { Number number = format.parse(s); td = number.doubleValue(); } catch (ParseException e) { - Log.e(TAG, "parsing exception", e); + log.error("parsing exception", e); } return td; } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/AtCommandTerminal.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/AtCommandTerminal.java index d0c3785c..7ccf41ad 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/AtCommandTerminal.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/AtCommandTerminal.java @@ -6,11 +6,13 @@ package com.SecUpwN.AIMSICD.utils.atcmd; import android.os.Message; -import android.util.Log; import java.io.File; import java.io.IOException; +import io.freefair.android.util.logging.AndroidLogger; +import io.freefair.android.util.logging.Logger; + /** * Description: ... * @@ -33,8 +35,7 @@ import java.io.IOException; */ public abstract class AtCommandTerminal { - protected static final String TAG = "AIMSICD"; - protected static final String mTAG = "AtCommandTerminal"; //ATCoP: + protected static Logger log = AndroidLogger.forClass(AtCommandTerminal.class); // message may be null if the response is not needed public abstract void send(String s, Message message); @@ -53,7 +54,7 @@ public abstract class AtCommandTerminal { try { term = new TtyPrivFile(smdFile.getAbsolutePath()); } catch (IOException e) { - Log.e(TAG, mTAG + " IOException in constructor", e); + log.error("IOException in constructor", e); // fall through } } diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/TtyPrivFile.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/TtyPrivFile.java index 6932bf32..aec68284 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/TtyPrivFile.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/TtyPrivFile.java @@ -5,8 +5,6 @@ */ package com.SecUpwN.AIMSICD.utils.atcmd; -import android.util.Log; - import java.io.IOException; @@ -42,7 +40,7 @@ public class TtyPrivFile extends TtyStream { mReadProc = read; mWriteProc = write; - Log.d(TAG, "mReadProc=" + mReadProc + ", mWriteProc=" + mWriteProc); + log.debug("mReadProc=" + mReadProc + ", mWriteProc=" + mWriteProc); } @Override @@ -54,7 +52,7 @@ public class TtyPrivFile extends TtyStream { mOutputStream.write("ATE0\r".getBytes("ASCII"));// disable local Echo mOutputStream.flush(); } catch (IOException e) { - Log.e(TAG, "moutputstream didnt close", e); + log.error("moutputstream didnt close", e); } mReadProc.destroy(); mWriteProc.destroy(); diff --git a/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/TtyStream.java b/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/TtyStream.java index d39f0034..80e1c8f2 100644 --- a/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/TtyStream.java +++ b/app/src/main/java/com/SecUpwN/AIMSICD/utils/atcmd/TtyStream.java @@ -6,7 +6,6 @@ package com.SecUpwN.AIMSICD.utils.atcmd; import android.os.Message; -import android.util.Log; import android.util.Pair; import java.io.BufferedReader; @@ -81,7 +80,7 @@ class TtyStream extends AtCommandTerminal { mOutputStream.write('\r'); mOutputStream.flush(); } catch (IOException e) { - Log.e(TAG, "Output IOException", e); + log.error("Output IOException", e); if (resultMessage != null) { resultMessage.obj = e; resultMessage.sendToTarget(); @@ -117,7 +116,7 @@ class TtyStream extends AtCommandTerminal { line = in.readLine(); if (line == null) throw new IOException("reader closed"); } catch (IOException e) { - Log.e(TAG, "Input IOException", e); + log.error("Input IOException", e); if (resultMessage != null) { resultMessage.obj = e; resultMessage.sendToTarget(); @@ -130,13 +129,13 @@ class TtyStream extends AtCommandTerminal { } while (!(line.equals("OK") || line.equals("ERROR") || line.startsWith("+CME ERROR"))); // XXX this logging could have sensitive info - //Log.d(TAG, "IO< " + lines); + //log.debug("IO< " + lines); if (resultMessage != null) { resultMessage.obj = lines; resultMessage.sendToTarget(); } else { - Log.d(TAG, "Data came in with no handler"); + log.debug("Data came in with no handler"); } } } catch (UnsupportedEncodingException e) { @@ -152,7 +151,7 @@ class TtyStream extends AtCommandTerminal { public void send(String s, Message resultMessage) { try { // XXX this logging could have sensitive info - //Log.d(TAG, "IO> " + s); + //log.debug("IO> " + s); mWriteQ.add(Pair.create(s.getBytes("ASCII"), resultMessage)); } catch (UnsupportedEncodingException e) { // we assume that if a String is being used for convenience, it must be ASCII -- GitLab