• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package org.robolectric.res.android;
2 
3 import static org.robolectric.res.android.Errors.*;
4 
5 // transliterated from https://android.googlesource.com/platform/frameworks/base/+/android-9.0.0_r12/libs/androidfw/ResourceTypes.cpp
6 public class IdmapEntries {
7 
hasEntries()8   public boolean hasEntries() {
9     if (mData == null) {
10       return false;
11     }
12 
13     return (Util.dtohs(mData[0]) > 0);
14   }
15 
16 //  int byteSize() {
17 //    if (mData == null) {
18 //      return 0;
19 //    }
20 //    short entryCount = Util.dtohs(mData[2]);
21 //    return (SIZEOF_SHORT * 4) + (SIZEOF_INT * static_cast<int>(entryCount));
22 //  }
23 
targetTypeId()24   byte targetTypeId() {
25     if (mData == null) {
26       return 0;
27     }
28     return (byte) Util.dtohs(mData[0]);
29   }
30 
overlayTypeId()31   public byte overlayTypeId() {
32     if (mData == null) {
33       return 0;
34     }
35     return (byte) Util.dtohs(mData[1]);
36   }
37 
lookup(int entryId, Ref<Short> outEntryId)38   public int lookup(int entryId, Ref<Short> outEntryId) {
39     short entryCount = Util.dtohs(mData[2]);
40     short offset = Util.dtohs(mData[3]);
41 
42     if (entryId < offset) {
43       // The entry is not present in this idmap
44       return BAD_INDEX;
45     }
46 
47     entryId -= offset;
48 
49     if (entryId >= entryCount) {
50       // The entry is not present in this idmap
51       return BAD_INDEX;
52     }
53 
54     throw new UnsupportedOperationException("todo"); // todo
55 
56 //    // It is safe to access the type here without checking the size because
57 //    // we have checked this when it was first loaded.
58 ////        final int[] entries = reinterpret_cast<final uint32_t*>(mData) + 2;
59 //        final int[] entries = reinterpret_cast<final uint32_t*>(mData) + 2;
60 //    int mappedEntry = Util.dtohl(entries[entryId]);
61 //    if (mappedEntry == 0xffffffff) {
62 //      // This entry is not present in this idmap
63 //      return BAD_INDEX;
64 //    }
65 //        *outEntryId = static_cast<short>(mappedEntry);
66 //    return NO_ERROR;
67   }
68 
69   private short[] mData;
70 
71 }
72