Throw proper exception in ResourcesManager

In M we would bubble up a NameNotFoundException when failing
to load an assetmanager from another application. We switched
to throwing an IllegalArgumentException, which isn't something
anyone should handle.

This change has ResourcesManager throw Resources.NotFoundException,
which callers like ApplicationPackageManager can catch and rethrow
with the appropriate checked exception. This adds more detail to
errors than we had in M.

Bug:28876344
Change-Id: I250aeef8a4ccfd90c6abef2243edc1c5337ebde9
diff --git a/core/java/android/app/ApplicationPackageManager.java b/core/java/android/app/ApplicationPackageManager.java
index 87511ee..8cc1bc4 100644
--- a/core/java/android/app/ApplicationPackageManager.java
+++ b/core/java/android/app/ApplicationPackageManager.java
@@ -1245,15 +1245,18 @@
             return mContext.mMainThread.getSystemContext().getResources();
         }
         final boolean sameUid = (app.uid == Process.myUid());
-        final Resources r = mContext.mMainThread.getTopLevelResources(
-                sameUid ? app.sourceDir : app.publicSourceDir,
-                sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
-                app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
-                mContext.mPackageInfo);
-        if (r != null) {
-            return r;
+        try {
+            return mContext.mMainThread.getTopLevelResources(
+                    sameUid ? app.sourceDir : app.publicSourceDir,
+                    sameUid ? app.splitSourceDirs : app.splitPublicSourceDirs,
+                    app.resourceDirs, app.sharedLibraryFiles, Display.DEFAULT_DISPLAY,
+                    mContext.mPackageInfo);
+        } catch (Resources.NotFoundException cause) {
+            final NameNotFoundException ex =
+                    new NameNotFoundException("Unable to open " + app.publicSourceDir);
+            ex.initCause(cause);
+            throw ex;
         }
-        throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
     }
 
     @Override