Add --ignore-package option.

Easier but ultimately less useful than generating API XML for stuff.
diff --git a/tools/apkcheck/README.txt b/tools/apkcheck/README.txt
index b922ee4..1681ed5 100644
--- a/tools/apkcheck/README.txt
+++ b/tools/apkcheck/README.txt
@@ -33,12 +33,18 @@
   --help
     Show options summary.
 
-  --uses-library=lib.xml
+  --uses-library=<lib.xml>
     Load additional public API list.  This is intended for APKs that
     use "uses-library" directives to pull in external libraries.  Since
     the external libraries are not part of the public API, their use
     would otherwise be flagged as illegal by apkcheck.
 
+  --ignore-package=<package-name>
+    Ignore errors generated by references to the named package (e.g.
+    "com.google.android.maps").  Warnings will be generated instead.
+    Useful for ignoring references to shared library content when
+    XML API data is not available.
+
   --[no-]warn
     Enable or disable warning messages.  These are disabled by default.
 
diff --git a/tools/apkcheck/src/com/android/apkcheck/ApkCheck.java b/tools/apkcheck/src/com/android/apkcheck/ApkCheck.java
index 42196a5..997fb48 100644
--- a/tools/apkcheck/src/com/android/apkcheck/ApkCheck.java
+++ b/tools/apkcheck/src/com/android/apkcheck/ApkCheck.java
@@ -18,8 +18,11 @@
 
 import org.xml.sax.*;
 import org.xml.sax.helpers.*;
-import java.io.*;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.Reader;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.Iterator;
 
 
@@ -45,6 +48,10 @@
     /* show errors? */
     private static boolean sShowErrors = true;
 
+    /* names of packages we're allowed to ignore */
+    private static HashSet<String> sIgnorablePackages = new HashSet<String>();
+
+
     /**
      * Program entry point.
      */
@@ -72,6 +79,9 @@
                     if (!parseApiDescr(apiDescr, libName))
                         return;
                 }
+            } else if (args[idx].startsWith("--ignore-package=")) {
+                String pkgName = args[idx].substring(args[idx].indexOf('=')+1);
+                sIgnorablePackages.add(pkgName);
             } else if (args[idx].equals("--warn")) {
                 sShowWarnings = true;
             } else if (args[idx].equals("--no-warn")) {
@@ -137,6 +147,7 @@
         System.err.println("Options:");
         System.err.println("  --help                  show this message");
         System.err.println("  --uses-library=lib.xml  load additional public API list");
+        System.err.println("  --ignore-package=pkg    don't show errors for references to this package");
         System.err.println("  --[no-]warn             enable or disable display of warnings");
         System.err.println("  --[no-]error            enable or disable display of errors");
     }
@@ -255,9 +266,18 @@
                 ClassInfo apkClassInfo = classIter.next();
 
                 if (badPackage) {
-                    /* list the offending classes */
-                    apkError("Illegal class ref: " +
-                        apkPkgInfo.getName() + "." + apkClassInfo.getName());
+                    /*
+                     * The package is not present in the public API file,
+                     * but simply saying "bad package" isn't all that
+                     * useful, so we emit the names of each of the classes.
+                     */
+                    if (isIgnorable(apkPkgInfo)) {
+                        apkWarning("Ignoring class ref: " +
+                            apkPkgInfo.getName() + "." + apkClassInfo.getName());
+                    } else {
+                        apkError("Illegal class ref: " +
+                            apkPkgInfo.getName() + "." + apkClassInfo.getName());
+                    }
                 } else {
                     checkClass(pubPkgInfo, apkClassInfo);
                 }
@@ -276,7 +296,10 @@
         ClassInfo pubClassInfo = pubPkgInfo.getClass(classInfo.getName());
 
         if (pubClassInfo == null) {
-            if (classInfo.hasNoFieldMethod()) {
+            if (isIgnorable(pubPkgInfo)) {
+                apkWarning("Ignoring class ref: " +
+                    pubPkgInfo.getName() + "." + classInfo.getName());
+            } else if (classInfo.hasNoFieldMethod()) {
                 apkWarning("Hidden class referenced: " +
                     pubPkgInfo.getName() + "." + classInfo.getName());
             } else {
@@ -328,6 +351,12 @@
         return true;
     }
 
+    /**
+     * Returns true if the package is in the "ignored" list.
+     */
+    static boolean isIgnorable(PackageInfo pkgInfo) {
+        return sIgnorablePackages.contains(pkgInfo.getName());
+    }
 
     /**
      * Prints a warning message about an APK problem.