Package com.casioeurope.mis.edt
Class SamLibrary
Object
SamLibrary
public class SamLibrary extends Object
The CASIO Enterprise Developer Tools SAM Library
- Since:
- 2.00
- API Note:
- The SAM Library is bound to the calling application on application startup time automatically.
The Library's lifecycle therefore depends on the application lifecycle.
Due to the Lifecycle of Android Applications and the underlying timing, it is strongly advised not to call any Library Methods inside theonCreate
method.
When the activity is being launched (and hence the process gets created), the same applies to theonStart
andonResume
methods.
If you need to call any Library methods at application start in one of the above mentioned methods, you should use theCallback
Mechanism offered by theonLibraryReady
method instead.
For instance, instead of callingSamLibrary.openSam()
directly inonCreate
, use this code to postpone it to aCallback
appropriately:
SamLibrary.onLibraryReady(new LibraryCallback() { public void onLibraryReady() { SamLibrary.openSam(); } });
Which can be simplified to:
SamLibrary.onLibraryReady(() -> { SamLibrary.openSam(); });
Or even further to:
SamLibrary.onLibraryReady(SamLibrary::openSam);
-
Method Summary
Modifier and Type Method Description static int
closeSam()
Close the SAM.static int
communicateAPDU(byte[] sendData, int sendLength, byte[] receiveData, int receiveLength)
Communicate with SAM card in APDU format.static int
communicateDirect(byte command, byte[] sendData, int sendLength, byte[] receiveData, int receiveLength)
Specify the command format and communicate directly with the SAM card.static int
getTimeOutDelay()
Get card timeout delay valuestatic boolean
isMethodSupported(String methodName)
static boolean
isMethodSupported(BigInteger method)
Check whether theMethod
indicated by theBigInteger
method parameter is supported on the currently active devicestatic void
onLibraryReady(LibraryCallback callback)
Add a new Callback to the Queue of Callbacks to be processed once the SAM Library Service becomes availablestatic int
openSam()
Open the SAM.static int
receiveATR(byte[] receiveData)
Get the ATR response data.static int
sendPowerOff()
Turn off the power of SAM card.static int
sendPowerOn()
Supply 5V power to the SAM card.static int
setTimeOutDelay(int delayMs)
Set card timeout delay value in milliseconds
-
Method Details
-
openSam
Open the SAM.- Returns:
int
:SUCCESS
: Success
ERROR_UNSUPPORTED
: Unsupported error- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.- API Note:
- Call this function when the application starts.
-
closeSam
Close the SAM.- Returns:
int
:SUCCESS
: Success
ERROR_UNSUPPORTED
: Unsupported error- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.- API Note:
- Call this function when the application terminates.
-
sendPowerOn
Supply 5V power to the SAM card.- Returns:
int
:SUCCESS
: Success
ERROR_NOTOPENED
: Non-open error
ERROR_CARDDETECT
: Card detection error
ERROR_COMMUNICATION
: Communication error
ERROR_INTERNAL
: Internal error
ERROR_UNSUPPORTED
: Unsupported error- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.- API Note:
- Send 5V power on command in ATR format.
-
sendPowerOff
Turn off the power of SAM card.- Returns:
int
:SUCCESS
: Success
ERROR_NOTOPENED
: Non-open error
ERROR_CARDDETECT
: Card detection error
ERROR_COMMUNICATION
: Communication error
ERROR_INTERNAL
: Internal error
ERROR_UNSUPPORTED
: Unsupported error- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.- API Note:
- Send power off command in ATR format.
-
receiveATR
public static int receiveATR(byte[] receiveData) throws RemoteException, UnsupportedOperationException, IllegalStateExceptionGet the ATR response data.- Parameters:
receiveData
-byte[]
: A buffer to store receive data.- Returns:
int
: Return the length of received data.
ERROR_NOTOPENED
: Non-open error
ERROR_UNSUPPORTED
: Unsupported error- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.IllegalStateException
- Gets thrown when the Library is not ready yet to accept method calls.
In such case, please useonLibraryReady
Method to add acallback
which then processes this method. See API Notes ofthis class
for further details.
-
communicateAPDU
public static int communicateAPDU(byte[] sendData, int sendLength, byte[] receiveData, int receiveLength) throws RemoteException, UnsupportedOperationException, IllegalStateExceptionCommunicate with SAM card in APDU format.- Parameters:
sendData
-byte[]
: A buffer to store send data.sendLength
-int
: Send data length.receiveData
-byte[]
: A buffer to store receive data.receiveLength
-int
: Receive data length.- Returns:
int
:SUCCESS
: Success
ERROR_NOTOPENED
: Non-open error
ERROR_CARDDETECT
: Card detection error
ERROR_COMMUNICATION
: Communication error
ERROR_DATA_LENGTH
: Data length error
ERROR_DATA_CHECKSUM
: Data checksum error
ERROR_DATA_SIZE
: Data size error
ERROR_EXECUTION
: Execution error
ERROR_PATTERN
: Pattern error
ERROR_COMMAND
: Command error
ERROR_INTERNAL
: Internal error
ERROR_UNSUPPORTED
: Unsupported error- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.IllegalStateException
- Gets thrown when the Library is not ready yet to accept method calls.
In such case, please useonLibraryReady
Method to add acallback
which then processes this method. See API Notes ofthis class
for further details.- API Note:
- Specify APDU format command.
-
communicateDirect
public static int communicateDirect(byte command, byte[] sendData, int sendLength, byte[] receiveData, int receiveLength) throws RemoteException, UnsupportedOperationException, IllegalStateExceptionSpecify the command format and communicate directly with the SAM card.- Parameters:
command
-byte
: Specify the command format.sendData
-byte[]
: A buffer to store send data.sendLength
-int
: Send data length.receiveData
-byte[]
: A buffer to store receive data.receiveLength
-int
: Receive data length.- Returns:
int
:SUCCESS
: Success
ERROR_NOTOPENED
: Non-open error
ERROR_CARDDETECT
: Card detection error
ERROR_COMMUNICATION
: Communication error
ERROR_DATA_LENGTH
: Data length error
ERROR_DATA_CHECKSUM
: Data checksum error
ERROR_DATA_SIZE
: Data size error
ERROR_EXECUTION
: Execution error
ERROR_PATTERN
: Pattern error
ERROR_COMMAND
: Command error
ERROR_INTERNAL
: Internal error
ERROR_UNSUPPORTED
: Unsupported error- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.IllegalStateException
- Gets thrown when the Library is not ready yet to accept method calls.
In such case, please useonLibraryReady
Method to add acallback
which then processes this method. See API Notes ofthis class
for further details.- API Note:
- Use this function when sending a command that can not be specified by communicateAPDU or sending any ATR format command.
-
getTimeOutDelay
public static int getTimeOutDelay() throws RemoteException, UnsupportedOperationException, IllegalStateExceptionGet card timeout delay value- Returns:
int
: Returns int value in milliseconds
ERROR_UNSUPPORTED
: Unsupported error- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.IllegalStateException
- Gets thrown when the Library is not ready yet to accept method calls.
In such case, please useonLibraryReady
Method to add acallback
which then processes this method. See API Notes ofthis class
for further details.
-
setTimeOutDelay
public static int setTimeOutDelay(int delayMs) throws RemoteException, UnsupportedOperationExceptionSet card timeout delay value in milliseconds- Parameters:
delayMs
-int
: Card response timeout in milliseconds- Returns:
int
:SUCCESS
: Success
ERROR_UNSUPPORTED
: Unsupported error- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.
-
isMethodSupported
Check whether theMethod
indicated by theBigInteger
method parameter is supported on the currently active device- Parameters:
method
-BigInteger
: Constant referencing the method to be checked- Returns:
boolean
:true
if the method is supported on the currently active device, otherwisefalse
- Throws:
IllegalStateException
- Gets thrown when the Library is not ready yet to accept method calls.
In such case, please useonLibraryReady
Method to add acallback
which then processes this method. See API Notes ofthis class
for further details.
-
isMethodSupported
Check whether theMethod
indicated by theString
methodName parameter is supported on the currently active device- Parameters:
methodName
-String
: Name of the method to be checked- Returns:
boolean
:true
if the method is supported on the currently active device, otherwisefalse
- Throws:
IllegalStateException
- Gets thrown when the Library is not ready yet to accept method calls.
In such case, please useonLibraryReady
Method to add acallback
which then processes this method. See API Notes ofthis class
for further details.
-
onLibraryReady
public static void onLibraryReady(LibraryCallback callback) throws RemoteException, UnsupportedOperationExceptionAdd a new Callback to the Queue of Callbacks to be processed once the SAM Library Service becomes available- Parameters:
callback
-LibraryCallback
: Instance of theLibraryCallback
Interface which holds theonLibraryReady()
Method which will get called once the regarding library becomes available- Throws:
RemoteException
- Gets thrown when access to the system service fails.UnsupportedOperationException
- Gets thrown when the current device does not support this method.
-