/** * Starts the session with the remote controllable device * * @param eventsListener */ public void startSession(DeviceEventsListener eventsListener) throws ControlPanelException { if (eventsListener == null) { throw new ControlPanelException("Events listener can't be NULL"); } deviceEventsListener = eventsListener; if (sessionId != null) { String msg = "The device is already in session: '" + deviceId + "', sessionId: '" + sessionId + "'"; Log.d(TAG, msg); deviceEventsListener.sessionEstablished(this, getControlPanelCollections()); return; } connMgr.registerEventListener(ConnManagerEventType.SESSION_JOINED, this); connMgr.registerEventListener(ConnManagerEventType.SESSION_LOST, this); connMgr.registerEventListener(ConnManagerEventType.SESSION_JOIN_FAIL, this); Log.d(TAG, "Device: '" + deviceId + "' starting session with sender: '" + sender + "'"); Status status = connMgr.joinSession(sender, deviceId); if (status != Status.OK) { String statusName = status.name(); Log.e(TAG, "Failed to join session: '" + statusName + "'"); deviceEventsListener.errorOccurred(this, statusName); return; } } // startSession
/** * Starts {@link ControlPanelService} which discovers controllable devices in its proximity. <br> * The ControlPanelService user is informed about the devices in proximity via the {@link * DeviceRegistry} interface. <br> * The discovery mechanism is implemented by receiving Announcement signals. <br> * * @param bus BusAttachment that the service should use * @param deviceRegistry Holds the information about the devices in proximity<br> * {@link DefaultDeviceRegistry} may be passed in to receive information about the devices * @throws ControlPanelException if failed to initialize the control panel service */ public void init(BusAttachment bus, DeviceRegistry deviceRegistry) throws ControlPanelException { if (deviceRegistry == null) { throw new ControlPanelException("deviceRegistry can't be NULL"); } AboutService aboutService = AboutServiceImpl.getInstance(); if (!aboutService.isClientRunning()) { throw new ControlPanelException( "The AboutService is not running, impossible to receive Announcement signals"); } // Perform the basic service initialization init(bus); this.deviceRegistry = deviceRegistry; Log.d(TAG, "Start listening for Announcement signals"); connMgr.registerEventListener(ConnManagerEventType.ANNOUNCEMENT_RECEIVED, this); // Add an announcement handler announcementReceiver = new AnnouncementReceiver(); for (String iface : ANNOUNCEMENT_IFACES) { aboutService.addAnnouncementHandler(announcementReceiver, new String[] {iface}); } } // init
/** Subscribe to receive foundAdvName and lostAdvName events of ConnectionManager */ void subscribeOnFoundLostEvents() { Log.d(TAG, "Register on ConnManager to receive events of found and lost advertised name"); connMgr.registerEventListener(ConnManagerEventType.FOUND_DEVICE, this); connMgr.registerEventListener(ConnManagerEventType.LOST_DEVICE, this); } // subscribeOnFoundLostEvents