Example #1
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 #2
0
String UrlUtils::AuthoritySafePath(
    /* [in] */ const String& authority,
    /* [in] */ const String& path)
{
    if (!authority.IsNull() &&
            !authority.IsEmpty() &&
            !path.IsEmpty() &&
            !path.StartWith(String("/")))
    {
        return String("/") + path;
    }
    return path;
}
ECode CSoundPool::SoundPoolImpl::Load(
    /* [in] */ const String& path,
    /* [in] */ Int32 priority,
    /* [out] */ Int32* result)
{
    VALIDATE_NOT_NULL(result);
    *result = 0;

    Slogger::I(TAG, "load [%s]", path.string());

    // pass network streams to player
    if (path.StartWith(String("http:"))) {
        *result = _Load(path, priority);
        return NOERROR;
    }
    // try local path

    // try {
    AutoPtr<IFile> f;
    CFile::New(path, (IFile**)&f);

    Boolean bval;
    f->Exists(&bval);
    if (!bval) {
        Logger::E(TAG, "error loading %s, file does not exists.");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }

    Int32 id = 0;
    AutoPtr<IParcelFileDescriptor> fd;
    CParcelFileDescriptor::Open(f, IParcelFileDescriptor::MODE_READ_ONLY, (IParcelFileDescriptor**)&fd);
    if (fd != NULL) {
        AutoPtr<IFileDescriptor> des;
        fd->GetFileDescriptor((IFileDescriptor**)&des);
        Int64 len;
        f->GetLength(&len);
        Slogger::I(TAG, "load length:%lld, priority:%d", len, priority);
        id = _Load(des, 0, len, priority);
        ICloseable::Probe(fd)->Close();
    }
    // } catch (java.io.IOException e) {
        // Log.e(TAG, "error loading " + path);
    // }
    *result = id;
    return NOERROR;
}
Example #4
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);
}
ECode IntentTile::Create(
    /* [in] */ IQSTileHost* host,
    /* [in] */ const String& spec,
    /* [out] */ IQSTile** tile)
{
    VALIDATE_NOT_NULL(tile);
    if (spec == NULL || !spec.StartWith(PREFIX) || !spec.EndWith(")")) {
        tile = NULL;
        // throw new IllegalArgumentException("Bad intent tile spec: " + spec);
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }
    const String action = spec.Substring(PREFIX.GetLength(), spec.GetLength() - 1);
    if (action.IsEmpty()) {
        tile = NULL;
        // throw new IllegalArgumentException("Empty intent tile spec action");
        return E_ILLEGAL_ARGUMENT_EXCEPTION;
    }
    *tile = new IntentTile(host, action);
    REFCOUNT_ADD(*tile);
    return NOERROR;
}
Example #6
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);
}
ECode CNetworkStatsFactory::ReadNetworkStatsDetail(
    /* [in] */ Int32 limitUid,
    /* [in] */ ArrayOf<String>* limitIfaces,
    /* [in] */ Int32 limitTag,
    /* [in] */ INetworkStats* lastStats,
    /* [out] */ INetworkStats** stats)
{
    VALIDATE_NOT_NULL(stats);
    FAIL_RETURN(ReadNetworkStatsDetailInternal(limitUid, limitIfaces, limitTag, lastStats, stats))

    {
        AutoLock lock(sStackedIfaces);
        // Sigh, xt_qtaguid ends up double-counting tx traffic going through
        // clatd interfaces, so we need to subtract it here.
        Int32 size;
        sStackedIfaces->GetSize(&size);
        for (Int32 i = 0; i < size; i++) {
            AutoPtr<IInterface> key, value;
            sStackedIfaces->GetKeyAt(i, (IInterface**)&key);
            sStackedIfaces->GetValueAt(i, (IInterface**)&value);
            String stackedIface, baseIface;
            IObject::Probe(key)->ToString(&stackedIface);
            IObject::Probe(value)->ToString(&baseIface);

            // Count up the tx traffic and subtract from root UID on the
            // base interface.
            AutoPtr<INetworkStatsEntry> adjust;
            CNetworkStatsEntry::New(baseIface, 0, 0, 0, 0L, 0L, 0L,
                    0L, 0L, (INetworkStatsEntry**)&adjust);
            AutoPtr<INetworkStatsEntry> entry;
            Int32 statsSize;
            (*stats)->GetSize(&statsSize);
            for (Int32 j = 0; j < statsSize; j++) {
                AutoPtr<INetworkStatsEntry> outEntry;
                (*stats)->GetValues(j, entry, (INetworkStatsEntry**)&outEntry);
                entry = outEntry;
                String iface;
                entry->GetIface(&iface);
                if (stackedIface.Equals(iface)) {
                    Int64 txBytes1, txBytes2;
                    adjust->GetTxBytes(&txBytes1);
                    entry->GetTxBytes(&txBytes2);
                    adjust->SetTxBytes(txBytes1 - txBytes2);
                    Int64 txPackets1, txPackets2;
                    adjust->GetTxPackets(&txPackets1);
                    entry->GetTxPackets(&txPackets2);
                    adjust->SetTxPackets(txPackets1 - txPackets2);
                }
            }
            FAIL_RETURN((*stats)->CombineValues(adjust))
        }
    }

    // Double sigh, all rx traffic on clat needs to be tweaked to
    // account for the dropped IPv6 header size post-unwrap.
    AutoPtr<INetworkStatsEntry> entry;
    Int32 size;
    (*stats)->GetSize(&size);
    for (Int32 i = 0; i < size; i++) {
        AutoPtr<INetworkStatsEntry> outEntry;
        (*stats)->GetValues(i, entry, (INetworkStatsEntry**)&outEntry);
        entry = outEntry;
        String iface;
        entry->GetIface(&iface);
        if (iface != NULL && iface.StartWith("clat")) {
            // Delta between IPv4 header (20b) and IPv6 header (40b)
            Int64 rxPackets;
            entry->GetRxPackets(&rxPackets);
            entry->SetRxBytes(rxPackets * 20);
            entry->SetRxPackets(0);
            entry->SetTxBytes(0);
            entry->SetTxPackets(0);
            FAIL_RETURN((*stats)->CombineValues(entry))
        }
    }
Example #8
0
Boolean StartsWithFilter::MatchesValue(
    /* in */ const String& value)
{
    return value != NULL && value.StartWith(mFilterValue);
}