hoelz.ro - Adding DuckDuckGo as an Android Browser Search Engine

Adding DuckDuckGo as an Android Browser Search Engine

A little while ago, I switched to DuckDuckGo as my primary search engine. However, the default browser on Android only offers me three choices: Bing, Yahoo, and Google. I figured that since the browser component of Android is open source, it shouldn't be too hard to add DuckDuckGo to the mix. So here's how I did it.

NOTE: I did a full backup using Titanium Backup before doing this. I also did this on a phone running CyanogenMod; you should be able to do this with a regular rooted phone, just compile from the Android project source instead of the CyanogenMod source. This worked for me, but I take no responsibility if you brick your phone attempting to do this!

Download the Android Browser Source

I figured that building the browser APK would be as simple as grabbing the source and running ant. Grabbing the source is easy, as the Android Git repository is hosted at http://android.git.kernel.org/. However, I use the CyanogenMod firmware for my phone, so I figured it'd be a better idea to build from their Git repository:

$ git clone git://github.com/CyanogenMod/android_packages_apps_Browser.git

I took a look at the files I'd just downloaded, and a build.xml file was nowhere to be found. The only thing close to resembling a build file was the Android.mk file, and some quick searching showed that that file was part of the Android build system. No matter, I thought; I'll just generate a build.xml using the android utility and use that! I don't want to build the whole Android project; I just want to build a custom browser!

$ android update project -p . --target 7 # Target 7 is the Android 2.2 SDK in my setup, since I'm using CyanogenMod 6

Well, that was painless!

$ ant release # fails!

Unfortunately, that didn't work either; it complained about some missing classes that are apparently only available when building the whole of the Android project.

Building CyanogenMod from Source

Instead of trying to figure out how to compile the browser by itself, I decided to just check out the full source from Github:

$ repo init -u git://github.com/CyanogenMod/android.git -b froyo-stable # again, CyanogenMod 6
$ repo sync -j16 # go grab lunch or something; this takes a while!

Then, according to the instructions on the CyanogenMod wiki, the next step is to load a setup script:

$ . build/envsetup.sh

This makes a few convenience functions available for building the Android source, mainly m, which builds the whole thing.

$ m

I ran this to make sure that the browser builds, and sure enough, it did!

Adding DuckDuckGo to the Search Engine List

Now that I have the build environment set up, I can make my modifications. It turns out that the search engine information is stored in two resource files, res/values/all_search_engines.xml and res/values/search_engines.xml. The former stores the localized names, addresses, and search engine patterns for each search engine, and the latter lists the search engines that the browser actually uses. So after a little editing, my res/values/search_engines.xml looked like this:

  1. <resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
  2. <string-array name="search_engines" translatable="false">
  3. <item>google</item>
  4. <item>yahoo</item>
  5. <item>bing</item>
  6. <item>ddg</item>
  7. </string-array>
  8. </resources>

…and I added the following to the end of my res/values/all_search_engines.xml:

  1. <string-array name="ddg" translatable="false">
  2. <item>Duck Duck Go</item>
  3. <item>duckduckgo.com/</item>
  4. <item>http://duckduckgo.com/favicon.ico</item>
  5. <item>http://duckduckgo.com/?q={searchTerms}</item>
  6. <item>UTF-8</item>
  7. <item>http://duckduckgo.com/?q={searchTerms}&amp;o=json</item>
  8. </string-array>

Re-build, and lo and behold, there's a Browser.apk under out/target/product/generic/system/app!

UPDATE: For CyanogenMod 7's browser source (and possibly Gingerbread's as well), res/values/search_engines.xml has become res/values/donottranslate-search_engines.xml.

Installing the new Browser.apk

Installing the new APK isn't as easy as just opening it in the package manager, since it's located under /system/app, which is read-only by default. You need to plug your phone in, turn on USB debugging, remount the filesystem to make it writable, delete the old Browser.apk, and install the new one.

$ adb remount
$ adb shell rm /system/app/Browser.apk
$ adb install Browser.apk

I also rebooted for good measure:

$ adb reboot

And here's the end product running on my phone!

Browser Settings Browser Search Search Resuls from DDG!

Discussion

Some oneSome one, 2011/03/03 16:46

Or you could have used https://github.com/johanhil/ddg-android which is in the market.

Rob HoelzRob Hoelz, 2011/03/03 16:50

Right, but that doesn't add the search engine to the browser itself. At least it didn't when I tried it…

andsands, 2011/08/25 23:53

I was looking for this information, Thanks a lot for posting

nandlalnandlal, 2011/10/28 06:19

Any update for newbies or technologically in-apt people such as myself to have DDG as default search engine in DROID OG CM7 (gingerbread 2.3.7). Mr Hoelz has attempted to help me but I don't know where to begin and what to look for as far as removing browser.apk and re-installing new browser.apk. Is there any simpler way to have DDG as search engine? Also any idea about SSl/https also by default? I know there is an option in browser setting whether to turn it on/off “incognito” mode but I want default or that is something not possible due to security certificate issue…

Rob HoelzRob Hoelz, 2011/10/28 13:07

nandlal-

If you have successfully built a new Browser.apk, instructions for adding it are shown in the Installing the new Browser.apk section of this page. As far as adding SSL/HTTPS by default; I'm not sure.

anonanon, 2012/01/30 19:50

Why are you two making it so complicated? Simply change HTTP to https!!

senormarquezsenormarquez, 2012/04/12 20:33

is there anyway you can show screenshots of every step? its not working for me. i'm on CyanogenMod 9

comms.megatroncomms.megatron, 2012/06/07 14:41

For this sort of editing xml files you can also just pull the apk from your phone using adb, use apktool to extract the resources, edit them and then use apktool (available on google code) and an apk signing app (search zip signer 2 in the market) to recompile the app. In android the xml resources are not compiled so are easy to extract and change. So (for cyanogenmod 9):

$ adb pull /system/app/Browser.apk $ apktool d Browser.apk Browser $ nano Browser/res/values/arrays.xml add:

<string-array name="duckduckgo">
      <item>DuckDuckGo</item>
      <item>duckduckgo.com</item>
      <item>https://duckduckgo.com/favicon.ico</item>
      <item>https://duckduckgo.com/?q={searchTerms}</item>
      <item>UTF-8</item>
      <item>https://duckduckgo.com/?q={searchTerms}&amp;o=json</item>
  </string-array>

$ nano Browser/res/values-en-rGB/arrays.xml add:

  <string-array name="search_engines">
	<item>duckduckgo</item>
      <item>google</item>
      <item>ask_uk</item>
      <item>yahoo_uk</item>
      <item>bing_en_GB</item>
  </string-array>

$ nano Browser/res/xml/andvanced_preferences.xml change: <com.android.browser.search.SearchEnginePreference android:title=”@string/pref_content_search_engine” android:key=“search_engine” android:summary=”@string/pref_content_search_engine_summary” android:defaultValue=“google” android:dialogTitle=”@string/pref_content_search_engine” /> to: <com.android.browser.search.SearchEnginePreference android:title=”@string/pref_content_search_engine” android:key=“search_engine” android:summary=”@string/pref_content_search_engine_summary” android:defaultValue=“duckduckgo” android:dialogTitle=”@string/pref_content_search_engine” />

$ apktool b Browser Browser.apk $ adb push Browser.apk /sdcard/Browser.apk

sign apk install done!

Rob HoelzRob Hoelz, 2012/06/07 14:45

Sorry, I didn't see your comment! I haven't tried this with CM9 yet, but it should work similarly.

Olivier MehaniOlivier Mehani, 2012/07/11 03:00

I'm currently trying the same thing on a CM9 build for my phone. It seems that res/values/search_engines.xml (all paths relative to the Browser/ directory) has been replaced by res/values/all_search_engines.xml. However, that file is created as part of the image build process by a Python script in tools/get_search_engines.py. This Python script takes its list of search engines from the Chromium source at http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/search_engines/template_url_prepopulate_data.cc.

I updated an issue on Chromium to mention it [0]. Hopefully, it will get there at some point!

In the meantime, thanks for the tip!

[0] https://code.google.com/p/chromium/issues/detail?id=101865

Olivier MehaniOlivier Mehani, 2012/07/11 03:01

I'm currently trying the same thing on a CM9 build for my phone. It seems that res/values/search_engines.xml (all paths relative to the Browser/ directory) has been replaced by res/values/all_search_engines.xml. However, that file is created as part of the image build process by a Python script in tools/get_search_engines.py. This Python script takes its list of search engines from the Chromium source at http://src.chromium.org/viewvc/chrome/trunk/src/chrome/browser/search_engines/template_url_prepopulate_data.cc.

I updated an issue on Chromium to mention it [0]. Hopefully, it will get there at some point!

In the meantime, thanks for the tip!

[0] https://code.google.com/p/chromium/issues/detail?id=101865

Enter your comment
If you can't read the letters on the image, download this .wav file to get them read to you.
 

Recent changes RSS feed Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki ipv6 ready