Class SessionManager

  • All Implemented Interfaces:

    
    public final class SessionManager
    
                        

    SessionManager implements the necessary functionality required to encrypt/decrypt data transferred between devices.

    SessionManager requires DeviceEngagement and Handover to be instantiated. Usually this is done after device engagement phase and this instance must be available after receiving data from devices, in order to decrypt them.

    
    public class SomeActivity extends androidx.appcompat.app.AppCompatActivity
         implements DeviceEngagementCallback, TransferReceiveCallback {
        private SessionManager sessionManager;
        private Map<String, Map<String, Map<String, Boolean>>> docRequests = ...
    
        @Override
        public void onEngage(@NonNull Received<EngagementReceived> engagementReceived) {
            engagementReceived.run(
                failure -> {
                    android.util.Log.e(TAG, failure.toString());
                },
                success -> {
                    DeviceEngagement deviceEngagement = success.getDeviceEngagement();
                    Handover handover = success.getHandover();
                    try {
                        sessionManager = new SessionManager(deviceEngagement, handover);
                        // create request
                        Request request = Request.create(docRequests, sessionManager);
                        // or get encrypted bytes
                        byte[] encryptedBytes = sessionManager..createRequest(docRequests);
    
                        // use deviceEngagement, handover and request or encryptedBytes to send
                        // via a Transfer implementation
                    } catch (SDKException e) {
                        android.util.Log.e(TAG, e.getMessage(), e);
                    }
                });
        }
    
        @Override
        public void onReceive(@NonNull Received<TransferReceived> transferReceived) {
            transferReceived.run(
                failure -> {
                    android.util.Log.e(TAG, failure.toString());
                },
                success -> {
                    success.runForDevice(receivedBytes -> {
                        try {
                             SessionData sessionData = sessionManager.decryptResponse(receivedBytes);
                             // do stuff with decrypted sessionData
                        } catch (SDKException e) {
                             // handle error when decrypting
                        }
                    });
                });
        }
    }