changeset 243:f49f6cc6b93d

8138686: api/jdk/dio/DevicePermission/index.html#devicePermission fails Summary: Suppost DevicePermission collections Reviewed-by: snazarki Contributed-by: olga.milovskaya@oracle.com
author snazarki
date Thu, 01 Oct 2015 15:53:03 +0300
parents ae4dc5f2d281
children fb31196e1167
files src/share/classes/com/oracle/dio/utils/Utils.java src/share/classes/jdk/dio/DevicePermission.java
diffstat 2 files changed, 61 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/com/oracle/dio/utils/Utils.java	Thu Oct 01 15:30:18 2015 +0300
+++ b/src/share/classes/com/oracle/dio/utils/Utils.java	Thu Oct 01 15:53:03 2015 +0300
@@ -61,6 +61,19 @@
         }
     }
 
+    public static String[] getActionsList(String actions) {
+        StringTokenizer tokez = new StringTokenizer(actions, ",", false);
+
+        int count = tokez.countTokens();
+
+        String[] actionsList = new String[count];
+
+        for (int i = 0; i < count; i++) {
+            actionsList[i] = tokez.nextToken();
+        }
+        return actionsList;
+    }
+
     /**
      * Checks if given <code>what</code> is included to
      * <code>where</code> list
@@ -276,7 +289,7 @@
     // Check all characters in the string are decimal digits
     private static boolean isNonNegativeNumber(String str, int radix) {
         try {
-            return Integer.parseInt(str, radix) >= 0;
+           return Integer.parseInt(str, radix) >= 0;
         } catch (NumberFormatException e) {
             return false;
         }
--- a/src/share/classes/jdk/dio/DevicePermission.java	Thu Oct 01 15:30:18 2015 +0300
+++ b/src/share/classes/jdk/dio/DevicePermission.java	Thu Oct 01 15:53:03 2015 +0300
@@ -283,6 +283,15 @@
             return false;
         }
 
+        return privateImplies(permission);
+    }
+
+    @Local(WeakDontRenameSubtypes = {"jdk.dio.DevicePermission"})
+    public String toString() {
+        return getClass().getName() + " \'" + getName() + "\' " + getActions();
+    }
+
+    boolean privateImplies(Permission permission) {
         if (!Utils.implies(getActions(), permission.getActions())) {
             return false;
         }
@@ -320,11 +329,6 @@
         return true;
     }
 
-    @Local(WeakDontRenameSubtypes = {"jdk.dio.DevicePermission"})
-    public String toString() {
-        return getClass().getName() + " \'" + getName() + "\' " + getActions();
-    }
-
     /**
      * Returns a new {@code PermissionCollection} for storing {@code DevicePermission} objects.
      * <p>
@@ -362,6 +366,14 @@
     }
 }
 
+final class LocalPermission extends DevicePermission {
+
+    LocalPermission(String name, String actionsList) {
+        super(name, actionsList);
+    }
+
+}
+
 final class PeripheralPermissionCollection extends PermissionCollection {
 
     private final Vector<DevicePermission> permissions = new Vector<>(6);
@@ -380,11 +392,38 @@
             return false;
         }
         DevicePermission perm = (DevicePermission) permission;
+
+        String[] actionsList = Utils.getActionsList(perm.getActions());
+
         Enumeration<DevicePermission> search = permissions.elements();
-        while (search.hasMoreElements()) {
-            if (search.nextElement().implies(perm)) {
-                return true;
+
+        int len = actionsList.length;
+
+        if (len <= 1) {
+
+            while (search.hasMoreElements()) {
+                if (search.nextElement().implies(perm)) {
+                    return true;
+                }
             }
+        } else {
+            DevicePermission splittedPerm;
+
+            boolean implyRes = true;
+            for (int i = 0; i < len && implyRes; i++) {
+                boolean res = false;
+                splittedPerm = new LocalPermission(permission.getName(), actionsList[i]);
+                search = permissions.elements();
+                while (search.hasMoreElements()) {
+                    DevicePermission p = search.nextElement();
+                    if (p.privateImplies(splittedPerm)) {
+                        res = true;
+                        break;
+                    }
+                }
+                implyRes = implyRes && res;
+            }
+            return implyRes;
         }
         return false;
     }