Commit 1f876ed7 authored by Bartek Fabiszewski's avatar Bartek Fabiszewski
Browse files

Remove debug output from production builds

parent e5a1402a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -32,5 +32,5 @@ android {
dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:25.2.0'
    compile 'com.android.support:appcompat-v7:25.3.0'
}
+17 −21
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ class DbAccess {
     * Get singleton instance
     * @return DbAccess singleton
     */
    public static synchronized DbAccess getInstance() {
    static synchronized DbAccess getInstance() {
        if (sInstance == null) {
            sInstance = new DbAccess();
        }
@@ -54,13 +54,11 @@ class DbAccess {
     * Opens database
     * @param context Context
     */
    public synchronized void open(Context context) {
    synchronized void open(Context context) {
        if(openCount.incrementAndGet() == 1) {
            mDbHelper = DbHelper.getInstance(context.getApplicationContext());
            db = mDbHelper.getWritableDatabase();
            Log.d(TAG, "[db open: " + db + "]");
        }
        Log.d(TAG, "[db open,  counter: " + openCount + "]");
    }

    /**
@@ -68,7 +66,8 @@ class DbAccess {
     *
     * @param loc Location
     */
    public void writeLocation(Location loc) {
    void writeLocation(Location loc) {
        if (Logger.DEBUG) { Log.d(TAG, "[writeLocation]"); }
        ContentValues values = new ContentValues();
        values.put(DbContract.Positions.COLUMN_TIME, loc.getTime() / 1000);
        values.put(DbContract.Positions.COLUMN_LATITUDE, loc.getLatitude());
@@ -86,7 +85,6 @@ class DbAccess {
            values.put(DbContract.Positions.COLUMN_ACCURACY, loc.getAccuracy());
        }
        values.put(DbContract.Positions.COLUMN_PROVIDER, loc.getProvider());
        Log.d(TAG, "[writeLocation]");

        db.insert(DbContract.Positions.TABLE_NAME, null, values);
    }
@@ -96,7 +94,7 @@ class DbAccess {
     *
     * @return Result set
     */
    public Cursor getUnsynced() {
    Cursor getUnsynced() {
        return db.query(DbContract.Positions.TABLE_NAME,
                new String[] {"*"},
                DbContract.Positions.COLUMN_SYNCED + "=?",
@@ -110,7 +108,7 @@ class DbAccess {
     *
     * @return Error message or null if none
     */
    public String getError() {
    String getError() {
        Cursor query = db.query(DbContract.Positions.TABLE_NAME,
                new String[] {DbContract.Positions.COLUMN_ERROR},
                DbContract.Positions.COLUMN_SYNCED + "=?",
@@ -131,7 +129,7 @@ class DbAccess {
     *
     * @param error Error message
     */
    public void setError(String error) {
    void setError(String error) {
        ContentValues values = new ContentValues();
        values.put(DbContract.Positions.COLUMN_ERROR, error);
        db.update(DbContract.Positions.TABLE_NAME,
@@ -148,7 +146,7 @@ class DbAccess {
     *
     * @param id Position id
     */
    public void setSynced(int id) {
    void setSynced(int id) {
        ContentValues values = new ContentValues();
        values.put(DbContract.Positions.COLUMN_SYNCED, "1");
        values.putNull(DbContract.Positions.COLUMN_ERROR);
@@ -163,7 +161,7 @@ class DbAccess {
     *
     * @return Count
     */
    public int countUnsynced() {
    int countUnsynced() {
        Cursor count = db.query(DbContract.Positions.TABLE_NAME,
                new String[] {"COUNT(*)"},
                DbContract.Positions.COLUMN_SYNCED + "=?",
@@ -183,7 +181,7 @@ class DbAccess {
     *
     * @return True if synchronization needed, false otherwise
     */
    public boolean needsSync() {
    boolean needsSync() {
        return (countUnsynced() > 0);
    }

@@ -192,7 +190,7 @@ class DbAccess {
     *
     * @return UTC timestamp in seconds
     */
    public long getLastTimestamp() {
    long getLastTimestamp() {
        Cursor query = db.query(DbContract.Positions.TABLE_NAME,
                new String[] {DbContract.Positions.COLUMN_TIME},
                null, null, null, null,
@@ -211,7 +209,7 @@ class DbAccess {
     *
     * @return Track id, zero if no track with valid id in database
     */
    public int getTrackId() {
    int getTrackId() {
        Cursor track = db.query(DbContract.Track.TABLE_NAME,
                new String[] {DbContract.Track.COLUMN_ID},
                DbContract.Track.COLUMN_ID + " IS NOT NULL",
@@ -230,7 +228,7 @@ class DbAccess {
     *
     * @return Track name, null if no track in database
     */
    public String getTrackName() {
    String getTrackName() {
        Cursor track = db.query(DbContract.Track.TABLE_NAME,
                new String[] {DbContract.Track.COLUMN_NAME},
                null, null, null, null, null,
@@ -248,7 +246,7 @@ class DbAccess {
     *
     * @param id New track id
     */
    public void setTrackId(int id) {
    void setTrackId(int id) {
        ContentValues values = new ContentValues();
        values.put(DbContract.Track.COLUMN_ID, id);
        db.update(DbContract.Track.TABLE_NAME,
@@ -262,7 +260,7 @@ class DbAccess {
     *
     * @param name New track name
     */
    public void newTrack(String name) {
    void newTrack(String name) {
        truncateTrack();
        truncatePositions();
        ContentValues values = new ContentValues();
@@ -275,7 +273,7 @@ class DbAccess {
     *
     * @return TrackSummary object
     */
    public TrackSummary getTrackSummary() {
    TrackSummary getTrackSummary() {
        Cursor positions = db.query(DbContract.Positions.TABLE_NAME,
                new String[] {"*"},
                null, null, null, null,
@@ -325,10 +323,8 @@ class DbAccess {
    /**
     * Closes database
     */
    public synchronized void close() {
        Log.d(TAG, "[db close,  counter: " + openCount + "]");
    synchronized void close() {
        if(openCount.decrementAndGet() == 0) {
            Log.d(TAG, "[db close: " + db + "]");
            if (db != null) {
                db.close();
            }
+18 −0
Original line number Diff line number Diff line
/*
 * Copyright (c) 2017 Bartek Fabiszewski
 * http://www.fabiszewski.net
 *
 * This file is part of μlogger-android.
 * Licensed under GPL, either version 3, or any later.
 * See <http://www.gnu.org/licenses/>
 */

package net.fabiszewski.ulogger;

/**
 * Turn on debug output by setting DEBUG to true
 */

class Logger {
    static final boolean DEBUG = false;
}
+30 −32
Original line number Diff line number Diff line
@@ -72,7 +72,7 @@ public class LoggerService extends Service {
     */
    @Override
    public void onCreate() {
        Log.d(TAG, "[onCreate]");
        if (Logger.DEBUG) { Log.d(TAG, "[onCreate]"); }
        thread = new LoggerThread();
        syncIntent = new Intent(getApplicationContext(), WebSyncService.class);

@@ -115,8 +115,7 @@ public class LoggerService extends Service {
     */
    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        Log.d(TAG, "[onStartCommand]");
        if (Logger.DEBUG) { Log.d(TAG, "[onStartCommand]"); }

        // start websync service if needed
        liveSync = prefs.getBoolean("prefLiveSync", false);
@@ -145,8 +144,7 @@ public class LoggerService extends Service {
     */
    @Override
    public void onDestroy() {

        Log.d(TAG, "[onDestroy]");
        if (Logger.DEBUG) { Log.d(TAG, "[onDestroy]"); }

        if (canAccessLocation()) {
            //noinspection MissingPermission
@@ -202,13 +200,13 @@ public class LoggerService extends Service {

        @Override
        public void interrupt() {
            Log.d(TAG, "[interrupt]");
            if (Logger.DEBUG) { Log.d(TAG, "[interrupt]"); }
            cleanup();
        }

        @Override
        public void finalize() throws Throwable {
            Log.d(TAG, "[finalize]");
            if (Logger.DEBUG) { Log.d(TAG, "[finalize]"); }
            cleanup();
            super.finalize();
        }
@@ -219,7 +217,7 @@ public class LoggerService extends Service {

        @Override
        public void run() {
            Log.d(TAG, "[run]");
            if (Logger.DEBUG) { Log.d(TAG, "[run]"); }
            showNotification(mNotificationManager, NOTIFICATION_ID);
            super.run();
        }
@@ -232,7 +230,7 @@ public class LoggerService extends Service {
     * @param mId Notification Id
     */
    private void showNotification(NotificationManager mNotificationManager, int mId) {
        Log.d(TAG, "[showNotification " + mId + "]");
        if (Logger.DEBUG) { Log.d(TAG, "[showNotification " + mId + "]"); }

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
@@ -257,7 +255,7 @@ public class LoggerService extends Service {
        @Override
        public void onLocationChanged(Location loc) {

            Log.d(TAG, "[location changed: " + loc + "]");
            if (Logger.DEBUG) { Log.d(TAG, "[location changed: " + loc + "]"); }

            if (!skipLocation(loc)) {

@@ -284,7 +282,7 @@ public class LoggerService extends Service {
        private boolean skipLocation(Location loc) {
            // accuracy radius too high
            if (loc.hasAccuracy() && loc.getAccuracy() > maxAccuracy) {
                Log.d(TAG, "[location accuracy above limit: " + loc.getAccuracy() + " > " + maxAccuracy + "]");
                if (Logger.DEBUG) { Log.d(TAG, "[location accuracy above limit: " + loc.getAccuracy() + " > " + maxAccuracy + "]"); }
                // reset gps provider to get better accuracy even if time and distance criteria don't change
                if (loc.getProvider().equals(LocationManager.GPS_PROVIDER)) {
                    restartUpdates(LocationManager.GPS_PROVIDER);
@@ -297,7 +295,7 @@ public class LoggerService extends Service {
                long elapsedMillis = SystemClock.elapsedRealtime() - lastUpdateRealtime;
                if (lastLocation.getProvider().equals(LocationManager.GPS_PROVIDER) && elapsedMillis < maxTimeMillis) {
                    // skip network provider
                    Log.d(TAG, "[location network provider skipped]");
                    if (Logger.DEBUG) { Log.d(TAG, "[location network provider skipped]"); }
                    return true;
                }
            }
@@ -309,8 +307,7 @@ public class LoggerService extends Service {
         * @param provider Location provider
         */
        private void restartUpdates(String provider) {

            Log.d(TAG, "[location restart provider " + provider + "]");
            if (Logger.DEBUG) { Log.d(TAG, "[location restart provider " + provider + "]"); }

            if (providerExists(provider) && canAccessLocation()) {
                //noinspection MissingPermission
@@ -327,7 +324,7 @@ public class LoggerService extends Service {
         */
        @Override
        public void onProviderDisabled(String provider) {
            Log.d(TAG, "[location provider " + provider + " disabled]");
            if (Logger.DEBUG) { Log.d(TAG, "[location provider " + provider + " disabled]"); }
        }

        /**
@@ -336,7 +333,7 @@ public class LoggerService extends Service {
         */
        @Override
        public void onProviderEnabled(String provider) {
            Log.d(TAG, "[location provider " + provider + " enabled]");
            if (Logger.DEBUG) { Log.d(TAG, "[location provider " + provider + " enabled]"); }
        }

        /**
@@ -347,7 +344,7 @@ public class LoggerService extends Service {
         */
        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            // todo remove debug output
            if (Logger.DEBUG) {
                final String statusString;
                switch (status) {
                    case OUT_OF_SERVICE:
@@ -367,3 +364,4 @@ public class LoggerService extends Service {
            }
        }
    }
}
+7 −7
Original line number Diff line number Diff line
@@ -107,7 +107,7 @@ public class MainActivity extends AppCompatActivity {
    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "[onResume]");
        if (Logger.DEBUG) { Log.d(TAG, "[onResume]"); }

        if (LoggerService.isRunning()) {
            toggleButton.setText(TXT_STOP);
@@ -125,7 +125,7 @@ public class MainActivity extends AppCompatActivity {
     */
    @Override
    protected void onPause() {
        Log.d(TAG, "[onPause]");
        if (Logger.DEBUG) { Log.d(TAG, "[onPause]"); }
        unregisterReceiver(mBroadcastReceiver);
        super.onPause();
    }
@@ -135,7 +135,7 @@ public class MainActivity extends AppCompatActivity {
     */
    @Override
    protected void onDestroy() {
        Log.d(TAG, "[onDestroy]");
        if (Logger.DEBUG) { Log.d(TAG, "[onDestroy]"); }
        if (db != null) {
            db.close();
        }
@@ -484,7 +484,7 @@ public class MainActivity extends AppCompatActivity {
        int count = db.countUnsynced();
        if (count > 0) {
            String error = db.getError();
            Log.d(TAG, "[sync error: " + error + "]");
            if (Logger.DEBUG) { Log.d(TAG, "[sync error: " + error + "]"); }
            if (error != null) {
                syncError = true;
                syncErrorLabel.setText(error);
@@ -529,7 +529,7 @@ public class MainActivity extends AppCompatActivity {
     * @param color Color
     */
    private void setSyncLed(int color) {
        Log.d(TAG, "[setSyncLed " + color + "]");
        if (Logger.DEBUG) { Log.d(TAG, "[setSyncLed " + color + "]"); }
        setLedColor(syncLed, color);
    }

@@ -541,7 +541,7 @@ public class MainActivity extends AppCompatActivity {
     * @param color Color
     */
    private void setLocLed(int color) {
        Log.d(TAG, "[setLocLed " + color + "]");
        if (Logger.DEBUG) { Log.d(TAG, "[setLocLed " + color + "]"); }
        setLedColor(locLed, color);
    }

@@ -564,7 +564,7 @@ public class MainActivity extends AppCompatActivity {
        @Override
        public void onReceive(Context context, Intent intent) {
            if (intent.getAction().equals(LoggerService.BROADCAST_LOCATION_UPDATED)) {
                Log.d(TAG, "[broadcast received " + intent + "]");
                if (Logger.DEBUG) { Log.d(TAG, "[broadcast received " + intent + "]"); }
                updateLocationLabel(LoggerService.lastUpdateRealtime());
                setLocLed(LED_GREEN);
            } else if (intent.getAction().equals(WebSyncService.BROADCAST_SYNC_DONE)) {
Loading