FORUMS
Remove All Ads from XDA

[GUIDE] Locating hidden values, random dialogs and hardcodes (AOSP/TW/Sense/XH)

5,962 posts
Thanks Meter: 13,341
 
Post Reply Email Thread
Introduction

Remember a time when an unthemed popup popped up in an app, and you tried all that you could to change the colors of it, then found out it wasn't even in the app you spent hours on at the first place? Damn right I do!!! Wasted so much of my youth looking for things in the wrong place.

In this guide I will be going over a desktop application called "Android Device Monitor", and how to use it for theming. This program is not bound to theming, as it can help many ROM developers like locating a CP'd commit and forgot where to set a textColor was set in a dialog. For example: https://github.com/TeamBliss-LP/andr...32dfa17313e215.

The guide will also outline other methods to locate hardcoded colors on most apps, and this is not bounded by device. This will theoretically work on any device running Android, as long as you enable USB debugging on your device. So it should theoretically work on TouchWiz, AOSP, CM, Sense, LG Home, XperiaHome, etc...

Most importantly, if your friend comes over with a non-rooted phone, fret not, this DOES NOT require root. So! If you happen to stumble here from a link I requested you to follow, I'll assume you're either a themer, or you're a user of a theme. For users, this guide would be used to aid the themer when the themer does not have access to what you are seeing in an app due to differences in software/region bound software/firmware versions/custom ROMs. For themers, I hav known about this trick for a while but haven't gotten the time to write it - but this saves me precious time solving "unsolvable" issues, like during the days when we didn't have Setting's dashboard exposed (before the January 27th commit).

To understand how this works, we have to understand how Android system works. We can change many colors through colors.xml, but styles, layouts and java can also change colors. We have to remember this structure. Left is greater than the corresponding right.

Java > Layout > Styles > Colors

In this guide, I will be focusing on using ADM to locate colors/usages of resources within Layouts, thus allowing you to locate things within styles/colors.

ATTENTION

This guide is NOT 100% guaranteed.

As many third party apps like Google+ designs it's layout through the java, and the overall code of the application. Using Android Device Monitor, it is the first steps of beginning to theme.

This guide is meant to be a STARTING GROUND when you face any issue. I cannot guarantee any success, but this has helped me find out whether many things are hardcoded or not. So having this as a utility will greatly help a lot of people new to theming!

I also do NOT have access to a TW/Sense/LG Home/XH device, so if you have any issues (non-connection issues) with using ADM to trace your screen, please tell me. But theoretically, this should work on any device.

What is Android Device Monitor?

Android Device Monitor is a desktop application that traces the running programs of your device connected to your PC. You can use this to debug as it shows many useful information.

But for this guide, I will use it to show how to use it to take a screenshot XML dump of your phone's screen, and you can mouseover the elements of your screenshot on your screen to locate the layout of the app, or whatever is on your screen.

Wow! That sounds cool! How do I get it?

All you have to do is install the Android Studio package from Google, and you will get it preinstalled with it.

You can download Android Studio from this link: http://developer.android.com/sdk/ind...FRCpaQodrhwHng

Make sure you install the prerequisite packages once installing and setting up Android Studio. This includes the complete SDK.

If you would like to install just the SDK, that is possible too: https://developer.android.com/sdk/in...html?pkg=tools

Make sure you install Android SDK Tools in the SDK Manager. Android Studio method is recommended as it comes with everything pre-installed once setting everything up.

Let's get started, shall we?

(*) Make sure you have installed adb/fastboot on your computer prior to continuing: http://forum.xda-developers.com/show...php?p=48915118
A great text editing tool is Notepad++, available here: https://notepad-plus-plus.org/

ON YOUR PHONE/TABLET
I will be using a Lollipop based CM ROM in this tutorial. Keep your device unplugged at this point.
  1. First you have to enable Developer Options by going into About Device in Settings, then clicking the Build number 7 times. This enables Developer Options directly in the main menu of Settings.
  2. Once activated, go into Developer Options
  3. Scroll down until you see Android debugging, then activate that.
  4. Plug your phone into the computer
  5. At this point, a popup will appear on your device to verify the RSA fingerprint of your computer. Click Always Allow from this Computer.
  6. ATTENTION: If you did not get a popup, adb is NOT installed correctly/your phone is not detected in ADB mode, or your computer does not have it set up properly. Follow my link above to get it set up quicker than using Android Studio's method. (*)
  7. Once you agreed to the popup, then go to the screen where you want to see what the problem is. For example, you want to find out why there is a random white dialog when toggling GPS telling you to improve location accuracy.
  8. Keep the screen turned on/turn on Stay Awake in Developer Options so it will keep your phone awake while plugged in. After this step, you have successfully finished using your phone.

ON YOUR COMPUTER
  1. ATTENTION: If you already use Android Studio to build your theme, you can skip steps 2 and 3. Also to note, you can always use search and locate the "monitor.exe" file in your Android Studio directory, but that is too fussy, as it likes to error out a lot.
  2. Open Android Studio, and create a new project, you need to Start a new Android Studio Project, follow all the steps till you click Finish.
  3. You may or may not be greeted with a couple of popups, just dismiss them.
  4. Once you get to a window with an available toolbar, click on Tools -> Android -> Android Device Monitor.
  5. ATTENTION: If you're running Android Studio 1.4.1 and above, click on the icon in the toolbar.
  6. On first launch you will get this popup, click Proceed
  7. Your phone will appear on the left, including all the processes and background services running on your phone.
  8. Click on your device, and click on the Dump View Hierarchy for UI Automator icon, an icon that should be next to the camera, with three stacked phones.
  9. At this point, the computer will dump whatever is on your screen, if your screen is off, it will dump a black screen, so you should have kept it awake.
  10. Once complete, you will want to hover over the unidentifiable object on your screen. So if the white dialog (as mentioned previously) when toggling location is a bother, we hover over the screen's focused dialog, and click on it. When selected, the area has a red rectangle.

You will then see a table on the bottom right identifying all its attributes. But most importantly, you will want to see that it is actually in package ID com.google.android.gms (Google Play Services), so you must invert that/theme that.


You can see how the table above told me that the package ID was com.google.android.gms, and thus I was able to go find it in the decompiled APK of Google Play Services.


Also to note, resource-id is also a great way to start, as it tells you the app's layout object ID, which allows you to find it within the app's res/layout folder by using Notepad++ and the Find in Files section. If by any chance, you get no information at all, you should check the structure of the app on the top right, and locate within layouts folder as well. For example, if you see a FrameLayout and textView x2, you have identified the structure of the activity fragment of the app, and it MAY help you for layouts.

In my commit at the beginning of this thread, I was locating an unthemed black text in a dialog, and found out that the dialog's resource-id was "dpi_edit", so I searched in res/layout using N++'s Find in Files tool and found out that it was in this file: https://github.com/TeamBliss-LP/andr...text_entry.xml. So I made the change to the textColor and pushed the commit to the source. Thus allowing users to have a visible DPI text color, even though we expected that the ?attr should work.


Demonstration on how to reverse locate a specific color
  1. Let's find something specific using this trace method, so for example, I would like to find the background of the switch bar in Settings. Pretend I don't know how. So following my above steps, I'm able to reach this:
  2. We see that under resource-id in the Node Detail box, it says: com.android.settings:id/switch_bar -- so we should search for switch_bar under res/layouts of com.android.settings (your decompiled settings).....
  3. We go into Notepad++, and use the Find in Files feature (Search -> Find in Files) and type in the resource-id after ":id/", which is "switch_bar"
  4. Click Find All and wait for it to finish. Afterwards, you will get a list of results with a hit. In this case, we have one result.
  5. Double click on the result, and you will be greeted with a layout XML with the ID. In the XML you will see that you have a bunch of stuff there, so with some smarts and some logic on the same line, you can see if the background is set to a hardcoded hex (hardcoded meaning there's a hex code there, as you can't modify layouts in CMTE, or is it rerouted to another color)
  6. We can see that the background was linked to a color variable, "switchbar_background", now change that in com.android.settings/res/values/colors.xml, then you tell me if I'm correct If you see something else in there, or are a ROM developer and trying to expose some values, replace the hardcoded hex to a rerouted color in the corresponding app's colors.xml, and you have successfully exposed it!


Troubleshooting

Q: There is an error every time I launch ADM again! What should I do?
A: The error is normal, just press OK and proceed. (This error in spoiler, if any others, message below)


Q: I keep getting a permission error with my device when I click the button and it doesn't draw my screenshot!
A: This happens when your device is extremely "dirty", a complete clean flash is required. In my case, I fastbooted stock and reflashed my custom ROM. You can try wiping data, as the permissions lie somewhere there.

Q: I still can't get my theme to theme the hardcoded thing, help!
A: As I said, this doesn't work for all cases, this is only a starting and ending ground to see if it is themable. If you can't find out what to do, then chances are you did everything you can!

Q: Any other tips?
A: If you really can't find it, but you have a specific color you want to get rid of, try using Photoshop's Eyedropper tool to pick out the color from the screenshot, then use Notepad++ to search for this color. You should find the hex from the color by clicking the color palette.

Q: What about using backgroundTint?
A: You can use this to target many white hardcoded (definite) backgrounds by adding a backgroundTint attribute, but this may affect other things, like the Paste tooltip will take on this backgroundTint thus you can't read the "Paste" text. But definitely, this is a great way to start targeting white backgrounds!

Q: I have more questions!
A: Post in the thread and tag me using @nicholaschum, I'm more likely to check if I get a notification.

XDA:DevDB Information
[GUIDE] Locating hidden values, random dialogs and hardcodes (AOSP/TW/Sense/XH), Theme for all devices (see above for details)

Contributors
nicholaschum

Version Information
Status: Stable

Created 2015-11-03
Last Updated 2015-11-06
The Following 23 Users Say Thank You to nicholaschum For This Useful Post: [ View ]
 
 
3rd November 2015, 08:22 PM |#2  
nicholaschum's Avatar
OP Recognized Developer / Recognized Themer
Flag University of Toronto St. George (Hometown: Hong Kong)
Thanks Meter: 13,341
 
Donate to Me
More
Reserved
3rd November 2015, 08:22 PM |#3  
nicholaschum's Avatar
OP Recognized Developer / Recognized Themer
Flag University of Toronto St. George (Hometown: Hong Kong)
Thanks Meter: 13,341
 
Donate to Me
More
Reserved
3rd November 2015, 09:13 PM |#4  
Troubadour666's Avatar
Recognized Contributor
Flag 43.7031 - 7.2661
Thanks Meter: 7,153
 
More
Thanks.

Sent from my GT-I9100 using XDA Free mobile app
4th November 2015, 12:31 AM |#5  
starbucks2010's Avatar
Senior Member
Thanks Meter: 1,095
 
Donate to Me
More
I always get a black screen on my PC. How can I solve it? My phone screen is always on.

Thank you for the guide.
4th November 2015, 12:34 AM |#6  
nicholaschum's Avatar
OP Recognized Developer / Recognized Themer
Flag University of Toronto St. George (Hometown: Hong Kong)
Thanks Meter: 13,341
 
Donate to Me
More
Quote:
Originally Posted by starbucks2010

I always get a black screen on my PC. How can I solve it? My phone screen is always on.

Thank you for the guide.

Hmm, that's a bit strange, because black screen is mainly when your screen is off, are you seeing the background processes of the app on the left of ADM?
4th November 2015, 01:02 AM |#7  
starbucks2010's Avatar
Senior Member
Thanks Meter: 1,095
 
Donate to Me
More
Solved. Actually, I have to have the screen on in the moment I start to take the "screenshot" of my phone. It's ok now.

I'm still looking for that white contact detail background ...

PS. Do you know what it means class = android.widget.RelativeLayout ? It doesn't give too much details so I don't know where should I search for it?
Thank you.
4th November 2015, 02:11 AM |#8  
nicholaschum's Avatar
OP Recognized Developer / Recognized Themer
Flag University of Toronto St. George (Hometown: Hong Kong)
Thanks Meter: 13,341
 
Donate to Me
More
Quote:
Originally Posted by starbucks2010

Solved. Actually, I have to have the screen on in the moment I start to take the "screenshot" of my phone. It's ok now.

I'm still looking for that white contact detail background ...

PS. Do you know what it means class = android.widget.RelativeLayout ? It doesn't give too much details so I don't know where should I search for it?
Thank you.

That means that the layout is using a RelativeLayout. It's a type of layout configuration. You should use N++ to see if you can find that RelativeLayout, as not all xmls have that layout.

Sent from my Xperia Z3 Tablet Compact LTE using Tapatalk
The Following User Says Thank You to nicholaschum For This Useful Post: [ View ]
4th November 2015, 12:27 PM |#9  
Jumba's Avatar
Senior Member
Flag Johannesburg
Thanks Meter: 710
 
Donate to Me
More
Thank you, great guide!
The Following User Says Thank You to Jumba For This Useful Post: [ View ] Gift Jumba Ad-Free
6th November 2015, 10:26 AM |#10  
starbucks2010's Avatar
Senior Member
Thanks Meter: 1,095
 
Donate to Me
More
For themers, this is the best guide and most useful, ever. It should be a sticky.

Thank you very much Nicolas.
The Following User Says Thank You to starbucks2010 For This Useful Post: [ View ] Gift starbucks2010 Ad-Free
6th November 2015, 03:44 PM |#11  
abo hani's Avatar
Senior Member
Flag St. Wendel
Thanks Meter: 4,614
 
More
Well, in the new version of Android Studio, there's no option for UI, Only Camera / Print, and other Monitor related options.
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes