Refactor connecting to SAP service and sending messages in queue
Sending and receiving works correctly, however establishing an SAP connection takes too long
This commit is contained in:
committed by
Frank Morgner
parent
023550ac11
commit
f2a68c95c1
@@ -120,6 +120,9 @@ public class MainActivity extends AppCompatActivity {
|
||||
IntentFilter intentFilter = new IntentFilter();
|
||||
intentFilter.addAction(EmulatorSingleton.TAG);
|
||||
bManager.registerReceiver(bReceiver, intentFilter);
|
||||
|
||||
Intent serviceIntent = new Intent(this.getApplicationContext(), SmartcardProviderService.class);
|
||||
startService(serviceIntent);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -60,7 +60,7 @@ public class SmartcardProviderService extends SAAgent {
|
||||
EmulatorSingleton.createEmulator(this);
|
||||
} catch (SsdkUnsupportedException e) {
|
||||
// try to handle SsdkUnsupportedException
|
||||
if (processUnsupportedException(e) == true) {
|
||||
if (processUnsupportedException(e)) {
|
||||
EmulatorSingleton.createEmulator(this);
|
||||
return;
|
||||
}
|
||||
@@ -73,6 +73,7 @@ public class SmartcardProviderService extends SAAgent {
|
||||
*/
|
||||
stopSelf();
|
||||
}
|
||||
findPeerAgents();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -82,13 +83,23 @@ public class SmartcardProviderService extends SAAgent {
|
||||
|
||||
@Override
|
||||
protected void onFindPeerAgentsResponse(SAPeerAgent[] peerAgents, int result) {
|
||||
switch (result) {
|
||||
case PEER_AGENT_FOUND:
|
||||
break;
|
||||
case FINDPEER_SERVICE_NOT_FOUND:
|
||||
break;
|
||||
case FINDPEER_DEVICE_NOT_CONNECTED:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
Log.d(TAG, "onFindPeerAgentResponse : result =" + result);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onServiceConnectionRequested(SAPeerAgent peerAgent) {
|
||||
if (peerAgent != null) {
|
||||
Toast.makeText(getBaseContext(), "connection accepted", Toast.LENGTH_SHORT).show();
|
||||
//TODO: Check for keys and everything
|
||||
acceptServiceConnectionRequest(peerAgent);
|
||||
}
|
||||
}
|
||||
@@ -98,6 +109,7 @@ public class SmartcardProviderService extends SAAgent {
|
||||
if (result == SAAgent.CONNECTION_SUCCESS) {
|
||||
if (socket != null) {
|
||||
mConnectionHandler = (ServiceConnection) socket;
|
||||
Toast.makeText(getBaseContext(), "connection established", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
} else if (result == SAAgent.CONNECTION_ALREADY_EXIST) {
|
||||
Log.e(TAG, "onServiceConnectionResponse, CONNECTION_ALREADY_EXIST");
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
tools:context="com.vsmartcard.smartcardemulator.MainActivity">
|
||||
tools:context="com.vsmartcard.acardemulator.MainActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:id="@+id/app_bar"
|
||||
|
||||
@@ -27,10 +27,10 @@
|
||||
]>
|
||||
<resources>
|
||||
|
||||
<application name="HelloAccessoryProvider" >
|
||||
<application name="VirtualSmartCardReader" >
|
||||
<serviceProfile
|
||||
id="/sample/hello"
|
||||
name="helloaccessory"
|
||||
id="/com/vsmcartcard"
|
||||
name="VirtualSmartCardReaderProvider"
|
||||
role="provider"
|
||||
serviceImpl="com.vsmartcard.acardemulator.SmartcardProviderService"
|
||||
version="1.0"
|
||||
|
||||
Reference in New Issue
Block a user