CloudServices/NativeSync: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
No edit summary
Line 66: Line 66:
=== Running Fennec ===
=== Running Fennec ===
[[Fennec/NativeUI | Building Fennec Native]]
[[Fennec/NativeUI | Building Fennec Native]]
After building birch, make the apk.
make -sj8 -C objdir-droid/ package
The apk will be something like $objdir/dist/fennec-11.apk


* Android device: (WFM)
* Android device: (WFM)

Revision as of 23:57, 2 December 2011

Native Sync

Setup

Setting up an Android dev environment

  • note: installing *all* the platform tools (all Android from 1 to 3.3) takes a while, if you only need a specific SDK version, just install from the GUI tool:
$SDK/tools/android

Emulators

  • create emulator with $SDK/tools/android, menubar>Tools>Manage AVDs...
  • Target (probably) needs to match build specified in .mozconfig (see Building Fennec Native below)
  • to launch:
$SDK/tools/emulator -wipe-data -avd <AVD> -partition-size 2047

(so you don't run into insufficient storage error)

After installation, fennec would crash on installation (unable to locate mozutils library, although it's in the apk). Possibly related to emulator failing to run NDK applications?

Running everything

You'll be wanting to run test-android-sync:

This depends on the android-sync project, as described in the Android testing docs:

android-sync dependencies

android-sync has the following dependencies:

  • sync-crypto, described below.
  • httpclientandroidlib, which provides a working modern version of the Apache HTTPClient under a different Java package.
  • json-simple 1.1 and commons-codec 1.2, which ship with Android.
  • Android 2.3.3.

For testing it requires:

sync-crypto dependencies

sync-crypto relies on Apache commons-codec 1.5, which includes Base32. The Android system libraries include the 8-year-old version 1.2. As a result, sync-crypto is packaged as an assembly jar (aka über jar). Simply run build.sh to instruct Maven to do the right thing.

An up-to-date version is checked in to the external directory in android-sync, with the mvnify script in that directory taking care of installing it in your local repository.

What you need to do

git clone https://github.com/rnewman/base64-unstub
git clone https://github.com/rnewman/log-unstub
git clone https://github.com/mozilla-services/android-sync
git clone https://github.com/mozilla-services/test-android-sync
pushd base64-unstub; mvn install; popd
pushd log-unstub;    mvn install; popd
pushd android-sync/external; ./mvnify; popd
pushd android-sync
mvn test

To do real Android development and testing, you need to import both android-sync and test-android-sync as projects in Eclipse with the ADT installed.

Note that both android-sync and sync-crypto have JUnit 4 tests that run in both Eclipse and Maven. android-sync also provides functionality to test-android-sync, which includes Android JUnit 3 tests for activity and store testing. This is to avoid the mammoth annoyance of testing in a VM without introducing robolectric.

Running Fennec

Building Fennec Native

After building birch, make the apk.

make -sj8 -C objdir-droid/ package

The apk will be something like $objdir/dist/fennec-11.apk

  • Android device: (WFM)
    • enable USB debugging: Settings > Applications > Development > USB debugging
$SDK/platform-tools/adb install -r <path-to-apk>
  • Emulator:
$SDK/tools/emulator
(as another process:)
$SDK/platform-tools/adb install -r <path-to-apk>

You may need to run adb kill-server, adb start-server if adb doesn't recognize the emulator.

N.B., NativeUI Fennec won't run in the emulator.

  • Logcat debug statements
adb logcat

Setting up Eclipse

If you want to use Eclipse:

  • Install it and the SDK plugin, as described in the Android SDK page.
  • Run these in your repo:
mvn -Declipse.workspace=<eclipse-workspace> eclipse:add-maven-repo
mvn -DdownloadJavadocs=true -DdownloadSources=true eclipse:eclipse
  • Open Eclipse, choose File > Import… Existing Project, pick your repo dir.
  • Correct formatting: Preferences > Java:Code style:Formatter, Edit…, change name to "Mozilla", change both indentation values to 2, tab policy = Spaces only, check "Align fields in columns".

Development

Let's stick to some fairly sane Java conventions: 2-space indenting (Java is wide enough as it is), Maven2 for dependencies and build, JUnit4 for unit tests. We can wire in Hudson later if we have time. "Simple" for HTTP test server.

Let's figure out bleeding edge stuff ("how do I get a SyncAdapter to work?") in throwaway projects. There will be a lot of these :)

We don't quite follow the Fennec/NativeUI/CodingStyle. See also the Android coding style.

Security

Goals: no less secure than currently, at most Fennec, Service, UI have access to credentials.

Android Docs on security

Sandboxing by using UIDs, specifically the section on "User IDs and File Access".

See also manifest entries:

android:sharedUserId The name of a Linux user ID that will be shared with other applications. By default, Android assigns each application its own unique user ID. However, if this attribute is set to the same value for two or more applications, they will all share the same ID — provided that they are also signed by the same certificate. Application with the same user ID can access each other's data and, if desired, run in the same process

Permissions

   <uses-permission android:name="android.permission.GET_ACCOUNTS" />
   <uses-permission android:name="android.permission.MANAGE_CREDENTIALS" />
   <uses-permission android:name="android.permission.USE_CREDENTIALS" />
   <uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS" />
   <uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
   <uses-permission android:name="android.permission.WRITE_SETTINGS" />
   <uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
   <uses-permission android:name="android.permission.READ_SYNC_STATS" />
   <uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
   <uses-permission android:name="android.permission.INTERNET"/>
   <uses-permission android:name="com.android.browser.permission.READ_HISTORY_BOOKMARKS"/>
   <uses-permission android:name="com.android.browser.permission.WRITE_HISTORY_BOOKMARKS"/>

Adjusting sync frequency

If API > 8, use ContentResolver.addPeriodicSync()

If API = 7, create a service with a periodic timer callback, and call ContentResolver.requestSync().

API < 6 does not support syncAdapter, so no worries.


Localization

http://developer.android.com/guide/topics/resources/localization.html

Schemas

TODO