Stepping through Android code on the phone - big line number discrepancy - java

I am trying to debug some code related to ListView on Samsung Captivate (Galaxy S). I put breakpoint somewhere in my code and when it stops I go back on the stack few frames to the ListView source.
Now, I can expect that there would be some mismatch as my phone probably has slightly different version of Android classes than source code that I use in my IDE. However, I get a discrepancy of over 300 lines. I don't see this discrepancy on emulator.
More over, stack trace shows ListView line number 3688 for method performItemClick() while ListView source only has 3644 lines and this method appears in it on line 3395. I looked at different versions of Android code and none of them has performItemClick() much closer to line 3688.
The only explanation I can think of is that Samsung changed Android code so much, but I can't see why would they do such change.
Is there some other reason that I am missing? Is there any way to force debugger to adjust lines automatically as currently I just can't step through this code?

Trying different versions won't help. Samsung modifies their framework code and they do not release the changes. I ran into the same problem with my Samsung Charge smartphone. They probably deal with the Galaxy in the same way. This is an unfortunate reality of the Apache license.
When I contacted Samsung about the issue I got the following response (with minor edits):
FRG83 android-2.2.1_r1 is [the right version number for the Samsung Charge].
Also, ''ListView.java'' file does not match between file on the phone and google original, because we modified it.
ListView.java is covered under Apache license which has no obligation to publish source code.
Please understand that we only publish open source codes that are covered licenses which have obligation of publishing.(ex. GPL, LGPL, MPL...etc).
The reason for mentioning ''Get android open source'' is only for build our Open source code.

It's possible that there are encoding differences that cause the number of carriage returns to vary. Try formatting the source with a single encoding and stripping out the excess line breaks.

I usually find that reading the documentation is more productive than stepping through 3rd party code if you want to understand it. Especially with big frameworks. There is also a good video on ListView that I would recommend.
That being said, sometimes even after you've read the documentation it still doesn't make sense and seeing it for real can help. The first thing to do is find out exactly which version you do have on your phone:
my phone probably has slightly different version of Android
and make sure your Android source code attached to eclipse is the same version. If the Android guys added new APIs to ListView it is perceivable that it could jump in size.
I, too, would be very surprised if Samsung modified these files.

Related

"E/android.hardware.audio#6.0-impl.ranchu: WriteThread::doWriteImpl:226: pcm_write failed with Operation not permitted" in Android Studio [duplicate]

I'm new to Android Studio, using latest version, and trying to code a basic calculator app.
For some reason, my logcat is full of
2021-01-11 14:38:35.288 6938-6938/? W/cmd: Can't find service car_service
This is really annoying for debugging.
How can I get rid of it ?
I'll change my comment to an answer, seeing as though it actually helped:
click on logcat at the bottom of android studio, then (i'm assuming) yours will show no filters, change that dropdown to show only selected application. Not really much I can explain here, except for the fact that if you don't have it setup like this, logcat will print out things which are irrelevant to your app in addition to the logs from your own application
Additionally, to all future readers... Android Logcat is quite verbose, especially on Emulators (where a lot of things throw errors/warnings) but not limited to; Samsung devices spit more log than useful information (And they are not alone), so a way to keep it under some control, is to (ab)use the Regex feature of the logcat filter in Android Studio.
E.g.:
Create a new LogCat Filter and filter by Tag, Message, or Package (or all 3 like I do):
This is an example I use in "Message":
^((?!EGL_emulation|eglCodecCommon|OpenGLRenderer|MicroDetectionWorker|MicroDetector|KeyguardClockSwitch|adbd|OIMC|base.apk|wakelock|com.google.android.apps.youtube.music).)*$
You can edit/add more to these and/or repeat it for LogTag, Message, or Package Name.
It's mostly trial and error. (some devices spit different spam via logcat).
My Log Tag filter for this "very filtered app" output is:
^((?!vendor.qti.bluetooth|AppDynamics|KeyguardUpdateMonitor|BatteryExternalStatsWorker|BatteryStatsService|tftp_server|Clock|libc|OnePlusSmartBoostManager|OnePlus|ANDR-RAMBOOST_SERVER|BoundBrokerSvc|DateView|BatteryStatsHelper|BoundBrokerSvc|RenderThread|FacsCacheGmsModule|DownloadProgressMonitor|MendelPackageState|GoogleTagManager|SELinux|Volley|ConfigFileUtils|NetRec|YouTubeMusic|GEL_DELAYED_EVENT_DEBUG|gms|AsyncOperation|angh|ContentCacheSuperpacksManager|SuperpacksManager|AwarenessClientProvider|WakeLock|GLSUser|perfetto|cmd|chatty|Binder|Fitness|Icing|GnssHAL_GnssInterface).)*$
and for Package Name:
^((?!EGL_emulation|eglCodecCommon|OpenGLRenderer|MicroDetectionWorker|MicroDetector|KeyguardClockSwitch|adbd|OIMC|base.apk|wakelock|com.google.android.apps.youtube.music).)*$
Of course your mileage will vary in what you need, and sometimes I edit these and add/remove some parts as I see fit.
This is how it looks:

How to auto receive calls programatically in android versions above kitkat

I am trying to develop an app which auto receive calls from particular numbers.
Like i can add the numbers that i want to auto receive. I did a lot of research and found similar questions but none of them worked. Some codes did work but only upto kitkat version and code did not work on versions above kitkat. I want the code that support all android versions. Its very important for me so please answer quickly. I really need your help.
I want the app to work in background so also please help me and write the code to implement this in a background service.
I was successful to run the app on versions upto kitkat but above kitkat the code does not work.
Android very specifically does NOT allow this, because doing so is an opening to a lot of telephone scams involving reversed charges. They've actually never allowed it, but people found hacks on old versions to get around that. Every time Google finds one of these, they shut it down in the next version. So there is no reliable way to do it, and if you find a way expect it to disappear shortly afterwards.

"Source code does not match the bytecode" for system files on Huawei

We are debugging an issue with one of our apps which affects only Huawei devices. To debug it, we purchased P20 Lite ANE-LX1. We've placed some breakpoints in our code and are investigating the full stack trace. The device has Android 8.0 installed, and we have the same SDK downloaded in our Android Studio.
When we attach our device to a debugger and try to investigate the stack trace we get the following errors in system source files:
After playing with the stack trace, we can confirm that indeed our source files do not correspond to what is installed on the device. Sometimes, the debugger points to a line where functionA is called, and in the stack trace, we see that functionB is called instead. The files which we could confirm are affected by this issue are:
VideoView,
MediaPlayer,
ContentProvider.
We've tried all the possible solutions which we could find, including cleaning the project, deleting any additional SDKs from Android Studio, modifying project settings - nothing helps to resolve this issue.
This leads us to believe that Huawei installs a modified version of Android 8.0 on their devices which is why we cannot debug the stack trace for the system files. We did contact Huawei to try and clarify this.
In the meantime, we'd appreciate if you could throw any relevant ideas at us. Maybe you know where to get the source files which Huawei installs on their devices? Or maybe you know how to fix this mismatch between source code and bytecode in some other way?
Update 1
Following the advice of Robert, I uninstalled the source codes for Android 26 and ran the app again on my Huawei. As soon as I jumped into the VideoView file, I saw the following picture:
I clicked on "Download" and it started downloading the source files:
After this, I was able to step into VideoView and it seemed to work fine. However, after this line it became obvious that these source files are also wrong:
When I try to step into the requestLayout function I get this:
And it is obviously a wrong result. In fact, if I click on "Step to the next line" I see the message about source code mismatch with the bytecode again.
Apparently Huawei forked AOSP and modified it's sources. This is what many manufacturers do and it's perfectly fine as long as source passes the Compatibility Test Suite. I myself saw encrypted video playback issues on Huawei P20 related to their approach to customizing the ROM.
But getting back to the point - you can get the exact framework code running on your device from /system/framework/arm/boot.oat or boot-framework.oat or /system/framework/boot.vdex. I don't know exactly how these files are structured but it varies between Android versions and between manufacturers. Once you get these files by adb pull (You surely need root to do this) you can perform oat->dex, dex->jar using dex2jar or other tools and you'll get the source. Traditionally it was possible to get framework code from /system/framework/framework.jar but after ART was introduced these files are often empty on system images and precompiled framework code is used instead.
I believe I ran into a similar issue on my phone, but I am using a Google Pixel. I was initially concerned that the phone was compromised somehow. I think it is less likely an issue with Huawei and more likely an issue with Android Studio not keeping the source packages up to date. Your Component Installer screenshot shows Android Studio downloading revision 1 of the SDK Source - yet most SDKs are using a later revision.
I detailed the solution to my problem elsewhere on StackOverflow: Source code does not match the bytecode for Android's View.java

v21 update to Android Studio, now I have activity_main & activity_main (v21)? Where do I work?

Android Studio was giving me a warning regarding an update to v21, so I did it. Now under my activity_main folder I have 2 files: activity_main and activity_main (v21). If I work on the activity_main folder, will Android studio update both files? Is the (v21) file necessary? I'm not sure what to do with it.
Stack Overflow encourages these types of questions to be downvoted/flagged/removed, but I will do a little bit better.
When you see sub/similar folders in your res/ folder (resources), what you’re seeing is/are alternate resources that will be used if the config_qualifier matches.
E.g.:
The layouts value folder is often seen to have layouts-v21 or similar versions.
Say you have this XML:
res/layout/main.xml
and you need to provide a layout for devices running API 21 or higher that contains a specific widget/view that only works on API 21…
One solution (but not the only one) is to provide an alternate resource for those devices and fallback to the original one, when not found:
res/layout-v21/main.xml
Android will automagically pick the “correct” one for you at runtime, if the device is running on API 21 or higher.
if you don’t provide it (say you only have main in the /layout folder, not the v21), when android fails to find it in layout-v21, it will try to go to the next (by precedence), in this case, just /layout.
If it can’t find it there, you will get an exception. :)
And that's “resources” 101. Hope it helps.
Now… to answer your question. You will need to work on “both” if they are different. In truth, depending which minApi you support (apparently below 21, otherwise you wouldn’t need to make an exception). If that’s the case (you’re supporting older than 21 devices), then yes, you need to work on both to ensure they work on all platforms.
Alternatively, for layouts, it’s usually not needed to have both. I’d say it’s preferred to have a single common layout, and specify styles.xml and themes in the respective v21 sub-folders.
What I mean is… if some_attribute only works on API 21+, you could have a:
values/styles.xml that doesn’t have the some_attribute and a
values-v21/styles.xml that has it. There are multiple ways to work around this and sometimes you do have to “copy paste” things to duplicate them. If you can support api 21+, them you will less often have to make these exceptions. (Since API 21 and 23 brought a load of changes… it’s common to make the distinction right there at that API level, like Android Studio does for you, because API 21 brought a lot of things that are unsupported in lower apis).

Android Debugging with Eclipse on my HTC Evo: Augh!

I've turned on USB debugging. I have the latest HTC Sync and android SDK components. I'm using Eclipse 3.5 on windows XP. I'm running Android 2.2, and am asking for 2.1 as the minimum in the debugger. I work in Eclipse/Java just about every day, and have for several years. I'm even writing an Eclipse plugin at work as I type this.... neither Eclipse nor Java are new to me by quite a stretch.
When I start a debug session for the "Skeleton App" sample project, I can see my Evo, and the activity launches (with any freshly saved changes), should I select it.
BUT: my breakpoints are ignored, and logCat doesn't see my app's output(see comments below).
*W*hat a *T*errible *F*ailure (As the api so artfully puts it)!
(oh look... a formatting bug. Looks like bold text wants white space to function properly 10/15/2010)
I have tried different android connection types (charge only, disk drive, HTC Sync, and USB tethering) to no avail. I've tried Eclipse 3.6 for a bit before yielding to the inevitable and reinstalling 3.5. I monkeyed with the emulator for a while but ran into a different set of issues (I had to reboot the emulator every time I wanted to make a change... Eclipse's auto-build/hot-swap has me spoiled).
Is there something I can add to (or remove from) the AndroidManifest.XML to deal with this? A magical incantation perhaps? Must I pray towards San Jose three times a day on a rug woven from kernel gurus' vast and scruffy beards? Is my Evo not Kosher? Must I be "sky clad" while debugging? Shall I teach my laptop to genuflect?
Have you followed all the points from here ? You need to set a flag in the manifest and also enable debugging on the actual device.
I found the solution to the debugger issue. Google comes through again:
I found an IOException hiding in my DDMS log: Address family not supported by protocol family: bind
Googling for that, plus "android" turned up the answer in the first link. Windows Vista specifies "localhost" as ":::1", but android doesn't really support IPv6 yet. Changing localhost to "127.0.0.1" resolved the issue.
This is defined in c:/windows/system32/drivers/etc/hosts. I needed to run notepad "as admin" in order to save the changes.
I also have an HTC Evo 4G, and have been having the same debugging problems with Eclipse Helios (3.6). I just learned to use this debugger a day or two ago, and it worked fine. I noticed that there was an automatic Android OS update in the last day or two, also. Perhaps this is just a coincidence.
BUT - my beard was indeed scruffy yesterday, as you suggest, and the debugger was working. I've since shaved. Bad idea, apparently.
Butt seriously - I powered down both Evo and computer (HP running Vista), removed battery from both, then started over. Same result, that is, no debugging.

Categories

Resources