Manager { public static void addFeatureToNode(byte deviceId,SparseArray<Class<? extends Feature>> features) throws InvalidFeatureBitMaskException { SparseArray<Class<? extends Feature>> updateMe; if(!sFeatureMapDecoder.containsKey(deviceId)){ updateMe = BLENodeDefines.FeatureCharacteristics.DEFAULT_MASK_TO_FEATURE.clone(); sFeatureMapDecoder.put(deviceId,updateMe); }else{ updateMe = sFeatureMapDecoder.get(deviceId); } SparseArray<Class<? extends Feature>> addMe = features.clone(); long mask=1; for(int i=0; i<32; i++ ){ Class<? extends Feature> featureClass = addMe.get((int)mask); if (featureClass != null) { updateMe.append((int) mask, featureClass); addMe.remove((int)mask); } mask=mask<<1; } if(addMe.size()!=0) throw new InvalidFeatureBitMaskException("Not all elements have a single bit in " + "as key"); } private  Manager(); static List<AdvertiseFilter> buildDefaultAdvertiseList(); static synchronized Manager getSharedInstance(); @RequiresPermission(allOf = { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN}) boolean startDiscovery(); @RequiresPermission(allOf = { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN}) boolean startDiscovery(int timeoutMs); @RequiresPermission(allOf = { Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.BLUETOOTH, Manifest.permission.BLUETOOTH_ADMIN}) boolean startDiscovery(int timeoutMs,List<AdvertiseFilter> filters); boolean hasConnectedNodes(); boolean isMPhy2Supported(); void addVirtualNode(); boolean addNode(final Node newNode); boolean stopDiscovery(); boolean isDiscovering(); void resetDiscovery(); void addListener(ManagerListener listener); void removeListener(ManagerListener listener); @Nullable Node getNodeWithTag(@NonNull String tag); @Nullable Node getNodeWithName(String name); List<Node> getNodes(); static void addFeatureToNode(byte deviceId,SparseArray<Class<? extends Feature>> features); static @NonNull SparseArray<Class<? extends Feature>> getNodeFeatures(byte deviceId);  }
@Test(expected = InvalidFeatureBitMaskException.class) public void addInvalidFeatureMask() throws InvalidFeatureBitMaskException{ SparseArray<Class<? extends Feature>> invalidMask = new SparseArray<>(1); invalidMask.append(3, Feature.class); Manager.addFeatureToNode((byte) 0x00, invalidMask); }
@Test public void checkNewDeviceType() throws InvalidFeatureBitMaskException, InvalidBleAdvertiseFormat { SparseArray<Class<? extends Feature>> featureList = new SparseArray<>(1); featureList.append(2, Feature.class); Manager.addFeatureToNode((byte) 0xFF, featureList); Node node = buildNodeWithId((byte) 0xFF); Assert.assertEquals(Node.Type.NUCLEO, node.getType()); Manager.addFeatureToNode((byte) 0x79, featureList); node = buildNodeWithId((byte) 0x79); Assert.assertEquals(Node.Type.GENERIC, node.getType()); }