Search in sources :

Example 6 with ResourcesImpl

use of android.content.res.ResourcesImpl in project android_frameworks_base by ResurrectionRemix.

the class ResourcesManager method redirectResourcesToNewImplLocked.

private void redirectResourcesToNewImplLocked(@NonNull final ArrayMap<ResourcesImpl, ResourcesKey> updatedResourceKeys) {
    // Bail early if there is no work to do.
    if (updatedResourceKeys.isEmpty()) {
        return;
    }
    // Update any references to ResourcesImpl that require reloading.
    final int resourcesCount = mResourceReferences.size();
    for (int i = 0; i < resourcesCount; i++) {
        final Resources r = mResourceReferences.get(i).get();
        if (r != null) {
            final ResourcesKey key = updatedResourceKeys.get(r.getImpl());
            if (key != null) {
                final ResourcesImpl impl = findOrCreateResourcesImplForKeyLocked(key);
                if (impl == null) {
                    throw new Resources.NotFoundException("failed to load");
                }
                r.setImpl(impl);
            }
        }
    }
    // Update any references to ResourcesImpl that require reloading for each Activity.
    for (final ActivityResources activityResources : mActivityResourceReferences.values()) {
        final int resCount = activityResources.activityResources.size();
        for (int i = 0; i < resCount; i++) {
            final Resources r = activityResources.activityResources.get(i).get();
            if (r != null) {
                final ResourcesKey key = updatedResourceKeys.get(r.getImpl());
                if (key != null) {
                    final ResourcesImpl impl = findOrCreateResourcesImplForKeyLocked(key);
                    if (impl == null) {
                        throw new Resources.NotFoundException("failed to load");
                    }
                    r.setImpl(impl);
                }
            }
        }
    }
}
Also used : ResourcesKey(android.content.res.ResourcesKey) Resources(android.content.res.Resources) ResourcesImpl(android.content.res.ResourcesImpl)

Example 7 with ResourcesImpl

use of android.content.res.ResourcesImpl in project android_frameworks_base by ResurrectionRemix.

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 ResourcesKey key = mResourceImpls.keyAt(i);
            final WeakReference<ResourcesImpl> weakImplRef = mResourceImpls.valueAt(i);
            final ResourcesImpl impl = weakImplRef != null ? weakImplRef.get() : null;
            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 8 with ResourcesImpl

use of android.content.res.ResourcesImpl in project android_frameworks_base by ResurrectionRemix.

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)

Example 9 with ResourcesImpl

use of android.content.res.ResourcesImpl in project android_frameworks_base by ResurrectionRemix.

the class ResourcesManager method createResourcesImpl.

@Nullable
private ResourcesImpl createResourcesImpl(@NonNull ResourcesKey key) {
    final DisplayAdjustments daj = new DisplayAdjustments(key.mOverrideConfiguration);
    daj.setCompatibilityInfo(key.mCompatInfo);
    final AssetManager assets = createAssetManager(key);
    if (assets == null) {
        return null;
    }
    final DisplayMetrics dm = getDisplayMetrics(key.mDisplayId, daj);
    final Configuration config = generateConfig(key, dm);
    final ResourcesImpl impl = new ResourcesImpl(assets, dm, config, daj);
    if (DEBUG) {
        Slog.d(TAG, "- creating impl=" + impl + " with key: " + key);
    }
    return impl;
}
Also used : AssetManager(android.content.res.AssetManager) Configuration(android.content.res.Configuration) DisplayAdjustments(android.view.DisplayAdjustments) ResourcesImpl(android.content.res.ResourcesImpl) DisplayMetrics(android.util.DisplayMetrics) Nullable(android.annotation.Nullable)

Example 10 with ResourcesImpl

use of android.content.res.ResourcesImpl in project android_frameworks_base by ResurrectionRemix.

the class ResourcesManager method applyConfigurationToResourcesLocked.

public final boolean applyConfigurationToResourcesLocked(@NonNull Configuration config, @Nullable CompatibilityInfo compat) {
    try {
        Trace.traceBegin(Trace.TRACE_TAG_RESOURCES, "ResourcesManager#applyConfigurationToResourcesLocked");
        if (!mResConfiguration.isOtherSeqNewer(config) && compat == null) {
            if (DEBUG || DEBUG_CONFIGURATION)
                Slog.v(TAG, "Skipping new config: curSeq=" + mResConfiguration.seq + ", newSeq=" + config.seq);
            return false;
        }
        int changes = mResConfiguration.updateFrom(config);
        // Things might have changed in display manager, so clear the cached displays.
        mDisplays.clear();
        DisplayMetrics defaultDisplayMetrics = getDisplayMetrics();
        if (compat != null && (mResCompatibilityInfo == null || !mResCompatibilityInfo.equals(compat))) {
            mResCompatibilityInfo = compat;
            changes |= ActivityInfo.CONFIG_SCREEN_LAYOUT | ActivityInfo.CONFIG_SCREEN_SIZE | ActivityInfo.CONFIG_SMALLEST_SCREEN_SIZE;
        }
        Resources.updateSystemConfiguration(config, defaultDisplayMetrics, compat);
        ApplicationPackageManager.configurationChanged();
        //Slog.i(TAG, "Configuration changed in " + currentPackageName());
        Configuration tmpConfig = null;
        for (int i = mResourceImpls.size() - 1; i >= 0; i--) {
            ResourcesKey key = mResourceImpls.keyAt(i);
            WeakReference<ResourcesImpl> weakImplRef = mResourceImpls.valueAt(i);
            ResourcesImpl r = weakImplRef != null ? weakImplRef.get() : null;
            if (r != null) {
                if (DEBUG || DEBUG_CONFIGURATION)
                    Slog.v(TAG, "Changing resources " + r + " config to: " + config);
                int displayId = key.mDisplayId;
                boolean isDefaultDisplay = (displayId == Display.DEFAULT_DISPLAY);
                DisplayMetrics dm = defaultDisplayMetrics;
                final boolean hasOverrideConfiguration = key.hasOverrideConfiguration();
                if (!isDefaultDisplay || hasOverrideConfiguration) {
                    if (tmpConfig == null) {
                        tmpConfig = new Configuration();
                    }
                    tmpConfig.setTo(config);
                    // Get new DisplayMetrics based on the DisplayAdjustments given
                    // to the ResourcesImpl. Update a copy if the CompatibilityInfo
                    // changed, because the ResourcesImpl object will handle the
                    // update internally.
                    DisplayAdjustments daj = r.getDisplayAdjustments();
                    if (compat != null) {
                        daj = new DisplayAdjustments(daj);
                        daj.setCompatibilityInfo(compat);
                    }
                    dm = getDisplayMetrics(displayId, daj);
                    if (!isDefaultDisplay) {
                        applyNonDefaultDisplayMetricsToConfiguration(dm, tmpConfig);
                    }
                    if (hasOverrideConfiguration) {
                        tmpConfig.updateFrom(key.mOverrideConfiguration);
                    }
                    r.updateConfiguration(tmpConfig, dm, compat);
                } else {
                    r.updateConfiguration(config, dm, compat);
                }
            //Slog.i(TAG, "Updated app resources " + v.getKey()
            //        + " " + r + ": " + r.getConfiguration());
            } else {
                //Slog.i(TAG, "Removing old resources " + v.getKey());
                mResourceImpls.removeAt(i);
            }
        }
        return changes != 0;
    } finally {
        Trace.traceEnd(Trace.TRACE_TAG_RESOURCES);
    }
}
Also used : Configuration(android.content.res.Configuration) ResourcesKey(android.content.res.ResourcesKey) DisplayAdjustments(android.view.DisplayAdjustments) ResourcesImpl(android.content.res.ResourcesImpl) DisplayMetrics(android.util.DisplayMetrics)

Aggregations

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