use of org.robolectric.res.android.Chunk.Iterator in project robolectric by robolectric.
the class LoadedArsc method LoadTable.
boolean LoadTable(Chunk chunk, LoadedIdmap loaded_idmap, boolean load_as_shared_library) {
// ResTable_header header = chunk.header<ResTable_header>();
ResTable_header header = chunk.asResTable_header();
if (header == null) {
logError("RES_TABLE_TYPE too small.");
return false;
}
int package_count = dtohl(header.packageCount);
int packages_seen = 0;
// packages_.reserve(package_count);
Chunk.Iterator iter = new Iterator(chunk.data_ptr(), chunk.data_size());
while (iter.HasNext()) {
Chunk child_chunk = iter.Next();
switch(child_chunk.type()) {
case RES_STRING_POOL_TYPE:
// Only use the first string pool. Ignore others.
if (global_string_pool_.getError() == NO_INIT) {
ResStringPool_header resStringPool_header = child_chunk.asResStringPool_header();
int err = global_string_pool_.setTo(resStringPool_header.myBuf(), resStringPool_header.myOffset(), child_chunk.size(), false);
if (err != NO_ERROR) {
logError("RES_STRING_POOL_TYPE corrupt.");
return false;
}
} else {
logWarning("Multiple RES_STRING_POOL_TYPEs found in RES_TABLE_TYPE.");
}
break;
case RES_TABLE_PACKAGE_TYPE:
{
if (packages_seen + 1 > package_count) {
logError("More package chunks were found than the " + package_count + " declared in the header.");
return false;
}
packages_seen++;
LoadedPackage loaded_package = LoadedPackage.Load(child_chunk, loaded_idmap, system_, load_as_shared_library);
if (!isTruthy(loaded_package)) {
return false;
}
packages_.add(loaded_package);
}
break;
default:
logWarning(String.format("Unknown chunk type '%02x'.", chunk.type()));
break;
}
}
if (iter.HadError()) {
logError(iter.GetLastError());
if (iter.HadFatalError()) {
return false;
}
}
return true;
}
use of org.robolectric.res.android.Chunk.Iterator in project robolectric by robolectric.
the class LoadedArsc method Load.
// Read-only view into a resource table. This class validates all data
// when loading, including offsets and lengths.
// class LoadedArsc {
// public:
// Load a resource table from memory pointed to by `data` of size `len`.
// The lifetime of `data` must out-live the LoadedArsc returned from this method.
// If `system` is set to true, the LoadedArsc is considered as a system provided resource.
// If `load_as_shared_library` is set to true, the application package (0x7f) is treated
// as a shared library (0x00). When loaded into an AssetManager, the package will be assigned an
// ID.
static LoadedArsc Load(StringPiece data, LoadedIdmap loaded_idmap, /* = null */
boolean system, /* = false */
boolean load_as_shared_library) /* = false */
{
// ATRACE_NAME("LoadedArsc::LoadTable");
// Not using make_unique because the constructor is private.
LoadedArsc loaded_arsc = new LoadedArsc();
loaded_arsc.system_ = system;
Chunk.Iterator iter = new Iterator(data, data.size());
while (iter.HasNext()) {
Chunk chunk = iter.Next();
switch(chunk.type()) {
case RES_TABLE_TYPE:
if (!loaded_arsc.LoadTable(chunk, loaded_idmap, load_as_shared_library)) {
return emptyBraces();
}
break;
default:
logWarning(String.format("Unknown chunk type '%02x'.", chunk.type()));
break;
}
}
if (iter.HadError()) {
logError(iter.GetLastError());
if (iter.HadFatalError()) {
return emptyBraces();
}
}
// return std.move(loaded_arsc);
return loaded_arsc;
}
Aggregations