FELIX-1030: apply patch from Dennis Geurts to fix issues revealed by new tests

git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@765541 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java b/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
index f13342b..d2dcf35 100644
--- a/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
+++ b/deviceaccess/src/main/java/org/apache/felix/das/DeviceManager.java
@@ -424,9 +424,11 @@
                     {
                         info( "used by driver: " + bundle.getSymbolicName() );
                         debug( "not idle: " + ref.getBundle().getSymbolicName() );
-                        list.add( ref );
                         break;
                     }
+                    
+                    list.add( ref );
+
                 }
             }
             return list;
diff --git a/deviceaccess/src/main/java/org/apache/felix/das/DriverAttributes.java b/deviceaccess/src/main/java/org/apache/felix/das/DriverAttributes.java
index 233be2d..a60b543 100644
--- a/deviceaccess/src/main/java/org/apache/felix/das/DriverAttributes.java
+++ b/deviceaccess/src/main/java/org/apache/felix/das/DriverAttributes.java
@@ -86,7 +86,7 @@
 
         for ( ServiceReference ref : used )
         {
-            if ( Util.isDeviceInstance( ref ) )
+            if ( Util.isDevice( ref ) )
             {
                 return true;
             }
@@ -103,13 +103,11 @@
 
     public void tryUninstall() throws BundleException
     {
-        if ( !isInUse() )
+    	
+        // only install if _we_ loaded the driver
+        if ( !isInUse() && m_dynamic )
         {
-            // only install if _we_ loaded the driver
-            if ( m_dynamic )
-            {
-                m_bundle.uninstall();
-            }
+        	m_bundle.uninstall();
         }
     }
 
diff --git a/deviceaccess/src/main/java/org/apache/felix/das/util/DeviceAnalyzer.java b/deviceaccess/src/main/java/org/apache/felix/das/util/DeviceAnalyzer.java
index e34eee7..0c29f74 100644
--- a/deviceaccess/src/main/java/org/apache/felix/das/util/DeviceAnalyzer.java
+++ b/deviceaccess/src/main/java/org/apache/felix/das/util/DeviceAnalyzer.java
@@ -84,6 +84,7 @@
             if ( !String[].class.isInstance( cat ) )
             {
                 m_log.log( LogService.LOG_ERROR, "invalid device: invalid device category: " + Util.showDevice( ref ) );
+                return;
             }
             if ( String[].class.cast( cat ).length == 0 )
             {
diff --git a/deviceaccess/src/main/java/org/apache/felix/das/util/Util.java b/deviceaccess/src/main/java/org/apache/felix/das/util/Util.java
index 69ba60d..09ed8c8 100644
--- a/deviceaccess/src/main/java/org/apache/felix/das/util/Util.java
+++ b/deviceaccess/src/main/java/org/apache/felix/das/util/Util.java
@@ -64,7 +64,25 @@
         return buffer.toString();
     }
 
-
+    public static boolean isDevice( ServiceReference ref )
+    {
+        try
+        {
+            Filter device = createFilter( "(|(%s=%s)(%s=%s))", new Object[]
+                { 
+            		Constants.OBJECTCLASS, Device.class.getName(),
+            		org.osgi.service.device.Constants.DEVICE_CATEGORY, "*" 
+            		}
+            );
+            return device.match( ref );
+        }
+        catch ( Exception e )
+        {
+            e.printStackTrace();
+        }
+        return false;
+    }
+    
     public static boolean isDeviceInstance( ServiceReference ref )
     {
         try