-
Notifications
You must be signed in to change notification settings - Fork 6
Session
When the conditions match the trigger defined in Plugin, PluginManagerService will start a session. Session enables plugins to communicate with PluginManagerService. During a session, developers can create different tasks to perform more actions on user's phone. A session may contain multiple tasks. When the plugin finishes its tasks and ready to start for a next coming trigger, the session will end.
Here is an example of an contact auto sharing plugin.
(Pic from Mika Nomura http://mikanomura.com/messageontap.html)
For a plugin which is able to help user auto send phone numbers in the contact saved in user's phone, developers may set a trigger to find out whether a message contains a person name and the keyword "phone number" or not. In MessageOnTap-core, SemanticUnderstandingThread and PluginManagerService will try to find out if this message matches the trigger. In this case, a message like "Send me Adam's phone number" will match the trigger. At the same time, the PluginManagerService will start a session. Plugin now may send a task in this session to find the phone number with name Adam in PersonalGraph. Let's imagine we do have a friend named Adam and his phone number is 412-1000-1000. The plugin can now send another task to PluginManagerService to enable another task to auto send messages to the person who wants this phone number. Then the session will stop and wait for the next match of trigger.
@Override
protected void initNewSession(long sid, HashMap<String, Object> params) throws Exception {
Log.e(TAG, "Session created here!");
Log.e(TAG, JSONUtils.hashMapToString(params));
// TID is something we might need to implement stateflow inside a plugin.
/*
* Divide all triggers into two groups, those whose message contains a whole DocName
* and those whose message only contains terms like doc or file.
* No matter which group was triggered, plugin is requested to query twice. In the first time
* the root is DocName, and in the second time the root is DocUrl.
* The difference between two groups is, if the message contains DocName, plugin have to
* query all the user's DocNames, and judge whether the message contains one of them, after that can
* the plugin step forward.
*/
if (triggerListHasName.contains((Trigger) params.get(EntityAttributes.PMS.TRIGGER_SOURCE))){
tree1.put(sid, (ParseTree) params.get(EntityAttributes.Graph.SYNTAX_TREE));
DocTime1.put(sid, getTimeString(params));
treeForSearch1.put(sid, AddNameRoot(tree1.get(sid), ALL_DOCNAME_ROOT_ID, DocTime1.get(sid), tag_time));
params.remove(EntityAttributes.Graph.SYNTAX_TREE);
params.put(EntityAttributes.Graph.SYNTAX_TREE, treeForSearch1);
tidFindAllDocName.put(sid, createTask(sid, MethodConstants.GRAPH_TYPE,
MethodConstants.GRAPH_METHOD_RETRIEVE, params));
} else {
tree2.put(sid, (ParseTree) params.get(EntityAttributes.Graph.SYNTAX_TREE));
DocTime2.put(sid, getTimeString(params));
treeForSearch2.put(sid, AddNameRoot(tree2.get(sid), FILTERED_DOCNAME_ROOT_ID,
DocTime2.get(sid), tag_time));
params.remove(EntityAttributes.Graph.SYNTAX_TREE);
params.put(EntityAttributes.Graph.SYNTAX_TREE, treeForSearch2);
tidFindDocName.put(sid, createTask(sid, MethodConstants.GRAPH_TYPE,
MethodConstants.GRAPH_METHOD_RETRIEVE, params));
}
}
@Override
protected void endSession(long sid) {
tidFindAllDocName.remove(sid); tidFindDocName.remove(sid); tidFindUrl1.remove(sid);
tidFindUrl2.remove(sid); tidBubble.remove(sid); tidDetails.remove(sid); tidDocSend.remove(sid);
tree1.remove(sid); tree2.remove(sid); treeForSearch1.remove(sid); treeForSearch2.remove(sid);
DocTime1.remove(sid); DocTime2.remove(sid); selectedDocUrl.remove(sid);
super.endSession(sid);
}
DataType | Name |
---|---|
String | mPackageName |
Set<long> | mUncompleted |
LongSparseArray<Task> | mTasks |
long | lastTID |
Function |
---|
Session(String,Task) |
Session(Task) |
Return Type | Function |
---|---|
String | getPackageName() |
void | setPackageName(String) |
Set<long> | getUncompletedTaskIDs |
boolean | isTaskCompleted(long) |
Task | newTask(Task) |
void | updateTaskResponse(long) |
void | updateTaskResponse(Task) |
Task | getTask(long) |
void | failTask(long) |
2017 MessageOnTap