Example #1
0
/**
 * See state strings defined in ril.h RIL_REQUEST_QUERY_AVAILABLE_NETWORKS
 */
ECode COperatorInfo::RilStateToState(
    /* [in] */ const String& s,
    /* [out] */ IOperatorInfoState* result)
{
    VALIDATE_NOT_NULL(result);
    if (s.Equals("unknown")) {
        *result = OperatorInfoState_UNKNOWN;
        return NOERROR;
    }
    else if (s.Equals("available")) {
        *result = OperatorInfoState_AVAILABLE;
        return NOERROR;
    }
    else if (s.Equals("current")) {
        *result = OperatorInfoState_CURRENT;
        return NOERROR;
    }
    else if (s.Equals("forbidden")) {
        *result = OperatorInfoState_FORBIDDEN;
        return NOERROR;
    }

    // throw new RuntimeException(
    //     "RIL impl error: Invalid network state '" + s + "'");
    return E_RUNTIME_EXCEPTION;
}
ECode PreferenceInflater::OnCreateCustomFromTag(
    /* [in] */ IXmlPullParser* parser,
    /* [in] */ IInterface* _parentPreference,
    /* [in] */ IAttributeSet* attrs,
    /* [out] */ Boolean* res)
{
    VALIDATE_NOT_NULL(res)
    *res = FALSE;

    AutoPtr<IPreference> parentPreference = IPreference::Probe(_parentPreference);
    assert(parentPreference != NULL);
    String tag;
    parser->GetName(&tag);
    if (tag.Equals(INTENT_TAG_NAME)) {
        AutoPtr<IIntent> intent;

        AutoPtr<IContext> ctx;
        GetContext((IContext**)&ctx);
        AutoPtr<IResources> resource;
        ctx->GetResources((IResources**)&resource);
        if (Intent::ParseIntent(resource, parser, attrs, (IIntent**)&intent) == (ECode)E_IO_EXCEPTION) {
            Slogger::D("PreferenceInflater", "Error parsing preference");
            return E_XML_PULL_PARSER_EXCEPTION;
        }

        if (intent != NULL) {
            parentPreference->SetIntent(intent);
        }

        *res = TRUE;
        return NOERROR;
    }
    else if (tag.Equals(EXTRA_TAG_NAME)) {
        AutoPtr<IContext> ctx;
        GetContext((IContext**)&ctx);
        AutoPtr<IResources> resource;
        ctx->GetResources((IResources**)&resource);
        AutoPtr<IBundle> data;
        parentPreference->GetExtras((IBundle**)&data);
        resource->ParseBundleExtra(EXTRA_TAG_NAME, attrs, data);
        if (XmlUtils::SkipCurrentTag(parser) == (ECode)E_IO_EXCEPTION) {
            Slogger::D("PreferenceInflater", "Error parsing preference");
            return E_XML_PULL_PARSER_EXCEPTION;
        }
        *res = TRUE;
        return NOERROR;
    }

    return NOERROR;
}
Example #3
0
ECode AllAppsList::RemovePackage(
    /* [in] */ const String& packageName,
    /* [in] */ IUserHandle* user)
{
    AutoPtr<IList> data = mData;
    Int32 size;
    data->GetSize(&size);
    for (Int32 i = size - 1; i >= 0; i--) {
        AutoPtr<IInterface> obj;
        data->Get(i, (IInterface**)&obj);
        AutoPtr<ApplicationInfo> info = (ApplicationInfo*)IObject::Probe(obj);

        AutoPtr<IComponentName> component;
        info->mIntent->GetComponent((IComponentName**)&component);

        Boolean res;
        info->mUser->Equals(user, &res);
        if (res) {
            String name;
            component->GetPackageName(&name);
            Boolean tmp;
            packageName.Equals(name, &tmp);
            if (tmp) {
                removed->Add(info);
                data->Remove(i);
            }
        }
    }
    // This is more aggressive than it needs to be.
    return mIconCache->Flush();
}
ECode DataConnectionStats::OnReceive(
    /* [in] */ IContext* context,
    /* [in] */ IIntent* intent)
{
    String action;
    intent->GetAction(&action);
    if (action.Equals(ITelephonyIntents::ACTION_SIM_STATE_CHANGED)) {
        UpdateSimState(intent);
        NotePhoneDataConnectionState();
    }
    else if (action.Equals(IConnectivityManager::CONNECTIVITY_ACTION) ||
        action.Equals(IConnectivityManager::INET_CONDITION_ACTION)) {
        NotePhoneDataConnectionState();
    }
    return NOERROR;
}
Example #5
0
ECode CKXmlSerializer::SetPrefix(
    /* [in] */ const String& _prefix,
    /* [in] */ const String& _ns)
{
    String prefix = _prefix;
    String ns = _ns;
    FAIL_RETURN(Check(FALSE));
    if (prefix.IsNull()) {
        prefix = "";
    }
    if (ns.IsNull()) {
        ns = "";
    }

    String def;
    FAIL_RETURN(GetPrefix(ns, TRUE, FALSE, &def));

    // boil out if already defined

    if (prefix.Equals(def)) {
        return NOERROR;
    }

    Int32 pos = ((*mNspCounts)[mDepth + 1]++) << 1;

    if (mNspStack->GetLength() < pos + 1) {
        AutoPtr<ArrayOf<String> > hlp = ArrayOf<String>::Alloc(mNspStack->GetLength() + 16);
        hlp->Copy(mNspStack, pos);
        mNspStack = hlp;
    }

    (*mNspStack)[pos++] = prefix;
    (*mNspStack)[pos] = ns;
    return NOERROR;
}
Example #6
0
FontFamily::FontFamily(
    /* [in] */ const String& lang,
    /* [in] */ const String& variant)
{
    Int32 varEnum = 0;
    if (variant.Equals("compact")) {
        varEnum = 1;
    } else if (variant.Equals("elegant")) {
        varEnum = 2;
    }
    mNativePtr = NativeCreateFamily(lang, varEnum);
    if (mNativePtr == 0) {
        // throw new IllegalStateException("error creating native FontFamily");
        assert(0 && "error creating native FontFamily");
    }
}
Example #7
0
ECode TimeZone::GetTimeZone(
    /* [in] */ const String& id,
    /* [out] */ ITimeZone** timeZone)
{
    VALIDATE_NOT_NULL(timeZone);
    *timeZone = NULL;
    if (id.IsNull()) {
        return E_NULL_POINTER_EXCEPTION;
    }

    AutoLock lock(sLock);

    // Special cases? These can clone an existing instance.
    // TODO: should we just add a cache to ZoneInfoDB instead?
    if (id.GetLength() == 3) {
        if (id.Equals("GMT")) {
            return sGMT->Clone(timeZone);
        }
        if (id.Equals("UTC")) {
            return sUTC->Clone(timeZone);
        }
    }

    // In the database?
    AutoPtr<IZoneInfo> zi;
    FAIL_RETURN(CZoneInfoDB::GetInstance()->MakeTimeZone(id, (IZoneInfo**)&zi))
    AutoPtr<ITimeZone> zone = ITimeZone::Probe(zi);
    // Custom time zone?
    if (zone == NULL && id.GetLength() > 3 && id.StartWith("GMT")) {
        zone = GetCustomTimeZone(id);
    }

    // We never return null; on failure we return the equivalent of "GMT".
    if (zone != NULL) {
        *timeZone = zone;
        REFCOUNT_ADD(*timeZone);
        return NOERROR;
    }

    return sGMT->Clone(timeZone);
}
Example #8
0
ECode CKXmlSerializer::GetFeature(
    /* [in] */ const String& name,
    /* [out] */ Boolean* value)
{
    VALIDATE_NOT_NULL(value);

    //return false;
    name.Equals("http://xmlpull.org/v1/doc/features.html#indent-output")
        ? *value = (*mIndent)[mDepth]
        : *value = FALSE;
    return NOERROR;
}
Example #9
0
Int64 Build::GetInt64(
    /* [in] */ const String& property)
{
    AutoPtr<ISystemProperties> sysProp;
    CSystemProperties::AcquireSingleton((ISystemProperties**)&sysProp);
    String retStr = GetStringProperty(property);
    sysProp->Get(property, UNKNOWN, &retStr);
    if (retStr.Equals(UNKNOWN))
        return -1;

    return StringUtils::ParseInt64(retStr);
}
Example #10
0
static Int64 GetInt64Property(
    /* [in] */ const String& property)
{
    AutoPtr<ISystemProperties> sysProp;
    CSystemProperties::AcquireSingleton((ISystemProperties**)&sysProp);
    String retStr = GetStringProperty(property);
    sysProp->Get(property, String("unknown")/*UNKNOWN*/, &retStr);
    if (retStr.Equals("unknown"))
        return -1;

    return StringUtils::ParseInt64(retStr);
}
Example #11
0
ECode CKXmlSerializer::SetFeature(
    /* [in] */ const String& name,
    /* [in] */ Boolean state)
{
    if (name.Equals("http://xmlpull.org/v1/doc/features.html#indent-output")) {
        (*mIndent)[mDepth] = state;
        return NOERROR;
    }
    else {
//        throw new RuntimeException("Unsupported Feature");
        return E_RUNTIME_EXCEPTION;
    }
}
Example #12
0
ECode Request::GetHostPort(
    /* [out] */ String* result)
{
    VALIDATE_NOT_NULL(result)

    String myScheme;
    mHost->GetSchemeName(&myScheme);
    Int32 myPort;
    mHost->GetPort(&myPort);

    String port;
    // Only send port when we must... many servers can't deal with it
    if ((myPort != 80 && myScheme.Equals("http")) ||
        (myPort != 443 && myScheme.Equals("https"))) {
        mHost->ToHostString(&port);
    }
    else {
        mHost->GetHostName(&port);
    }

    *result = port;
    return NOERROR;
}
ECode CMediaMetadataRetriever::SetDataSource(
    /* [in] */ IContext* context,
    /* [in] */ IUri* uri)
{
    if (uri == NULL) {
        //throw new IllegalArgumentException();
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }

    String scheme;
    String path;
    uri->GetScheme(&scheme);
    if(scheme == NULL || scheme.Equals("file")) {
       uri->GetPath(&path);
       return SetDataSource(path);
    }

    AutoPtr<IAssetFileDescriptor> fd = NULL;
    // try {
    AutoPtr<IContentResolver> resolver;
    context->GetContentResolver((IContentResolver**)&resolver);
    String u;
    Int64 startoffset, declaredlength;
    Boolean tmp;
    AutoPtr<IFileDescriptor> descriptor;

    ECode ec = resolver->OpenAssetFileDescriptor(uri, String("r"), (IAssetFileDescriptor**)&fd);
    if (ec == (ECode)E_FILE_NOT_FOUND_EXCEPTION) {
        ec = E_ILLEGAL_ARGUMENT_EXCEPTION;
        FAIL_GOTO(ec, _EXIT_);
    }

    if (fd == NULL) {
        ec = E_ILLEGAL_ARGUMENT_EXCEPTION;
        FAIL_GOTO(ec, _EXIT_);
    }

    ec = fd->GetFileDescriptor((IFileDescriptor**)&descriptor);
    FAIL_GOTO(ec, _EXIT_)

    if (!descriptor->Valid(&tmp)) {
        ec = E_ILLEGAL_ARGUMENT_EXCEPTION;
        FAIL_GOTO(ec, _EXIT_)
    }
Example #14
0
ECode CKXmlSerializer::WriteEndTag(
    /* [in] */ const String& ns,
    /* [in] */ const String& name)
{
    if (!mPending) {
        mDepth--;
    }
    //        if (namespace == null)
    //          namespace = "";

    if ((ns.IsNull()
        && !(*mElementStack)[mDepth * 3].IsNull())
        || (!ns.IsNull()
            && !ns.Equals((*mElementStack)[mDepth * 3]))
        || !(*mElementStack)[mDepth * 3 + 2].Equals(name)) {
//        throw new IllegalArgumentException("</{"+namespace+"}"+name+"> does not match start");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }

    if (mPending) {
        FAIL_RETURN(Check(TRUE));
        mDepth--;
    }
    else {
        if ((*mIndent)[mDepth + 1]) {
            FAIL_RETURN(IWriter::Probe(mWriter)->Write(String("\r\n")));
            for (Int32 i = 0; i < mDepth; i++) {
                FAIL_RETURN(IWriter::Probe(mWriter)->Write(String("  ")));
            }
        }

        FAIL_RETURN(IWriter::Probe(mWriter)->Write(String("</")));
        String prefix = (*mElementStack)[mDepth * 3 + 1];
        if (!prefix.IsEmpty()) {
            FAIL_RETURN(IWriter::Probe(mWriter)->Write(prefix));
            FAIL_RETURN(IWriter::Probe(mWriter)->Write(':'));
        }
        FAIL_RETURN(IWriter::Probe(mWriter)->Write(name));
        FAIL_RETURN(IWriter::Probe(mWriter)->Write('>'));
    }

    (*mNspCounts)[mDepth + 1] = (*mNspCounts)[mDepth];
    return NOERROR;
}
Example #15
0
void SettingsHelper::SetGpsLocation(
    /* [in] */ const String& value)
{
    AutoPtr<IInterface> obj;
    mContext->GetSystemService(IContext::USER_SERVICE, (IInterface**)&obj);
    AutoPtr<IUserManager> um = IUserManager::Probe(obj);
    Boolean res;
    if (um->HasUserRestriction(IUserManager::DISALLOW_SHARE_LOCATION, &res), res) {
        return;
    }

    String GPS = ILocationManager::GPS_PROVIDER;
    Boolean enabled = GPS.Equals(value) ||
            value.StartWith(GPS + String(",")) ||
            value.EndWith(String(",") + GPS) ||
            value.Contains(String(",") + GPS + String(","));
    AutoPtr<ISettingsSecure> secure;
    CSettingsSecure::AcquireSingleton((ISettingsSecure**)&secure);
    AutoPtr<IContentResolver> resolver;
    mContext->GetContentResolver((IContentResolver**)&resolver);
    secure->SetLocationProviderEnabled(resolver, GPS, enabled);
}
Example #16
0
StringFilter* StringFilter::GetFilter(
    /* [in] */ ValueProvider* valueProvider,
    /* [in] */ IXmlPullParser* parser,
    /* [in] */ Int32 attributeIndex)
{
    String attributeName;
    String attriValue;
    parser->GetAttributeName(attributeIndex, &attributeName);
    parser->GetAttributeValue(attributeIndex, &attriValue);

    switch (attributeName.GetChar(0)) {
        case 'e':
            if (!attributeName.Equals(ATTR_EQUALS)) {
                return NULL;
            }
            return new EqualsFilter(valueProvider, attriValue);
        case 'i':
            if (!attributeName.Equals(ATTR_IS_NULL)) {
                return NULL;
            }
            return new IsNullFilter(valueProvider, attriValue);
        case 's':
            if (!attributeName.Equals(ATTR_STARTS_WITH)) {
                return NULL;
            }
            return new StartsWithFilter(valueProvider, attriValue);
        case 'c':
            if (!attributeName.Equals(ATTR_CONTAINS)) {
                return NULL;
            }
            return new ContainsFilter(valueProvider, attriValue);
        case 'p':
            if (!attributeName.Equals(ATTR_PATTERN)) {
                return NULL;
            }
            return new PatternStringFilter(valueProvider, attriValue);
        case 'r':
            if (!attributeName.Equals(ATTR_REGEX)) {
                return NULL;
            }
            return new RegexFilter(valueProvider, attriValue);
    }
    return NULL;
}
Example #17
0
ECode AllAppsList::UpdatePackage(
    /* [in] */ IContext* context,
    /* [in] */ const String& packageName,
    /* [in] */ IUserHandle* user)
{
    AutoPtr<IInterface> obj;
    context->GetSystemService(IContext::LAUNCHER_APPS_SERVICE, (IInterface**)&obj);
    AutoPtr<ILauncherApps> launcherApps = ILauncherApps::Probe(obj);
    AutoPtr<IList> matches;
    launcherApps->GetActivityList(packageName, user, (IList**)&matches);

    Int32 size;
    matches->Gize(size);
    if (size > 0) {
        // Find disabled/removed activities and remove them from data and add them
        // to the removed list.
        Int32 _size;
        mData->GetSize(&_size);
        for (Int32 i = _size - 1; i >= 0; i--) {
            AutoPtr<IInterface> obj;
            mData->Get(i, (IInterface**)&obj);
            AutoPtr<ApplicationInfo> applicationInfo = (ApplicationInfo*)IObject::Probe(obj);
            AutoPtr<IComponentName> component;
            applicationInfo->mIntent->GetComponent((IComponentName**)&component);

            Boolean res;
            user->Equals(applicationInfo->mUser, &res);
            if (res) {
                String pname;
                component->GetPackageName(&pname);
                Boolean tmp;
                packageName.Equals(pname, &tmp);
                if (tmp)) {
                    if (!FindActivity(matches, component, user)) {
                        mRemoved->Add(applicationInfo);
                        mIconCache->Remove(component);
                        mData->Remove(i);
                    }
                }
            }
        }

        // Find enabled activities and add them to the adapter
        // Also updates existing activities with new labels/icons
        Int32 count;
        matches->GetSize(&count);
        for (Int32 i = 0; i < count; i++) {
            AutoPtr<IInterface> obj;
            mMatches->Get(i, (IInterface**)&obj);
            AutoPtr<ILauncherActivityInfo> info = ILauncherActivityInfo::Preobe(obj);

            AutoPtr<IComponentName> name;
            info->GetComponentName((IComponentName**)&name);
            String pname;
            name->GetPackageName(&pname);
            String cname;
            name->GetShortClassName(&cname);
            AutoPtr<ApplicationInfo> applicationInfo = FindApplicationInfoLocked(
                    pname,
                    cname,
                    user);
            if (applicationInfo == NULL) {
                AutoPtr<ApplicationInfo> tmp = new ApplicationInfo(info, user, mIconCache, NULL);
                Add(tmp);
            }
            else {
                mIconCache->Remove(applicationInfo->mComponentName);
                mIconCache->GetTitleAndIcon(applicationInfo, info, NULL);
                modified->Add(applicationInfo);
            }
        }
    }
ECode CMenuInflater::ParseMenu(
    /* [in] */ IXmlPullParser* parser,
    /* [in] */ IAttributeSet* attrs,
    /* [in] */ IMenu* menu)
{
    AutoPtr<MenuState> menuState = new MenuState(menu, this);

    Int32 eventType = 0;
    parser->GetEventType(&eventType);
    String tagName;
    Boolean lookingForEndOfUnknownTag = FALSE;
    String unknownTagName;

    // This loop will skip to the menu start tag
    do {
        if (eventType == IXmlPullParser::START_TAG) {
            parser->GetName(&tagName);
            if (XML_MENU.Equals(tagName)) {
                // Go to next tag
                parser->Next(&eventType);
                break;
            }

            //throw new RuntimeException("Expecting menu, got " + tagName);
            return E_RUNTIME_EXCEPTION;
        }
        parser->Next(&eventType);
    } while (eventType != IXmlPullParser::END_DOCUMENT);

    Boolean reachedEndOfMenu = FALSE;
    while (!reachedEndOfMenu) {
        switch (eventType) {
            case IXmlPullParser::START_TAG:
                if (lookingForEndOfUnknownTag) {
                    break;
                }

                parser->GetName(&tagName);
                if (XML_GROUP.Equals(tagName)) {
                    menuState->ReadGroup(attrs);
                }
                else if (XML_ITEM.Equals(tagName)) {
                    menuState->ReadItem(attrs);
                }
                else if (XML_MENU.Equals(tagName)) {
                    // A menu start tag denotes a submenu for an item
                    AutoPtr<ISubMenu> subMenu;
                    FAIL_RETURN(menuState->AddSubMenuItem((ISubMenu**)&subMenu));

                    // Parse the submenu into returned SubMenu
                    ParseMenu(parser, attrs, subMenu);
                }
                else {
                    lookingForEndOfUnknownTag = TRUE;
                    unknownTagName = tagName;
                }
                break;

            case IXmlPullParser::END_TAG:
                parser->GetName(&tagName);
                if (lookingForEndOfUnknownTag && tagName.Equals(unknownTagName)) {
                    lookingForEndOfUnknownTag = FALSE;
                    unknownTagName = NULL;
                }
                else if (XML_GROUP.Equals(tagName)) {
                    menuState->ResetGroup();
                }
                else if (XML_ITEM.Equals(tagName)) {
                    // Add the item if it hasn't been added (if the item was
                    // a submenu, it would have been added already)
                    if (!menuState->HasAddedItem()) {
                        Boolean result = FALSE;
                        if (menuState->mItemActionProvider != NULL &&
                                (menuState->mItemActionProvider->HasSubMenu(&result), result)) {
                            AutoPtr<ISubMenu> subMenu;
                            FAIL_RETURN(menuState->AddSubMenuItem((ISubMenu**)&subMenu));
                        }
                        else {
                            FAIL_RETURN(menuState->AddItem());
                        }
                    }
                }
                else if (XML_MENU.Equals(tagName)) {
                    reachedEndOfMenu = TRUE;
                }
                break;

            case IXmlPullParser::END_DOCUMENT:
                //throw new RuntimeException("Unexpected end of document");
                return E_RUNTIME_EXCEPTION;
        }

        parser->Next(&eventType);
    }
    return NOERROR;
}
Example #19
0
ECode AnimatedStateListDrawable::Inflate(
    /* [in] */ /*@NonNull*/ IResources* r,
    /* [in] */ /*@NonNull*/ IXmlPullParser* parser,
    /* [in] */ /*@NonNull*/ IAttributeSet* attrs,
    /* [in] */ /*@Nullable*/ IResourcesTheme* theme) /*throws XmlPullParserException, IOException*/
{
    AutoPtr<ArrayOf<Int32> > attrIds = TO_ATTRS_ARRAYOF(R::styleable::AnimatedStateListDrawable);
    AutoPtr<ITypedArray> a;
    FAIL_RETURN(ObtainAttributes(r, theme, attrs, attrIds, (ITypedArray**)&a));

    StateListDrawable::InflateWithAttributes(r, parser, a, R::styleable::AnimatedStateListDrawable_visible);

    AutoPtr<StateListState> stateListState = GetStateListState();
    Boolean value = FALSE;
    Int32 ivalue = 0;
    a->GetBoolean(R::styleable::AnimatedStateListDrawable_variablePadding, FALSE, &value);
    stateListState->SetVariablePadding(value);
    a->GetBoolean(R::styleable::AnimatedStateListDrawable_constantSize, FALSE, &value);
    stateListState->SetConstantSize(value);

    a->GetInt32(R::styleable::AnimatedStateListDrawable_enterFadeDuration, 0, &ivalue);
    stateListState->SetEnterFadeDuration(ivalue);
    a->GetInt32(R::styleable::AnimatedStateListDrawable_exitFadeDuration, 0, &ivalue);
    stateListState->SetExitFadeDuration(ivalue);

    a->GetBoolean(R::styleable::AnimatedStateListDrawable_dither, TRUE, &value);
    SetDither(value);
    a->GetBoolean(R::styleable::AnimatedStateListDrawable_autoMirrored, FALSE, &value);
    SetAutoMirrored(value);
    a->Recycle();

    Int32 type = 0;

    Int32 innerDepth = 0;
    parser->GetDepth(&innerDepth);
    innerDepth += 1;
    Int32 depth = 0;
    while ((parser->Next(&type), type) != IXmlPullParser::END_DOCUMENT
            && ((parser->GetDepth(&depth), depth) >= innerDepth
            || type != IXmlPullParser::END_TAG)) {
        if (type != IXmlPullParser::START_TAG) {
            continue;
        }

        if (depth > innerDepth) {
            continue;
        }

        String name;
        parser->GetName(&name);
        if (name.Equals(ELEMENT_ITEM)) {
            Int32 value = 0;
            FAIL_RETURN(ParseItem(r, parser, attrs, theme, &value));
        }
        else if (name.Equals(ELEMENT_TRANSITION)) {
            Int32 value = 0;
            FAIL_RETURN(ParseTransition(r, parser, attrs, theme, &value));
        }
    }

    AutoPtr<ArrayOf<Int32> > states;
    GetState((ArrayOf<Int32>**)&states);
    OnStateChange(states);
    return NOERROR;
}
ECode CRecognitionManagerService::FindAvailRecognizer(
    /* [in] */ const String& prefPackage,
    /* [in] */ Int32 userHandle,
    /* [out] */ IComponentName** componentName)
{
    VALIDATE_NOT_NULL(componentName);
    *componentName = NULL;

    AutoPtr<IPackageManager> packageManager;
    FAIL_RETURN(mContext->GetPackageManager((IPackageManager**)&packageManager));
    assert(packageManager != NULL);
    AutoPtr<IIntent> intent;
    FAIL_RETURN(CIntent::New(IRecognitionService::SERVICE_INTERFACE, (IIntent**)&intent));

    AutoPtr<IObjectContainer> available;
    FAIL_RETURN(packageManager->QueryIntentServicesAsUser(intent, 0, userHandle, (IObjectContainer**)&available));
    Int32 numAvailable;
    assert(available != NULL);
    available->GetObjectCount(&numAvailable);

    if (0 == numAvailable) {
        Slogger::W(TAG, "no available voice recognition services found for user %d ", userHandle);
        return E_NULL_POINTER_EXCEPTION;
    }
    else {
        Boolean hasNext = FALSE;
        AutoPtr<IObjectEnumerator> enumerator;
        AutoPtr<IResolveInfo> resolveInfo;
        AutoPtr<IServiceInfo> serviceInfo;
        String packageName, name;
        if (NULL != prefPackage)  {
            FAIL_RETURN(available->GetObjectEnumerator((IObjectEnumerator**)&enumerator));
            while(enumerator->MoveNext(&hasNext), hasNext) {
                AutoPtr<IInterface> obj;
                enumerator->Current((IInterface**)&obj);
                resolveInfo = IResolveInfo::Probe(obj);
                resolveInfo->GetServiceInfo((IServiceInfo**)&serviceInfo);
                serviceInfo->GetPackageName(&packageName);
                serviceInfo->GetName(&name);
                if (prefPackage.Equals(packageName)) {
                    return CComponentName::New(packageName, name, componentName);
                }
            }
        }
        if (numAvailable > 1) {
            Slogger::W(TAG, "more than one voice recognition service found, picking first");
        }

        enumerator = NULL;
        FAIL_RETURN(available->GetObjectEnumerator((IObjectEnumerator**)&enumerator));
        enumerator->MoveNext(&hasNext);
        AutoPtr<IInterface> obj;
        enumerator->Current((IInterface**)&obj);
        resolveInfo = IResolveInfo::Probe(obj);
        serviceInfo = NULL;
        resolveInfo->GetServiceInfo((IServiceInfo**)&serviceInfo);
        serviceInfo->GetPackageName(&packageName);
        serviceInfo->GetName(&name);
        return CComponentName::New(packageName, name, componentName);
    }
}
Example #21
0
   void StringParserTester::Test()
   {  
      String s = "AAAA";
      if (s.CompareNoCase(_T("aaaa")) != 0) throw;

      s = "AAAA";
      if (s.CompareNoCase(_T("bbbb")) == 0) throw;

      s = "AAAA";
      if (s.Equals(_T("aaaa"), true)) throw;

      s = "AAAA";
      if (!s.Equals(_T("aaaa"), false)) throw;

      s = "ZZZZZ";
      if (!s.Equals(_T("ZZZZZ"), false)) throw;

      s = "";
      if (!s.Equals(_T(""), false)) throw;

      // Test a few String functions
      String sTest = "TEST";
      sTest.Replace(_T("TEST"), _T("test"));
      if (sTest != _T("test")) throw;

      sTest = "test";
      sTest.Replace(_T("TEST"), _T("dummy"));
      if (sTest != _T("test")) throw;

      sTest = "test";
      sTest.ReplaceNoCase(_T("TEST"), _T("TEST"));
      if (sTest != _T("TEST")) throw;

      sTest = "TeSt";
      sTest.ReplaceNoCase(_T("TEST"), _T("TEST"));
      if (sTest != _T("TEST")) throw;

      sTest = "TestDummy";
      sTest.ReplaceNoCase(_T("testdummy"), _T("TestDummyReplaced"));
      if (sTest != _T("TestDummyReplaced")) throw;

      sTest = "TestDummy";
      sTest.ReplaceNoCase(_T("test"), _T("TestA"));
      if (sTest != _T("TestADummy")) throw;

      sTest = "Test Test Test Test";
      sTest.ReplaceNoCase(_T("Test"), _T("TEST"));
      if (sTest != _T("TEST TEST TEST TEST")) throw;
      
      sTest = "Test TestA Test Test";
      sTest.ReplaceNoCase(_T("TestA"), _T("TESTB"));
      if (sTest != _T("Test TESTB Test Test")) throw;
 
      // Check email addresses

      
      if (StringParser::IsValidEmailAddress("@")) throw;
      if (StringParser::IsValidEmailAddress("a")) throw;      
      if (StringParser::IsValidEmailAddress("test@")) throw;
      if (StringParser::IsValidEmailAddress("@.com")) throw;
      if (StringParser::IsValidEmailAddress("\"va@ff\"@test.co.uk")) throw;
      if (StringParser::IsValidEmailAddress("some one@test.co.uk")) throw;
      if (StringParser::IsValidEmailAddress("<someone@test.co.uk>")) throw;
      if (StringParser::IsValidEmailAddress("va ff@test.co.uk")) throw;
      if (!StringParser::IsValidEmailAddress("test@test.com")) throw;
      if (!StringParser::IsValidEmailAddress("test@hmailserver.com")) throw;
      if (!StringParser::IsValidEmailAddress("test_test@hmailserver.com")) throw;
      if (!StringParser::IsValidEmailAddress("bill@microsoft.com")) throw;
      if (!StringParser::IsValidEmailAddress("martin@hmailserver.com")) throw;
      if (!StringParser::IsValidEmailAddress("vaff@test.co.uk")) throw;
      if (!StringParser::IsValidEmailAddress("va'ff@test.co.uk")) throw;
      if (!StringParser::IsValidEmailAddress("\"va ff\"@test.co.uk")) throw;
      

      if (StringParser::ExtractAddress("\"va@ff\"@test.co.uk").Compare(_T("\"va@ff\"")) != 0) throw;
      if (StringParser::ExtractAddress("test@test.co.uk").Compare(_T("test")) != 0) throw;
      if (StringParser::ExtractAddress("t'est@test.co.uk").Compare(_T("t'est")) != 0) throw;
      if (StringParser::ExtractAddress("\"t@es@\"@test.co.uk").Compare(_T("\"t@es@\"")) != 0) throw;
      if (StringParser::ExtractAddress("test@test").Compare(_T("test")) != 0) throw;
      if (StringParser::ExtractAddress("t\"est@test.com").Compare(_T("t\"est")) != 0) throw;

      if (StringParser::ExtractDomain("t\"est@test.com").Compare(_T("test.com")) != 0) throw;
      if (StringParser::ExtractDomain("t'est@test.co.uk").Compare(_T("test.co.uk")) != 0) throw;
      if (StringParser::ExtractDomain("\"t@est\"@test.co.uk").Compare(_T("test.co.uk")) != 0) throw;
      if (StringParser::ExtractDomain("\"t@es@\"@test.co.uk").Compare(_T("test.co.uk")) != 0) throw;
      if (StringParser::ExtractDomain("test@test.com").Compare(_T("test.com")) != 0) throw;

      if (!StringParser::WildcardMatch("Test", "Test")) throw;
      if (!StringParser::WildcardMatch("", "")) throw;
      if (!StringParser::WildcardMatch("Test*", "Testar")) throw;
      if (!StringParser::WildcardMatch("Test*", "Test")) throw;
      if (StringParser::WildcardMatch("Test*", "Te")) throw;

	  if (!StringParser::WildcardMatch("*two*", "one-two-three")) throw;
	  if (StringParser::WildcardMatch("*two*", "one-three")) throw;
	  if (StringParser::WildcardMatch("?two?", "one-two-three")) throw;
	  if (!StringParser::WildcardMatch("?two?", "-two-")) throw;

     // Short strings.
     if (!StringParser::WildcardMatch("?", "A")) throw;
     if (StringParser::WildcardMatch("?", "AA")) throw;
     if (!StringParser::WildcardMatch("*", "A")) throw;
     if (!StringParser::WildcardMatch("*", "AA")) throw;
     if (!StringParser::WildcardMatch("*", "")) throw;
     if (StringParser::WildcardMatch("?", "")) throw;

     // Unicode strings
     if (!StringParser::WildcardMatch(_T("??語"), _T("標準語"))) throw;
     if (StringParser::WildcardMatch(_T("?語"), _T("標準語"))) throw;
     if (!StringParser::WildcardMatch(_T("?準?"), _T("標準語"))) throw;
     if (StringParser::WildcardMatch(_T("?準"), _T("標準語"))) throw;
     if (!StringParser::WildcardMatch(_T("標*"), _T("標準語"))) throw;

     // Matching email addresses
     if (!StringParser::WildcardMatch("test@*", "test@test.com")) throw;
     if (!StringParser::WildcardMatch("test@test.co.*", "test@test.co.uk")) throw;
     if (StringParser::WildcardMatch("test@test.co.*", "test@test.com")) throw;
     if (StringParser::WildcardMatch("test@test.co.*", "test@test.co")) throw;

     // Long strings.
     String k10String;
     for (int i = 0; i < 1000; i++)
        k10String  += "AAAAAAAAAA";

     String s310CharString;
     for (int i = 0; i < 31; i++)
        s310CharString  += "AAAAAAAAAA";

     if (!StringParser::WildcardMatch(_T("*"), k10String)) throw;
     if (!StringParser::WildcardMatch(s310CharString, s310CharString)) throw;

     char *p = 0;
     p = StringParser::Search("test", 4, "e");
     if (*p != 'e') throw;
     p = StringParser::Search("test", 4, "es");
     if (*p != 'e') throw;     
     p = StringParser::Search("test", 4, "n");
     if (p != 0) throw;      
     p = StringParser::Search("test", 4, "t");
     if (*p != 't') throw; 
     p = StringParser::Search("test ", 5, " ");
     if (*p != ' ') throw;  
     p = StringParser::Search("lest ", 5, "l");
     if (*p != 'l') throw; 
     p = StringParser::Search("testp", 4, "p");
     if (p != 0) throw;  
     p = StringParser::Search("testp", 5, "");
     if (*p != 't') throw;  
     p = StringParser::Search("", 0, "test");
     if (p != 0) throw;  
     p = StringParser::Search("", 0, "");
     if (p != 0) throw;  
     p = StringParser::Search("test", 4, "p");
     if (p != 0) throw;  
     p = StringParser::Search("test", 4, "feb");
     if (p != 0) throw;

      // RESULT:
      /*
         Strings containing 80% us-ascii characters:
         QP is about 50% faster.

         Strings containing 100% non-usascii
         B64 is about 10% faster.
      */

     String input = _T("A B C");
     std::vector<String> result = StringParser::SplitString(input, _T(" "));
     if (result.size() != 3)
        throw;

     input = "A B";
     result = StringParser::SplitString(input, " ");
     if (result.size() != 2)
        throw;

     // Test Contains and ContainsNoCase
     String s1 = "Test";
     String s2 = "Test";
     Assert(s1.Contains(s2));

     s1 = "Test";
     s2 = "Tes";
     Assert(s1.Contains(s2));

     s1 = "Test";
     s2 = "est";
     Assert(s1.Contains(s2));

     s1 = "Test";
     s2 = "est";
     Assert(s1.Contains(s2));

     s1 = "Te";
     s2 = "Tes";
     Assert(!s1.Contains(s2));

     s1 = "Test";
     s2 = "TEST";
     Assert(!s1.Contains(s2));

     s1 = "Test";
     s2 = "TEST";
     Assert(s1.ContainsNoCase(s2));

     s1 = "ABCDEFGHIJKLMNOPQ";
     s2 = "hijkl";
     Assert(s1.ContainsNoCase(s2));

     s1 = "ABCDEFGHIJKLMNOPQ";
     s2 = "hijkl";
     Assert(!s1.Contains(s2));

   }
Example #22
0
	bool operator== (const String& left, const String& right)
	{
		return left.Equals(right);
	}
ECode ProfileManagerService::LoadXml(
    /* [in] */ IXmlPullParser* xpp,
    /* [in] */ IContext* context)
{
    Int32 event;
    xpp->Next(&event);
    String active;
    String _name;
    while (event != IXmlPullParser::END_TAG || !String("profiles").Equals((xpp->GetName(&_name), _name))) {
        if (event == IXmlPullParser::START_TAG) {
            String name;
            xpp->GetName(&name);
            if (name.Equals("active")) {
                xpp->NextText(&active);
                Logger::D(TAG, "Found active: %s", active.string());
            }
            else if (name.Equals("profile")) {
                AutoPtr<IProfileHelper> phl;
                CProfileHelper::AcquireSingleton((IProfileHelper**)&phl);
                AutoPtr<IProfile> prof;
                phl->FromXml(xpp, context, (IProfile**)&prof);
                AddProfileInternal(prof.Get());
                // Failsafe if no active found
                if (active.IsNull()) {
                    AutoPtr<IUUID> uuid;
                    prof->GetUuid((IUUID**)&uuid);
                    uuid->ToString(&active);
                }
            }
            else if (name.Equals("notificationGroup")) {
                AutoPtr<INotificationGroupHelper> ngh;
                CNotificationGroupHelper::AcquireSingleton((INotificationGroupHelper**)&ngh);
                AutoPtr<INotificationGroup> ng;
                ngh->FromXml(xpp, context, (INotificationGroup**)&ng);
                AddNotificationGroupInternal(ng);
            }
        }
        else if (event == IXmlPullParser::END_DOCUMENT) {
            Slogger::E("ProfileManagerService", "Premature end of file while reading %p", PROFILE_FILE.Get());
            // throw new IOException("Premature end of file while reading " + PROFILE_FILE);
            return E_IO_EXCEPTION;
        }
        xpp->Next(&event);
    }
    // Don't do initialisation on startup. The AudioManager doesn't exist yet
    // and besides, the volume settings will have survived the reboot.
    // try {
        // Try / catch block to detect if XML file needs to be upgraded.
        ECode ec = NOERROR;
        AutoPtr<IUUIDHelper> uudh;
        CUUIDHelper::AcquireSingleton((IUUIDHelper**)&uudh);
        AutoPtr<IUUID> uuid;
        uudh->FromString(active, (IUUID**)&uuid);
        Boolean flag = FALSE;
        ec = SetActiveProfile(uuid.Get(), FALSE, &flag);
    // } catch (IllegalArgumentException e) {
        if (ec == (ECode)E_ILLEGAL_ARGUMENT_EXCEPTION) {
            Boolean flag = FALSE;
            mProfileNames->ContainsKey(StringUtils::ParseCharSequence(active), &flag);
            if (flag) {
                AutoPtr<IInterface> obj;
                mProfileNames->Get(StringUtils::ParseCharSequence(active), (IInterface**)&obj);
                IUUID* uid = IUUID::Probe(obj);
                SetActiveProfile(uid, FALSE, &flag);
            }
            else {
                // Final fail-safe: We must have SOME profile active.
                // If we couldn't select one by now, we'll pick the first in the set.
                AutoPtr<ICollection> values;
                mProfiles->GetValues((ICollection**)&values);
                AutoPtr<IIterator> it;
                values->GetIterator((IIterator**)&it);
                AutoPtr<IInterface> obj;
                it->GetNext((IInterface**)&obj);
                IProfile* profile = IProfile::Probe(obj);
                SetActiveProfile(profile, FALSE);
            }
            // This is a hint that we probably just upgraded the XML file. Save changes.
            mDirty = TRUE;
        }
    // }
    return NOERROR;
}
Example #24
0
ECode CdmaMmiCode::ProcessCode()
{
    // try {
    Boolean b;
    if (IsPinPukCommand(&b), b) {
        // TODO: This is the same as the code in GsmMmiCode.java,
        // MmiCode should be an abstract or base class and this and
        // other common variables and code should be promoted.

        // sia = old PIN or PUK
        // sib = new PIN
        // sic = new PIN
        String oldPinOrPuk = mSia;
        String newPinOrPuk = mSib;
        Int32 pinLen = newPinOrPuk.GetLength();

        AppState state;
        if (IsRegister(&b), b) {
            if (!newPinOrPuk.Equals(mSic)) {
                // password mismatch; return error
                HandlePasswordError(R::string::mismatchPin);
            }
            else if (pinLen < 4 || pinLen > 8 ) {
                // invalid length
                HandlePasswordError(R::string::invalidPin);
            }
            else if (mSc.Equals(SC_PIN)
                    && mUiccApplication != NULL
                    && (mUiccApplication->GetState(&state), state) == APPSTATE_PUK) {
                // Sim is puk-locked
                HandlePasswordError(R::string::needPuk);
            }
            else if (mUiccApplication != NULL) {
                Logger::D(LOGTAG, "process mmi service code using UiccApp sc=%s", mSc.string());

                // We have an app and the pre-checks are OK
                if (mSc.Equals(SC_PIN)) {
                    AutoPtr<IMessage> msg;
                    ObtainMessage(EVENT_SET_COMPLETE, TO_IINTERFACE(this), (IMessage**)&msg);
                    mUiccApplication->ChangeIccLockPassword(oldPinOrPuk, newPinOrPuk, msg);
                }
                else if (mSc.Equals(SC_PIN2)) {
                    AutoPtr<IMessage> msg;
                    ObtainMessage(EVENT_SET_COMPLETE, TO_IINTERFACE(this), (IMessage**)&msg);
                    mUiccApplication->ChangeIccFdnPassword(oldPinOrPuk, newPinOrPuk, msg);
                }
                else if (mSc.Equals(SC_PUK)) {
                    AutoPtr<IMessage> msg;
                    ObtainMessage(EVENT_SET_COMPLETE, TO_IINTERFACE(this), (IMessage**)&msg);
                    mUiccApplication->SupplyPuk(oldPinOrPuk, newPinOrPuk, msg);
                }
                else if (mSc.Equals(SC_PUK2)) {
                    AutoPtr<IMessage> msg;
                    ObtainMessage(EVENT_SET_COMPLETE, TO_IINTERFACE(this), (IMessage**)&msg);
                    mUiccApplication->SupplyPuk2(oldPinOrPuk, newPinOrPuk, msg);
                }
                else {
                    // throw new RuntimeException("Unsupported service code=" + mSc);
                    return E_RUNTIME_EXCEPTION;
                }
            }
            else {
                // throw new RuntimeException("No application mUiccApplicaiton is NULL");
                return E_RUNTIME_EXCEPTION;
            }
        }
        else {
            // throw new RuntimeException ("Ivalid register/action=" + mAction);
            return E_RUNTIME_EXCEPTION;
        }
    }
    // } catch (RuntimeException exc) {
    //     mState = IMmiCodeState_FAILED;
    //     mMessage = mContext.getText(R::string::mmiError);
    //     mPhone.onMMIDone(this);
    // }

    return NOERROR;
}
void OverlayDisplayAdapter::UpdateOverlayDisplayDevicesLocked()
{
    AutoPtr<IContext> context = GetContext();

    AutoPtr<IContentResolver> cr;
    context->GetContentResolver((IContentResolver**)&cr);
    String value;
    Settings::Global::GetString(cr, ISettingsGlobal::OVERLAY_DISPLAY_DEVICES, &value);
    if (value.IsNull()) {
        value = String("");
    }

    if (value.Equals(mCurrentOverlaySetting)) {
        return;
    }
    mCurrentOverlaySetting = value;

    if (!mOverlays.IsEmpty()) {
        Slogger::I(TAG, "Dismissing all overlay display devices.");

        List<AutoPtr<OverlayDisplayHandle> >::Iterator iter = mOverlays.Begin();
        for (; iter != mOverlays.End(); ++iter) {
            (*iter)->DismissLocked();
        }
        mOverlays.Clear();
    }



    AutoPtr<ArrayOf<String> > parts;
    StringUtils::Split(value, String(";"), (ArrayOf<String> **)&parts);
    if (parts != NULL) {
        AutoPtr<IResources> resources;
        context->GetResources((IResources**)&resources);
        assert(resources != NULL);

        String part;
        Int32 count = 0, width, height, densityDpi;
        Boolean matched;
        ECode ec = NOERROR;
        for (Int32 i = 0; i < parts->GetLength(); ++i) {
            part = (*parts)[i];

            AutoPtr<IMatcher> matcher;
            SETTING_PATTERN->Matcher(part, (IMatcher**)&matcher);
            matcher->Matches(&matched);
            if (matched) {
                if (count >= 4) {
                    Slogger::W(TAG, "Too many overlay display devices specified: %s", value.string());
                    break;
                }

                IMatchResult* mr = IMatchResult::Probe(matcher);
                String strGroup;
                mr->Group(1, &strGroup);
                ec = StringUtils::Parse(strGroup, 10, &width);
                if (ec == (ECode)E_NUMBER_FORMAT_EXCEPTION) continue;
                mr->Group(2, &strGroup);
                ec = StringUtils::Parse(strGroup, 10, &height);
                if (ec == (ECode)E_NUMBER_FORMAT_EXCEPTION) continue;
                mr->Group(3, &strGroup);
                ec = StringUtils::Parse(strGroup, 10, &densityDpi);
                if (ec == (ECode)E_NUMBER_FORMAT_EXCEPTION) continue;

                String flagString;
                mr->Group(4, &flagString);
                if (width >= MIN_WIDTH && width <= MAX_WIDTH
                    && height >= MIN_HEIGHT && height <= MAX_HEIGHT
                    && densityDpi >= IDisplayMetrics::DENSITY_LOW
                    && densityDpi <= IDisplayMetrics::DENSITY_XXHIGH) {
                    Int32 number = ++count;

                    String name;
                    resources->GetString(R::string::display_manager_overlay_display_name, &name);
                    Int32 gravity = ChooseOverlayGravity(number);

                    Boolean secure = !flagString.IsNull() && flagString.Contains(",secure");

                    Slogger::I(TAG, "Showing overlay display device #%d: name=%s, width=%d, height=%d, densityDpi=%d, secure=%d",
                        number, name.string(), width, height, densityDpi, secure);

                    AutoPtr<OverlayDisplayHandle> handle = new OverlayDisplayHandle(this, name,
                        width, height, densityDpi, gravity, secure);
                    mOverlays.PushBack(handle);

                    continue;
                }
            }
            else if (part.IsEmpty()) {
                continue;
            }

            Slogger::W(TAG, "Malformed overlay display devices setting: %s", value.string());
        }
    }
}
Example #26
0
Boolean EqualsFilter::MatchesValue(
    /* in */ const String& value)
{
    return value != NULL && value.Equals(mFilterValue);
}
ECode CObjInfoList::AcquireDynamicEnumInfo(
    /* [in] */ const String& fullName,
    /* [in] */ ArrayOf<String>* itemNames,
    /* [in] */ ArrayOf<Int32>* itemValues,
    /* [out] */ IEnumInfo** enumInfo)
{
    if (fullName.IsNull() || itemNames == NULL
        || itemValues == NULL || !enumInfo
        || itemNames->GetLength() != itemValues->GetLength()) {
        return E_INVALID_ARGUMENT;
    }

    InfoLinkNode* node = mEnumInfoHead;
    String enumName;
    String enumNamespace;
    AutoPtr<CEnumInfo> enumInfoObj;
    Int32 count = 0, i = 0;

    LockHashTable(EntryType_Enum);
    for (; node; node = node->mNext) {
        enumInfoObj = (CEnumInfo *)node->mInfo;
        enumInfoObj->GetName(&enumName);
        enumInfoObj->GetNamespace(&enumNamespace);

        Int32 index = fullName.LastIndexOf(".");
        String name = index > 0 ? fullName.Substring(index + 1) : fullName;
        String nameSpace = index > 0 ? fullName.Substring(0, index - 1) : String("");
        if (name.Equals(enumName) && nameSpace.Equals(enumNamespace)) {
            enumInfoObj->GetItemCount(&count);
            if (count != itemNames->GetLength()) {
                if (!name.IsEmpty()) {
                    UnlockHashTable(EntryType_Enum);
                    return E_DATAINFO_EXIST;
                }
                else {
                    continue;
                }
            }

            AutoPtr< ArrayOf<String> > _itemNames = enumInfoObj->mItemNames;
            AutoPtr< ArrayOf<Int32> > _itemValues = enumInfoObj->mItemValues;
            for (i = 0; i < count; i++) {
                if (!(*itemNames)[i].Equals((*_itemNames)[i])) {
                    if (!name.IsEmpty()) {
                        UnlockHashTable(EntryType_Enum);
                        return E_DATAINFO_EXIST;
                    }
                    else {
                        continue;
                    }
                }
                if ((*itemValues)[i] != (*_itemValues)[i]) {
                    if (!name.IsEmpty()) {
                        UnlockHashTable(EntryType_Enum);
                        return E_DATAINFO_EXIST;
                    }
                    else {
                        continue;
                    }
                }
            }

            *enumInfo = enumInfoObj;
            (*enumInfo)->AddRef();
            return NOERROR;
        }
    }

    enumInfoObj = new CEnumInfo();
    if (enumInfoObj == NULL) {
        UnlockHashTable(EntryType_Enum);
        return E_OUT_OF_MEMORY;
    }

    ECode ec = enumInfoObj->InitDynamic(fullName, itemNames, itemValues);
    if (FAILED(ec)) {
        UnlockHashTable(EntryType_Enum);
        return ec;
    }

    ec = AddInfoNode(enumInfoObj, &mEnumInfoHead);
    if (FAILED(ec)) {
        UnlockHashTable(EntryType_Enum);
        return ec;
    }

    *enumInfo = enumInfoObj;
    (*enumInfo)->AddRef();

    UnlockHashTable(EntryType_Enum);

    return NOERROR;
}
void RegisteredServicesCache::ReadPersistentServicesLocked()
{
    mUserServices.Clear();
    if (mSerializerAndParser == NULL) {
        return;
    }
    AutoPtr<IFileInputStream> fis;
    // try {
    AutoPtr<IFile> file;
    ASSERT_SUCCEEDED(mPersistentServicesFile->GetBaseFile((IFile**)&file));
    Boolean exists;
    file->Exists(&exists);
    mPersistentServicesFileDidNotExist = !exists;
    if (mPersistentServicesFileDidNotExist) {
        return;
    }
    if (FAILED(mPersistentServicesFile->OpenRead((IFileInputStream**)&fis))) {
        Slogger::W(TAG, "Error reading persistent services, starting from scratch");
        if (fis != NULL) {
            // try {
            ICloseable::Probe(fis)->Close();
            // } catch (java.io.IOException e1) {
            // }
        }
        return;
    }
    AutoPtr<IXmlPullParser> parser;
    Xml::NewPullParser((IXmlPullParser**)&parser);
    if (FAILED(parser->SetInput(IInputStream::Probe(fis), String(NULL)))) {
        Slogger::W(TAG, "Error reading persistent services, starting from scratch");
        if (fis != NULL) {
            // try {
            ICloseable::Probe(fis)->Close();
            // } catch (java.io.IOException e1) {
            // }
        }
        return;
    }
    Int32 eventType;
    if (FAILED(parser->GetEventType(&eventType))) {
        Slogger::W(TAG, "Error reading persistent services, starting from scratch");
        if (fis != NULL) {
            // try {
            ICloseable::Probe(fis)->Close();
            // } catch (java.io.IOException e1) {
            // }
        }
        return;
    }
    while (eventType != IXmlPullParser::START_TAG
        && eventType != IXmlPullParser::END_DOCUMENT) {
        if (FAILED(parser->Next(&eventType))) {
            Slogger::W(TAG, "Error reading persistent services, starting from scratch");
            if (fis != NULL) {
                // try {
                ICloseable::Probe(fis)->Close();
                // } catch (java.io.IOException e1) {
                // }
            }
            return;
        }
    }
    String tagName;
    if (FAILED(parser->GetName(&tagName))) {
        Slogger::W(TAG, "Error reading persistent services, starting from scratch");
        if (fis != NULL) {
            // try {
            ICloseable::Probe(fis)->Close();
            // } catch (java.io.IOException e1) {
            // }
        }
        return;
    }
    if (tagName.Equals("services")) {
        if (FAILED(parser->Next(&eventType))) {
            Slogger::W(TAG, "Error reading persistent services, starting from scratch");
            if (fis != NULL) {
                // try {
                ICloseable::Probe(fis)->Close();
                // } catch (java.io.IOException e1) {
                // }
            }
            return;
        }
        Int32 depth;
        do {
            if (eventType == IXmlPullParser::START_TAG && (parser->GetDepth(&depth), depth == 2)) {
                if (FAILED(parser->GetName(&tagName))) {
                    Slogger::W(TAG, "Error reading persistent services, starting from scratch");
                    if (fis != NULL) {
                        // try {
                        ICloseable::Probe(fis)->Close();
                        // } catch (java.io.IOException e1) {
                        // }
                    }
                    return;
                }
                if (tagName.Equals("service")) {
                    AutoPtr<IInterface> service;
                    mSerializerAndParser->CreateFromXml(parser, (IInterface**)&service);
                    if (service == NULL) {
                        break;
                    }
                    String uidString;
                    if (FAILED(parser->GetAttributeValue(String(NULL), String("uid"), &uidString))) {
                        Slogger::W(TAG, "Error reading persistent services, starting from scratch");
                        if (fis != NULL) {
                            // try {
                            ICloseable::Probe(fis)->Close();
                            // } catch (java.io.IOException e1) {
                            // }
                        }
                        return;
                    }
                    Int32 uid = StringUtils::ParseInt32(uidString);
                    AutoPtr<UserServices> user = FindOrCreateUserLocked(UserHandle::GetUserId(uid));
                    AutoPtr<IInteger32> iuid;
                    CInteger32::New(uid, (IInteger32**)&iuid);
                    (user->mPersistentServices)[service] = iuid;
                }
            }
            if (FAILED(parser->Next(&eventType))) {
                Slogger::W(TAG, "Error reading persistent services, starting from scratch");
                if (fis != NULL) {
                    // try {
                    ICloseable::Probe(fis)->Close();
                    // } catch (java.io.IOException e1) {
                    // }
                }
                return;
            }
        } while (eventType != IXmlPullParser::END_DOCUMENT);
    }
    // } catch (Exception e) {
    //     Log.w(TAG, "Error reading persistent services, starting from scratch", e);
    // } finally {
    //     if (fis != null) {
    //         try {
    //             fis.close();
    //         } catch (java.io.IOException e1) {
    //         }
    //     }
    // }
}
ECode CObjInfoList::AcquireDynamicStructInfo(
    /* [in] */ const String& name,
    /* [in] */ ArrayOf<String>* fieldNames,
    /* [in] */ ArrayOf<IDataTypeInfo*>* fieldTypeInfos,
    /* [out] */ IStructInfo** structInfo)
{
    if (name.IsNullOrEmpty() || fieldNames == NULL
        || fieldTypeInfos == NULL || !structInfo
        || fieldNames->GetLength() != fieldTypeInfos->GetLength()) {
        return E_INVALID_ARGUMENT;
    }

    InfoLinkNode* node = mStructInfoHead;
    String structName;
    AutoPtr<CStructInfo> structInfoObj;
    Int32 count = 0, i = 0;
    LockHashTable(EntryType_Struct);
    for (; node; node = node->mNext) {
        structInfoObj = (CStructInfo *)node->mInfo;
        structInfoObj->GetName(&structName);

        if (name.Equals(structName)) {
            structInfoObj->GetFieldCount(&count);
            if (count != fieldNames->GetLength()) {
                UnlockHashTable(EntryType_Struct);
                return E_DATAINFO_EXIST;
            }

            AutoPtr< ArrayOf<String> > _fieldNames = structInfoObj->mFieldNames;
            AutoPtr< ArrayOf<IDataTypeInfo*> > _fieldTypeInfos = structInfoObj->mFieldTypeInfos;
            for (i = 0; i < count; i++) {
                if (!(*fieldNames)[i].Equals((*_fieldNames)[i])) {
                    UnlockHashTable(EntryType_Struct);
                    return E_DATAINFO_EXIST;
                }
                if ((*_fieldTypeInfos)[i] != (*fieldTypeInfos)[i]) {
                    UnlockHashTable(EntryType_Struct);
                    return E_DATAINFO_EXIST;
                }
            }

            *structInfo = structInfoObj;
            (*structInfo)->AddRef();
            UnlockHashTable(EntryType_Struct);
            return NOERROR;
        }
    }

    structInfoObj = new CStructInfo();
    if (structInfoObj == NULL) {
        UnlockHashTable(EntryType_Struct);
        return E_OUT_OF_MEMORY;
    }

    ECode ec = structInfoObj->InitDynamic(name, fieldNames, fieldTypeInfos);
    if (FAILED(ec)) {
        UnlockHashTable(EntryType_Struct);
        return ec;
    }

    ec = AddInfoNode(structInfoObj, &mStructInfoHead);
    if (FAILED(ec)) {
        UnlockHashTable(EntryType_Struct);
        return ec;
    }

    *structInfo = structInfoObj;
    (*structInfo)->AddRef();

    UnlockHashTable(EntryType_Struct);

    return NOERROR;
}