Example #1
0
/**
 * Removes the {@code Provider} with the specified name form the collection
 * of providers. If the the {@code Provider} with the specified name is
 * removed, all provider at a greater position are shifted down one
 * position.
 *
 * <p>Returns silently if {@code name} is {@code null} or no provider with the
 * specified name is installed.
 *
 * @param name
 *            the name of the provider to remove.
 */
ECode CSecurity::RemoveProvider(
    /* [in] */ const String& name)
{
    AutoLock lock(this);
    // It is not clear from spec.:
    // 1. if name is null, should we checkSecurityAccess or not?
    //    throw SecurityException or not?
    // 2. as 1 but provider is not installed
    // 3. behavior if name is empty string?

    AutoPtr<IProvider> p;
    if (name.IsNullOrEmpty()) {
        return NOERROR;
    }
    GetProvider(name, (IProvider**)&p);
    if (p == NULL) {
        return NOERROR;
    }
    Int32 number;
    p->GetProviderNumber(&number);
    AutoPtr<IServices> services;
    CServices::AcquireSingleton((IServices**)&services);
    services->RemoveProvider(number);
    RenumProviders();
    p->SetProviderNumber(-1);
    return NOERROR;
}
ECode CUriBuilder::AppendQueryParameter(
    /* [in] */ const String& key,
    /* [in] */ const String& value)
{
    // This URI will be hierarchical.
    mOpaquePart = NULL;

    String nullStr;
    String keyParam, valueParam;
    Uri::Encode(key, nullStr, &keyParam);
    Uri::Encode(value, nullStr, &valueParam);

    StringBuilder sb(keyParam);
    sb += "=";
    sb += valueParam;
    String encodedParameter = sb.ToString();

    if (mQuery == NULL) {
        mQuery = Uri::Part::FromEncoded(encodedParameter);
        return NOERROR;
    }

    String oldQuery = mQuery->GetEncoded();
    if (oldQuery.IsNullOrEmpty()) {
        mQuery = Uri::Part::FromEncoded(encodedParameter);
    } else {
        sb.Reset();
        sb += oldQuery;
        sb += "&";
        sb += encodedParameter;
        mQuery = Uri::Part::FromEncoded(sb.ToString());
    }

    return NOERROR;
}
Example #3
0
String Observer::GetBusInterfaceName(
    /* [in] */ IInterfaceInfo* intf)
{
    AutoPtr<IAnnotationInfo> annotation;
    intf->GetAnnotation(Globals::Annotation_BusInterface, (IAnnotationInfo**)&annotation);

    if (annotation != NULL) {
        String name;
        annotation->GetValue(String("name"), &name);
        if (!name.IsNullOrEmpty()) {
            return name;
        }
    }

    String name, ns;
    intf->GetName(&name);
    intf->GetNamespace(&ns);
    if (ns.IsNullOrEmpty()) {
        return name;
    }

    StringBuilder sb(ns);
    sb += ".";
    sb += name;
    return sb.ToString();
}
Example #4
0
ECode SQLiteSession::ExecuteForLastInsertedRowId(
    /* [in] */ const String& sql,
    /* [in] */ ArrayOf<IInterface*>* bindArgs,
    /* [in] */ Int32 connectionFlags,
    /* [in] */ ICancellationSignal* cancellationSignal,
    /* [out] */ Int64* id)
{
    VALIDATE_NOT_NULL(id);
    *id = 0;

    if (sql.IsNullOrEmpty()) {
        //throw new IllegalArgumentException("sql must not be null.");
        Slogger::E("SQLiteSession", "sql must not be null.");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }

    Boolean isSuccess;
    FAIL_RETURN(ExecuteSpecial(sql, bindArgs, connectionFlags, cancellationSignal, &isSuccess))
    if (isSuccess) {
        *id = 0;
        return NOERROR;
    }

    FAIL_RETURN(AcquireConnection(sql, connectionFlags, cancellationSignal)) // might throw
    //try {
    ECode ec = mConnection->ExecuteForLastInsertedRowId(sql, bindArgs, cancellationSignal, id); // might throw
    //} finally {
    FAIL_RETURN(ReleaseConnection()) // might throw
    //}
    return ec;
}
Example #5
0
ECode SQLiteSession::Prepare(
    /* [in] */ const String& sql,
    /* [in] */ Int32 connectionFlags,
    /* [in] */ ICancellationSignal* cancellationSignal,
    /* [in] */ SQLiteStatementInfo* outStatementInfo)
{
    if (sql.IsNullOrEmpty()) {
        //throw new IllegalArgumentException("sql must not be null.");
        Slogger::E("SQLiteSession", "sql must not be null.");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }

    if (cancellationSignal != NULL) {
        FAIL_RETURN(cancellationSignal->ThrowIfCanceled())
    }

    ECode ec = AcquireConnection(sql, connectionFlags, cancellationSignal); // might throw
    if (FAILED(ec)) {
        Slogger::E("SQLiteSession", "Failed to AcquireConnection %s", sql.string());
        return ec;
    }
    //try {
    ec = mConnection->Prepare(sql, outStatementInfo); // might throw
    if (FAILED(ec)) {
        Slogger::E("SQLiteSession", "Failed to Prepare %s", sql.string());
    }

    //} finally {
    ec = ReleaseConnection(); // might throw
    if (FAILED(ec)) {
        Slogger::E("SQLiteSession", "Failed to ReleaseConnection %s", sql.string());
    }
    //}
    return ec;
}
Example #6
0
ECode Request::AddHeader(
    /* [in] */ const String& name,
    /* [in] */ const String& value)
{
    if (name.IsNullOrEmpty()) {
        HttpLog::E(String("Null http header name"));
        return E_NULL_POINTER_EXCEPTION;
    }
    if (value.IsNullOrEmpty() || value.GetLength() == 0) {
        String damage = String("Null or empty value for header \"") + name + String("\"");
        HttpLog::E(damage);
        return E_RUNTIME_EXCEPTION;
    }

    // TODO: Waiting for BasicHttpRequest
    assert(0);
    return NOERROR;
    // return mHttpRequest->AddHeader(name, value);
}
Example #7
0
Boolean CSyncManager::InitStaticMembers()
{
    if(mIsStaticMemberInitialized == TRUE){
        return TRUE;
    }

    String localSyncDelayString = SystemProperties::Get("sync.local_sync_delay");
    Int64 localSyncDelay = 30 * 1000; // 30 seconds
    if (!localSyncDelayString.IsNullOrEmpty()) {
//        try
//        {
            Int64 tempSyncDelay = localSyncDelayString.ToInt64();
            if (tempSyncDelay > 0) {
                localSyncDelay = tempSyncDelay;
            }
//        }
//        catch (NumberFormatException nfe)
//        {
//            // ignore, use default
//        }
    }

    LOCAL_SYNC_DELAY = localSyncDelay;

    String maxTimePerSyncString = SystemProperties::Get("sync.max_time_per_sync");
    Int64 maxTimePerSync = 5 * 60 * 1000; // 5 minutes

    if (!maxTimePerSyncString.IsNullOrEmpty()) {
        Int64 tempTimePerSync = maxTimePerSyncString.ToInt64();

        if (tempTimePerSync > 0) {
            maxTimePerSync = tempTimePerSync;
        }
    }

    MAX_TIME_PER_SYNC = maxTimePerSync;

    INITIAL_ACCOUNTS_ARRAY = ArrayOf<IAccount*>::Alloc(0);

    return TRUE;
}
Example #8
0
ECode Build::EnsureFingerprintProperty()
{
    String value = GetStringProperty(String("ro.build.fingerprint"));
    if (value.IsNullOrEmpty()) {
        // try {
        AutoPtr<ISystemProperties> sysProp;
        CSystemProperties::AcquireSingleton((ISystemProperties**)&sysProp);
        sysProp->Set(String("ro.build.fingerprint"), FINGERPRINT);
        // } catch (IllegalArgumentException e) {
        //     Slog.e(TAG, "Failed to set fingerprint property", e);
        // }
    }
    return NOERROR;
}
Example #9
0
/**
 * Get cookie(s) for a given url so that it can be set to "cookie:" in http
 * request header.
 * @param url The url needs cookie
 * @return The cookies in the format of NAME=VALUE [; NAME=VALUE]
 */
String AwCookieManager::GetCookie(
    /* [in] */ const String& url)
{
    String cookie = NativeGetCookie(url);
    // Return null if the string is empty to match legacy behavior
    //return cookie == NULL || cookie.Trim().IsEmpty() ? NULL : cookie;
    if (cookie.IsNullOrEmpty())
    {
        return String(NULL);
    }
    if (cookie.Trim().IsEmpty())
    {
        return String(NULL);
    }
    return cookie;
}
Example #10
0
ECode CJDBCConnection::constructor(
    /* [in] */ const String& url,
    /* [in] */ const String& enc,
    /* [in] */ const String& pwd,
    /* [in] */ const String& drep,
    /* [in] */ const String& vfs)
{
    ECode ec = NOERROR;
    if (url.StartWith("sqlite:/")) {
        mDbfile = url.Substring(0, 8);
    } else if (url.StartWith("jdbc:sqlite:/")) {
        mDbfile = url.Substring(0, 13);
    } else {
        return E_SQL_EXCEPTION;
    }

    this->mUrl = url;
    this->mEnc = enc;
    this->mVfs = vfs;

    ec = Open(mReadonly, (IDatabase**)&mDb);
    if (FAILED(ec)) {
        return E_SQL_EXCEPTION;
    }

    if (!pwd.IsNullOrEmpty()) {
        ec = mDb->Key(pwd);
        if (FAILED(ec)) {
            return E_SQL_EXCEPTION;
        }
    }

    IBusyHandler* hd = IBusyHandler::Probe(this);
    ec = mDb->BusyHandler(hd);
    //ec = mDb->BusyHandler(this);
    if (FAILED(ec)) {
        if (mDb != NULL) {
            mDb->Close();
        }
    }
    if (!drep.IsNull() && (drep.StartWith("j") || drep.StartWith("J"))) {
        mUseJulian = TRUE;
    }

    return NOERROR;
}
Example #11
0
static AutoPtr<ArrayOf<String> > GetStringPropertyList(
    /* [in] */ const String& property,
    /* [in] */ const String& separator)
{
    AutoPtr<ISystemProperties> sysProp;
    CSystemProperties::AcquireSingleton((ISystemProperties**)&sysProp);
    String value;
    sysProp->Get(property, &value);

    AutoPtr<ArrayOf<String> > array;
    if (value.IsNullOrEmpty()) {
        array = ArrayOf<String>::Alloc(0);
    }
    else {
        StringUtils::Split(value, separator, (ArrayOf<String>**)&array);
    }
    return array;
}
Example #12
0
ECode SQLiteSession::ExecuteForCursorWindow(
    /* [in] */ const String& sql,
    /* [in] */ ArrayOf<IInterface*>* bindArgs,
    /* [in] */ ICursorWindow* window,
    /* [in] */ Int32 startPos,
    /* [in] */ Int32 requiredPos,
    /* [in] */ Boolean countAllRows,
    /* [in] */ Int32 connectionFlags,
    /* [in] */ ICancellationSignal* cancellationSignal,
    /* [out] */ Int32* result)
{
    VALIDATE_NOT_NULL(result);
    *result = 0;

    if (sql.IsNullOrEmpty()) {
        //throw new IllegalArgumentException("sql must not be null.");
        Slogger::E("SQLiteSession", "sql must not be null.");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }
    if (window == NULL) {
        //throw new IllegalArgumentException("window must not be null.");
        Slogger::E("SQLiteSession", "window must not be null.");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }

    Boolean isSuccess;
    FAIL_RETURN(ExecuteSpecial(sql, bindArgs, connectionFlags, cancellationSignal, &isSuccess))
    if (isSuccess) {
        window->Clear();
        *result = 0;
        return NOERROR;
    }

    FAIL_RETURN(AcquireConnection(sql, connectionFlags, cancellationSignal)) // might throw
    //try {
    ECode ec = mConnection->ExecuteForCursorWindow(sql, bindArgs,
            window, startPos, requiredPos, countAllRows, cancellationSignal, result); // might throw
    //} finally {
    FAIL_RETURN(ReleaseConnection()) // might throw
    //}
    return ec;
}
Example #13
0
/**
 * Some devices split the fingerprint components between multiple
 * partitions, so we might derive the fingerprint at runtime.
 */
static String DeriveFingerprint() {
    String finger = GetStringProperty(String("ro.build.fingerprint"));
    if (finger.IsNullOrEmpty()) {
        StringBuilder sb;
        sb += GetStringProperty(String("ro.product.brand"));
        sb.AppendChar('/');
        sb += GetStringProperty(String("ro.product.name"));
        sb.AppendChar('/');
        sb += GetStringProperty(String("ro.product.device"));
        sb.AppendChar(':');
        sb += GetStringProperty(String("ro.build.version.release"));
        sb.AppendChar('/');
        sb += GetStringProperty(String("ro.build.id"));
        sb.AppendChar('/');
        sb += GetStringProperty(String("ro.build.version.incremental"));
        sb.AppendChar(':');
        sb += GetStringProperty(String("ro.build.type"));
        sb.AppendChar('/');
        sb += GetStringProperty(String("ro.build.tags"));
        finger = sb.ToString();
    }
    return finger;
}
ECode CRecognitionManagerService::GetCurRecognizer(
    /* [in] */ Int32 userHandle,
    /* [out] */ IComponentName** componentName)
{
    VALIDATE_NOT_NULL(componentName);
    *componentName = NULL;

    String curRecognizer;
    AutoPtr<IContentResolver> contentResolver;
    mContext->GetContentResolver((IContentResolver**)&contentResolver);
    AutoPtr<ISettingsSecure> settingsSecure;
    CSettingsSecure::AcquireSingleton((ISettingsSecure**)&settingsSecure);
    settingsSecure->GetStringForUser(contentResolver, ISettingsSecure::VOICE_RECOGNITION_SERVICE, userHandle, &curRecognizer);
    if (curRecognizer.IsNullOrEmpty()) {
        *componentName = NULL;
        return NOERROR;
    }
    if (DEBUG) {
        Slogger::I(TAG, "getCurRecognizer curRecognizer=%s user=%d", curRecognizer.string(), userHandle);
    }
    AutoPtr<IComponentNameHelper> helper;
    CComponentNameHelper::AcquireSingleton((IComponentNameHelper**)&helper);
    return helper->UnflattenFromString(curRecognizer, componentName);
}
/**
 * Called when the <code>selectionString</code> has changed.
 */
void AccessibilityInjectorFallback::OnSelectionStringChange(
    /* [in] */ const String& selectionString)
{
//    if (DEBUG) {
//        Log.d(LOG_TAG, "Selection string: " + selectionString);
//    }
    mIsLastSelectionStringNull = (selectionString.IsNull());
    if (mScheduledEventStack.IsEmpty()) {
        return;
    }

    AutoPtr<IAccessibilityEvent> event = mScheduledEventStack.GetTop();
    mScheduledEventStack.Pop();
    if ((event != NULL) && !selectionString.IsNullOrEmpty()) {
        AutoPtr<IObjectContainer> container;
        event->GetText((IObjectContainer**)&container);
        AutoPtr<ICharSequence> csSelectionString;
        CStringWrapper::New(selectionString, (ICharSequence**)&csSelectionString);
        container->Add(csSelectionString);
        event->SetFromIndex(0);
        event->SetToIndex(selectionString.GetLength());
        SendAccessibilityEvent(event);
    }
}
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;
}