需求如下:
These are the filters, in priority order:
1- GetCardInput.AcqIndexList:
If application send this list, then the library must search just for these index in the table.
For example:
GetCardInput.AcqIndexList = ('1701', '1702', '1703').
In this case, if the card inserted/swiped does not match with these three rows, library must return GetCardOutput.ReturnCode = CARDAPPNAV.
IF GetCardInput.AcqIndexList == null, then try to filter by CardAppType:
2- GetCardInput.CardAppType:
If application sends GetCardInput.CardAppType == 1, then the library must filter all the table by app type and return just rows with app type == 1.
If application sends GetCardInput.CardAppType == 2, then the library must filter all the table by app type and return just rows with app type == 2.
If the card inserted/swiped does not match, library must return GetCardOutput.ReturnCode = CARDAPPNAV.
If application sends GetCardInput.CardAppType == 99, then the library use the hole table rows.
IF GetCardInput.CardAppType == 0, then try to filter by AcquirerId:
3- GetCardInput.AcquirerId:
In this case, the library must filter all the table by acquirer id;
4- If application sends GetCardInput.CardAppType != 0 and Acquirer Id != 0, then library must use the both values to filter the table.
1.在把AID添加到内核的时候执行添加动作。进入过滤状态设计模式。退出的时候就已经把值赋值好了。
首先,需要设置context类,这个类包括数据库句柄。
GetCardInput inputData;
List
public boolean addAidList() {
cardFilterContext.setState(new InitialState(cardFilterContext));
try {
while (true) {
cardFilterContext.applyFilter();
if (cardFilterContext.getState() instanceof QuitFiltertable) {
// Logic for quitting CVM
Logs.d(TAG, "QuitFiltertable");
addAidToEmvList();
return true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
其中,抽象状态类。要设置成抽象,因为还有公共的实现函数。并且把context类放在里面,
便于具体状态类继承并使用。
public abstract class State {
protected CardFilterContext cardFilterContext;
public State(CardFilterContext cardFilterContext ) {
this.cardFilterContext = cardFilterContext;
}
static final String TAG = InitializeAppState.class.getSimpleName();
public abstract void applyFilter();
public List processQueryResult(List
3.具体状态类。
public class InitialState extends State {
private final String TAG = "InitialState";
public InitialState(CardFilterContext context) {
super(context);
}
@Override
public void applyFilter() {
if (cardFilterContext.inputData.getAcqIndexList() != null && !cardFilterContext.inputData.getAcqIndexList().isEmpty()) {
// Execute AcqIndexList filter
List acqIndexList = cardFilterContext.inputData.getAcqIndexList();
List
还有一个需求就是返回ReturnCode = CARDAPPNAV.
如果拿到选择应用的结果就返回并设置对应的ReturnCode
public boolean Appselect() {
ContextAppSelete contextAppSelete = new ContextAppSelete();
contextAppSelete.setState(new SelectAppState(contextAppSelete));
try {
while (true) {
contextAppSelete.executeSelectFinalApp();
if (contextAppSelete.getState() instanceof QuitFinalAppState) {
contextAppSelete.executeSelectFinalApp();
if (contextAppSelete.getErrorCode()!=0) {
getCardOutput.setReturnCode(contextAppSelete.getReturnCodes());
return false;
} else {
emv_candlist = contextAppSelete.getEmvCandlist();
Logs.d(TAG, "emv_candlist.aid " + tools.hexString(emv_candlist.aid, 0, emv_candlist.aidLen));
return true;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}