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;
- }
- throw new NameNotFoundException("Unable to open " + app.publicSourceDir);
+ 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;
+ }
}
@Override
* Protected so that tests can override and returns something a fixed value.
*/
@VisibleForTesting
- protected DisplayMetrics getDisplayMetrics(int displayId) {
+ protected @NonNull DisplayMetrics getDisplayMetrics(int displayId) {
DisplayMetrics dm = new DisplayMetrics();
final Display display =
getAdjustedDisplay(displayId, DisplayAdjustments.DEFAULT_DISPLAY_ADJUSTMENTS);
// already.
if (key.mResDir != null) {
if (assets.addAssetPath(key.mResDir) == 0) {
- throw new IllegalArgumentException("failed to add asset path " + key.mResDir);
+ throw new Resources.NotFoundException("failed to add asset path " + key.mResDir);
}
}
if (key.mSplitResDirs != null) {
for (final String splitResDir : key.mSplitResDirs) {
if (assets.addAssetPath(splitResDir) == 0) {
- throw new IllegalArgumentException(
+ throw new Resources.NotFoundException(
"failed to add split asset path " + splitResDir);
}
}
return config;
}
- private ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
+ private @NonNull ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
AssetManager assets = createAssetManager(key);
DisplayMetrics dm = getDisplayMetrics(key.mDisplayId);
Configuration config = generateConfig(key, dm);
* Gets an existing Resources object tied to this Activity, or creates one if it doesn't exist
* or the class loader is different.
*/
- private Resources getOrCreateResourcesForActivityLocked(@NonNull IBinder activityToken,
+ private @NonNull Resources getOrCreateResourcesForActivityLocked(@NonNull IBinder activityToken,
@NonNull ClassLoader classLoader, @NonNull ResourcesImpl impl) {
final ActivityResources activityResources = getOrCreateActivityResourcesStructLocked(
activityToken);
* Gets an existing Resources object if the class loader and ResourcesImpl are the same,
* otherwise creates a new Resources object.
*/
- private Resources getOrCreateResourcesLocked(@NonNull ClassLoader classLoader,
+ private @NonNull Resources getOrCreateResourcesLocked(@NonNull ClassLoader classLoader,
@NonNull ResourcesImpl impl) {
// Find an existing Resources that has this ResourcesImpl set.
final int refCount = mResourceReferences.size();
* {@link ClassLoader#getSystemClassLoader()} is used.
* @return a Resources object from which to access resources.
*/
- public Resources createBaseActivityResources(@NonNull IBinder activityToken,
+ public @NonNull Resources createBaseActivityResources(@NonNull IBinder activityToken,
@Nullable String resDir,
@Nullable String[] splitResDirs,
@Nullable String[] overlayDirs,
* {@link #applyConfigurationToResourcesLocked(Configuration, CompatibilityInfo)}
* is called.
*/
- private Resources getOrCreateResources(@Nullable IBinder activityToken,
+ private @NonNull Resources getOrCreateResources(@Nullable IBinder activityToken,
@NonNull ResourcesKey key, @NonNull ClassLoader classLoader) {
synchronized (this) {
if (DEBUG) {
* {@link ClassLoader#getSystemClassLoader()} is used.
* @return a Resources object from which to access resources.
*/
- public Resources getResources(@Nullable IBinder activityToken,
+ public @NonNull Resources getResources(@Nullable IBinder activityToken,
@Nullable String resDir,
@Nullable String[] splitResDirs,
@Nullable String[] overlayDirs,