Wednesday, March 22, 2017

Manipulating the UI of existing native applications at runtime

Leave a Comment

I know this sounds "hacky" but I would like to personalize some UIs of the applications I have already installed in my Android. E.g. Using the same fonts, colors, etc. I know this sounds weird but I'm not thinking in creating an app for others but me, so it is not a problem if I have to root my phone or have it in debug mode. Any clue?

PS: I already saw some answers suggesting to decompress/compress the apk, but I don't want to modify the applications' sources, just injecting some style (as Stylish extension do it for Web applications) at runtime.

PS2: As Cordova apps are built with Web technologies, it may be possible to have a DOM to manipulate but how to do it from the outside?

Thanks in advance!

1 Answers

Answers 1

Disclaimer: since the question is very general, so is this answer.


Let's consider the example of the CyanogenMod (now retired...) Theme Engine. Here are some excerpets from an article that described how it worked (emphasis added here):

At the most basic level, themes are simply a mechanism to allow resources to be replaced at runtime ... just think of them as the elements which make up the application’s UI. Whenever an application is started, Android loads up the resources associated with that app and the application makes requests for these resources.

Normally...

That’s the normal flow of retrieving resources, but what happens when a theme is applied? When the system loads the resources for the application, it checks if there is a theme applied and if there is, it adds the themed resources to the original resources. This is the point at which the magic happens. When the app requests a resource, the system will check if there is a themed version of it and if so, returns the themed resource, and if not it simply returns the original. The key point here is the original resources are never modified/moved/altered, the system simply returns a resource from the theme instead of the original. As you can see in the diagram below, there is no difference as far as the application is concerned.

With a Theme present

This is done by leveraging a framework known as Runtime Resource Overlays, which was contributed to AOSP by Sony in 2014. Part of the RRO framework is a tool called IDMAP. IDMAP inspects the resources in an application and compares the resource types and names to those in the themed resources. For those resources that match it stores a mapping of the original resource to the matching resource in the theme. Once this process is complete we are left with an efficient way to determine if a resource is themed and where that resource resides.

... and it goes on some more.

A more recent tool that does this is called Substratum1, 2.

I think these should get you on the right path.

If You Enjoyed This, Take 5 Seconds To Share It

0 comments:

Post a Comment