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