SDK开发过程示意图如下:



请求SE服务及配置SE连接

内部SE

1)SE的服务用于设备驱动SE,SDK通过SEConnectionManager请求SE的服务,当SE请求成功后会通过notifyServiceReady通知应用已请求成功。

Android平台实例代码:

// Implement the SEServiceListener interface
/** Get Secure Element Connection Manager instance */
SEConnectionManager seConMgr = SEConnectionManager.getInstance();
/** Request to the services */
seConMgr.requestService(applicationContext, this);
// pass in a SEServiceListener
// implement notifyServiceReady to listen for connection ready
public void notifyServiceReady(int[] availableSecureElements) {
    LOG.info("SE Service ready");
}

iOS平台的示例代码:

// MySecureElementManager.h
@interface MySecureElementManager : NSObject<ISEServiceDelegate>
-(void) initializeConnectionManager;
@end

// MySecureElementManager.m
@implementation MySecureElementManager
-(void) initializeConnectionManager {
/** Get Secure Element Connection Manager instance */
SEConnectionManager *seConManager = [SEConnectionManager getInstance];
/** Request to the services */
[seConManager requestService:self];
}
// Implement this method for further actions
-(void) notifyServiceReady:(NSArray *)availableSecureElements {
//Manage next actions here...
}
@end

2)SE服务请求成功后,需配置我们要使用的SE的类型,并添加SEConnection 到SEConnectionManager中。

Android平台实例代码:

/** Configuration object */
SEConfiguration seConfig = new SEConfiguration();
/** Type of Secure Element(SE) */
seConfig.setType(SEConfiguration.SE_TYPE_SIM); // SE on SIM
/** Create the SEConnection instance through the SEConnectionManager */
String readerName = seConnectionManager.addSEConnection(seConfig);

iOS平台的示例代码:

/** Configuration object */
SEConfiguration *config = [[SEConfiguration alloc] init];
/** Secure Element type is OTI */
[config setType:SEConfiguration_SE_TYPE_WAVE_OTI];
NSString *readerName = [seConManager addSEConnection:config];
蓝牙外部SE

BLSELib通过蓝牙和SE进行通信,它的基本流程和SELib一致。只是不需要去请求SE的服务,直接创建蓝牙SE的连接并添加BluetoothSEConnection到SEConnectionManager中。

Android平台实例代码:

//add Bluetooth SE Connection
SEConfiguration seConfiguration = new SEConfiguration();
seConfiguration.setType(SEConfiguration.SE_TYPE_ESE);
//pass bluetooth connection to SE connection
bConnection = new BluetoothSEConnection(seConfiguration, bleConn);
String readerName = SEConnectionManager.getInstance().addSEConnection(bConnection, "bluetooth");

iOS平台的示例代码

SEConnectionManager *seConManager = [SEConnectionManager getInstance];
SEConfiguration *config = [[SEConfiguration alloc]init];
[config setType:SEConfiguration_SE_TYPE_ESE];
//add Custom SE Connection
BluetoothSEConnection *connection = [[BluetoothSEConnection alloc] initWithConfiguration:config andBLEConnection: bleConn];
NSString *readerName = [seConManager addSEConnection:connection
withReaderName:@"bluetooth"];

Provisioning Proxy配置并初始化

配置并初始化Provisioning Proxy;配置信息主要包括上下文context,readerName(4.1中获得),URL,default timeout。

Android平台示例代码:

/** Configuration object */ 
Configuration provisioningConfig = new Configuration(); 
/** Set application context */ 
provisioningConfig.setApplicationContext(getApplicationContext()); 
/** Set SE Connection reader name */ 
provisioningConfig.setSEReaderName(readerName); //pass SEConnection reader name returned by SEConnectionManager 
/** Default URL */ 
provisioningConfig.setDefaultURL("http://host/path"); 
/** Set Default Connection Timeout to 20 seconds */ 
provisioningConfig.setDefaultConnectionTimeout(20000);

iOS平台的示例代码

/** Configuration object */
ProxyAgentConfiguration*Config = [[ProxyAgentConfiguration alloc]init];
/** Set SE Connection reader name */
[Config setSEReaderName:readerName]; //pass SEConnection reader name
returned by SEConnectionManager
/** Default URL */
[Config setDefaultURL:@"http://host/path"];

配置Service参数并执行PP Agent

Service是概念是指Link TSM Sever提供的某个服务, 如创建一个SD、或者下载一个安全应用等。配置Service参数,主要是配置某个Service的URL,不同URL提供不同服务,具体参数需联系技术支持。

然后通过launch Agent, 执行对SE的操作, Agent 会通知APP,业务执行状态,业务执行结果以及一些业务用户提醒信息。Agent的通知有过程通知和结果通知。

过程通知:

notifyProgress(int progress) :业务执行百分比

notifyUserInfo(UserInfo info) : 执行过程中提示用户的信息

Android平台示例代码:

/** Configure and instantiate Provisioning interface */
Agent agent = Agent.getInstance(provisioningConfig, notification, userNotification); // pass in a Notification and UserNotification implementation to listen for notifications

/** Configuration serviceParameters object */ 
ServiceParameters serviceParams = new ServiceParameters(); 
serviceParams.setRequestType(ServiceParameters.REQUEST_TYPE_DEFAULT);
serviceParams.setUrl(“https://tsm.xxxx.com”);    //URL,由TSM提供
agent.launch(serviceParams);

iOS平台示例代码

/** Configure and instantiate Provisioning interface */
ProxyAgent agent = [ProxyAgent getInstance:Config andNotification:
notification andUserNotification:userNotification]; 
// pass in aNotification and UserNotification implementation to listen for notifications

ProxyAgentServiceParams *params = [[ProxyAgentServiceParams alloc] initWithURL: url];
[agent launch:params]