From dc2d484be25cd1542410cd745a77a810d92c75b3 Mon Sep 17 00:00:00 2001 From: Eric Kok Date: Wed, 24 Jul 2013 20:05:45 +0200 Subject: [PATCH] Don't write to Android logcat if app is build in release mode. --- core/src/org/transdroid/core/gui/log/Log.java | 7 ++++++- .../core/gui/navigation/NavigationHelper.java | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/core/src/org/transdroid/core/gui/log/Log.java b/core/src/org/transdroid/core/gui/log/Log.java index 2721ce24..bd9c7430 100644 --- a/core/src/org/transdroid/core/gui/log/Log.java +++ b/core/src/org/transdroid/core/gui/log/Log.java @@ -3,9 +3,11 @@ package org.transdroid.core.gui.log; import java.sql.SQLException; import java.util.Date; +import org.androidannotations.annotations.Bean; import org.androidannotations.annotations.EBean; import org.androidannotations.annotations.EBean.Scope; import org.androidannotations.annotations.OrmLiteDao; +import org.transdroid.core.gui.navigation.NavigationHelper; import org.transdroid.daemon.util.ITLogger; import android.content.Context; @@ -27,13 +29,16 @@ public class Log implements ITLogger { private Context context; @OrmLiteDao(helper = DatabaseHelper.class, model = ErrorLogEntry.class) Dao errorLogDao; + @Bean + protected NavigationHelper navigationHelper; protected Log(Context context) { this.context = context; } protected void log(String logName, int priority, String message) { - android.util.Log.println(priority, LOG_NAME, message); + if (!navigationHelper.inDebugMode()) + android.util.Log.println(priority, LOG_NAME, message); try { // Store this log message to the database errorLogDao.create(new ErrorLogEntry(priority, logName, message)); diff --git a/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java b/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java index 2543ca11..2a3dd573 100644 --- a/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java +++ b/core/src/org/transdroid/core/gui/navigation/NavigationHelper.java @@ -6,6 +6,7 @@ import org.transdroid.core.R; import android.annotation.SuppressLint; import android.content.Context; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageInfo; import android.content.pm.PackageManager.NameNotFoundException; import android.text.Spannable; @@ -34,6 +35,7 @@ public class NavigationHelper { @RootContext protected Context context; + private Boolean inDebugMode; private static ImageLoader imageCache; /** @@ -89,6 +91,23 @@ public class NavigationHelper { } } + /** + * Returns whether the application is running in debug mode, as opposed to release mode. Use to show/hide features + * in the ui based on the build mode. + * @return True if the app is compiled in/running as debug mode, false otherwise + */ + public boolean inDebugMode() { + try { + if (inDebugMode == null) { + PackageInfo pi = context.getPackageManager().getPackageInfo(context.getPackageName(), 0); + inDebugMode = (pi.applicationInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0; + } + return inDebugMode; + } catch (NameNotFoundException e) { + return false; + } + } + /** * Returns whether the device is considered small (i.e. a phone) rather than large (i.e. a tablet). Can, for * example, be used to determine if a dialog should be shown full screen. Currently is true if the device's smallest