void NotifyApplication(final EnrolleeInfo result) { // Get a handler that can be used to post to the main thread /* Handler mainHandler = new Handler(context.getMainLooper()); Runnable myRunnable = new Runnable() { @Override public void run() { finishListener.deviceOnBoardingStatus(result); } }; mainHandler.post(myRunnable); */ Log.i( TAG, "Scanning is finished with result, IP : " + result.getIpAddr() + "Notifying " + "to Application"); finishListener.deviceOnBoardingStatus(result); }
/* * The API is used for checking the device entry in the list maintained for the device * notifications. * If device entry is not found in the list, app is notified. * If the device entry is found in the device, as application is already notified it will * continue */ private boolean CheckForDeviceEntryAndNotify(String ipAddr, String macAddr, boolean isReachable) { final EnrolleeInfo result = new EnrolleeInfo(); boolean deviceAddedToList = false; if (appNotification.size() > 0) { for (EnrolleeOnBoardingInfo ipDeviceOnBoardingNotification : appNotification) { EnrolleeOnBoardingInfo ipEnrolleeDevice = (EnrolleeOnBoardingInfo) ipDeviceOnBoardingNotification; boolean macAddressComparison = ipEnrolleeDevice.getHWAddr().equalsIgnoreCase(macAddr) ? true : false; if (macAddressComparison) { deviceAddedToList = true; if (ipDeviceOnBoardingNotification.isAdditionNotified() && isReachable) { continue; } else if (ipDeviceOnBoardingNotification.isRemovalNotified() && !isReachable) { continue; } else { result.setIpAddr(ipAddr); result.setHWAddr(macAddr); result.setReachable(isReachable); appNotification.remove(ipDeviceOnBoardingNotification); if (isReachable) { appNotification.add( new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false, true)); } else { // This case will happen during the transition from connected to // disconneted. This case need not be notified to application. // Notifying this state will cause failure of OnBoarding } NotifyApplication(result); return true; } } } if (!deviceAddedToList) { if (isReachable) { appNotification.add( new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false, true)); result.setIpAddr(ipAddr); result.setHWAddr(macAddr); result.setReachable(isReachable); NotifyApplication(result); } else { // This case will happen for the first time device is listed, but reachability // is false. This case need not be notified to application. Notifying this // state will cause failure of OnBoarding } return true; } } else { if (isReachable) { appNotification.add( new EnrolleeOnBoardingInfo(ipAddr, macAddr, "", isReachable, false, true)); result.setIpAddr(ipAddr); result.setHWAddr(macAddr); result.setReachable(isReachable); NotifyApplication(result); } else { // This case will happen for the first time device is listed, but // reachability is false. This case need not be notified to // application. Notifying this state will cause failure of OnBoarding } return true; } return false; }