How to Port phoneME™ Advanced Software to
Google Android, iPhone, OpenMoko, LiMO,
and More
Hinkmond Wong, Senior Staff Eng...
Learn how to port an open source
Java™ Platform, Micro Edition (Java ME)
implementation to new mobile platforms such
as Go...
Agenda

 Introduction to phoneME™ software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced softwar...
Agenda

 Introduction to phoneME software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced software...
Introduction to phoneME Software

 Project phoneME software is the open source version of Java
 ME technology
 Subversion ...
Agenda

 Introduction to phoneME software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced software...
Building phoneME Advanced Software

 Source code at java.net
 Code bundles
  • https://phoneme.dev.java.net/downloads_page...
Building phoneME Advanced Software
                               ROOT


trunk         releases         builds     compone...
Building phoneME Advanced Software
                    components




           ...   midp   jsr 75   jsr 172            ...
Building phoneME Advanced Software

 Download
  • Using “svn co” command
  • Checkout the needed components
 Build (Tools ...
Building phoneME Advanced Software

 svn co
 https://phoneme.dev.java.net/svn/phoneme/components/cdc/tr
 unk cdc

 svn co
...
Agenda

 Introduction to phoneME software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced software...
Porting Layers of phoneME Advanced Software

 Core Layer
  • Threads
  • IO
  • Networking
 Graphics Layer
  • Personal Pr...
Porting Layers of phoneME Advanced
Software

                         PP/PBP (native + Java)


                  VM (nativ...
Agenda

 Introduction to phoneME software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced software...
Porting Core Layer

 Threads
  • POSIX standard
  • Follow existing port
  • Examples:
     •   cdc/src/linux/javavm/runti...
Porting Core Layer

 IO
  • Common standard for open, seek, read, close, etc. among popular
    OS's
  • Follow existing p...
Porting Core Layer

 Networking
  • Common standard for connect, send, receive, timeout, etc. among
    popular OS's
  • F...
Porting Core Layer
 Rest of Core Layer
  • Host Porting Interface (HPI)
  • See cdc/src/share/javavm/include/porting/
  • ...
Agenda

 Introduction to phoneME software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced software...
Porting Graphics Layer
 Personal Basis Profile
  • Basic Graphics Primitives
  • Ex. drawArc(), drawLine(), drawOval(), dr...
Porting Layers of phoneME Advanced
Software

                           PP/PBP

                  VM

       Threads   IO ...
Porting Graphics Layer
 Personal Profile
  • AWT Peer Components (map to native toolkit peers)
  • java.awt.*: Button, Dia...
Porting Layers of phoneME Advanced
Software

                           PP/PBP

                  VM

       Threads   IO ...
Agenda

 Introduction to phoneME software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced software...
Example Cases: Google Android
 Google Android
  • Start with Linux port of phoneME Advanced software
  • Approach as dual ...
Example Cases: Apple iPhone
 iPhone
  • Start with darwin (MacOS) port of phoneME Advanced software (need
    to link with...
Example Cases: Other
 OpenMoko, LiMO, and other Linux based devices
  • Start with linux/GTK port of phoneME Advanced soft...
Agenda

 Introduction to phoneME software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced software...
Code Sample: IO
 src/linux/native/java/io/UnixFileSystem_md.c
 ---
 JNIEXPORT jlong JNICALL
 Java_java_io_UnixFileSystem_g...
Code Sample: Porting Networking
 src/linux/native/java/net/Inet4AddressImpl_md.c
 ---
 JNIEXPORT jobjectArray JNICALL
 Jav...
Code Sample: Porting Basic Graphics
src/share/basis/native/awt/qt/QtImage.cpp
---
JNIEXPORT void JNICALL
Java_java_awt_QtI...
Code Sample: Porting Graphics Widget
src/share/personal/native/awt/qt/QtButtonPeer.cc
---

JNIEXPORT void JNICALL
Java_sun...
Agenda

 Introduction to phoneME software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced software...
Testing Your Port
 HelloWorld
  • bin/cvm -cp testclasses.zip HelloWorld
     • Hello world.
 VM tests
  • bin/cvm -cp tes...
Demo: How to Port phoneME
Advanced Software




                        2008 JavaOneSM Conference | java.sun.com/javaone |...
Agenda

 Introduction to phoneME software
 Building phoneME Advanced software
 Porting Layers of phoneME Advanced software...
Summary

 Many new and interesting phone platforms exist
 The phoneME Advanced software project allows for open
 source de...
For More Information

 See:
  • http://community.java.net/mobileandembedded/
  • https://phoneme.dev.java.net/
  • http://...
Questions and Answers



 Q&A




                        2008 JavaOneSM Conference | java.sun.com/javaone |   40
Hinkmond Wong, Senior Staff Engineer, Sun
Microsystems, Inc.
TS-6304




                                     2008 JavaOne...
Upcoming SlideShare
Loading in …5
×

How to Port phoneME Advanced Software to Google Android ...

2,766 views
2,626 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,766
On SlideShare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
23
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

How to Port phoneME Advanced Software to Google Android ...

  1. 1. How to Port phoneME™ Advanced Software to Google Android, iPhone, OpenMoko, LiMO, and More Hinkmond Wong, Senior Staff Engineer, Sun Microsystems, Inc. TS-6304
  2. 2. Learn how to port an open source Java™ Platform, Micro Edition (Java ME) implementation to new mobile platforms such as Google Android, iPhone, OpenMoko, LiMO, and more. 2008 JavaOneSM Conference | java.sun.com/javaone | 2
  3. 3. Agenda Introduction to phoneME™ software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 3
  4. 4. Agenda Introduction to phoneME software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 4
  5. 5. Introduction to phoneME Software Project phoneME software is the open source version of Java ME technology Subversion repository on java.net • https://phoneme.dev.java.net/source/browse/phoneme/ Supported by email lists, forums, and wiki pages Two stack: • phoneME Advance software: Java ME CDC based technology • phoneME Feature software: Java ME CLDC/MIDP based technology Dual Licensed • GPL version 2 • Sun Commercial License 2008 JavaOneSM Conference | java.sun.com/javaone | 5
  6. 6. Agenda Introduction to phoneME software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 6
  7. 7. Building phoneME Advanced Software Source code at java.net Code bundles • https://phoneme.dev.java.net/downloads_page.html Direct SVN repository access • https://phoneme.dev.java.net/svn/phoneme Trunks exist for each component • Warning: many branches exist for each component 2008 JavaOneSM Conference | java.sun.com/javaone | 7
  8. 8. Building phoneME Advanced Software ROOT trunk releases builds components www Source code Tagged versions of the components GPL, copyrights, etc. Website 2008 JavaOneSM Conference | java.sun.com/javaone | 8
  9. 9. Building phoneME Advanced Software components ... midp jsr 75 jsr 172 ... *Note: see other JSRs in our repository phoneME phoneME Feature Advanced 2008 JavaOneSM Conference | java.sun.com/javaone | 9
  10. 10. Building phoneME Advanced Software Download • Using “svn co” command • Checkout the needed components Build (Tools Required): • GNU make (version 3.81) • gcc (version 3.x or 4.x) • ant (version 1.6.5) Getting Started Guide: • https://phoneme.dev.java.net/content/phoneme_advanced_r2.html 2008 JavaOneSM Conference | java.sun.com/javaone | 10
  11. 11. Building phoneME Advanced Software svn co https://phoneme.dev.java.net/svn/phoneme/components/cdc/tr unk cdc svn co https://phoneme.dev.java.net/svn/phoneme/components/tools/ trunk tools cd cdc/build/linux-x86-generic make J2ME_CLASSLIB=foundation 2008 JavaOneSM Conference | java.sun.com/javaone | 11
  12. 12. Agenda Introduction to phoneME software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 12
  13. 13. Porting Layers of phoneME Advanced Software Core Layer • Threads • IO • Networking Graphics Layer • Personal Profile: Proper Subset of Abstract Windowing Toolkit (AWT) from Java Platform, Standard Edition, (Java SE) version 1.4.2 • Personal Basis Profile: Proper Subset of drawing primitives from Java SE version 1.4.2 platform 2008 JavaOneSM Conference | java.sun.com/javaone | 13
  14. 14. Porting Layers of phoneME Advanced Software PP/PBP (native + Java) VM (native) Threads IO Networking (native) (native) (native) Graphics (native) Native OS/Graphics 2008 JavaOneSM Conference | java.sun.com/javaone | 14
  15. 15. Agenda Introduction to phoneME software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 15
  16. 16. Porting Core Layer Threads • POSIX standard • Follow existing port • Examples: • cdc/src/linux/javavm/runtime/threads_md.c • cdc/src/solaris/javavm/runtime/threads_md.c • cdc/src/darwin/javavm/runtime/threads_md.c • cdc/src/vxworks/javavm/runtime/threads_md.c • cdc/src/win32/javavm/runtime/threads_md.c Map to native POSIX threads calls in machine dependent (*_md.c) file 2008 JavaOneSM Conference | java.sun.com/javaone | 16
  17. 17. Porting Core Layer IO • Common standard for open, seek, read, close, etc. among popular OS's • Follow existing port • Examples: • cdc/src/linux/javavm/runtime/io_md.c • cdc/src/solaris/javavm/runtime/io_md.c • cdc/src/darwin/javavm/runtime/io_md.c • cdc/src/vxworks/javavm/runtime/io_md.c • cdc/src/win32/javavm/runtime/io_md.c Map to native I/O calls in machine dependent (*_md.c) file 2008 JavaOneSM Conference | java.sun.com/javaone | 17
  18. 18. Porting Core Layer Networking • Common standard for connect, send, receive, timeout, etc. among popular OS's • Follow existing port • Examples: • cdc/src/linux/javavm/runtime/net_md.c • cdc/src/darwin/javavm/runtime/net_md.c • cdc/src/win32/javavm/runtime/net_md.c Map to native networking calls in machine dependent (*_md.c) file 2008 JavaOneSM Conference | java.sun.com/javaone | 18
  19. 19. Porting Core Layer Rest of Core Layer • Host Porting Interface (HPI) • See cdc/src/share/javavm/include/porting/ • ansi/ globals.h jni.h sync.h vm-defs.h • defs.h int.h linker.h system.h • doubleword.h io.h memory.h threads.h • endianness.h java_props.h net.h time.h • float.h jit/ path.h timezone.h Use (*_md.c) files form an existing port (linux, darwin [MacOS], win32) as a guide 2008 JavaOneSM Conference | java.sun.com/javaone | 19
  20. 20. Agenda Introduction to phoneME software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 20
  21. 21. Porting Graphics Layer Personal Basis Profile • Basic Graphics Primitives • Ex. drawArc(), drawLine(), drawOval(), drawPolygon(), drawRect(), drawRoundRect(), fill*(), etc. Map Graphics components to native Toolkit • Toolkit, Component, Frame, Window, Graphics Environment, Fonts, Images Use existing Personal Basis Profile port as a guide • grep native cdc/src/share/basis/classes/awt/qt/java/awt/QtGraphics* • See: pCopyArea(), pDrawArc(), pDrawLine(), pDrawOval(), pDrawPolygon(), pDrawRect(), pDrawRoundRect() • Map to native functions • Ex. in Qt, p.drawArc, p.drawEllipse, p.drawLine, etc. 2008 JavaOneSM Conference | java.sun.com/javaone | 21
  22. 22. Porting Layers of phoneME Advanced Software PP/PBP VM Threads IO Networking Graphics Native OS/Graphics GTK Basic Graphics Primitives 2008 JavaOneSM Conference | java.sun.com/javaone | 22
  23. 23. Porting Graphics Layer Personal Profile • AWT Peer Components (map to native toolkit peers) • java.awt.*: Button, Dialog, Label, Scrollbar, TextArea, Window, Image, Font, etc. Map AWT widgets to native Toolkit widgets • Toolkit, Component, Frame, Window, Graphics Environment, Fonts, Images, Button, Dialog, Scrollbar, TextArea, etc. Use existing Personal Profile port as a guide • grep native cdc/src/share/personal/classes/awt/peer_based/sun/awt/qt/* • See: pCopyArea(), pDrawArc(), pDrawLine(), pDrawOval(), pDrawPolygon(), pDrawRect(), pDrawRoundRect() • Map to native functions • Ex. in Qt, p.drawArc, p.drawEllipse, p.drawLine, etc. 2008 JavaOneSM Conference | java.sun.com/javaone | 23
  24. 24. Porting Layers of phoneME Advanced Software PP/PBP VM Threads IO Networking Graphics Native OS/Graphics GTK AWT Peer Components 2008 JavaOneSM Conference | java.sun.com/javaone | 24
  25. 25. Agenda Introduction to phoneME software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 25
  26. 26. Example Cases: Google Android Google Android • Start with Linux port of phoneME Advanced software • Approach as dual stack • Port phoneME Advanced software to native Linux OS and native GUI Toolkit that will exist on Android emulator host • Difficult part: Wrap Android Activity (application) to launch Java Virtual Machine (Ex. Compile Java SE wrapper application to launch Java Virtual Machine. Compile it to Dalvik bytecodes) Reference Android stack on a device • http://euedge.com/blog/2007/12/06/google-android-runs-on-sharp- zaurus-sl-c760/ Reference running native App from Android emulator • http://groups.google.com/group/android- developers/browse_thread/thread/f31003bbed8bf7a9/ 2008 JavaOneSM Conference | java.sun.com/javaone | 26
  27. 27. Example Cases: Apple iPhone iPhone • Start with darwin (MacOS) port of phoneME Advanced software (need to link with Objective-C) • Port phoneME Advanced software to iPhone SDK • Port core porting layer (threads, IO, and networking) to iPhone MacOS layer • Port graphics to Core Graphics (Quartz 2D) and UIKit for drawing primitives (Personal Basis Profile) Reference to iPhone SDK info • http://developer.apple.com/iPhone/library/navigation/index.html Reference to iPhone Graphics • http://developer.apple.com/iPhone/library/referencelibrary/GettingS tarted/GS_Graphics_iPhone/index.html 2008 JavaOneSM Conference | java.sun.com/javaone | 27
  28. 28. Example Cases: Other OpenMoko, LiMO, and other Linux based devices • Start with linux/GTK port of phoneME Advanced software • Port phoneME Advanced software to specific device Linux distro and GTK • Port core porting layer (threads, IO, and networking) using existing Linux port • Port graphics to GTK GUI toolkit Reference to OpenMoko • http://wiki.openmoko.org/wiki/Main_Page Reference to LiMO • http://wiki.openmoko.org/wiki/OpenmokoFramework 2008 JavaOneSM Conference | java.sun.com/javaone | 28
  29. 29. Agenda Introduction to phoneME software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 29
  30. 30. Code Sample: IO src/linux/native/java/io/UnixFileSystem_md.c --- JNIEXPORT jlong JNICALL Java_java_io_UnixFileSystem_getLastModifiedTime(JNIEnv *env, jobject this, jobject file) { jlong rv = 0; ... struct stat sb; if (stat(path, &sb) == 0) { rv = 1000 * (jlong)sb.st_mtime; 2008 JavaOneSM Conference | java.sun.com/javaone | 30
  31. 31. Code Sample: Porting Networking src/linux/native/java/net/Inet4AddressImpl_md.c --- JNIEXPORT jobjectArray JNICALL Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this, jstring host) { const char *hostname; jobjectArray ret = 0; jclass byteArrayCls; struct hostent res, *hp = 0; char buf[HENT_BUF_SIZE]; ... /* Try once, with our static buffer. */ #ifdef __GLIBC__ gethostbyname_r(hostname, &res, buf, sizeof(buf), &hp, &h_error); 2008 JavaOneSM Conference | java.sun.com/javaone | 31
  32. 32. Code Sample: Porting Basic Graphics src/share/basis/native/awt/qt/QtImage.cpp --- JNIEXPORT void JNICALL Java_java_awt_QtImage_pDrawImage (JNIEnv * env, jclass cls, jint qtGraphDescDest, jint qtImageDescSrc, jint x, jint y, jobject bg) { ... p.drawPixmap(x, y, pm); 2008 JavaOneSM Conference | java.sun.com/javaone | 32
  33. 33. Code Sample: Porting Graphics Widget src/share/personal/native/awt/qt/QtButtonPeer.cc --- JNIEXPORT void JNICALL Java_sun_awt_qt_QtButtonPeer_setLabelNative (JNIEnv *env, jobject thisObj, jstring label) { ... QString* labelString = awt_convertToQString(env, label); ((QpPushButton *)buttonPeer->getWidget())- >setText(*labelString); 2008 JavaOneSM Conference | java.sun.com/javaone | 33
  34. 34. Agenda Introduction to phoneME software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 34
  35. 35. Testing Your Port HelloWorld • bin/cvm -cp testclasses.zip HelloWorld • Hello world. VM tests • bin/cvm -cp testclasses.zip Test • *CONGRATULATIONS: test Test completed with 411 tests passed and 0 failures • *Output lines starting with a * should be checked for correctness • *They can be compared to src/share/javavm/test/TestExpectedResult PBP test • bin/cvm -cp democlasses.jar basis.DemoFrame PP test • bin/cvm -cp democlasses.jar personal.DemoFrame 2008 JavaOneSM Conference | java.sun.com/javaone | 35
  36. 36. Demo: How to Port phoneME Advanced Software 2008 JavaOneSM Conference | java.sun.com/javaone | 36
  37. 37. Agenda Introduction to phoneME software Building phoneME Advanced software Porting Layers of phoneME Advanced software Porting Core Layer (threads, IO, and networking) Porting Graphics Layers (Personal Basis and Personal Profiles) Example Cases Sample Code Testing Port Summary 2008 JavaOneSM Conference | java.sun.com/javaone | 37
  38. 38. Summary Many new and interesting phone platforms exist The phoneME Advanced software project allows for open source development of a Java ME technology implementation Porting phoneME Advanced software to the new phone platforms can be handled in a methodical way Submit your port back to the Java ME Community and participate in our project 2008 JavaOneSM Conference | java.sun.com/javaone | 38
  39. 39. For More Information See: • http://community.java.net/mobileandembedded/ • https://phoneme.dev.java.net/ • http://wiki.java.net/bin/view/People/HinkmondWong (updated slides and downloads) 2008 JavaOneSM Conference | java.sun.com/javaone | 39
  40. 40. Questions and Answers Q&A 2008 JavaOneSM Conference | java.sun.com/javaone | 40
  41. 41. Hinkmond Wong, Senior Staff Engineer, Sun Microsystems, Inc. TS-6304 2008 JavaOneSM Conference | java.sun.com/javaone | 41

×