Sun Microsystems, Inc.
4150 Network Circle
Santa Clara, California 95054
U.S.A. 650-960-1300
Porting MIDP
MIDP Reference Implementation, Version 2.0 FCS
Java™ 2 Platform, Micro Edition
November, 2002
Please
Recycle
Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, U.S.A. All rights reserved.
Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this
document. In particular, and without limitation, these intellectual property rights may include one or more of the U.S. patents listed
at http://www.sun.com/patents and one or more additional patents or pending patent applications in the U.S. and in other
countries.
This document and the product to which it pertains are distributed under licenses restricting their use, copying, distribution, and
decompilation. No part of the product or of this document may be reproduced in any form by any means without prior written
authorization of Sun and its licensors, if any.
Third-party software, including font technology, is copyrighted and licensed from Sun suppliers.
Sun, Sun Microsystems, the Sun logo, Solaris, Java, J2ME, J2SE, Javadoc, JVM, and Java Developer Connection are trademarks or
registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries.
UNIX is a registered trademark in the United States and other countries, exclusively licensed through X/Open Company, Ltd.
The Adobe® logo is a registered trademark of Adobe Systems, Incorporated.
Federal Acquisitions: Commercial Software - Government Users Subject to Standard License Terms and Conditions.
DOCUMENTATION IS PROVIDED “AS IS” AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND
WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE
LEGALLY INVALID.
Copyright © 2002 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, California 95054, Etats-Unis. Tous droits réservés.
Sun Microsystems, Inc. a les droits de propriété intellectuels relatants à la technologie incorporée dans le produit qui est décrit dans
ce document. En particulier, et sans la limitation, ces droits de propriété intellectuels peuvent inclure un ou plus des brevets
américains énumérés à http://www.sun.com/patents et un ou les brevets plus supplémentaires ou les applications de brevet
en attente dans les Etats - Unis et dans les autres pays.
Ce produit ou document est protégé par un copyright et distribué avec des licences qui en restreignent l’utilisation, la copie, la
distribution, et la décompilation. Aucune partie de ce produit ou document ne peut être reproduite sous aucune forme, par quelque
moyen que ce soit, sans l’autorisation préalable et écrite de Sun et de ses bailleurs de licence, s’il y ena.
Le logiciel détenu par des tiers, et qui comprend la technologie relative aux polices de caractères, est protégé par un copyright et
licencié par des fournisseurs de Sun.
Sun, Sun Microsystems, le logo Sun, Solaris, Java, J2ME, J2SE, Javadoc, JVM, et Java Developer Connection sont des marques de
fabrique ou des marques déposées de Sun Microsystems, Inc. aux Etats-Unis et dans d’autres pays.
UNIX est une marque enregistree aux Etats-Unis et dans d'autres pays et licenciée exclusivement par X/Open Company Ltd.
Le logo Adobe® est une marque déposée de Adobe Systems, Incorporated.
LA DOCUMENTATION EST FOURNIE “EN L’ÉTAT” ET TOUTES AUTRES CONDITIONS, DECLARATIONS ET GARANTIES
EXPRESSES OU TACITES SONT FORMELLEMENT EXCLUES, DANS LA MESURE AUTORISEE PAR LA LOI APPLICABLE, Y
COMPRIS NOTAMMENT TOUTE GARANTIE IMPLICITE RELATIVE A LA QUALITE MARCHANDE, A L’APTITUDE A UNE
UTILISATION PARTICULIERE OU A L’ABSENCE DE CONTREFAÇON.
iii
Contents
Preface xi
1. Introduction 1
1.1 Product Architecture 2
1.2 Porting Requirements 4
1.2.1 Hardware Requirements 4
1.2.2 Software Requirements 5
1.2.3 Compiler Requirements 6
1.2.4 Requirements of the Completed Port 7
2. Beginning a MIDP Port 9
2.1 Preparing to Port MIDP 9
2.2 Porting Device-Specific Configuration Code 11
2.3 Trying It Out 12
3. The Event Model 13
3.1 Event Model Overview 13
3.2 Events From the Virtual Machine 14
3.3 Events From MIDP 15
3.4 Native Functions 16
4. Persistent Storage 17
4.1 Porting the Native Layer 18
4.2 Customizing the Java Layer 19
iv Porting MIDP • November, 2002
5. Thread-Safety in LCDUI 21
5.1 Requirements 21
5.2 Design Approach 22
5.3 Coding Conventions 23
5.3.1 General Conventions 24
5.3.2 Public Method Conventions 24
5.3.3 Constructor Conventions 26
5.3.4 Event-Handling Method Conventions 27
5.3.5 Application Callout Conventions 27
5.3.6 Graphics Conventions 29
5.4 The serviceRepaints Method 30
6. LCDUI Graphical User Interface 31
6.1 Overview 31
6.2 Issues in Porting Low Level API Functionality 32
6.2.1 Drawing Graphics Primitives 32
6.2.2 Porting PNG Transparency 40
6.3 Using Native Widgets for MIDP Screens 42
6.3.1 General Instructions 42
6.3.2 Example: Replacing Part of DateField 43
6.3.3 Pop-Up Choice Groups 51
6.4 Porting the Game Package 52
7. Security 53
7.1 Overview 54
7.2 Permissions 55
7.3 Key Storage 56
8. Networking 57
8.1 Porting the Native Layer 58
8.2 Customizing the Java Layer 58
8.2.1 Generic Connections 59
8.2.2 Comm 59
Contents v
8.2.3 IP Support 59
8.2.4 Secure Connections 60
8.2.5 HTTP 1.1 61
8.2.6 HTTPS 63
8.2.7 Internal Utilities 64
9. The Application Management System 65
9.1 Porting main.c 66
9.2 Customizing AMS 66
10. Push Functionality 69
10.1 Design Considerations 70
10.1.1 Protocols 70
10.1.2 Listening for Incoming Data 70
10.1.3 Message Buffering 70
10.1.4 User Interaction 71
10.1.5 MIDlet Concurrency 71
10.2 Porting the Native Layer 72
10.3 Customizing the Java Layer 73
11. Porting the Audio Building Block 75
11.1 Overview 76
11.1.1 Architecture 76
11.1.2 Implementing the Player Interface 77
11.2 Porting Synthetic Tones 79
11.2.1 Architectural Considerations 79
11.2.2 Generating Single Tones 86
11.2.3 Generating Tone Sequences 86
11.3 Porting Sampled Audio 88
11.3.1 Architectural Considerations 88
11.3.2 Implementing the Playback of Sampled Audio 90
12. Building Your Port 95