diff options
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp | 11 | ||||
| -rw-r--r-- | libs/utils/BackupData.cpp | 196 | ||||
| -rw-r--r-- | libs/utils/BackupHelpers.cpp | 215 | ||||
| -rw-r--r-- | libs/utils/ResourceTypes.cpp | 87 |
4 files changed, 248 insertions, 261 deletions
diff --git a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp index 3f19c85a54..784dfa585f 100644 --- a/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp +++ b/libs/surfaceflinger/DisplayHardware/DisplayHardware.cpp @@ -218,9 +218,14 @@ void DisplayHardware::init(uint32_t dpy) mRefreshRate = fbDev->fps; char property[PROPERTY_VALUE_MAX]; - if (property_get("ro.sf.lcd_density", property, NULL) <= 0) { - LOGW("ro.sf.lcd_density not defined, using 160 dpi by default."); - strcpy(property, "160"); + /* Read density from build-specific ro.sf.lcd_density property + * except if it is overriden by qemu.sf.lcd_density. + */ + if (property_get("qemu.sf.lcd_density", property, NULL) <= 0) { + if (property_get("ro.sf.lcd_density", property, NULL) <= 0) { + LOGW("ro.sf.lcd_density not defined, using 160 dpi by default."); + strcpy(property, "160"); + } } mDensity = atoi(property) * (1.0f/160.0f); diff --git a/libs/utils/BackupData.cpp b/libs/utils/BackupData.cpp index 8c9f87528e..6a7f056464 100644 --- a/libs/utils/BackupData.cpp +++ b/libs/utils/BackupData.cpp @@ -86,46 +86,6 @@ BackupDataWriter::write_padding_for(int n) } status_t -BackupDataWriter::WriteAppHeader(const String8& packageName, int cookie) -{ - if (m_status != NO_ERROR) { - return m_status; - } - - ssize_t amt; - - amt = write_padding_for(m_pos); - if (amt != 0) { - return amt; - } - - app_header_v1 header; - ssize_t nameLen; - - nameLen = packageName.length(); - - header.type = tolel(BACKUP_HEADER_APP_V1); - header.packageLen = tolel(nameLen); - header.cookie = cookie; - - amt = write(m_fd, &header, sizeof(app_header_v1)); - if (amt != sizeof(app_header_v1)) { - m_status = errno; - return m_status; - } - m_pos += amt; - - amt = write(m_fd, packageName.string(), nameLen+1); - if (amt != nameLen+1) { - m_status = errno; - return m_status; - } - m_pos += amt; - - return NO_ERROR; -} - -status_t BackupDataWriter::WriteEntityHeader(const String8& key, size_t dataSize) { if (m_status != NO_ERROR) { @@ -188,40 +148,11 @@ BackupDataWriter::WriteEntityData(const void* data, size_t size) return NO_ERROR; } -status_t -BackupDataWriter::WriteAppFooter(int cookie) -{ - if (m_status != NO_ERROR) { - return m_status; - } - - ssize_t amt; - - amt = write_padding_for(m_pos); - if (amt != 0) { - return amt; - } - - app_footer_v1 footer; - ssize_t nameLen; - - footer.type = tolel(BACKUP_FOOTER_APP_V1); - footer.entityCount = tolel(m_entityCount); - footer.cookie = cookie; - - amt = write(m_fd, &footer, sizeof(app_footer_v1)); - if (amt != sizeof(app_footer_v1)) { - m_status = errno; - return m_status; - } - m_pos += amt; - - return NO_ERROR; -} BackupDataReader::BackupDataReader(int fd) :m_fd(fd), + m_done(false), m_status(NO_ERROR), m_pos(0), m_entityCount(0) @@ -260,32 +191,31 @@ BackupDataReader::Status() } while(0) status_t -BackupDataReader::ReadNextHeader(int* type) +BackupDataReader::ReadNextHeader(bool* done, int* type) { + *done = m_done; if (m_status != NO_ERROR) { return m_status; } int amt; - SKIP_PADDING(); + // No error checking here, in case we're at the end of the stream. Just let read() fail. + skip_padding(); amt = read(m_fd, &m_header, sizeof(m_header)); + *done = m_done = (amt == 0); CHECK_SIZE(amt, sizeof(m_header)); + m_pos += sizeof(m_header); + if (type) { + *type = m_header.type; + } // validate and fix up the fields. m_header.type = fromlel(m_header.type); switch (m_header.type) { - case BACKUP_HEADER_APP_V1: - m_header.app.packageLen = fromlel(m_header.app.packageLen); - if (m_header.app.packageLen < 0) { - LOGD("App header at %d has packageLen<0: 0x%08x\n", (int)m_pos, - (int)m_header.app.packageLen); - m_status = EINVAL; - } - m_header.app.cookie = m_header.app.cookie; - break; case BACKUP_HEADER_ENTITY_V1: + { m_header.entity.keyLen = fromlel(m_header.entity.keyLen); if (m_header.entity.keyLen <= 0) { LOGD("Entity header at %d has keyLen<=0: 0x%08x\n", (int)m_pos, @@ -294,52 +224,31 @@ BackupDataReader::ReadNextHeader(int* type) } m_header.entity.dataSize = fromlel(m_header.entity.dataSize); m_entityCount++; - break; - case BACKUP_FOOTER_APP_V1: - m_header.footer.entityCount = fromlel(m_header.footer.entityCount); - if (m_header.footer.entityCount < 0) { - LOGD("Entity header at %d has entityCount<0: 0x%08x\n", (int)m_pos, - (int)m_header.footer.entityCount); - m_status = EINVAL; + + // read the rest of the header (filename) + size_t size = m_header.entity.keyLen; + char* buf = m_key.lockBuffer(size); + if (buf == NULL) { + m_status = ENOMEM; + return m_status; } - m_header.footer.cookie = m_header.footer.cookie; + int amt = read(m_fd, buf, size+1); + CHECK_SIZE(amt, (int)size+1); + m_key.unlockBuffer(size); + m_pos += size+1; + SKIP_PADDING(); + m_dataEndPos = m_pos + m_header.entity.dataSize; + break; + } default: LOGD("Chunk header at %d has invalid type: 0x%08x", (int)m_pos, (int)m_header.type); m_status = EINVAL; } - m_pos += sizeof(m_header); - if (type) { - *type = m_header.type; - } return m_status; } -status_t -BackupDataReader::ReadAppHeader(String8* packageName, int* cookie) -{ - if (m_status != NO_ERROR) { - return m_status; - } - if (m_header.type != BACKUP_HEADER_APP_V1) { - return EINVAL; - } - size_t size = m_header.app.packageLen; - char* buf = packageName->lockBuffer(size); - if (buf == NULL) { - packageName->unlockBuffer(); - m_status = ENOMEM; - return m_status; - } - int amt = read(m_fd, buf, size+1); - CHECK_SIZE(amt, (int)size+1); - packageName->unlockBuffer(size); - m_pos += size+1; - *cookie = m_header.app.cookie; - return NO_ERROR; -} - bool BackupDataReader::HasEntities() { @@ -355,19 +264,8 @@ BackupDataReader::ReadEntityHeader(String8* key, size_t* dataSize) if (m_header.type != BACKUP_HEADER_ENTITY_V1) { return EINVAL; } - size_t size = m_header.entity.keyLen; - char* buf = key->lockBuffer(size); - if (key == NULL) { - key->unlockBuffer(); - m_status = ENOMEM; - return m_status; - } - int amt = read(m_fd, buf, size+1); - CHECK_SIZE(amt, (int)size+1); - key->unlockBuffer(size); - m_pos += size+1; + *key = m_key; *dataSize = m_header.entity.dataSize; - SKIP_PADDING(); return NO_ERROR; } @@ -381,42 +279,36 @@ BackupDataReader::SkipEntityData() return EINVAL; } if (m_header.entity.dataSize > 0) { - int pos = lseek(m_fd, m_header.entity.dataSize, SEEK_CUR); + int pos = lseek(m_fd, m_dataEndPos, SEEK_SET); return pos == -1 ? (int)errno : (int)NO_ERROR; } else { return NO_ERROR; } } -status_t +ssize_t BackupDataReader::ReadEntityData(void* data, size_t size) { if (m_status != NO_ERROR) { - return m_status; + return -1; } - int amt = read(m_fd, data, size); - CHECK_SIZE(amt, (int)size); - m_pos += size; - return NO_ERROR; -} - -status_t -BackupDataReader::ReadAppFooter(int* cookie) -{ - if (m_status != NO_ERROR) { - return m_status; + int remaining = m_dataEndPos - m_pos; + //LOGD("ReadEntityData size=%d m_pos=0x%x m_dataEndPos=0x%x remaining=%d\n", + // size, m_pos, m_dataEndPos, remaining); + if (remaining <= 0) { + return 0; } - if (m_header.type != BACKUP_FOOTER_APP_V1) { - return EINVAL; + if (size > remaining) { + size = remaining; } - if (m_header.footer.entityCount != m_entityCount) { - LOGD("entity count mismatch actual=%d expected=%d", m_entityCount, - m_header.footer.entityCount); - m_status = EINVAL; - return m_status; + //LOGD(" reading %d bytes", size); + int amt = read(m_fd, data, size); + if (amt < 0) { + m_status = errno; + return -1; } - *cookie = m_header.footer.cookie; - return NO_ERROR; + m_pos += amt; + return amt; } status_t diff --git a/libs/utils/BackupHelpers.cpp b/libs/utils/BackupHelpers.cpp index 4c3e37dd1c..d65a457f39 100644 --- a/libs/utils/BackupHelpers.cpp +++ b/libs/utils/BackupHelpers.cpp @@ -47,27 +47,6 @@ namespace android { #define LOGP(x...) LOGD(x) #endif -struct SnapshotHeader { - int magic0; - int fileCount; - int magic1; - int totalSize; -}; - -struct FileState { - int modTime_sec; - int modTime_nsec; - int size; - int crc32; - int nameLen; -}; - -struct FileRec { - char const* file; // this object does not own this string - bool deleted; - FileState s; -}; - const static int ROUND_UP[4] = { 0, 3, 2, 1 }; static inline int @@ -310,7 +289,8 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD for (int i=0; i<fileCount; i++) { String8 key(keys[i]); FileRec r; - char const* file = r.file = files[i]; + char const* file = files[i]; + r.file = file; struct stat st; err = stat(file, &st); @@ -351,20 +331,20 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD } else if (cmp > 0) { // file added - LOGP("file added: %s", g.file); - write_update_file(dataStream, q, g.file); + LOGP("file added: %s", g.file.string()); + write_update_file(dataStream, q, g.file.string()); m++; } else { // both files exist, check them const FileState& f = oldSnapshot.valueAt(n); - int fd = open(g.file, O_RDONLY); + int fd = open(g.file.string(), O_RDONLY); if (fd < 0) { // We can't open the file. Don't report it as a delete either. Let the // server keep the old version. Maybe they'll be able to deal with it // on restore. - LOGP("Unable to open file %s - skipping", g.file); + LOGP("Unable to open file %s - skipping", g.file.string()); } else { g.s.crc32 = compute_crc32(fd); @@ -375,7 +355,7 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD g.s.modTime_sec, g.s.modTime_nsec, g.s.size, g.s.crc32); if (f.modTime_sec != g.s.modTime_sec || f.modTime_nsec != g.s.modTime_nsec || f.size != g.s.size || f.crc32 != g.s.crc32) { - write_update_file(dataStream, fd, p, g.file); + write_update_file(dataStream, fd, p, g.file.string()); } close(fd); @@ -395,7 +375,7 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD while (m<fileCount) { const String8& q = newSnapshot.keyAt(m); FileRec& g = newSnapshot.editValueAt(m); - write_update_file(dataStream, q, g.file); + write_update_file(dataStream, q, g.file.string()); m++; } @@ -404,6 +384,86 @@ back_up_files(int oldSnapshotFD, BackupDataWriter* dataStream, int newSnapshotFD return 0; } +#define RESTORE_BUF_SIZE (8*1024) + +RestoreHelperBase::RestoreHelperBase() +{ + m_buf = malloc(RESTORE_BUF_SIZE); +} + +RestoreHelperBase::~RestoreHelperBase() +{ + free(m_buf); +} + +status_t +RestoreHelperBase::WriteFile(const String8& filename, BackupDataReader* in) +{ + ssize_t err; + size_t dataSize; + String8 key; + int fd; + void* buf = m_buf; + ssize_t amt; + int mode; + int crc; + struct stat st; + FileRec r; + + err = in->ReadEntityHeader(&key, &dataSize); + if (err != NO_ERROR) { + return err; + } + + // TODO: World readable/writable for now. + mode = 0666; + + // Write the file and compute the crc + crc = crc32(0L, Z_NULL, 0); + fd = open(filename.string(), O_CREAT|O_RDWR|O_TRUNC, mode); + if (fd == -1) { + LOGW("Could not open file %s -- %s", filename.string(), strerror(errno)); + return errno; + } + + while ((amt = in->ReadEntityData(buf, RESTORE_BUF_SIZE)) > 0) { + err = write(fd, buf, amt); + if (err != amt) { + close(fd); + LOGW("Error '%s' writing '%s'", strerror(errno), filename.string()); + return errno; + } + crc = crc32(crc, (Bytef*)buf, amt); + } + + close(fd); + + // Record for the snapshot + err = stat(filename.string(), &st); + if (err != 0) { + LOGW("Error stating file that we just created %s", filename.string()); + return errno; + } + + r.file = filename; + r.deleted = false; + r.s.modTime_sec = st.st_mtime; + r.s.modTime_nsec = 0; // workaround sim breakage + //r.s.modTime_nsec = st.st_mtime_nsec; + r.s.size = st.st_size; + r.s.crc32 = crc; + + m_files.add(key, r); + + return NO_ERROR; +} + +status_t +RestoreHelperBase::WriteSnapshot(int fd) +{ + return write_snapshot_file(fd, m_files);; +} + #if TEST_BACKUP_HELPERS #define SCRATCH_DIR "/data/backup_helper_test/" @@ -560,7 +620,6 @@ backup_helper_test_four() FileState states[4]; FileRec r; r.deleted = false; - r.file = NULL; states[0].modTime_sec = 0xfedcba98; states[0].modTime_nsec = 0xdeadbeef; @@ -689,41 +748,27 @@ backup_helper_test_four() // hexdump -v -e '" " 8/1 " 0x%02x," "\n"' data_writer.data const unsigned char DATA_GOLDEN_FILE[] = { - 0x41, 0x70, 0x70, 0x31, 0x0b, 0x00, 0x00, 0x00, - 0xdd, 0xcc, 0xbb, 0xaa, 0x6e, 0x6f, 0x5f, 0x70, - 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x00, 0x44, 0x61, 0x74, 0x61, 0x0b, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x6e, 0x6f, 0x5f, 0x70, 0x61, 0x64, 0x64, 0x69, 0x6e, 0x67, 0x5f, 0x00, 0x6e, 0x6f, 0x5f, 0x70, 0x61, 0x64, 0x64, 0x69, - 0x6e, 0x67, 0x5f, 0x00, 0x41, 0x70, 0x70, 0x31, - 0x0c, 0x00, 0x00, 0x00, 0xdd, 0xcc, 0xbb, 0xaa, + 0x6e, 0x67, 0x5f, 0x00, 0x44, 0x61, 0x74, 0x61, + 0x0c, 0x00, 0x00, 0x00, 0x0d, 0x00, 0x00, 0x00, 0x70, 0x61, 0x64, 0x64, 0x65, 0x64, 0x5f, 0x74, 0x6f, 0x5f, 0x5f, 0x33, 0x00, 0xbc, 0xbc, 0xbc, - 0x44, 0x61, 0x74, 0x61, 0x0c, 0x00, 0x00, 0x00, - 0x0d, 0x00, 0x00, 0x00, 0x70, 0x61, 0x64, 0x64, - 0x65, 0x64, 0x5f, 0x74, 0x6f, 0x5f, 0x5f, 0x33, - 0x00, 0xbc, 0xbc, 0xbc, 0x70, 0x61, 0x64, 0x64, - 0x65, 0x64, 0x5f, 0x74, 0x6f, 0x5f, 0x5f, 0x33, - 0x00, 0xbc, 0xbc, 0xbc, 0x41, 0x70, 0x70, 0x31, - 0x0d, 0x00, 0x00, 0x00, 0xdd, 0xcc, 0xbb, 0xaa, 0x70, 0x61, 0x64, 0x64, 0x65, 0x64, 0x5f, 0x74, - 0x6f, 0x5f, 0x32, 0x5f, 0x5f, 0x00, 0xbc, 0xbc, + 0x6f, 0x5f, 0x5f, 0x33, 0x00, 0xbc, 0xbc, 0xbc, 0x44, 0x61, 0x74, 0x61, 0x0d, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x70, 0x61, 0x64, 0x64, 0x65, 0x64, 0x5f, 0x74, 0x6f, 0x5f, 0x32, 0x5f, 0x5f, 0x00, 0xbc, 0xbc, 0x70, 0x61, 0x64, 0x64, 0x65, 0x64, 0x5f, 0x74, 0x6f, 0x5f, 0x32, 0x5f, - 0x5f, 0x00, 0xbc, 0xbc, 0x41, 0x70, 0x70, 0x31, - 0x0a, 0x00, 0x00, 0x00, 0xdd, 0xcc, 0xbb, 0xaa, - 0x70, 0x61, 0x64, 0x64, 0x65, 0x64, 0x5f, 0x74, - 0x6f, 0x31, 0x00, 0xbc, 0x44, 0x61, 0x74, 0x61, + 0x5f, 0x00, 0xbc, 0xbc, 0x44, 0x61, 0x74, 0x61, 0x0a, 0x00, 0x00, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x70, 0x61, 0x64, 0x64, 0x65, 0x64, 0x5f, 0x74, 0x6f, 0x31, 0x00, 0xbc, 0x70, 0x61, 0x64, 0x64, - 0x65, 0x64, 0x5f, 0x74, 0x6f, 0x31, 0x00, 0xbc, - 0x46, 0x6f, 0x6f, 0x74, 0x04, 0x00, 0x00, 0x00, - 0x99, 0x99, 0x77, 0x77 + 0x65, 0x64, 0x5f, 0x74, 0x6f, 0x31, 0x00 + }; const int DATA_GOLDEN_FILE_SIZE = sizeof(DATA_GOLDEN_FILE); @@ -733,12 +778,6 @@ test_write_header_and_entity(BackupDataWriter& writer, const char* str) int err; String8 text(str); - err = writer.WriteAppHeader(text, 0xaabbccdd); - if (err != 0) { - fprintf(stderr, "WriteAppHeader failed with %s\n", strerror(err)); - return err; - } - err = writer.WriteEntityHeader(text, text.length()+1); if (err != 0) { fprintf(stderr, "WriteEntityHeader failed with %s\n", strerror(err)); @@ -779,8 +818,6 @@ backup_helper_test_data_writer() err |= test_write_header_and_entity(writer, "padded_to_2__"); err |= test_write_header_and_entity(writer, "padded_to1"); - writer.WriteAppFooter(0x77779999); - close(fd); err = compare_file(filename, DATA_GOLDEN_FILE, DATA_GOLDEN_FILE_SIZE); @@ -800,70 +837,59 @@ test_read_header_and_entity(BackupDataReader& reader, const char* str) String8 string; int cookie = 0x11111111; size_t actualSize; + bool done; + int type; // printf("\n\n---------- test_read_header_and_entity -- %s\n\n", str); - err = reader.ReadNextHeader(); - if (err != 0) { - fprintf(stderr, "ReadNextHeader (for app header) failed with %s\n", strerror(err)); - goto done; + err = reader.ReadNextHeader(&done, &type); + if (done) { + fprintf(stderr, "should not be done yet\n"); + goto finished; } - - err = reader.ReadAppHeader(&string, &cookie); if (err != 0) { - fprintf(stderr, "ReadAppHeader failed with %s\n", strerror(err)); - goto done; - } - if (string != str) { - fprintf(stderr, "ReadAppHeader expected packageName '%s' got '%s'\n", str, string.string()); - err = EINVAL; - goto done; + fprintf(stderr, "ReadNextHeader (for app header) failed with %s\n", strerror(err)); + goto finished; } - if (cookie != (int)0xaabbccdd) { - fprintf(stderr, "ReadAppHeader expected cookie 0x%08x got 0x%08x\n", 0xaabbccdd, cookie); + if (type != BACKUP_HEADER_ENTITY_V1) { err = EINVAL; - goto done; - } - - err = reader.ReadNextHeader(); - if (err != 0) { - fprintf(stderr, "ReadNextHeader (for entity header) failed with %s\n", strerror(err)); - goto done; + fprintf(stderr, "type=0x%08x expected 0x%08x\n", type, BACKUP_HEADER_ENTITY_V1); } err = reader.ReadEntityHeader(&string, &actualSize); if (err != 0) { fprintf(stderr, "ReadEntityHeader failed with %s\n", strerror(err)); - goto done; + goto finished; } if (string != str) { fprintf(stderr, "ReadEntityHeader expected key '%s' got '%s'\n", str, string.string()); err = EINVAL; - goto done; + goto finished; } if ((int)actualSize != bufSize) { fprintf(stderr, "ReadEntityHeader expected dataSize 0x%08x got 0x%08x\n", bufSize, actualSize); err = EINVAL; - goto done; + goto finished; } err = reader.ReadEntityData(buf, bufSize); if (err != NO_ERROR) { fprintf(stderr, "ReadEntityData failed with %s\n", strerror(err)); - goto done; + goto finished; } if (0 != memcmp(buf, str, bufSize)) { fprintf(stderr, "ReadEntityData expected '%s' but got something starting with " - "%02x %02x %02x %02x\n", str, buf[0], buf[1], buf[2], buf[3]); + "%02x %02x %02x %02x '%c%c%c%c'\n", str, buf[0], buf[1], buf[2], buf[3], + buf[0], buf[1], buf[2], buf[3]); err = EINVAL; - goto done; + goto finished; } // The next read will confirm whether it got the right amount of data. -done: +finished: if (err != NO_ERROR) { fprintf(stderr, "test_read_header_and_entity failed with %s\n", strerror(err)); } @@ -923,23 +949,6 @@ backup_helper_test_data_reader() if (err == NO_ERROR) { err = test_read_header_and_entity(reader, "padded_to1"); } - - if (err == NO_ERROR) { - err = reader.ReadNextHeader(); - if (err != 0) { - fprintf(stderr, "ReadNextHeader (for app header) failed with %s\n", strerror(err)); - } - - if (err == NO_ERROR) { - int cookie; - err |= reader.ReadAppFooter(&cookie); - if (cookie != 0x77779999) { - fprintf(stderr, "app footer cookie expected=0x%08x actual=0x%08x\n", - 0x77779999, cookie); - err = EINVAL; - } - } - } } close(fd); diff --git a/libs/utils/ResourceTypes.cpp b/libs/utils/ResourceTypes.cpp index 3d12dca7a3..69d47f0c87 100644 --- a/libs/utils/ResourceTypes.cpp +++ b/libs/utils/ResourceTypes.cpp @@ -3830,9 +3830,45 @@ status_t ResTable::parsePackage(const ResTable_package* const pkg, #define CHAR16_ARRAY_EQ(constant, var, len) \ ((len == (sizeof(constant)/sizeof(constant[0]))) && (0 == memcmp((var), (constant), (len)))) -void ResTable::print() const +void print_complex(uint32_t complex, bool isFraction) +{ + const float MANTISSA_MULT = + 1.0f / (1<<Res_value::COMPLEX_MANTISSA_SHIFT); + const float RADIX_MULTS[] = { + 1.0f*MANTISSA_MULT, 1.0f/(1<<7)*MANTISSA_MULT, + 1.0f/(1<<15)*MANTISSA_MULT, 1.0f/(1<<23)*MANTISSA_MULT + }; + + float value = (complex&(Res_value::COMPLEX_MANTISSA_MASK + <<Res_value::COMPLEX_MANTISSA_SHIFT)) + * RADIX_MULTS[(complex>>Res_value::COMPLEX_RADIX_SHIFT) + & Res_value::COMPLEX_RADIX_MASK]; + printf("%f", value); + + if (isFraction) { + switch ((complex>>Res_value::COMPLEX_UNIT_SHIFT)&Res_value::COMPLEX_UNIT_MASK) { + case Res_value::COMPLEX_UNIT_PX: printf("px"); break; + case Res_value::COMPLEX_UNIT_DIP: printf("dp"); break; + case Res_value::COMPLEX_UNIT_SP: printf("sp"); break; + case Res_value::COMPLEX_UNIT_PT: printf("pt"); break; + case Res_value::COMPLEX_UNIT_IN: printf("in"); break; + case Res_value::COMPLEX_UNIT_MM: printf("mm"); break; + default: printf(" (unknown unit)"); break; + } + } else { + switch ((complex>>Res_value::COMPLEX_UNIT_SHIFT)&Res_value::COMPLEX_UNIT_MASK) { + case Res_value::COMPLEX_UNIT_FRACTION: printf("%%"); break; + case Res_value::COMPLEX_UNIT_FRACTION_PARENT: printf("%%p"); break; + default: printf(" (unknown unit)"); break; + } + } +} + +void ResTable::print(bool inclValues) const { - printf("mError=0x%x (%s)\n", mError, strerror(mError)); + if (mError != 0) { + printf("mError=0x%x (%s)\n", mError, strerror(mError)); + } #if 0 printf("mParams=%c%c-%c%c,\n", mParams.language[0], mParams.language[1], @@ -3947,6 +3983,8 @@ void ResTable::print() const (void*)(entriesStart + thisOffset)); continue; } + + const Res_value* value = NULL; if ((dtohs(ent->flags)&ResTable_entry::FLAG_COMPLEX) != 0) { printf("<bag>"); } else { @@ -3962,7 +4000,7 @@ void ResTable::print() const continue; } - const Res_value* value = (const Res_value*) + value = (const Res_value*) (((const uint8_t*)ent) + esize); printf("t=0x%02x d=0x%08x (s=0x%04x r=0x%02x)", (int)value->dataType, (int)dtohl(value->data), @@ -3973,6 +4011,49 @@ void ResTable::print() const printf(" (PUBLIC)"); } printf("\n"); + + if (inclValues) { + if (value != NULL) { + printf(" "); + if (value->dataType == Res_value::TYPE_NULL) { + printf("(null)\n"); + } else if (value->dataType == Res_value::TYPE_REFERENCE) { + printf("(reference) 0x%08x\n", value->data); + } else if (value->dataType == Res_value::TYPE_ATTRIBUTE) { + printf("(attribute) 0x%08x\n", value->data); + } else if (value->dataType == Res_value::TYPE_STRING) { + size_t len; + const char16_t* str = pkg->header->values.stringAt( + value->data, &len); + if (str == NULL) { + printf("(string) null\n"); + } else { + printf("(string) \"%s\"\n", + String8(str, len).string()); + } + } else if (value->dataType == Res_value::TYPE_FLOAT) { + printf("(float) %g\n", *(const float*)&value->data); + } else if (value->dataType == Res_value::TYPE_DIMENSION) { + printf("(dimension) "); + print_complex(value->data, false); + printf("\n"); + } else if (value->dataType == Res_value::TYPE_FRACTION) { + printf("(fraction) "); + print_complex(value->data, true); + printf("\n"); + } else if (value->dataType >= Res_value::TYPE_FIRST_COLOR_INT + || value->dataType <= Res_value::TYPE_LAST_COLOR_INT) { + printf("(color) #%08x\n", value->data); + } else if (value->dataType == Res_value::TYPE_INT_BOOLEAN) { + printf("(boolean) %s\n", value->data ? "true" : "false"); + } else if (value->dataType >= Res_value::TYPE_FIRST_INT + || value->dataType <= Res_value::TYPE_LAST_INT) { + printf("(int) 0x%08x or %d\n", value->data, value->data); + } else { + printf("(unknown type)\n"); + } + } + } } } } |