可多选的javacard applet,与多个逻辑通道上设置各自不同的applet是有区别的。
Java Card 2.2支持逻辑通道(logical channels)的概念,允许最多智能卡中的16个应用程序会话同时开启,每个逻辑通道一个会话。因为卡片中的APDU的处理不能中断,并且每个APDU包含一个到逻辑通道(在CLA字节)的引用,变动的APDU可以拟同步地访问卡片上的许多小应用程序。
你可以设计一个小应用程序被多次选择;也就是说,每次和一个以上逻辑通道通信。多选的小应用程序必须实现
javacard.Framework.MultiSelectable接口和相应方法。
4.2 Multiselectable Applets
Applets having the capability of being selected on multiple logical channels at the same time, or accepting other applets belonging to the same package being selected simultaneously, are referred to as multiselectable applets.
An applet’s context is active when either an instance of the applet is already active, or when another applet instance from the same package is active. For more information about contexts see Section 6.1.2 "Contexts and Context Switching.” An attempt to select an applet instance when the applet’s context is active, is referred to as a multiselection attempt. If successful, multiselection occurs, and the applet instance becomes multiselected.
Multiselectable applets shall implement the javacard.framework.MultiSelectable
interface. In case of multiselection, the applet instance will be informed by invoking its methods MultiSelectable.select
andMultiSelectable.deselect
during selection and deselection respectively.
When an applet instance not currently active is the first one selected in its package, its Applet.select
method is called. Subsequent multiselections to this applet instance or selection of other applet instances in the same package shall result in a call to MultiSelectable.select
method. This method is defined in the MultiSelectable
interface. Its only purpose is to inform the applet instance that it will be multiselected. The applet instance may accept or reject a multiselection attempt.
If a multiselection attempt is made on an applet which does not implement the MultiSelectable
interface, the selection shall be rejected by the Java Card RE.
When a multiselected applet instance is deselected from one of the logical channels, the method MultiSelectable.deselect
is called. Only when the multiselected applet instance is the last active applet instance in the applet’s context, is its regular method Applet.deselect
called.
There are two cases of multiselection:
- When two distinct applet instances from within the same package are multiselected, each applet instance shares the same
CLEAR_ON_DESELECT
memory transient segment. The applet instances share objects within the context firewall as well as their transient data. The Java Card RE shall not reset thisCLEAR_ON_DESELECT
transient objects until all applet instances within the package are deselected.(Refer to FIGURE 2.)
FIGURE 2 – Different applet instances in same package
- When the same applet instance is multiselected on two different logical channels simultaneously, it shares the
CLEAR_ON_DESELECT
memory segment space across logical channels. The Java Card RE shall not reset theCLEAR_ON_DESELECT
transient objects until all applet instances within the package are deselected. (Refer to FIGURE 3.)
FIGURE 3 – Same applet instance selected on multiple logical channels
In both cases of multiselection described above, the applet(s) must implement the MultiSelectable
interface. If the applet(s) do not support this feature, then the selection must be rejected by the Java Card RE.
Method Summary | |
void |
deselect(boolean appInstStillActive) Called by the Java Card runtime environment to inform that this currently selected applet instance is being deselected on this logical channel while the same applet instance or another applet instance from the same package is still active on another logical channel. |
boolean |
select(boolean appInstAlreadyActive) Called by the Java Card runtime environment to inform that this applet instance has been selected while the same applet instance or another applet instance from the same package is active on another logical channel. |