Search in sources :

Example 11 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.

the class ShadowArscAssetManager method loadResourceBagValue.

/**
 * Returns true if the resource was found, filling in mRetStringBlock and
 * mRetData.
 */
@Implementation
@HiddenApi
protected final int loadResourceBagValue(int ident, int bagEntryId, TypedValue outValue, boolean resolve) {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return 0;
    }
    final ResTable res = am.getResources();
    return loadResourceBagValueInternal(ident, bagEntryId, outValue, resolve, res);
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable(org.robolectric.res.android.ResTable) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 12 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.

the class ShadowArscAssetManager method init.

@HiddenApi
@Implementation(minSdk = VERSION_CODES.KITKAT_WATCH)
protected void init(boolean isSystem) {
    // if (isSystem) {
    // verifySystemIdmaps();
    // }
    Path androidFrameworkJarPath = RuntimeEnvironment.getAndroidFrameworkJarPath();
    Preconditions.checkNotNull(androidFrameworkJarPath);
    if (isSystem) {
        synchronized (ShadowArscAssetManager.class) {
            if (systemCppAssetManager == null) {
                systemCppAssetManager = new CppAssetManager();
                systemCppAssetManager.addDefaultAssets(androidFrameworkJarPath);
            }
        }
        this.cppAssetManager = systemCppAssetManager;
    } else {
        this.cppAssetManager = new CppAssetManager();
        cppAssetManager.addDefaultAssets(androidFrameworkJarPath);
    }
    ALOGV("Created AssetManager %s for Java object %s\n", cppAssetManager, ShadowArscAssetManager.class);
}
Also used : Path(java.nio.file.Path) AssetPath(org.robolectric.res.android.AssetPath) CppAssetManager(org.robolectric.res.android.CppAssetManager) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 13 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.

the class ShadowArscAssetManager method getArrayStringResource.

@HiddenApi
@Implementation
protected final String[] getArrayStringResource(int arrayResId) {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return null;
    }
    final ResTable res = am.getResources();
    final Ref<bag_entry[]> startOfBag = new Ref<>(null);
    final int N = res.lockBag(arrayResId, startOfBag);
    if (N < 0) {
        return null;
    }
    String[] array = new String[N];
    final Ref<Res_value> valueRef = new Ref<>(null);
    final bag_entry[] bag = startOfBag.get();
    int strLen = 0;
    for (int i = 0; ((int) i) < N; i++) {
        valueRef.set(bag[i].map.value);
        String str = null;
        // Take care of resolving the found resource to its final value.
        int block = res.resolveReference(valueRef, bag[i].stringBlock, null);
        if (kThrowOnBadId) {
            if (block == BAD_INDEX) {
                throw new IllegalStateException("Bad resource!");
            }
        }
        if (valueRef.get().dataType == DataType.STRING.code()) {
            final ResStringPool pool = res.getTableStringBlock(block);
            str = pool.stringAt(valueRef.get().data);
            // }
            if (str == null) {
                res.unlockBag(startOfBag);
                return null;
            }
            array[i] = str;
        // str is not NULL at that point, otherwise ExceptionCheck would have been true.
        // If we have a large amount of strings in our array, we might
        // overflow the local reference table of the VM.
        // env.DeleteLocalRef(str);
        }
    }
    res.unlockBag(startOfBag);
    return array;
}
Also used : Res_value(org.robolectric.res.android.ResourceTypes.Res_value) CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable(org.robolectric.res.android.ResTable) Ref(org.robolectric.res.android.Ref) ResStringPool(org.robolectric.res.android.ResStringPool) ResTable.bag_entry(org.robolectric.res.android.ResTable.bag_entry) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 14 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.

the class ShadowArscAssetManager method getResourceIdentifier.

@HiddenApi
@Implementation
public int getResourceIdentifier(String name, String defType, String defPackage) {
    if (Strings.isNullOrEmpty(name)) {
        return 0;
    }
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return 0;
    }
    int ident = am.getResources().identifierForName(name, defType, defPackage);
    return ident;
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Example 15 with CppAssetManager

use of org.robolectric.res.android.CppAssetManager in project robolectric by robolectric.

the class ShadowArscAssetManager method setConfiguration.

@HiddenApi
@Implementation(minSdk = O)
public void setConfiguration(int mcc, int mnc, String locale, int orientation, int touchscreen, int density, int keyboard, int keyboardHidden, int navigation, int screenWidth, int screenHeight, int smallestScreenWidthDp, int screenWidthDp, int screenHeightDp, int screenLayout, int uiMode, int colorMode, int sdkVersion) {
    CppAssetManager am = assetManagerForJavaObject();
    if (am == null) {
        return;
    }
    ResTable_config config = new ResTable_config();
    // memset(&config, 0, sizeof(config));
    // const char* locale8 = locale != NULL ? env->GetStringUTFChars(locale, NULL) : NULL;
    // Constants duplicated from Java class android.content.res.Configuration.
    int kScreenLayoutRoundMask = 0x300;
    int kScreenLayoutRoundShift = 8;
    config.mcc = mcc;
    config.mnc = mnc;
    config.orientation = orientation;
    config.touchscreen = touchscreen;
    config.density = density;
    config.keyboard = keyboard;
    config.inputFlags = keyboardHidden;
    config.navigation = navigation;
    config.screenWidth = screenWidth;
    config.screenHeight = screenHeight;
    config.smallestScreenWidthDp = smallestScreenWidthDp;
    config.screenWidthDp = screenWidthDp;
    config.screenHeightDp = screenHeightDp;
    config.screenLayout = screenLayout;
    config.uiMode = uiMode;
    config.colorMode = (byte) colorMode;
    config.sdkVersion = sdkVersion;
    config.minorVersion = 0;
    // In Java, we use a 32bit integer for screenLayout, while we only use an 8bit integer
    // in C++. We must extract the round qualifier out of the Java screenLayout and put it
    // into screenLayout2.
    config.screenLayout2 = (byte) ((screenLayout & kScreenLayoutRoundMask) >> kScreenLayoutRoundShift);
    am.setConfiguration(config, locale);
// if (locale != null) env->ReleaseStringUTFChars(locale, locale8);
}
Also used : CppAssetManager(org.robolectric.res.android.CppAssetManager) ResTable_config(org.robolectric.res.android.ResTable_config) HiddenApi(org.robolectric.annotation.HiddenApi) Implementation(org.robolectric.annotation.Implementation)

Aggregations

Implementation (org.robolectric.annotation.Implementation)24 CppAssetManager (org.robolectric.res.android.CppAssetManager)24 HiddenApi (org.robolectric.annotation.HiddenApi)18 ResTable (org.robolectric.res.android.ResTable)9 Ref (org.robolectric.res.android.Ref)8 FileNotFoundException (java.io.FileNotFoundException)6 Asset (org.robolectric.res.android.Asset)5 Res_value (org.robolectric.res.android.ResourceTypes.Res_value)5 ResourceName (org.robolectric.res.android.ResTable.ResourceName)4 ResTable.bag_entry (org.robolectric.res.android.ResTable.bag_entry)4 ResTable_config (org.robolectric.res.android.ResTable_config)3 String8 (org.robolectric.res.android.String8)2 SparseArray (android.util.SparseArray)1 Path (java.nio.file.Path)1 AccessMode (org.robolectric.res.android.Asset.AccessMode)1 AssetDir (org.robolectric.res.android.AssetDir)1 AssetPath (org.robolectric.res.android.AssetPath)1 DynamicRefTable (org.robolectric.res.android.DynamicRefTable)1 ResStringPool (org.robolectric.res.android.ResStringPool)1 ResTableTheme (org.robolectric.res.android.ResTableTheme)1