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);
}
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);
}
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;
}
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;
}
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);
}
Aggregations