Settings

Theme

Spying on Android events without modifying source code

kamalmarhubi.com

42 points by kalmar 9 years ago · 5 comments

Reader

pawadu 9 years ago

I wonder if you can achieve the same thing by inserting a debug class that replaces the original parent. That is, change the code to go from

    View <-- MyView
to

    View <-- DebugView <-- MyView
You might even be able to do this without decompiling the code.
  • on_and_off 9 years ago

    That's the idea behind the probe lib : https://github.com/lucasr/probe/blob/master/library/src/main...

    So, when you write an android app, most of time you describe your ui's layout in xml files. This xml is then translated to a binary blob during the compilation (you don't have to know/care about this intermediary format though). When you need the corresponding ui, you use a layoutInflater in order to 'inflate' the xml : read its content and create the corresponding views.

    One nifty trick is that since the LayoutInflater instantiate the views, it is the perfect place to replace a view by another. For example, that's how the support lib works (well, modulo some hacks, the layoutInflater was not thought out for this initially). When you ask for an ImageView in your xml, the support lib provides you with an AppCompatImageView instead, adding some new capabilities independently of the OS version.

    probe goes a little bit further and dynamically add some methods to any class that it inflates, in order to add some layout debugging capabilities.

  • kalmarOP 9 years ago

    (OP here) I think that would be a useful thing to do in some situations, but it often won't get what you'd like. There's no guarantee that a view will ever call it's superclass' implementation, so inserting code has to be done a the leaf view classes not further up.

  • microcolonel 9 years ago

    When it comes to Java, it might be simpler to decompile anyway; but yeah, totally doable.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection