use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowLegacyAssetManager method openNonAsset.
@HiddenApi
@Implementation
public final InputStream openNonAsset(int cookie, String fileName, int accessMode) throws IOException {
final ResName resName = qualifyFromNonAssetFileName(fileName);
final FileTypedResource typedResource = (FileTypedResource) getResourceTable().getValue(resName, config);
if (typedResource == null) {
throw new IOException("Unable to find resource for " + fileName);
}
InputStream stream;
if (accessMode == AssetManager.ACCESS_STREAMING) {
stream = Fs.getInputStream(typedResource.getPath());
} else {
stream = new ByteArrayInputStream(Fs.getBytes(typedResource.getPath()));
}
if (RuntimeEnvironment.getApiLevel() >= P) {
Asset asset = Asset.newFileAsset(typedResource);
long assetPtr = Registries.NATIVE_ASSET_REGISTRY.register(asset);
// Camouflage the InputStream as an AssetInputStream so subsequent instanceof checks pass.
stream = ShadowAssetInputStream.createAssetInputStream(stream, assetPtr, realObject);
}
return stream;
}
use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowLegacyAssetManager method getResourceTextArray.
@HiddenApi
@Implementation
public CharSequence[] getResourceTextArray(int resId) {
TypedResource value = getAndResolve(resId, config, true);
if (value == null)
return null;
List<TypedResource> items = getConverter(value).getItems(value);
CharSequence[] charSequences = new CharSequence[items.size()];
for (int i = 0; i < items.size(); i++) {
TypedResource typedResource = resolve(items.get(i), config, resId);
charSequences[i] = getConverter(typedResource).asCharSequence(typedResource);
}
return charSequences;
}
use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowParcel method readParcelableCreator.
@HiddenApi
@Implementation(minSdk = JELLY_BEAN_MR2)
public Parcelable.Creator<?> readParcelableCreator(ClassLoader loader) {
// note: calling `readString` will also consume the string, and increment the data-pointer.
// which is exactly what we need, since we do not call the real `readParcelableCreator`.
final String name = realObject.readString();
if (name == null) {
return null;
}
Parcelable.Creator<?> creator;
try {
// If loader == null, explicitly emulate Class.forName(String) "caller
// classloader" behavior.
ClassLoader parcelableClassLoader = (loader == null ? getClass().getClassLoader() : loader);
// Avoid initializing the Parcelable class until we know it implements
// Parcelable and has the necessary CREATOR field.
Class<?> parcelableClass = Class.forName(name, false, /* initialize */
parcelableClassLoader);
if (!Parcelable.class.isAssignableFrom(parcelableClass)) {
throw new BadParcelableException("Parcelable protocol requires that the " + "class implements Parcelable");
}
Field f = parcelableClass.getField("CREATOR");
// this is a fix for JDK8<->Android VM incompatibility:
// Apparently, JDK will not allow access to a public field if its
// class is not visible (private or package-private) from the call-site.
f.setAccessible(true);
if ((f.getModifiers() & Modifier.STATIC) == 0) {
throw new BadParcelableException("Parcelable protocol requires " + "the CREATOR object to be static on class " + name);
}
Class<?> creatorType = f.getType();
if (!Parcelable.Creator.class.isAssignableFrom(creatorType)) {
// parcelableClass unnecessarily.
throw new BadParcelableException("Parcelable protocol requires a " + "Parcelable.Creator object called " + "CREATOR on class " + name);
}
creator = (Parcelable.Creator<?>) f.get(null);
} catch (IllegalAccessException e) {
Log.e(TAG, "Illegal access when unmarshalling: " + name, e);
throw new BadParcelableException("IllegalAccessException when unmarshalling: " + name);
} catch (ClassNotFoundException e) {
Log.e(TAG, "Class not found when unmarshalling: " + name, e);
throw new BadParcelableException("ClassNotFoundException when unmarshalling: " + name);
} catch (NoSuchFieldException e) {
throw new BadParcelableException("Parcelable protocol requires a " + "Parcelable.Creator object called " + "CREATOR on class " + name);
}
if (creator == null) {
throw new BadParcelableException("Parcelable protocol requires a " + "non-null Parcelable.Creator object called " + "CREATOR on class " + name);
}
return creator;
}
use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowResources method loadDrawable.
@HiddenApi
@Implementation(maxSdk = KITKAT_WATCH)
protected Drawable loadDrawable(TypedValue value, int id) {
Drawable drawable = reflector(ResourcesReflector.class, realResources).loadDrawable(value, id);
setCreatedFromResId(realResources, id, drawable);
return drawable;
}
use of org.robolectric.annotation.HiddenApi in project robolectric by robolectric.
the class ShadowMotionEvent method nativeAddBatch.
@Implementation(minSdk = LOLLIPOP)
@HiddenApi
protected static void nativeAddBatch(long nativePtr, long eventTimeNanos, PointerCoords[] pointerCoordsObjArray, int metaState) {
NativeInput.MotionEvent event = getNativeMotionEvent(nativePtr);
int pointerCount = event.getPointerCount();
validatePointerCoordsObjArray(pointerCoordsObjArray, pointerCount);
NativeInput.PointerCoords[] rawPointerCoords = new NativeInput.PointerCoords[pointerCount];
for (int i = 0; i < pointerCount; i++) {
PointerCoords pointerCoordsObj = pointerCoordsObjArray[i];
checkNotNull(pointerCoordsObj);
rawPointerCoords[i] = pointerCoordsToNative(pointerCoordsObj, event.getXOffset(), event.getYOffset());
}
event.addSample(eventTimeNanos, rawPointerCoords);
event.setMetaState(event.getMetaState() | metaState);
}
Aggregations