StriWrapLineStart(const String8& s, R_len_t v) : str(s.c_str()) { nbytes = s.length()+v; count = s.countCodePoints()+v; width = stri__width_string(s.c_str(), s.length()); str.append(std::string(v, ' ')); }
/* * Determine whether or not we want to try to compress this file based * on the file extension. */ bool okayToCompress(Bundle* bundle, const String8& pathName) { String8 ext = pathName.getPathExtension(); int i; if (ext.length() == 0) return true; for (i = 0; i < NELEM(kNoCompressExt); i++) { if (strcasecmp(ext.string(), kNoCompressExt[i]) == 0) return false; } const android::Vector<const char*>& others(bundle->getNoCompressExtensions()); for (i = 0; i < (int)others.size(); i++) { const char* str = others[i]; int pos = pathName.length() - strlen(str); if (pos < 0) { continue; } const char* path = pathName.string(); if (strcasecmp(path + pos, str) == 0) { return false; } } return true; }
void BaseCamAdapter:: showParameters(String8 const& param) const { static char bufParam[4096]; const int count = 768; char *pbuf = bufParam; char ch; uint32_t len; uint32_t i, loop; pbuf[0] = 0; len = param.length(); if ( len > 4096) { len = 4096; } ::strcpy(pbuf, param.string()); loop = (len + count - 1) / count; CAM_LOGD("[showParameters]: %d, %d \n", loop, len); for (i = 0; i < loop; i++) { ch = pbuf[count]; pbuf[count] = 0; CAM_LOGD("(%s) \n", pbuf); pbuf[count] = ch; pbuf += count; } }
void IParamsManager:: showParameters(String8 const& rs8Param) { String8 s8Log; ssize_t const max_cpy_len = 767; size_t loop = 0; size_t const len = rs8Param.length(); char const* pHead = rs8Param.string(); char const*const pEnd = pHead + len; for (; pHead < pEnd;) { ssize_t cpy_len = pEnd - pHead; if ( cpy_len > max_cpy_len ) { cpy_len = max_cpy_len; } s8Log.setTo(pHead, cpy_len); CAM_LOGD("%s", s8Log.string()); pHead += cpy_len; loop++; } MY_LOGD("%zu %zu", loop, len); }
/****************************************************************************** * Splits a comma delimited string to a List of int Vector. * Example string: "(10000,26623),(10000,30000)" *******************************************************************************/ bool ParamsManager:: splitRange(String8 const& s8Input, List< Vector<int> >& rOutput) { rOutput.clear(); // if ( s8Input.isEmpty() ) { MY_LOGW("empty string"); return false; } // int endIndex, fromIndex = 1; int endIndex_input = s8Input.length()-1; if ( s8Input[0] != '(' || s8Input[endIndex_input] != ')' ) { MY_LOGW("Invalid range list string=%s", s8Input.string()); return false; } // do { endIndex = s8Input.find("),(", fromIndex); if (endIndex == -1) endIndex = endIndex_input; // Vector<int> vOut; String8 const s8SubString(s8Input.string()+fromIndex, endIndex-fromIndex); if ( splitInt(s8SubString, vOut) ) { rOutput.push_back(vOut); } // fromIndex = endIndex + 3; } while (endIndex != endIndex_input); // return (rOutput.size() > 0); }
const char *CameraParameters::get(const char *key) const { String8 v = mMap.valueFor(String8(key)); if (v.length() == 0) return 0; return v.string(); }
void HDMIAudioCaps::getChannelMasksForAF(String8& masks) { Mutex::Autolock _l(mLock); masks.clear(); // If the sink does not support basic audio, then it supports no audio. if (!mBasicAudioSupported) return; masks.append("AUDIO_CHANNEL_OUT_STEREO"); // To keep things simple, only report mode information for the mode // which supports the maximum number of channels. ssize_t ndx = getMaxChModeNdx_l(); if (ndx < 0) return; if (mModes[ndx].max_ch >= 6) { if (masks.length()) masks.append("|"); masks.append((mModes[ndx].max_ch >= 8) ? "AUDIO_CHANNEL_OUT_5POINT1|AUDIO_CHANNEL_OUT_7POINT1" : "AUDIO_CHANNEL_OUT_5POINT1"); } }
AudioParameter::AudioParameter(const String8& keyValuePairs) { char *str = new char[keyValuePairs.length()+1]; mKeyValuePairs = keyValuePairs; char *last; strcpy(str, keyValuePairs.string()); char *pair = strtok_r(str, ";", &last); while (pair != NULL) { if (strlen(pair) != 0) { size_t eqIdx = strcspn(pair, "="); String8 key = String8(pair, eqIdx); String8 value; if (eqIdx == strlen(pair)) { value = String8(""); } else { value = String8(pair + eqIdx + 1); } if (mParameters.indexOfKey(key) < 0) { mParameters.add(key, value); } else { mParameters.replaceValueFor(key, value); } } else { ALOGV("AudioParameter() cstor empty key value pair"); } pair = strtok_r(NULL, ";", &last); } delete[] str; }
void printRefs() const { String8 text; { Mutex::Autolock _l(mMutex); char buf[128]; sprintf(buf, "Strong references on RefBase %p (weakref_type %p):\n", mBase, this); text.append(buf); printRefsLocked(&text, mStrongRefs); sprintf(buf, "Weak references on RefBase %p (weakref_type %p):\n", mBase, this); text.append(buf); printRefsLocked(&text, mWeakRefs); } { char name[100]; snprintf(name, 100, DEBUG_REFS_CALLSTACK_PATH "/%p.stack", this); int rc = open(name, O_RDWR | O_CREAT | O_APPEND, 644); if (rc >= 0) { write(rc, text.string(), text.length()); close(rc); ALOGD("STACK TRACE for %p saved in %s", this, name); } else ALOGE("FAILED TO PRINT STACK TRACE for %p in %s: %s", this, name, strerror(errno)); } }
status_t BackupDataWriter::WriteEntityHeader(const String8& key, size_t dataSize) { if (m_status != NO_ERROR) { return m_status; } ssize_t amt; amt = write_padding_for(m_pos); if (amt != 0) { return amt; } String8 k; if (m_keyPrefix.length() > 0) { k = m_keyPrefix; k += ":"; k += key; } else { k = key; } if (DEBUG) { ALOGD("Writing header: prefix='%s' key='%s' dataSize=%d", m_keyPrefix.string(), key.string(), dataSize); } entity_header_v1 header; ssize_t keyLen; keyLen = k.length(); header.type = tolel(BACKUP_HEADER_ENTITY_V1); header.keyLen = tolel(keyLen); header.dataSize = tolel(dataSize); if (DEBUG) ALOGI("writing entity header, %d bytes", sizeof(entity_header_v1)); amt = write(m_fd, &header, sizeof(entity_header_v1)); if (amt != sizeof(entity_header_v1)) { m_status = errno; return m_status; } m_pos += amt; if (DEBUG) ALOGI("writing entity header key, %ld bytes", keyLen+1); amt = write(m_fd, k.string(), keyLen+1); if (amt != keyLen+1) { m_status = errno; return m_status; } m_pos += amt; amt = write_padding_for(keyLen+1); m_entityCount++; return amt; }
int FwdLockEngine::onGetDrmObjectType(int uniqueId, const String8& path, const String8& mimeType) { String8 mimeStr = String8(mimeType); LOG_VERBOSE("FwdLockEngine::onGetDrmObjectType"); /* Checks whether * 1. path and mime type both are not empty strings (meaning unavailable) else content is unknown * 2. if one of them is empty string and if other is known then its a DRM Content Object. * 3. if both of them are available, then both may be of known type * (regardless of the relation between them to make it compatible with other DRM Engines) */ if (((0 == path.length()) || onCanHandle(uniqueId, path)) && ((0 == mimeType.length()) || IsMimeTypeSupported(mimeType)) && (mimeType != path) ) { return DrmObjectType::CONTENT; } return DrmObjectType::UNKNOWN; }
static void appendInputDeviceConfigurationFileRelativePath(String8& path, const String8& name, InputDeviceConfigurationFileType type) { path.append(CONFIGURATION_FILE_DIR[type]); for (size_t i = 0; i < name.length(); i++) { char ch = name[i]; if (!isValidNameChar(ch)) { ch = '_'; } path.append(&ch, 1); } path.append(CONFIGURATION_FILE_EXTENSION[type]); }
Element *Element::createFromStream(Context *rsc, IStream *stream) { // First make sure we are reading the correct object RsA3DClassID classID = (RsA3DClassID)stream->loadU32(); if (classID != RS_A3D_CLASS_ID_ELEMENT) { LOGE("element loading skipped due to invalid class id\n"); return NULL; } String8 name; stream->loadString(&name); Component component; component.loadFromStream(stream); uint32_t fieldCount = stream->loadU32(); if (!fieldCount) { return (Element *)Element::create(rsc, component.getType(), component.getKind(), component.getIsNormalized(), component.getVectorSize());; } const Element **subElems = new const Element *[fieldCount]; const char **subElemNames = new const char *[fieldCount]; size_t *subElemNamesLengths = new size_t[fieldCount]; uint32_t *arraySizes = new uint32_t[fieldCount]; String8 elemName; for (uint32_t ct = 0; ct < fieldCount; ct ++) { stream->loadString(&elemName); subElemNamesLengths[ct] = elemName.length(); char *tmpName = new char[subElemNamesLengths[ct]]; memcpy(tmpName, elemName.string(), subElemNamesLengths[ct]); subElemNames[ct] = tmpName; arraySizes[ct] = stream->loadU32(); subElems[ct] = Element::createFromStream(rsc, stream); } const Element *elem = Element::create(rsc, fieldCount, subElems, subElemNames, subElemNamesLengths, arraySizes); for (uint32_t ct = 0; ct < fieldCount; ct ++) { delete [] subElemNames[ct]; subElems[ct]->decUserRef(); } delete[] subElems; delete[] subElemNames; delete[] subElemNamesLengths; delete[] arraySizes; return (Element *)elem; }
void EventLog::TagBuffer::writeString8(const String8& value) { if (mOverflow) return; const int32_t stringLen = value.length(); const size_t needed = 1 + sizeof(int32_t) + stringLen; if (mPos + needed > STORAGE_MAX_SIZE) { mOverflow = true; return; } mStorage[mPos + 0] = EVENT_TYPE_STRING; memcpy(&mStorage[mPos + 1], &stringLen, sizeof(int32_t)); memcpy(&mStorage[mPos + 5], value.string(), stringLen); mPos += needed; }
bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) { const String8 plugInId = getSupportedPlugInId(mimeType); bool result = (EMPTY_STRING != plugInId) ? true : false; if (0 < path.length()) { if (result) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); result = rDrmEngine.canHandle(uniqueId, path); } else { result = canHandle(uniqueId, path); } } return result; }
/****************************************************************************** * Function: usbCamGetParameters * Description: This function allocates memory for parameter string, * composes and returns the parameter string * * Input parameters: * camHal - camera HAL handle * * Return values: * Address to the parameter string * * Notes: none *****************************************************************************/ char* usbCamGetParameters(camera_hardware_t *camHal) { ALOGD("%s: E", __func__); char *parms = NULL; char* rc = NULL; String8 str; QCameraParameters qParam = camHal->qCamParams; //qParam.dump(); str = qParam.flatten( ); rc = (char *)malloc(sizeof(char)*(str.length()+1)); if(rc != NULL){ memset(rc, 0, sizeof(char)*(str.length()+1)); strncpy(rc, str.string(), str.length()); rc[str.length()] = 0; parms = rc; } PRINT_PARAM_STR(parms); ALOGD("%s: X", __func__); return (parms); } /* usbCamGetParameters */
bool PropertyMap::tryGetProperty(const String8& key, int32_t& outValue) const { String8 stringValue; if (! tryGetProperty(key, stringValue) || stringValue.length() == 0) { return false; } char* end; int value = strtol(c_str(stringValue), & end, 10); if (*end != '\0') { ALOGW("Property key '%s' has invalid value '%s'. Expected an integer.", c_str(key), c_str(stringValue)); return false; } outValue = value; return true; }
bool PropertyMap::tryGetProperty(const String8& key, float& outValue) const { String8 stringValue; if (! tryGetProperty(key, stringValue) || stringValue.length() == 0) { return false; } char* end; float value = strtof(stringValue.string(), & end); if (*end != '\0') { ALOGW("Property key '%s' has invalid value '%s'. Expected a float.", key.string(), stringValue.string()); return false; } outValue = value; return true; }
bool DrmManager::canHandle(int uniqueId, const String8& path, const String8& mimeType) { Mutex::Autolock _l(mLock); const String8 plugInId = getSupportedPlugInId(mimeType); bool result = (EMPTY_STRING != plugInId) ? true : false; if (0 < path.length()) { if (result) { IDrmEngine& rDrmEngine = mPlugInManager.getPlugIn(plugInId); result = rDrmEngine.canHandle(uniqueId, path); } else { String8 extension = path.getPathExtension(); if (String8("") != extension) { result = canHandle(uniqueId, path); } } } return result; }
status_t AudioHardware::setParameters(const String8& keyValuePairs) { AudioParameter param = AudioParameter(keyValuePairs); String8 value; String8 key; const char BT_NREC_KEY[] = "bt_headset_nrec"; const char BT_NAME_KEY[] = "bt_headset_name"; const char BT_NREC_VALUE_ON[] = "on"; LOGV("setParameters() %s", keyValuePairs.string()); if (keyValuePairs.length() == 0) return BAD_VALUE; key = String8(BT_NREC_KEY); if (param.get(key, value) == NO_ERROR) { if (value == BT_NREC_VALUE_ON) { mBluetoothNrec = true; } else { mBluetoothNrec = false; LOGI("Turning noise reduction and echo cancellation off for BT " "headset"); } } key = String8(BT_NAME_KEY); if (param.get(key, value) == NO_ERROR) { mBluetoothId = 0; for (int i = 0; i < mNumSndEndpoints; i++) { if (!strcasecmp(value.string(), mSndEndpoints[i].name)) { mBluetoothId = mSndEndpoints[i].id; LOGI("Using custom acoustic parameters for %s", value.string()); break; } } if (mBluetoothId == 0) { LOGI("Using default acoustic parameters " "(%s not in acoustic database)", value.string()); doRouting(); } } return NO_ERROR; }
void scanFile(const char *path) { sp<FileSource> file = new FileSource(path); CHECK_EQ(file->initCheck(), (status_t)OK); ID3 tag(file); if (!tag.isValid()) { printf("FAIL %s\n", path); } else { printf("SUCCESS %s\n", path); ID3::Iterator it(tag, NULL); while (!it.done()) { String8 id; it.getID(&id); CHECK(id.length() > 0); if (id[0] == 'T') { String8 text; it.getString(&text); printf(" found text frame '%s': %s\n", id.string(), text.string()); } else { printf(" found frame '%s'.\n", id.string()); } it.next(); } size_t dataSize; String8 mime; const void *data = tag.getAlbumArt(&dataSize, &mime); if (data) { printf("found album art: size=%zu mime='%s'\n", dataSize, mime.string()); hexdump(data, dataSize > 128 ? 128 : dataSize); } } }
status_t A2dpAudioInterface::A2dpAudioStreamOut::setParameters(const String8& keyValuePairs) { AudioParameter param = AudioParameter(keyValuePairs); String8 value; String8 key = String8("a2dp_sink_address"); status_t status = NO_ERROR; int device; LOGV("A2dpAudioStreamOut::setParameters() %s", keyValuePairs.string()); if (param.get(key, value) == NO_ERROR) { if (value.length() != strlen("00:00:00:00:00:00")) { status = BAD_VALUE; } else { setAddress(value.string()); } param.remove(key); } key = String8("closing"); if (param.get(key, value) == NO_ERROR) { mClosing = (value == "true"); param.remove(key); } key = AudioParameter::keyRouting; if (param.getInt(key, device) == NO_ERROR) { if (AudioSystem::isA2dpDevice((AudioSystem::audio_devices)device)) { mDevice = device; status = NO_ERROR; } else { status = BAD_VALUE; } param.remove(key); } if (param.size()) { status = BAD_VALUE; } return status; }
MediaScanResult StagefrightMediaScanner::processFileInternal( const char *path, const char *mimeType, MediaScannerClient &client) { const char *extension = strrchr(path, '.'); if (!extension) { return MEDIA_SCAN_RESULT_SKIPPED; } if (!FileHasAcceptableExtension(extension)) { return MEDIA_SCAN_RESULT_SKIPPED; } #ifndef ANDROID_DEFAULT_CODE #ifdef MTK_DRM_APP // add dcf meta data for dcf file // check extension first LOGV("processFileInternal() : the extension: %s", extension); bool isOMADrmDcf = false; if (0 == strcasecmp(extension, ".dcf")) { String8 tmp(path); DrmManagerClient* drmManagerClient = new DrmManagerClient(); DrmMetadata* dcfMetadata = drmManagerClient->getMetadata(&tmp); if (dcfMetadata == NULL) { LOGW("scan: OMA DRM v1: failed to get drm metadata, not scanned into db."); delete drmManagerClient; client.setMimeType("bad mime type"); return MEDIA_SCAN_RESULT_SKIPPED; } struct Map { const char* from; int to; }; static const Map kMap[] = { {DrmMetaKey::META_KEY_IS_DRM, METADATA_KEY_IS_DRM}, // "is_drm" {DrmMetaKey::META_KEY_CONTENT_URI, METADATA_KEY_DRM_CONTENT_URI}, {DrmMetaKey::META_KEY_OFFSET, METADATA_KEY_DRM_OFFSET}, {DrmMetaKey::META_KEY_DATALEN, METADATA_KEY_DRM_DATALEN}, {DrmMetaKey::META_KEY_RIGHTS_ISSUER, METADATA_KEY_DRM_RIGHTS_ISSUER}, {DrmMetaKey::META_KEY_CONTENT_NAME, METADATA_KEY_DRM_CONTENT_NAME}, {DrmMetaKey::META_KEY_CONTENT_DESCRIPTION, METADATA_KEY_DRM_CONTENT_DES}, {DrmMetaKey::META_KEY_CONTENT_VENDOR, METADATA_KEY_DRM_CONTENT_VENDOR}, {DrmMetaKey::META_KEY_ICON_URI, METADATA_KEY_DRM_ICON_URI} , {DrmMetaKey::META_KEY_METHOD, METADATA_KEY_DRM_METHOD}, {DrmMetaKey::META_KEY_MIME, METADATA_KEY_DRM_MIME} }; static const size_t kNumMapEntries = sizeof(kMap) / sizeof(kMap[0]); int action = Action::PLAY; String8 type; for (size_t i = 0; i < kNumMapEntries; ++i) { String8 value = dcfMetadata->get(String8(kMap[i].from)); if (value.length() != 0) { if (kMap[i].to == METADATA_KEY_DRM_MIME) { value = DrmMtkUtil::toCommonMime(value.string()); // not audio/video/image -> not scan into db type.setTo(value.string(), 6); if (0 != strcasecmp(type.string(), "audio/") && 0 != strcasecmp(type.string(), "video/") && 0 != strcasecmp(type.string(), "image/")) { LOGW("scan: OMA DRM v1: invalid drm media file mime type[%s], not added into db.", value.string()); delete dcfMetadata; delete drmManagerClient; client.setMimeType("bad mime type"); return MEDIA_SCAN_RESULT_SKIPPED; } client.setMimeType(value.string()); LOGD("scan: OMA DRM v1: drm original mime type[%s].", value.string()); // determine the Action it shall used. if ((0 == strcasecmp(type.string(), "audio/")) || (0 == strcasecmp(type.string(), "video/"))) { action = Action::PLAY; } else if ((0 == strcasecmp(type.string(), "image/"))) { action = Action::DISPLAY; } } if (kMap[i].to == METADATA_KEY_IS_DRM) { isOMADrmDcf = (value == String8("1")); } client.addStringTag(kMap[i].from, value.string()); LOGD("scan: OMA DRM v1: client.addString tag[%s] value[%s].", kMap[i].from, value.string()); } } // if there's no valid rights for this file currently, just return OK // to make sure it can be scanned into db. if (isOMADrmDcf && RightsStatus::RIGHTS_VALID != drmManagerClient->checkRightsStatus(tmp, action)) { LOGD("scan: OMA DRM v1: current no valid rights, return OK so that it can be added into db."); delete dcfMetadata; delete drmManagerClient; return MEDIA_SCAN_RESULT_OK; } // when there's valid rights, should contine to add extra metadata LOGD("scan: OMA DRM v1: current valid rights, continue to add extra info."); delete dcfMetadata; dcfMetadata = NULL; delete drmManagerClient; drmManagerClient = NULL; // if picture then we need not to scan with extractors. if (isOMADrmDcf && 0 == strcasecmp(type.string(), "image/")) { LOGD("scan: OMA DRM v1: for DRM image we do not sniff with extractors."); return MEDIA_SCAN_RESULT_OK; } } #endif #endif if (!strcasecmp(extension, ".mid") || !strcasecmp(extension, ".smf") || !strcasecmp(extension, ".imy") || !strcasecmp(extension, ".midi") || !strcasecmp(extension, ".xmf") || !strcasecmp(extension, ".rtttl") || !strcasecmp(extension, ".rtx") || !strcasecmp(extension, ".ota") || !strcasecmp(extension, ".mxmf")) { return HandleMIDI(path, &client); } sp<MediaMetadataRetriever> mRetriever(new MediaMetadataRetriever); status_t status = mRetriever->setDataSource(path); if (status) { #ifndef ANDROID_DEFAULT_CODE //if this still need on ICS // set mime type to "bad mime type" for unsupported format, otherwise the file will be included in Gallery/Music LOGE("processFile '%s' - not supported", path); client.setMimeType("bad mime type"); return MEDIA_SCAN_RESULT_SKIPPED; #else return MEDIA_SCAN_RESULT_ERROR; #endif } const char *value; if ((value = mRetriever->extractMetadata( METADATA_KEY_MIMETYPE)) != NULL) { status = client.setMimeType(value); if (status) { return MEDIA_SCAN_RESULT_ERROR; } } struct KeyMap { const char *tag; int key; }; static const KeyMap kKeyMap[] = { { "tracknumber", METADATA_KEY_CD_TRACK_NUMBER }, { "discnumber", METADATA_KEY_DISC_NUMBER }, { "album", METADATA_KEY_ALBUM }, { "artist", METADATA_KEY_ARTIST }, { "albumartist", METADATA_KEY_ALBUMARTIST }, { "composer", METADATA_KEY_COMPOSER }, { "genre", METADATA_KEY_GENRE }, { "title", METADATA_KEY_TITLE }, { "year", METADATA_KEY_YEAR }, { "duration", METADATA_KEY_DURATION }, { "writer", METADATA_KEY_WRITER }, { "compilation", METADATA_KEY_COMPILATION }, { "isdrm", METADATA_KEY_IS_DRM }, // "isdrm" #ifdef MTK_S3D_SUPPORT {"stereotype",METADATA_KEY_STEREO_3D}, //stereo 3d info #endif }; static const size_t kNumEntries = sizeof(kKeyMap) / sizeof(kKeyMap[0]); for (size_t i = 0; i < kNumEntries; ++i) { const char *value; if ((value = mRetriever->extractMetadata(kKeyMap[i].key)) != NULL) { #ifndef ANDROID_DEFAULT_CODE #ifdef MTK_DRM_APP if (kKeyMap[i].key == METADATA_KEY_IS_DRM) { if (isOMADrmDcf) { LOGD("set METADATA_KEY_IS_DRM to 1 for OMA DRM v1."); value = "1"; } } #endif #endif status = client.addStringTag(kKeyMap[i].tag, value); LOGD("processFileInternal() : client.addString tag[%s] value[%s]", kKeyMap[i].tag, value); if (status != OK) { return MEDIA_SCAN_RESULT_ERROR; } #ifndef ANDROID_DEFAULT_CODE if (kKeyMap[i].key == METADATA_KEY_DURATION) { if (!strcasecmp(extension, ".mp3") || !strcasecmp(extension, ".aac") || !strcasecmp(extension, ".amr") || !strcasecmp(extension, ".awb")) { client.addStringTag("isAccurateDuration", "0"); } else if (!strcasecmp(extension, ".wav") || !strcasecmp(extension, ".ogg") || !strcasecmp(extension, ".oga")) { client.addStringTag("isAccurateDuration", "1"); } } #endif // ANDROID_DEFAULT_CODE } } #ifndef ANDROID_DEFAULT_CODE LOGD("processFileInternal '%s' - return OK", path); #endif return MEDIA_SCAN_RESULT_OK; }
bool parse(const String8& str, ConfigDescription* out) { Vector<String8> parts = AaptUtil::splitAndLowerCase(str, '-'); ConfigDescription config; AaptLocaleValue locale; ssize_t index = 0; ssize_t localeIndex = 0; const ssize_t N = parts.size(); const char* part = parts[index].string(); if (str.length() == 0) { goto success; } if (parseMcc(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseMnc(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } // Locale spans a few '-' separators, so we let it // control the index. localeIndex = locale.initFromDirName(parts, index); if (localeIndex < 0) { return false; } else if (localeIndex > index) { locale.writeTo(&config); index = localeIndex; if (index >= N) { goto success; } part = parts[index].string(); } if (parseLayoutDirection(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseSmallestScreenWidthDp(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenWidthDp(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenHeightDp(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenLayoutSize(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenLayoutLong(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseOrientation(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseUiModeType(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseUiModeNight(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseDensity(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseTouchscreen(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseKeysHidden(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseKeyboard(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseNavHidden(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseNavigation(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenSize(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseVersion(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } // Unrecognized. return false; success: if (out != NULL) { #ifndef HAVE_ANDROID_OS applyVersionForCompatibility(&config); #else // Calling applyVersionForCompatibility when compiling a theme can cause // the path to be changed by AAPT which results in the themed assets not being // loaded. The only time (as of right now) that aapt is run on an android device // is when it is being used for themes, so this should be the correct behavior // in this case. If AAPT is ever used on an android device for some other reason, // we will need to change this. printf("AAPT is running on Android, skipping applyVersionForCompatibility"); #endif *out = config; } return true; }
bool parse(const String8& str, ConfigDescription* out) { Vector<String8> parts = AaptUtil::splitAndLowerCase(str, '-'); ConfigDescription config; AaptLocaleValue locale; ssize_t index = 0; ssize_t localeIndex = 0; const ssize_t N = parts.size(); const char* part = parts[index].string(); if (str.length() == 0) { goto success; } if (parseMcc(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseMnc(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } // Locale spans a few '-' separators, so we let it // control the index. localeIndex = locale.initFromDirName(parts, index); if (localeIndex < 0) { return false; } else if (localeIndex > index) { locale.writeTo(&config); index = localeIndex; if (index >= N) { goto success; } part = parts[index].string(); } if (parseLayoutDirection(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseSmallestScreenWidthDp(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenWidthDp(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenHeightDp(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenLayoutSize(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenLayoutLong(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenRound(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseOrientation(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseUiModeType(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseUiModeNight(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseDensity(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseTouchscreen(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseKeysHidden(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseKeyboard(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseNavHidden(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseNavigation(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseScreenSize(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } if (parseVersion(part, &config)) { index++; if (index == N) { goto success; } part = parts[index].string(); } // Unrecognized. return false; success: if (out != NULL) { applyVersionForCompatibility(&config); *out = config; } return true; }
static inline size_t write(void* buffer, size_t offset, const String8& value) { memcpy(static_cast<char*>(buffer) + offset, value.string(), value.length()); return (value.length() + 3) & ~3; }
status_t AaptGroupEntry::parseNamePart(const String8& part, int* axis, uint32_t* value) { ResTable_config config; // IMSI - MCC if (getMccName(part.string(), &config)) { *axis = AXIS_MCC; *value = config.mcc; return 0; } // IMSI - MNC if (getMncName(part.string(), &config)) { *axis = AXIS_MNC; *value = config.mnc; return 0; } // locale - language if (part.length() == 2 && isalpha(part[0]) && isalpha(part[1])) { *axis = AXIS_LANGUAGE; *value = part[1] << 8 | part[0]; return 0; } // locale - language_REGION if (part.length() == 5 && isalpha(part[0]) && isalpha(part[1]) && part[2] == '_' && isalpha(part[3]) && isalpha(part[4])) { *axis = AXIS_LANGUAGE; *value = (part[4] << 24) | (part[3] << 16) | (part[1] << 8) | (part[0]); return 0; } // orientation if (getOrientationName(part.string(), &config)) { *axis = AXIS_ORIENTATION; *value = config.orientation; return 0; } // density if (getDensityName(part.string(), &config)) { *axis = AXIS_DENSITY; *value = config.density; return 0; } // touchscreen if (getTouchscreenName(part.string(), &config)) { *axis = AXIS_TOUCHSCREEN; *value = config.touchscreen; return 0; } // keyboard hidden if (getKeysHiddenName(part.string(), &config)) { *axis = AXIS_KEYSHIDDEN; *value = config.inputFlags; return 0; } // keyboard if (getKeyboardName(part.string(), &config)) { *axis = AXIS_KEYBOARD; *value = config.keyboard; return 0; } // navigation if (getNavigationName(part.string(), &config)) { *axis = AXIS_NAVIGATION; *value = config.navigation; return 0; } // screen size if (getScreenSizeName(part.string(), &config)) { *axis = AXIS_SCREENSIZE; *value = config.screenSize; return 0; } // version if (getVersionName(part.string(), &config)) { *axis = AXIS_VERSION; *value = config.version; return 0; } return 1; }
bool AaptGroupEntry::initFromDirName(const char* dir, String8* resType) { Vector<String8> parts; String8 mcc, mnc, loc, orient, den, touch, key, keysHidden, nav, size, vers; const char *p = dir; const char *q; while (NULL != (q = strchr(p, '-'))) { String8 val(p, q-p); val.toLower(); parts.add(val); //printf("part: %s\n", parts[parts.size()-1].string()); p = q+1; } String8 val(p); val.toLower(); parts.add(val); //printf("part: %s\n", parts[parts.size()-1].string()); const int N = parts.size(); int index = 0; String8 part = parts[index]; // resource type if (!isValidResourceType(part)) { return false; } *resType = part; index++; if (index == N) { goto success; } part = parts[index]; // imsi - mcc if (getMccName(part.string())) { mcc = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not mcc: %s\n", part.string()); } // imsi - mnc if (getMncName(part.string())) { mnc = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not mcc: %s\n", part.string()); } // locale - language if (part.length() == 2 && isalpha(part[0]) && isalpha(part[1])) { loc = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not language: %s\n", part.string()); } // locale - region if (loc.length() > 0 && part.length() == 3 && part[0] == 'r' && part[0] && part[1]) { loc += "-"; part.toUpper(); loc += part.string() + 1; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not region: %s\n", part.string()); } // orientation if (getOrientationName(part.string())) { orient = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not orientation: %s\n", part.string()); } // density if (getDensityName(part.string())) { den = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not density: %s\n", part.string()); } // touchscreen if (getTouchscreenName(part.string())) { touch = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not touchscreen: %s\n", part.string()); } // keyboard hidden if (getKeysHiddenName(part.string())) { keysHidden = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not keysHidden: %s\n", part.string()); } // keyboard if (getKeyboardName(part.string())) { key = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not keyboard: %s\n", part.string()); } if (getNavigationName(part.string())) { nav = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not navigation: %s\n", part.string()); } if (getScreenSizeName(part.string())) { size = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not screen size: %s\n", part.string()); } if (getVersionName(part.string())) { vers = part; index++; if (index == N) { goto success; } part = parts[index]; } else { //printf("not version: %s\n", part.string()); } // if there are extra parts, it doesn't match return false; success: this->mcc = mcc; this->mnc = mnc; this->locale = loc; this->orientation = orient; this->density = den; this->touchscreen = touch; this->keysHidden = keysHidden; this->keyboard = key; this->navigation = nav; this->screenSize = size; this->version = vers; // what is this anyway? this->vendor = ""; return true; }
/* * Process a regular file, adding it to the archive if appropriate. * * If we're in "update" mode, and the file already exists in the archive, * delete the existing entry before adding the new one. */ bool processFile(Bundle* bundle, ZipFile* zip, String8 storageName, const sp<const AaptFile>& file) { const bool hasData = file->hasData(); ZipEntry* entry; bool fromGzip = false; status_t result; /* * See if the filename ends in ".EXCLUDE". We can't use * String8::getPathExtension() because the length of what it considers * to be an extension is capped. * * The Asset Manager doesn't check for ".EXCLUDE" in Zip archives, * so there's no value in adding them (and it makes life easier on * the AssetManager lib if we don't). * * NOTE: this restriction has been removed. If you're in this code, you * should clean this up, but I'm in here getting rid of Path Name, and I * don't want to make other potentially breaking changes --joeo */ int fileNameLen = storageName.length(); int excludeExtensionLen = strlen(kExcludeExtension); if (fileNameLen > excludeExtensionLen && (0 == strcmp(storageName.string() + (fileNameLen - excludeExtensionLen), kExcludeExtension))) { fprintf(stderr, "warning: '%s' not added to Zip\n", storageName.string()); return true; } if (strcasecmp(storageName.getPathExtension().string(), ".gz") == 0) { fromGzip = true; storageName = storageName.getBasePath(); } if (bundle->getUpdate()) { entry = zip->getEntryByName(storageName.string()); if (entry != NULL) { /* file already exists in archive; there can be only one */ if (entry->getMarked()) { fprintf(stderr, "ERROR: '%s' exists twice (check for with & w/o '.gz'?)\n", file->getPrintableSource().string()); return false; } if (!hasData) { const String8& srcName = file->getSourceFile(); time_t fileModWhen; fileModWhen = getFileModDate(srcName.string()); if (fileModWhen == (time_t) -1) { // file existence tested earlier, return false; // not expecting an error here } if (fileModWhen > entry->getModWhen()) { // mark as deleted so add() will succeed if (bundle->getVerbose()) { printf(" (removing old '%s')\n", storageName.string()); } zip->remove(entry); } else { // version in archive is newer if (bundle->getVerbose()) { printf(" (not updating '%s')\n", storageName.string()); } entry->setMarked(true); return true; } } else { // Generated files are always replaced. zip->remove(entry); } } } //android_setMinPriority(NULL, ANDROID_LOG_VERBOSE); if (fromGzip) { result = zip->addGzip(file->getSourceFile().string(), storageName.string(), &entry); } else if (!hasData) { /* don't compress certain files, e.g. PNGs */ int compressionMethod = bundle->getCompressionMethod(); if (!okayToCompress(bundle, storageName)) { compressionMethod = ZipEntry::kCompressStored; } result = zip->add(file->getSourceFile().string(), storageName.string(), compressionMethod, &entry); } else { result = zip->add(file->getData(), file->getSize(), storageName.string(), file->getCompressionMethod(), &entry); } if (result == NO_ERROR) { if (bundle->getVerbose()) { printf(" '%s'%s", storageName.string(), fromGzip ? " (from .gz)" : ""); if (entry->getCompressionMethod() == ZipEntry::kCompressStored) { printf(" (not compressed)\n"); } else { printf(" (compressed %d%%)\n", calcPercent(entry->getUncompressedLen(), entry->getCompressedLen())); } } entry->setMarked(true); } else { if (result == ALREADY_EXISTS) { fprintf(stderr, " Unable to add '%s': file already in archive (try '-u'?)\n", file->getPrintableSource().string()); } else { fprintf(stderr, " Unable to add '%s': Zip add failed (%d)\n", file->getPrintableSource().string(), result); } return false; } return true; }