Confirmed users
355
edits
Nalexander (talk | contribs) No edit summary |
Nalexander (talk | contribs) (Revert catastrophic "re-format as HTML" changes.) |
||
| Line 1: | Line 1: | ||
Native Sync | = Native Sync = | ||
== Setup == | == Setup == | ||
[[Mobile/Fennec/Android_OtherBuildEnvs#Mac_OSX | 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: | |||
$ANDROID_HOME/tools/android | |||
=== Emulators === | === Emulators === | ||
* to create: | |||
Use the command line <tt>$ANDROID_HOME/tools/android</tt>, or use the graphical Android AVD Manager (from within Eclipse: <tt>Window > AVD Manager</tt>). | |||
$ANDROID_HOME/tools/android create avd -t android-10 -n NAME -c 2047M | |||
produces the output | |||
Android 2.3.3 is a basic Android platform. | Auto-selecting single ABI armeabi | ||
Do you wish to create a custom hardware profile [no] | Android 2.3.3 is a basic Android platform. | ||
Created AVD 'NAME' based on Android 2.3.3, ARM (armeabi) processor, | Do you wish to create a custom hardware profile [no] | ||
with the following hardware config: | Created AVD 'NAME' based on Android 2.3.3, ARM (armeabi) processor, | ||
hw.lcd.density=240 | with the following hardware config: | ||
vm.heapSize=24 | hw.lcd.density=240 | ||
hw.ramSize=256 | vm.heapSize=24 | ||
hw.ramSize=256 | |||
{{note|Target (in the example above, <tt>android-10</tt>) probably needs to match build specified in .mozconfig (see Building Fennec Native below).}} | |||
* to launch: | |||
$ANDROID_HOME/tools/emulator -wipe-data -avd NAME -partition-size 2047 | |||
{{note|The partition size is set large so that you don't run into an insufficient storage error.}} | |||
* to delete: | |||
$ANDROID_HOME/tools/android delete avd -n NAME | |||
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 == | == Running everything == | ||
The main <tt>android-sync</tt> source repository is hosted on github: | |||
https://github.com/mozilla-services/android-sync | |||
Try | |||
git clone git@github.com:mozilla-services/android-sync.git | |||
=== android-sync dependencies === | === 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: | |||
* JUnit 4.1. | |||
* org.simpleframework.simple, for HTTP testing. | |||
* Tiny “un-stub” packages for android.util.Log, android.util.Base64, and android.content.SharedPreferences. | |||
These live on github, and must be built and installed. | |||
** https://github.com/rnewman/base64-unstub | |||
** https://github.com/rnewman/log-unstub | |||
** https://github.com/rnewman/sharedpreferences-stub | |||
=== sync-crypto dependencies === | === 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). | |||
=== What you need to do === | === What you need to do === | ||
git clone https://github.com/rnewman/log-unstub | git clone https://github.com/rnewman/base64-unstub | ||
git clone https://github.com/rnewman/sharedpreferences-stub | git clone https://github.com/rnewman/log-unstub | ||
git clone https://github.com/mozilla-services/android-sync | git clone https://github.com/rnewman/sharedpreferences-stub | ||
pushd base64-unstub; mvn install; popd | git clone https://github.com/mozilla-services/android-sync | ||
pushd log-unstub; mvn install; popd | pushd base64-unstub; mvn install; popd | ||
pushd sharedpreferences-stub; mvn install; popd | pushd log-unstub; mvn install; popd | ||
pushd android-sync | pushd sharedpreferences-stub; mvn install; popd | ||
git checkout develop | pushd android-sync | ||
./preprocess.sh | git checkout develop | ||
mvn test | ./preprocess.sh | ||
mvn test | |||
{{note|<tt>mvn assembly:assembly</tt> may fail, however, it is still ok to proceed.}} | |||
To do real Android development and testing, you need to import android-sync as a project 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. The subdirectory android-sync/test 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 === | === Running Fennec === | ||
The directions at [[Fennec/NativeUI | Building Native Fennec]] should be correct, specifically [[Fennec/NativeUI#How_To_Build | How To Build]]. | |||
After building Fennec, make the apk. | |||
make -sj8 -C objdir-droid/ package | |||
The apk will be something like <tt>objdir-droid/dist/fennec-12.0a1.en-US.android-arm.apk</tt>. | |||
==== Running Fennec on an Android device ==== | ==== Running Fennec on an Android device ==== | ||
* Ensure USB debugging is enabled on your Android device: fom the home screen, select <tt>Settings > Applications > Development > USB debugging</tt>. | |||
* Ensure your Android device is connected to your computer's USB port. | |||
* Run | |||
$ANDROID_HOME/platform-tools/adb install -r objdir-droid/dist/fennec*apk | |||
==== Running Fennec on an emulator ==== | ==== Running Fennec on an emulator ==== | ||
* Ensure the emulator is running. | |||
* Run | |||
$ANDROID_HOME/platform-tools/adb install -r objdir-droid/dist/fennec*apk | |||
{{note|You may need to run <tt>adb kill-server; adb start-server</tt> if adb doesn't recognize the emulator.}} | |||
==== Accessing Fennec/Android Sync debug statements ==== | ==== Accessing Fennec/Android Sync debug statements ==== | ||
$ANDROID_HOME/platform-tools/adb logcat | |||
=== Setting up Eclipse === | === Setting up Eclipse === | ||
If you want to use Eclipse: | |||
* Install Eclipse and the SDK plugin, as described in the Android SDK page. | |||
* Correct formatting: <tt>Preferences > Java > Code style > Formatter > Edit...</tt>, set profile name to <tt>Mozilla</tt>, set <tt>Tab policy</tt> to <tt>Spaces only</tt> change both <tt>Indentation size</tt> and <tt>Tab size</tt> to 2, and check <tt>Align fields in columns</tt>. | |||
* Run these commands in your <tt>android-sync</tt> git repository directory (don't forget to checkout the <tt>develop</tt> branch): | |||
mvn -Declipse.workspace=<path-to-eclipse-workspace> eclipse:add-maven-repo | |||
mvn -DdownloadJavadocs=true -DdownloadSources=true eclipse:eclipse | mvn -DdownloadJavadocs=true -DdownloadSources=true eclipse:eclipse | ||
* Install the project and classpath files (again in your git repository directory), making sure to update the paths where necessary in both files: | |||
cp example.project .project | |||
cp example.classpath .classpath | cp example.classpath .classpath | ||
* Open Eclipse, choose <tt>File > Import... > General > Existing Projects into Workspace</tt>, and specify your git repository directory. | |||
{{note|You may need to set <tt>M2_REPO</tt> (for example, as described at [http://www.mkyong.com/maven/how-to-configure-m2_repo-variable-in-eclipse-ide/]) to something like <tt>$HOME/.m2/repository</tt>.}} | |||
==== To run the unit test suite under Eclipse ==== | ==== To run the unit test suite under Eclipse ==== | ||
* First configure the test suite launcher, under <tt>Preferences > Run/Debug > Launching > Default Launchers</tt>. Set the Debug and Run launchers to <tt>Android JUnit Test Launcher</tt>. | |||
* Select the <tt>android-sync</tt> project and execute <tt>Run > Run As ... > JUnit Test</tt>. | |||
==== To run the integration test suite under Eclipse ==== | ==== To run the integration test suite under Eclipse ==== | ||
* Add the <tt>test</tt> subdirectory as a sub-project using <tt>File > Import > Existing project</tt>. | |||
* Refresh and clean everything. | |||
* Select the <tt>test</tt> project and execute <tt>Run > Run As ... > Android JUnit Test</tt>. | |||
== Development == | == 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 [http://source.android.com/source/code-style.html the Android coding style]. | |||
=== Running unit test code coverage === | === Running unit test code coverage === | ||
To see the current unit test code coverage (using the Maven plugin integrating Cobertura), from the <tt>android-sync</tt> directory run | |||
mvn cobertura:cobertura | |||
browse | |||
./target/site/cobertura/index.html | |||
and click on <tt>org.mozilla.gecko</tt>. | |||
{{note|At this time, you can't see the current integration test code coverage.}} | |||
== Security == | == Security == | ||
Goals: no less secure than currently, at most Fennec, Service, UI have access to credentials. | |||
[http://developer.android.com/guide/topics/security/security.html Android Docs on security ] | |||
Sandboxing by using UIDs, specifically the section on "User IDs and File Access". | |||
See also [http://developer.android.com/guide/topics/manifest/manifest-element.html manifest entries]: | |||
<blockquote><tt>android:sharedUserId</tt> | <blockquote><tt>android:sharedUserId</tt> | ||
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</blockquote> | 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</blockquote> | ||
== Permissions == | == 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.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 == | == 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. | |||
Triggering a sync: | |||
android:supportsUploading defaults to true and if true an upload-only sync will be requested for all syncadapters associated with an | |||
authority whenever that authority's content provider does a notifyChange(android.net.Uri, android.database.ContentObserver, boolean) with | |||
syncToNetwork set to true. | |||
== Altering Sync settings == | == Altering Sync settings == | ||
android:syncAdapterSettingsAction defaults to null and if supplied it specifies an Intent action of an activity that can be used to adjust the sync adapter's sync settings. The activity must live in the same package as the sync adapter. | |||
== Localization == | == Localization == | ||
http://developer.android.com/guide/topics/resources/localization.html | |||
== Schemas == | == Schemas == | ||
TODO | |||
== Gotchas == | == Gotchas == | ||
Android's sqlite cursors are limited. Oh, and the heap is limited. We have to be very careful about how much data we store and process at one time. | |||
<blockquote cite="http | |||
<blockquote cite="http://stackoverflow.com/questions/1407442/android-sqlite-and-huge-data-sets"><p>“You are out of heap space. With a 16MB non-compacting heap, and the fact that a Cursor holds the entire result set in the heap, that is not out of the question. CursorWindow only supports 1MB of data, which is what the error message suggests more directly.</p><p>If there is a logical way to divide your queries into discrete chunks, you could do incremental queries and use CursorJoiner to stitch them together, and see if that helps.”</p></blockquote> | |||
== jvoll's notes == | == jvoll's notes == | ||
Having trouble with the emulator when loading Fennec and Sync onto it? Use: emulator -avd android-14 -partition-size 2047 | |||
-android:permission="org.mozilla.gecko.permissions.BROWSER_PROVIDER"/ | Lines to remove from mobile/android/base/AndroidManifest.xml.in if you don't feel like working around the permissions stuff: | ||
- | -android:permission="org.mozilla.gecko.permissions.BROWSER_PROVIDER"/> from both providers | ||
-<permission android:name="org.mozilla.gecko.permissions.BROWSER_PROVIDER" android:protectionLevel="signature"/> | |||
Tests failing and seeing a ProfileDatabaseException logged in logcat? This usually happens when you did a fresh install of fennec and haven't opened it yet. So, just open Fennec. If that fails (and this works for other weird stuff too), go to apps and stop Fennec, clear app data and/or in extreme cases uninstall and reinstall it. This stuff *should* all be fixed shortly, but for now these are good work arounds. | |||
Accessing android db on emulator: | |||
adb shell | adb shell | ||
cd /data/data/org.mozilla.fennec_jason/files/mozilla/yvzvl036.default | cd /data/data/org.mozilla.fennec_jason/files/mozilla/yvzvl036.default | ||
sqlite3 browser.db (or w/e database is wanted) | sqlite3 browser.db (or w/e database is wanted) | ||
== Troubleshooting == | == Troubleshooting == | ||
=== "R cannot be resolved" === | === "R cannot be resolved" === | ||
Something is wrong with xml resolution. Check your Eclipse console errors in xml files, which will prevent Eclipse from building resource (R) files - resolve them first. | |||
Things to try: | |||
*Update string resources: ./preprocess | |||
*Project > Clean, then rebuild the project. Alternatively, you can delete the gen/ directory, and Eclipse will rebuild automatically (Project > Build Automatically checked) | |||
=== Loading apk: "Insufficient space" error on emulator === | === Loading apk: "Insufficient space" error on emulator === | ||
Start an emulator with "-partition-size 2047" as a flag, to set emulator size. | |||