Search in sources :

Example 6 with ResourcesKey

use of android.content.res.ResourcesKey in project android_frameworks_base by AOSPA.

the class ResourcesManager method appendLibAssetForMainAssetPath.

/**
     * Appends the library asset path to any ResourcesImpl object that contains the main
     * assetPath.
     * @param assetPath The main asset path for which to add the library asset path.
     * @param libAsset The library asset path to add.
     */
public void appendLibAssetForMainAssetPath(String assetPath, String libAsset) {
    synchronized (this) {
        // Record which ResourcesImpl need updating
        // (and what ResourcesKey they should update to).
        final ArrayMap<ResourcesImpl, ResourcesKey> updatedResourceKeys = new ArrayMap<>();
        final int implCount = mResourceImpls.size();
        for (int i = 0; i < implCount; i++) {
            final ResourcesImpl impl = mResourceImpls.valueAt(i).get();
            final ResourcesKey key = mResourceImpls.keyAt(i);
            if (impl != null && key.mResDir.equals(assetPath)) {
                if (!ArrayUtils.contains(key.mLibDirs, libAsset)) {
                    final int newLibAssetCount = 1 + (key.mLibDirs != null ? key.mLibDirs.length : 0);
                    final String[] newLibAssets = new String[newLibAssetCount];
                    if (key.mLibDirs != null) {
                        System.arraycopy(key.mLibDirs, 0, newLibAssets, 0, key.mLibDirs.length);
                    }
                    newLibAssets[newLibAssetCount - 1] = libAsset;
                    updatedResourceKeys.put(impl, new ResourcesKey(key.mResDir, key.mSplitResDirs, key.mOverlayDirs, newLibAssets, key.mDisplayId, key.mOverrideConfiguration, key.mCompatInfo));
                }
            }
        }
        redirectResourcesToNewImplLocked(updatedResourceKeys);
    }
}
Also used : ResourcesKey(android.content.res.ResourcesKey) ArrayMap(android.util.ArrayMap) ResourcesImpl(android.content.res.ResourcesImpl)

Example 7 with ResourcesKey

use of android.content.res.ResourcesKey in project android_frameworks_base by AOSPA.

the class ResourcesManager method applyNewResourceDirsLocked.

final void applyNewResourceDirsLocked(@NonNull final String baseCodePath, @NonNull final String[] newResourceDirs) {
    try {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesManager#applyNewResourceDirsLocked");
        ApplicationPackageManager.configurationChanged();
        if (Process.myUid() == Process.SYSTEM_UID) {
            // Resources.getSystem() will *not* use overlays for applications.)
            if (FRAMEWORK_RESOURCES_PATH.equals(baseCodePath)) {
                final ResourcesKey key = new ResourcesKey(FRAMEWORK_RESOURCES_PATH, null, newResourceDirs, null, Display.DEFAULT_DISPLAY, null, null);
                final ResourcesImpl impl = createResourcesImpl(key);
                Resources.getSystem().setImpl(impl);
            }
        }
        final ArrayMap<ResourcesImpl, ResourcesKey> updatedResourceKeys = new ArrayMap<>();
        final int implCount = mResourceImpls.size();
        for (int i = 0; i < implCount; i++) {
            final ResourcesImpl impl = mResourceImpls.valueAt(i).get();
            final ResourcesKey key = mResourceImpls.keyAt(i);
            if (impl != null && key.mResDir != null && key.mResDir.equals(baseCodePath)) {
                updatedResourceKeys.put(impl, new ResourcesKey(key.mResDir, key.mSplitResDirs, newResourceDirs, key.mLibDirs, key.mDisplayId, key.mOverrideConfiguration, key.mCompatInfo));
            }
        }
        invalidatePath("/");
        redirectResourcesToNewImplLocked(updatedResourceKeys);
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
    }
}
Also used : ResourcesKey(android.content.res.ResourcesKey) ArrayMap(android.util.ArrayMap) ResourcesImpl(android.content.res.ResourcesImpl)

Example 8 with ResourcesKey

use of android.content.res.ResourcesKey in project android_frameworks_base by AOSPA.

the class ResourcesManager method getResources.

/**
     * Gets or creates a new Resources object associated with the IBinder token. References returned
     * by this method live as long as the Activity, meaning they can be cached and used by the
     * Activity even after a configuration change. If any other parameter is changed
     * (resDir, splitResDirs, overrideConfig) for a given Activity, the same Resources object
     * is updated and handed back to the caller. However, changing the class loader will result in a
     * new Resources object.
     * <p/>
     * If activityToken is null, a cached Resources object will be returned if it matches the
     * input parameters. Otherwise a new Resources object that satisfies these parameters is
     * returned.
     *
     * @param activityToken Represents an Activity. If null, global resources are assumed.
     * @param resDir The base resource path. Can be null (only framework resources will be loaded).
     * @param splitResDirs An array of split resource paths. Can be null.
     * @param overlayDirs An array of overlay paths. Can be null.
     * @param libDirs An array of resource library paths. Can be null.
     * @param displayId The ID of the display for which to create the resources.
     * @param overrideConfig The configuration to apply on top of the base configuration. Can be
     * null. Mostly used with Activities that are in multi-window which may override width and
     * height properties from the base config.
     * @param compatInfo The compatibility settings to use. Cannot be null. A default to use is
     * {@link CompatibilityInfo#DEFAULT_COMPATIBILITY_INFO}.
     * @param classLoader The class loader to use when inflating Resources. If null, the
     * {@link ClassLoader#getSystemClassLoader()} is used.
     * @return a Resources object from which to access resources.
     */
@Nullable
public Resources getResources(@Nullable IBinder activityToken, @Nullable String resDir, @Nullable String[] splitResDirs, @Nullable String[] overlayDirs, @Nullable String[] libDirs, int displayId, @Nullable Configuration overrideConfig, @NonNull CompatibilityInfo compatInfo, @Nullable ClassLoader classLoader) {
    try {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesManager#getResources");
        final ResourcesKey key = new ResourcesKey(resDir, splitResDirs, overlayDirs, libDirs, displayId, // Copy
        overrideConfig != null ? new Configuration(overrideConfig) : null, compatInfo);
        classLoader = classLoader != null ? classLoader : ClassLoader.getSystemClassLoader();
        return getOrCreateResources(activityToken, key, classLoader);
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
    }
}
Also used : Configuration(android.content.res.Configuration) ResourcesKey(android.content.res.ResourcesKey) Nullable(android.annotation.Nullable)

Example 9 with ResourcesKey

use of android.content.res.ResourcesKey in project platform_frameworks_base by android.

the class ResourcesManager method getResources.

/**
     * Gets or creates a new Resources object associated with the IBinder token. References returned
     * by this method live as long as the Activity, meaning they can be cached and used by the
     * Activity even after a configuration change. If any other parameter is changed
     * (resDir, splitResDirs, overrideConfig) for a given Activity, the same Resources object
     * is updated and handed back to the caller. However, changing the class loader will result in a
     * new Resources object.
     * <p/>
     * If activityToken is null, a cached Resources object will be returned if it matches the
     * input parameters. Otherwise a new Resources object that satisfies these parameters is
     * returned.
     *
     * @param activityToken Represents an Activity. If null, global resources are assumed.
     * @param resDir The base resource path. Can be null (only framework resources will be loaded).
     * @param splitResDirs An array of split resource paths. Can be null.
     * @param overlayDirs An array of overlay paths. Can be null.
     * @param libDirs An array of resource library paths. Can be null.
     * @param displayId The ID of the display for which to create the resources.
     * @param overrideConfig The configuration to apply on top of the base configuration. Can be
     * null. Mostly used with Activities that are in multi-window which may override width and
     * height properties from the base config.
     * @param compatInfo The compatibility settings to use. Cannot be null. A default to use is
     * {@link CompatibilityInfo#DEFAULT_COMPATIBILITY_INFO}.
     * @param classLoader The class loader to use when inflating Resources. If null, the
     * {@link ClassLoader#getSystemClassLoader()} is used.
     * @return a Resources object from which to access resources.
     */
@Nullable
public Resources getResources(@Nullable IBinder activityToken, @Nullable String resDir, @Nullable String[] splitResDirs, @Nullable String[] overlayDirs, @Nullable String[] libDirs, int displayId, @Nullable Configuration overrideConfig, @NonNull CompatibilityInfo compatInfo, @Nullable ClassLoader classLoader) {
    try {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesManager#getResources");
        final ResourcesKey key = new ResourcesKey(resDir, splitResDirs, overlayDirs, libDirs, displayId, // Copy
        overrideConfig != null ? new Configuration(overrideConfig) : null, compatInfo);
        classLoader = classLoader != null ? classLoader : ClassLoader.getSystemClassLoader();
        return getOrCreateResources(activityToken, key, classLoader);
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
    }
}
Also used : Configuration(android.content.res.Configuration) ResourcesKey(android.content.res.ResourcesKey) Nullable(android.annotation.Nullable)

Example 10 with ResourcesKey

use of android.content.res.ResourcesKey in project platform_frameworks_base by android.

the class ResourcesManager method invalidatePath.

/**
     * Invalidate and destroy any resources that reference content under the
     * given filesystem path. Typically used when unmounting a storage device to
     * try as hard as possible to release any open FDs.
     */
public void invalidatePath(String path) {
    synchronized (this) {
        int count = 0;
        for (int i = 0; i < mResourceImpls.size(); ) {
            final ResourcesKey key = mResourceImpls.keyAt(i);
            if (key.isPathReferenced(path)) {
                final ResourcesImpl res = mResourceImpls.removeAt(i).get();
                if (res != null) {
                    res.flushLayoutCache();
                }
                count++;
            } else {
                i++;
            }
        }
        Log.i(TAG, "Invalidated " + count + " asset managers that referenced " + path);
    }
}
Also used : ResourcesKey(android.content.res.ResourcesKey) ResourcesImpl(android.content.res.ResourcesImpl)

Aggregations

ResourcesKey (android.content.res.ResourcesKey)38 ResourcesImpl (android.content.res.ResourcesImpl)28 Configuration (android.content.res.Configuration)20 Nullable (android.annotation.Nullable)10 Resources (android.content.res.Resources)10 ArrayMap (android.util.ArrayMap)9 DisplayMetrics (android.util.DisplayMetrics)5 DisplayAdjustments (android.view.DisplayAdjustments)5