/** * Handle session join failed * * @param args */ private void handleSessionJoinFailed(Map<String, Object> args) { String deviceId = (String) args.get("DEVICE_ID"); Object statusObj = args.get("STATUS"); if (statusObj == null || !(statusObj instanceof Status)) { return; } String status = ((Status) statusObj).name(); Log.w( TAG, "Received SESSION_JOIN_FAIL event for deviceId: '" + deviceId + "', this deviceId is: '" + this.deviceId + "', Status: '" + status + "'"); if (deviceId == null || !deviceId.equals(this.deviceId)) { return; } this.sessionId = null; connMgr.unregisterEventListener(ConnManagerEventType.SESSION_JOINED, this); connMgr.unregisterEventListener(ConnManagerEventType.SESSION_LOST, this); connMgr.unregisterEventListener(ConnManagerEventType.SESSION_JOIN_FAIL, this); deviceEventsListener.errorOccurred(this, status); } // handleSessionJoinedFailed
/** * Stops all the device activities <br> * close session <br> * stop find adv name <br> * stop scheduled service <br> * Set is reachable to false */ void stopDeviceActivities() { isReachable.set(false); try { connMgr.cancelFindAdvertisedName(sender); } catch (ControlPanelException cpe) { Log.e(TAG, "Failed to call cancelFindAdvertisedName(), Error: '" + cpe.getMessage() + "'"); } connMgr.unregisterEventListener(ConnManagerEventType.FOUND_DEVICE, this); connMgr.unregisterEventListener(ConnManagerEventType.LOST_DEVICE, this); Status status = endSession(); if (status != Status.OK) { Log.e(TAG, "Failed to end the session, Status: '" + status + "'"); } stopDeviceFoundVerificationService(); for (Unit unit : unitMap.values()) { unit.release(); } unitMap.clear(); } // stopDeviceActivities
/** * Handle session lost * * @param args */ private void handleSessionLost(Map<String, Object> args) { Integer sessionId = (Integer) args.get("SESSION_ID"); Log.w( TAG, "Received SESSION_LOST event for sessionId: '" + sessionId + "', this device sessionId is: '" + this.sessionId + "'"); if (sessionId == null || !sessionId.equals(this.sessionId)) { return; } this.sessionId = null; connMgr.unregisterEventListener(ConnManagerEventType.SESSION_JOINED, this); connMgr.unregisterEventListener(ConnManagerEventType.SESSION_LOST, this); connMgr.unregisterEventListener(ConnManagerEventType.SESSION_JOIN_FAIL, this); deviceEventsListener.sessionLost(this); } // handleSessionLost
/** * End the session with the remote controllable device * * @return {@link Status} of endSession execution */ public Status endSession() { Log.i(TAG, "endSession has been called, leaving the session"); if (sessionId == null) { Log.w(TAG, "Fail to execute endSession, sessionId is NULL, returning Status of FAIL"); return Status.FAIL; } Status status; try { status = connMgr.leaveSession(sessionId); } catch (ControlPanelException cpe) { Log.e( TAG, "Failed to call leaveSession, Error: '" + cpe.getMessage() + "', returning status of FAIL"); return Status.FAIL; } String logMsg = "endSession return Status is: '" + status + "'"; if (status == Status.OK) { sessionId = null; Log.i(TAG, logMsg); // Unregister the session relevant events connMgr.unregisterEventListener(ConnManagerEventType.SESSION_JOINED, this); connMgr.unregisterEventListener(ConnManagerEventType.SESSION_LOST, this); connMgr.unregisterEventListener(ConnManagerEventType.SESSION_JOIN_FAIL, this); } else { Log.w(TAG, logMsg); } return status; } // endSession