[Galaxy Tab 10.1 Android Development] Hooolm:
:mad: BACKGROUND

If you use an Android tablet to surf the web, you often face the issue that if you visit a web site that has a mobile version, the server checks your User Agent and says "Android, eh? You're a phone!" - and bumps you to mobile.nfl.com instead of www.nfl.com, which sucks because phone optimized web sites tend to look bad on a 10.1" 1280x800. For example, you want this not this.

So, you can handle that quite easily, you ask the browser to present itself as something else.

:confused: CAUSE

Default, my tablet presents itself as...

Mozilla/5.0 (Linux; U; Android 3.1; en-gb; GT-P7500 Build/HMJ37) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 Safari/534.13

...and that's when all the web sites say "Android, aha! You're a phone!"

But I can instruct the tablet browser to present itself as anything else, for example...

Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.215 Safari/535.1

...which is handy because it makes all the web sites say "Aha! You're a Chrome browser running on MacOS X 10.7 Lion!", therefore showing me the proper web sites.

:rolleyes: ONE SOLUTION

You can do this by decompiling /system/framework/framework-res.apk

Open /res/values/strings.xml, search for the string "web_user_agent" and you'll see this:

<string name="web_user_agent" formatted="false">Mozilla/5.0 (Linux; U; Android %s) AppleWebKit/534.13 (KHTML, like Gecko) Version/4.0 %sSafari/534.13</string>

You can change this blue string into whatever you want.

However, if you do this you're stuck without a proper "android" user agent.

That could be a pain in the ass if you've got an app that relies on a hidden browser window to complete a sign-in authentication, checking the user agent in the process...*cough*NFLGamePassForAndroidTablet*cough* :eek:

:D ANOTHER, MORE ELEGANT, SOLUTION

The more elegant version, however is decompiling /system/app/Browser.apk

Open the file /res/xml/advanced_preferences.xml if you want the menu item in Advanced settings

or open the file /res/xml/general_preferences.xml if you want the menu item in General settings

Insert this…

<ListPreference android:entries="@array/pref_development_ua_choices" android:title="@string/pref_development_uastring" android:key="user_agent" android:defaultValue="0" android:entryValues="@array/pref_development_ua_values" />

... somewhere, between/above/below some other node. I've put it over the ...

<com.android.browser.search.SearchEnginePreference …

... node, giving me this new menu item in Advanced...

... opening this menu ...

Compile it back and there you go.

This fix is basically just shortcutting around the about:debug route by moving the option out of the hidden debug menu, but it's quite convenient to have the option easily accessible without entering debug mode, and you're not stuck without an "Android" user agent.

HOW TO DO THIS, STEP BY STEP.

(mirrored from post #25)

Teaching has never been my strong feat but I'll give it a shot.

Please note:

The "Setup to build" part is for Windows, recreated from memory, and may be inaccurate. I love you guys but I'm not gonna wipe my system and start over just to retrace my steps ;)

For the entire guide, I'm pre-supposing basic computer skills, a rudimentary understanding of ADB, folder structures, file management, text editing and "what do you mean command line??!" :)

== Set up to build:

If you don't have Java installed, download and install Java from java.com

Download APK Manager 5 and remember to thank the guy.

Place it in a folder in C:\ so you have a directory stucture like this:

C:\apkmanager5

C:\apkmanager5\other

C:\apkmanager5\place-apk-here-for-modding

...etc

C:\apkmanager5 is the home dir for our purposes, so from now on assume we're in C:\apkmanager5 unless I say otherwise.

Run Script.bat

Select 24 "Exit"

(this should create any dirs and logfiles that may be missing)

== Get the required files and prepare for editing

Pull the following .APKs from your phone via ADB or extract them from your ROM.zip to /place-apk-here-for-modding in our homedir. You should make a backup of at least Browser.apk, just in case.

/system/app/Browser.apk

/system/framework/framework-res.apk

/system/framework/twframework-res.apk

Run the following commands from a command prompt in our home dir:

java -jar other/apktool.jar if place-apk-here-for-modding/framework-res.apk

java -jar other/apktool.jar if place-apk-here-for-modding/twframework-res.apk

The command line will return:

I: Framework installed to: C:\Users\((username))\apktool\framework\1.apk

I: Framework installed to: C:\Users\((username))\apktool\framework\2.apk

== Decompile and edit

Run Script.bat

(this will open the apkmanager window)

Enter 19 "Select compression level for apk's"

Enter 0 (compression=0)

Enter 22 "Set current project"

Select the number for "Browser.apk"

Select 9 "Decompile apk"

It'll say "Decompiling apk" and hang for a while.

Open a file explorer/total commander/whatever on your computer, and go to /projects in our home dir. You'll see that we now have the decompiled Browser.apk in there.

Go to /projects/Browser.apk/res/xml/ and open general_preferences.xml with a text editor. Notepad, Notepad++, Ultraedit or something, not Word ;)

Add the purple code, so the content looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android">
[COLOR="Indigo"][I][B]<ListPreference android:entries="@array/pref_development_ua_choices" android:title="@string/pref_development_uastring" android:key="user_agent" android:defaultValue="0" android:entryValues="@array/pref_development_ua_values" />[/B][/I][/COLOR]
<com.android.browser.BrowserHomepagePreference android:hint="@string/http" android:maxLength="8192" android:title="@string/pref_content_homepage" android:key="homepage" android:inputType="textMultiLine|textUri" />
<PreferenceCategory android:title="@string/pref_general_sync_title">
<Preference android:title="@string/pref_personal_sync_with_chrome" android:key="sync_with_chrome" android:summary="@string/pref_personal_sync_with_chrome_summary" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/pref_general_autofill_title">
<CheckBoxPreference android:title="@string/pref_autofill_enabled" android:key="autofill_enabled" android:summary="@string/pref_autofill_enabled_summary" android:defaultValue="true" />
<PreferenceScreen android:title="@string/pref_autofill_profile_editor" android:key="autofill_profile" android:summary="@string/pref_autofill_profile_editor_summary" android:fragment="com.android.browser.AutoFillSettingsFragment" />
</PreferenceCategory>
</PreferenceScreen>

The purple code shows the UAstring item in General Preferences just above the "Set homepage" item.

== Compile

Go back to the apkmanager window.

Select 11 "Compile apk"

It'll output "Building Apk" and think about it for a while.

Apkmanager will ask, "Is this a system Apk?"

"y" - yes it is.

Then it will ask, "Aside from the signatures, would you like to copy over any additional files that you didn't modify from the original apk in order to ensure least # of errors?"

"y" - yes, you want to do that.

apkmanager will extract those original files and then present you with this screen:

Read that, then I'll explain it :)

Right. At this point apkmanager has made a copy of the original, compiled Browser.apk files in C:\apkmanager5\keep

As the name "keep" suggests, whatever is in here will be kept and carried on to your new build, so:

For every file that you have changed in /projects/Browser.apk/, you need to delete the counterpart in /keep/.

That way, apkmanager knows to keep your unchanged files unchanged but grab your changed file(s) from /projects/Browser.apk. It may seem like dumb way of doing it but it makes sense that you don't want your computer to compile more than it has to. Compiling takes time and CPU, and...well...the less is done, the less can go wrong.

In this case you edited /projects/Browser.apk/res/xml/general_preferences.xml

So you have to delete /keep/res/xml/general_preferences.xml

AND you have to delete /keep/resources.arsc as well!

Whenever you have changed any XML in an .apk, you also have to delete /keep/resources.arsc when compiling. The apk's resource table is compiled into resources.arsc, so if you dont delete it from keep/, you're gonna keep that and carry it over into your new, modified Browser.apk, and your changes won't come through :)

Ok, after deleting those two files, you "Press any key to continue ...", all the resources are compressed, and now you have a modified Browser.apk in place-apk-here-for-modding/

Wrap it in a flashable zip and flash it.

("How" is outside the scope of this guide)

As it turns out, this is actually a rather general guide on decompiling, editing and recompiling stuff for honeycomb. You can use the exact same method to edit other apks like, framework-res.apk and SystemUI.apk.