Mobile/Fennec/Android/CommonTips: Difference between revisions

From MozillaWiki
< Mobile‎ | Fennec‎ | Android
Jump to navigation Jump to search
(Created page with "== Common Tips and How-To's == === Finding relevant code === Almost all of the Fennec-specific code is in the mozilla-central source tree under: mobile/android/... Of par...")
 
Line 13: Line 13:


If you are looking for something specific, use the code-search tool at http://dxr.mozilla.org/ to search for relevant pieces of code.
If you are looking for something specific, use the code-search tool at http://dxr.mozilla.org/ to search for relevant pieces of code.
=== Coding Style ===
The Java style follow the [https://developer.mozilla.org/en-US/docs/Developer_Guide/Coding_Style#Java_practices Mozilla Coding Style].
==== Common nits in Reviews ====
Check for these nits before asking for review for a patch:
* Remove trailing whitespace
* Spacing
** Four spaces for Java indent (for main Fennec code - [https://github.com/mozilla-services/android-sync android-sync github project] has different spacing)
** Around operators (+, -, etc.) and :
** Between comment "//" and text
* Braces for Java if statements, even if they are one line
* Comments should be full sentences (capitalization, punctuation)
** Good comments are useful and clear even for someone reading a particular area of code for the first time
* Avoid using single-letter variables in almost all cases - it makes code harder to read


=== Debugging ===
=== Debugging ===
Line 18: Line 34:


For Android Java code, if you have IntelliJ set up, the debugger works well and allows you to set breakpoints, inspect variables and objects, etc. Debugging without an IDE is much more primitive, and you can try using Android Log statements and inspecting logcat.
For Android Java code, if you have IntelliJ set up, the debugger works well and allows you to set breakpoints, inspect variables and objects, etc. Debugging without an IDE is much more primitive, and you can try using Android Log statements and inspecting logcat.
See http://developer.android.com/tools/debugging/ddms.html


=== Lint ===
=== Lint ===

Revision as of 01:09, 11 September 2015

Common Tips and How-To's

Finding relevant code

Almost all of the Fennec-specific code is in the mozilla-central source tree under:

mobile/android/...

Of particular interest to most new contributors will be:

mobile/android/base/BrowserApp.java # the main Android activity that starts when you open Fennec
mobile/android/chrome/content/browser.js # the main JavaScript file that controls Gecko to make it do what we want

If you are looking for something specific, use the code-search tool at http://dxr.mozilla.org/ to search for relevant pieces of code.

Coding Style

The Java style follow the Mozilla Coding Style.

Common nits in Reviews

Check for these nits before asking for review for a patch:

  • Remove trailing whitespace
  • Spacing
    • Four spaces for Java indent (for main Fennec code - android-sync github project has different spacing)
    • Around operators (+, -, etc.) and :
    • Between comment "//" and text
  • Braces for Java if statements, even if they are one line
  • Comments should be full sentences (capitalization, punctuation)
    • Good comments are useful and clear even for someone reading a particular area of code for the first time
  • Avoid using single-letter variables in almost all cases - it makes code harder to read

Debugging

For the JavaScript parts of the code base, remote debugging with a desktop version of Firefox is the most effective way to see what is going on, add breakpoints, etc.

For Android Java code, if you have IntelliJ set up, the debugger works well and allows you to set breakpoints, inspect variables and objects, etc. Debugging without an IDE is much more primitive, and you can try using Android Log statements and inspecting logcat.

See http://developer.android.com/tools/debugging/ddms.html

Lint

We provide some support for linting tools. See Mobile/Fennec/Android/Lint for a list of linting tools we support and expect to be run.

Add an Android string resource

  1. Add an XML string entity to mobile/android/base/locales/en-US/android_strings.dtd with the English string you want to add.
  2. Add a <string> element to mobile/android/base/strings.xml.in.
  3. Build using mach build mobile/android/base or your IDE.

Your new string should appear in org.mozilla.gecko.R.string. Here's an example patch that adds the single string pref_private_data_syncedTabs.

Why is this necessary? Mozilla's main localization process is based on XML entities. Localization teams localize the XML entity definitions using existing tools, but they do not see strings.xml itself. Building prepares the final strings.xml for use. You can be sure your changes are in place by finding your entity and string in $OBJDIR/mobile/android/base/res/values/strings.xml.

Modify an existing Android string resource

  1. Find the relevant <string> element in mobile/android/base/strings.xml.in.
  2. Find the underlying English string entity in mobile/android/base/locales/en-US/android_strings.dtd. Usually, you'll see <string>&string_entity;<string>; the string entity is string_entity.
  3. If your change is just fixing a typo (spelling error, capitalization, whitespace), just update the android_strings.dtd.
  4. If you are really changing the string, you also need to change the entity name. It's traditional to add or increment a trailing integer, like string_entity2.
  5. Build using mach build mobile/android/base or your IDE.

Your updated string should appear. Here's an example patch that changes several strings, including renaming tab_queue_notification_text_singular to tab_queue_notification_text_singular2.

Why is this necessary? Mozilla's localization process only recognizes new string entities, not modified string entities. (The old, unused entity is automatically ignored and eventually deleted.)

Add a new Robocop test

  1. Add a Java test file named like mobile/android/tests/browser/robocop/testMyThing.java. This will get your test compiled into the Robocop APK.
  2. Add your test file/name section like [testMyThing] to mobile/android/tests/browser/robocop/robocop.ini. Without this, the Robocop test harness will not know about your test!
  3. Optionally add HTML, JS, and CSS resources to folder mobile/android/tests/browser/robocop.
  4. Run mach build to get them built/installed before running your test.
  5. Run mach build build/mobile/robocop to update the Robocop APK.
  6. Make sure you have host binaries downloaded and configured, following Host Builds (MOZ_HOST_BIN).
  7. Run mach robocop testMyThing to run your new test on your device.
  8. Iterate!

Here's an example patch that adds a fairly complicated new testSelectionCarets test.

See also some tips on writing UITests.

Copy a profile from your phone

E.g., to explore with sqlite3. Use Copy Profile.