• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.shadows;
2 
3 import static android.os.Build.VERSION_CODES.LOLLIPOP;
4 
5 import android.content.res.AssetManager.AssetInputStream;
6 import java.io.InputStream;
7 import org.robolectric.RuntimeEnvironment;
8 import org.robolectric.annotation.Implementation;
9 import org.robolectric.annotation.Implements;
10 import org.robolectric.annotation.RealObject;
11 import org.robolectric.res.android.Asset;
12 import org.robolectric.res.android.Registries;
13 import org.robolectric.shadows.ShadowAssetInputStream.Picker;
14 import org.robolectric.util.ReflectionHelpers;
15 
16 @SuppressWarnings("UnusedDeclaration")
17 @Implements(value = AssetInputStream.class, shadowPicker = Picker.class)
18 public class ShadowArscAssetInputStream extends ShadowAssetInputStream {
19 
20   @RealObject
21   private AssetInputStream realObject;
22 
23   @Override
getDelegate()24   InputStream getDelegate() {
25     return realObject;
26   }
27 
getAsset()28   private Asset getAsset() {
29     int apiLevel = RuntimeEnvironment.getApiLevel();
30     long assetPtr;
31     if (apiLevel >= LOLLIPOP) {
32       assetPtr = ReflectionHelpers.callInstanceMethod(realObject, "getNativeAsset");
33     } else {
34       assetPtr =
35           ((Integer) ReflectionHelpers.callInstanceMethod(realObject, "getAssetInt")).longValue();
36     }
37     return Registries.NATIVE_ASSET_REGISTRY.getNativeObject(assetPtr);
38   }
39 
40   @Override
isNinePatch()41   boolean isNinePatch() {
42     Asset asset = getAsset();
43     return asset != null && asset.isNinePatch();
44   }
45 }
46