Is it okay to use emojis in Logcat logs? - android

I am using emojis in log cat messages in order to make the logs easier on the eye. So far it works fine, but I wonder if I'll hit any character compatibility issues on older Android devices. My app's minimumSdkVersion is 16.
Examples:
companion object {
private const val TAG = "\uD83D\uDD36SomeClass"
}
...
Log.d(TAG, "⏰ Something happened!")
Is there anything I should be worried about? Are there any reasons against doing this?

Not sure about your emojis in Logcat but I think that if you want to make your life easier use the TAG that inside your Log.d.
For example, here is a log with a custom TAG:
Log.d("myTag","something to show");
After you run your app all you need to do is to search the same tag name within your logcat, like this:
Another thing that you should think about that if you want to search for a specific log would it be comfortable to search the logcat using emojis?
In my opinion, simply searching your tag name to find your log makes thing super easy.

Related

Obfuscating or removing string literal from all calls to Log-function in Android

We are building an Android application where we use Timber for Log-output. We have defined our own .e, .d, .v etc functions and use if (BuildConfig.DEBUG) to see if we should output the log. This takes care of the issue that we don't want to output Debug-logs in our releases but all the string literals used in our functions calls are still present in the compiled source code. We furthermore use ProGuard for obfuscation. To exemplify, in a class we can have:
somObj.normalFunction(variable)
Log.d("This secret class achieved its secret mission!");
In our release, this will not be seen in the app logs but if you reverse-engineer the APK you will see something like:
q.b(m)
z.a("This secret class achieved its secret mission!");
which can give a hint to the hackers about what class they are looking at.
So what we're looking for is to either be able to completely REMOVE all the Log function calls at compile time (using some pre-processing, annotation or something, but hopefully without having to add something before EVERY function call) OR to obfuscate all the String literal parameters to those function calls. So, two ideal solutions would be if the source, just before compilation, instead looks like:
q.b(m);
or
q.b(m);
z.a("jgasoisamgp23mmwaföfm,ak,ä")
Just by thinking I can see two bad ways to achieve this. Either we surround ALL calls to Log.d with if(BuildConfig.DEBUG) which will make the compiler remove them before compilation. But this is very tideous. OR, we make sure that every time you want to add a log-printout you need to do
Log.d(LogClass.getLog(1234))
and you then define ALL those logs inside LogClass and then remove them with if(BuildConfig.DEBUG) and return null in getLog if that's the case. But that makes it more tideous every time you want to add a log.
So finally, is there any GOOD solution to this?
DISCLAIMER: I work for PreEmptive, the company that makes PreEmptive Protection - DashO.
DashO is capable of removing calls to specific methods (e.g., Log methods). While this doesn't remove the instructions to load the string literal, just the call itself, DashO also offers String Encryption, which would offer some protection to those string literals.
As an example, I ran this class through DashO:
public class App {
public static void main(String[] args) {
Log.d("Secret message here");
}
}
After removing calls to Log.d with String Encryption on, the decompiled output looks like this:
public class App
{
public static void main(String[] paramArrayOfString)
{
a.replace("Bwpfpb7u|ih}z{?($0&", -12 - -61);
}
}
DashO offers other protections (e.g., Control Flow Obfuscation) that tend to break decompilers; I've turned those off for this demonstration.
What I would do is one or some of the following:
Use Timber (so you don't need to bother removing things or adding if statements). You simply do this once in your Application#onCreate(); if you are in DEBUG, then you plant a DebugTree that prints to the console. Else, you plant an "empty tree" that does nothing.
Simulate Timber but create your own "YourLogger" class and do the same (if you don't want to include a "third-party" library even though it's just one class). So you'd have YourLogger.v("tag", "string") and inside you'd do: if (debug) { Log.v(tag, string); } and so on and so forth for all other log types.
Use Proguard to strip the logging, and what not.
1 and 2 imply you go through your app and replace all Log. lines with either Timber. or YourLogger.
Option 3 wouldn't need that, since the code would be removed during obfuscation and the calls would do nothing, but this is mode complicated (and I haven't done it in years, don't even remember how it's done, probably easy to look it up).
I'd go for 1.
Update
Since apparently I don't know how to read, I think that in order to achieve this, your only bet is to have some sort of lookup mechanism for the actual text you want to emit/hide.
Strings.xml is the easiest, since it's included with Android and you can even localize the error messages (if that were needed, of course). Yes, there's a lookup time penalty, but I'd say unless you're iterating over thousands of items and logging different strings every time or something, the penalty wont' be noticeable (I don't have data for this, you'd have to benchmark).
Alternatively, instead of relying on resources, you could just use a file, read it, and load the strings in memory... a trade off; do you use more memory at the cost of simplicity and time to code the solution, or do you use the built-in mechanism and pay the CPU time?

I want Qt-app to look like Qt-app rather than Android-native

Due to removing upper bar (where clock, battery and other such things are situated) I have access to QtActivity.java.
I have tried to set
public String ENVIRONMENT_VARIABLES = "QT_USE_ANDROID_NATIVE_DIALOGS=0";
but without any result.
And there is one strange thing: on the first start of the app it looks like Android-app(ugly and curvy), but on the second run it starts looking like normal Qt-app.
I want program not to use Android styles from the start.
What can I do?
P.S. I use QWidgets, no QQuick/QML
Alas, but this method doesn't work under Android: Can I run a Qt application with a specific theme?
Just add this line to main()
QApplication::setStyle(QStyleFactory::create("Fusion"));
No need to edit AndroidManifest.xml or QtActivity.java

MonkeyTalk Android Detect String Containing \n for Button Tap

I am using MonkeyTalk to automate some user test cases for my Android app. Everything is working fine except for when I try and detect a button containing this string:
"Connect\n(Code Required)"
I get this error:
FAILURE: Unable to find Button(Connect\n(Code required))
If I change the button to "Connect" and perform a tap on that value MonkeyTalk has no trouble, but something about the line break must be throwing it off.
After some searching I found this thread that confirmed my suspicious about the line break. There was one suggested fix here, to set the default encoding to UTF-8 (Select the Project > File > Properties > Resources)
However this did not work for me.
I have also tried to find the button using a wildcard like so:
"*(Code Required)"
But this does not seem to be supported either.
Maybe there is an alternative line break character I could use?
Thanks in advance for the help!
Maybe there's a carriage return in there? I know in most text editors a new line actually consists of (carriage return)+(newline).
Also take a look at this:
TextView carriage return not working
Also, depending on how flexible your requirements are, you could use the #N MonkeyId replacement to get the Nth button.
IN javascript you can use below command
app.button("buttonname").tap(x, y);
Use android:contentDesxription="your_component_id" in your view xml file definition or view.setContentDescription("your_component_id"); directly on view in code to make it easy to access in MonkeyTalk.

Android LogCat Filter for multiple tags in Eclipse

Clicked on create filter could not figure out from docs how to create a filter for say two or more tags. If I have two tags com.test.TestClassA and com.test.TestClassB how do I create a filter that shows log for both of these classes? I saw how you can start ADB for only certain tags, but how can this be done in eclipse? Please provide details thanks. What exactly do I need to enter on the tag line when creating a new filter in eclipse?
As pointed by Brain Reinhold you can combine tag filters with vertical bar | (which obviously means logical "OR"). You can also use that (as well as other Regex) syntax in the logcat search box (by preceding tags with tag: prefix):
tag:com.test.TestClassA|com.test.TestClassB
More complex filtering is also possible. For example here is the search filter that displays messages from either android.process.media or com.android.camera apps, which have at least one digit (\d) in the message text and are tagged with either dalvikvm or AndroidRuntime tags:
app:android.process.media|com.android.camera tag:dalvikvm|AndroidRuntime text:\d
One short and useful filter is tag:^(?!dalvikvm) which removes all those noisy Dalvik logs.
It's also worth mentioning that you can quickly disable any part of the filter by placing vertical bar at the end of the part you wish to disable (e.g. placing | right after app:android.process.media|com.android.camera in the example above effectively disables filtering by application name while still preserving filtering by tags and text).
In the latest version of the SDK for Eclipse which now shows two versions for logcat (one deprecated); in the undeprecated version one can combine filters using OR bars: |.
For example when clicking on the + and bringing up a dialog to create a new filter, give your filter a name and then in one of the fields (for example TAG) enter com.lampreynetworks|Bluetooth and you will see output for all tags containing com.lampreynetworks and Bluetooth. The '*' is implicit here as if any part of the TAG contains any of that text it will be displayed. Also note, there must be no spaces between the OR bars!
I have not tried combining the 'by TAG' and 'by (some other option)' but somehow I have a feeling that will not work.
On Feb 12, 2:58 am, AndroidDevTime wrote:
If I have two tags
com.test.TestClassA and com.test.TestClassB how do I create a filter
that shows log for both of these classes?
The "Log tag" field accepts Java regular expressions, so do this:
^com.test.TestClassA$|^com.test.TestClassB$
which matches exactly those tags you specified. You could be more economical/efficient/whatever with the regular expression, depending on how much you want to muck around with that.
It is not possible right now.
#see http://groups.google.com/group/android-developers/browse_thread/thread/17356ef7bdf1550f?pli=1
I also wish it were...
I just do it from the command line. Having a different terminal for each adb filter. Then if you line them up side by side you can get a good idea of what is happening.
The only way I have seen is Create a Filter using PID so that evey log message of your application will be displayed in that Filter. I wonder if this is possible through tag names in the current version of the ADT for eclipse.
Use proclogcat: http://devtcg.blogspot.com/2010/04/logcat-improved.html
It lets you filter by your package name instead.

android.util.Log when publishing - what can I do / not do

I've got a hell of a lot of Log.i Log.d Log.e in my code for a recent app I've done. I'm about to publish this app and I don't really want people seeing it when they plug there phone into adb, but I do want it there for my own debugging.
I was wanting to extend android.util.log and just have a boolean switch in there so I could just turn off the log when I publish and turn it on when developing but this class is final, am I missing a trick?
I don't really want to go through my code an remove all, true if worst comes to worst I could do a ctrl+h global replace Log for //Log but that does suck as an answer.
I also realise that Log.d is stripped out at runtime but it is still ran (losing a little performance) so not running this would be an added bonus.
Yeah so basically I'm looking for a way to toggle my debug on and off programatically, this can also allow me later on to make it a preference or something if people want to view it or help out and send it on.
What do you guys implement for this?
Thanks
As Octavian points out inserting a logging constant would be the best way to do this. Writing a new class for this that calls the original logging methods if debugging is enabled is not a good idea.
Good practice:
if (C.D) { Log.d(C.T, "your log text here " + foo + bar); }
Bad practice:
YourLog.d("your log text here " + foo + bar);
// and in YourLog.java's d() method:
... { if (debugging) Log.d(tag, text); }
The first solution is very fast if the constant D of class C is false. If you have complex string operations for creating your logging string they will not be executed if debugging is deactivated. The compiler can even remove these operations at compile time if D is false, which may result in zero runtime overhead. The second (bad) solution will always build the whole string and call a method, which is overhead you don't need.
In general the first solution would be best. And yes, I really call the class and members C, D and T (Constants/Debugging/Tag) - for performance reasons during typing. ;-)
obfuscate using Proguard as proguard has commands to use to filter it out when you write your proguard config file..nice and simple and it works
It is generally a good practice to not include them in your distribution code in any way since they will need to be processed which just leads to unnecessary battery drain.
You could set a boolean in your application somewhere to indicate development or release version of your code and have a lot of if blocks checking for the flag and executing your log code or not but this just leads to code bloat.
You should get rid of them once you no longer need them.

Categories

Resources