Simplify debugging logging via Utils

This commit is contained in:
Daniel Martí 2015-08-20 18:37:25 -07:00
parent 4c75f6078d
commit 96014a7365
5 changed files with 22 additions and 22 deletions

View File

@ -47,7 +47,7 @@ public class CompatibilityChecker extends Compatibility {
for (FeatureInfo fi : pm.getSystemAvailableFeatures()) { for (FeatureInfo fi : pm.getSystemAvailableFeatures()) {
logMsg.append('\n').append(fi.name); logMsg.append('\n').append(fi.name);
} }
Log.d(TAG, logMsg.toString()); Utils.DebugLog(TAG, logMsg.toString());
} }
for (FeatureInfo fi : pm.getSystemAvailableFeatures()) { for (FeatureInfo fi : pm.getSystemAvailableFeatures()) {
features.add(fi.name); features.add(fi.name);
@ -102,23 +102,19 @@ public class CompatibilityChecker extends Compatibility {
} }
if (!features.contains(feat)) { if (!features.contains(feat)) {
Collections.addAll(incompatibleReasons, feat.split(",")); Collections.addAll(incompatibleReasons, feat.split(","));
if (BuildConfig.DEBUG) { Utils.DebugLog(TAG, apk.id + " vercode " + apk.vercode
Log.d(TAG, apk.id + " vercode " + apk.vercode
+ " is incompatible based on lack of " + feat); + " is incompatible based on lack of " + feat);
} }
} }
} }
}
if (!compatibleApi(apk.nativecode)) { if (!compatibleApi(apk.nativecode)) {
for (final String code : apk.nativecode) { for (final String code : apk.nativecode) {
incompatibleReasons.add(code); incompatibleReasons.add(code);
} }
if (BuildConfig.DEBUG) { Utils.DebugLog(TAG, apk.id + " vercode " + apk.vercode
Log.d(TAG, apk.id + " vercode " + apk.vercode
+ " only supports " + Utils.CommaSeparatedList.str(apk.nativecode) + " only supports " + Utils.CommaSeparatedList.str(apk.nativecode)
+ " while your architectures are " + cpuAbisDesc); + " while your architectures are " + cpuAbisDesc);
} }
}
return incompatibleReasons; return incompatibleReasons;
} }

View File

@ -258,9 +258,7 @@ public class Preferences implements SharedPreferences.OnSharedPreferenceChangeLi
@Override @Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if (BuildConfig.DEBUG) { Utils.DebugLog(TAG, "Invalidating preference '" + key + "'.");
Log.d(TAG, "Invalidating preference '" + key + "'.");
}
uninitialize(key); uninitialize(key);
switch (key) { switch (key) {

View File

@ -633,4 +633,16 @@ public final class Utils {
} }
} }
public static void DebugLog(String tag, String msg) {
if (BuildConfig.DEBUG) {
Log.d(tag, msg);
}
}
public static void DebugLog(String tag, String msg, Throwable tr) {
if (BuildConfig.DEBUG) {
Log.d(tag, msg, tr);
}
}
} }

View File

@ -59,9 +59,7 @@ public class FileCompat extends Compatibility {
dest.getAbsolutePath() dest.getAbsolutePath()
}; };
try { try {
if (BuildConfig.DEBUG) { Utils.DebugLog(TAG, "Executing command: " + commands[0] + " " + commands[1] + " " + commands[2]);
Log.d(TAG, "Executing command: " + commands[0] + " " + commands[1] + " " + commands[2]);
}
Process proc = Runtime.getRuntime().exec(commands); Process proc = Runtime.getRuntime().exec(commands);
Utils.consumeStream(proc.getInputStream()); Utils.consumeStream(proc.getInputStream());
Utils.consumeStream(proc.getErrorStream()); Utils.consumeStream(proc.getErrorStream());
@ -109,9 +107,7 @@ public class FileCompat extends Compatibility {
}; };
try { try {
if (BuildConfig.DEBUG) { Utils.DebugLog(TAG, "Executing following command: " + args[0] + " " + args[1] + " " + args[2]);
Log.d(TAG, "Executing following command: " + args[0] + " " + args[1] + " " + args[2]);
}
Process proc = Runtime.getRuntime().exec(args); Process proc = Runtime.getRuntime().exec(args);
Utils.consumeStream(proc.getInputStream()); Utils.consumeStream(proc.getInputStream());
Utils.consumeStream(proc.getErrorStream()); Utils.consumeStream(proc.getErrorStream());

View File

@ -85,9 +85,7 @@ public class WifiStateChangeService extends Service {
FDroidApp.ipAddressString = getIpAddressFromNetworkInterface(); FDroidApp.ipAddressString = getIpAddressFromNetworkInterface();
} }
Thread.sleep(1000); Thread.sleep(1000);
if (BuildConfig.DEBUG) { Utils.DebugLog(TAG, "waiting for an IP address...");
Log.d(TAG, "waiting for an IP address...");
}
} }
if (isCancelled()) // can be canceled by a change via WifiStateChangeReceiver if (isCancelled()) // can be canceled by a change via WifiStateChangeReceiver
return null; return null;