1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| package demo_applet_apdu;
import uicc.toolkit.*;
import uicc.usim.access.USIMConstants ;
import uicc.access.*;
import javacard.framework.*;
import javacard.security.*;
import javacardx.crypto.*;
public class example_applet_apdu extends javacard.framework.Applet implements ToolkitInterface,uicc.toolkit.ToolkitConstants
{
// variables obligatoires
private ToolkitRegistry reg ;
final byte DCS_8_BIT_DATA =0x04 ;
private FileView uiccView ;
private byte[] messageToDisplay = { (byte) 0x61,(byte) 0x62,(byte) 0x63,(byte) 0x64,(byte) 0x31,(byte) 0x32,(byte) 0x33,(byte) 0x34 };
/**
Constructeur de lapplet
*/
public example_applet_apdu ( byte[] bArray,short bOffset,byte bLength )
{
// Enregistrement de lapplet
register(bArray,(short)(bOffset+1),(byte) bArray [bOffset]);
// Référence de lapplet
// avec lobjet ToolkitRegistry
reg=ToolkitRegistrySystem.getEntry();
tempBuffer =JCSystem.makeTransientByteArray(( short ) 155,JCSystem.CLEAR_ON_RESET );
// référence de lobjet File View
uiccView = UICCSystem.getTheUICCView (JCSystem.CLEAR_ON_RESET);
}
/**
Methode dinstallation invoquée par le JCRE à linstallation
@param bArray tableau doctet pour lAID
@param bOffset début de lAID
@param bLength longueur de lAID
*/
public static void install ( byte [] bArray ,short bOffset , byte bLength ) {
// création de lapplet Java SIM toolkit
applet_test StkCommandsExampleApplet = new
example_applet_apdu(bArray,bOffset,bLength);
}
/**
Methode invoquée par la plateforme GSM
*/
public Shareable getShareableInterfaceObject (AID clientAID,byte parameter )
{
if ((parameter==(byte) 0x01 )&&(clientAID == null )) {
return ((Shareable) this );
}
return null ;
}
/**
Method invoquée par la plateforme SIM tollkit
@param event représentation en octets
de lévénement déclenché
*/
public void processToolkit ( short event ) {
if ( event ==EVENT_PROACTIVE_HANDLER_AVAILABLE )
{
reg.clearEvent(EVENT_PROACTIVE_HANDLER_AVAILABLE );
displayText ();
}
}
/**
Methode invoquée par le JCRE
@param apdu objet APDU entrant
*/
public void process ( APDU apdu ) {
// ignore la commande
// de sélection de lapplet
if ( selectingApplet ()) {
return ;
}
reg.setEvent(EVENT_PROACTIVE_HANDLER_AVAILABLE);
}
public void displayMessage ( ProactiveHandlerproHdlr,byte [] messageBuffer,boolean flag ) {
// reconstruction du proactive handler
//et affichage du message défini
proHdlr.initDisplayText(( byte ) 0,DCS_8_BIT_DATA,messageBuffer,( short ) 0, ( short ) ( messageBuffer.length ));
proHdlr.send ();
// arrêt de lexécution de lapplet
if ( flag ) {
ToolkitException.throwIt (( short ) 0x0000 );
}
}
private void displayText () {
ProactiveHandler proHdlr = ProactiveHandlerSystem.getTheHandler ();
displayMessage(proHdlr,messageToDisplay,false );
}
} |
Partager