Robert Craig avatar Robert Craig committed f3ba51a

Pretty print MMAC debug statements.

signer tags and permission sets are just dumped to logcat
in one big blob. Rewrite code to pretty print these
instances.

Comments (0)

Files changed (1)

core/java/android/content/pm/SELinuxMMAC.java

                     }
                     InstallPolicy type = determineInstallPolicyType(parser, true);
                     if (type != null) {
-                        if (DEBUG_POLICY_INSTALL)
-                            Slog.i(TAG, "<signer> tag: (" + cert + ") assigned "
-                                   + type);
+                        if (DEBUG_POLICY_INSTALL) {
+                            // Pretty print the cert
+                            int rowLength = 75;
+                            int certLength = cert.length();
+                            int rows = certLength / rowLength;
+                            Slog.i(TAG, "<signer> tag:");
+                            for (int j = 0; j <= rows; j++) {
+                                int start = rowLength * j;
+                                int rowEndIndex = (rowLength * j) + rowLength;
+                                int end = rowEndIndex < certLength ? rowEndIndex : certLength;
+                                Slog.i(TAG,  cert.substring(start, end));
+                            }
+                            Slog.i(TAG,  "    Assigned: " + type);
+                        }
 
                         SIG_POLICY.put(signature, type);
                     }
             StringBuilder out = new StringBuilder();
             out.append("[");
             if (policyPerms != null) {
-                out.append(TextUtils.join(",", new TreeSet<String>(policyPerms)));
+                out.append(TextUtils.join(",\n", new TreeSet<String>(policyPerms)));
             } else {
                 out.append("allow-all");
             }
                 return pkgPolicy.get(pkg.packageName).passedPolicyChecks(pkg);
             }
 
-            if (!policyPerms.containsAll(pkg.requestedPermissions)) {
-                Slog.w(TAG, MMAC_DENY + " Policy whitelist rejected package "
-                       + pkg.packageName + ". The maximal set is: " + toString());
-                return false;
+            Iterator itr = pkg.requestedPermissions.iterator();
+            while (itr.hasNext()) {
+                String perm = (String)itr.next();
+                if (!policyPerms.contains(perm)) {
+                    Slog.w(TAG, MMAC_DENY + " Policy whitelist rejected package "
+                           + pkg.packageName + ". The rejected permission is " + perm +
+                           " The maximal set allowed is: " + toString());
+                    return false;
+                }
             }
             return true;
         }
 
         @Override
         public String toString() {
-            return "allowed-permissions => " + super.toString();
+            return "allowed-permissions => \n" + super.toString();
         }
     }
 
 
         @Override
         public String toString() {
-            return "denied-permissions => " + super.toString();
+            return "denied-permissions => \n" + super.toString();
         }
     }
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.