ECode CActivityOne::OnCreate( /* [in] */ IBundle* savedInstanceState) { SetContentView(0x7f030000); AutoPtr<IView> view = FindViewById(0x7f050000); AutoPtr<INumberPicker> numberPicker = INumberPicker::Probe(view); assert(numberPicker != NULL); ArrayOf<String>* rangs = ArrayOf<String>::Alloc(10); (*rangs)[0] = String("0"); (*rangs)[1] = String("1"); (*rangs)[2] = String("2"); (*rangs)[3] = String("3"); (*rangs)[4] = String("4"); (*rangs)[5] = String("5"); (*rangs)[6] = String("6"); (*rangs)[7] = String("7"); (*rangs)[8] = String("8"); (*rangs)[9] = String("9"); Int32 len = rangs->GetLength(); numberPicker->SetRangeEx(0, 9, *rangs); return NOERROR; }
Handle64 StringBlock::NativeCreate( /* [in] */ const ArrayOf<Byte>& data, /* [in] */ Int32 offset, /* [in] */ Int32 size) { Int32 len = data.GetLength(); if (offset < 0 || offset >= len || size < 0 || size > len || (offset + size) > len) { assert(0); // jniThrowException(env, "java/lang/IndexOutOfBoundsException", NULL); return 0; } android::ResStringPool* osb = new android::ResStringPool( data.GetPayload() + offset, size, TRUE); if (osb == NULL || osb->getError() != android::NO_ERROR) { assert(0); // jniThrowException(env, "java/lang/IllegalArgumentException", NULL); return 0; } return (Handle64)osb; }
ECode CGeckoSmsManager::OnRecieve( IContext *pContext, IIntent *pIntent) { // TODO: Try to find the receiver number to be able to populate // SmsMessage.receiver. // TODO: Get the id and the date from the stock app saved message. // Using the stock app saved message require us to wait for it to // be saved which can lead to race conditions. String action; pIntent->GetAction(&action); if (action.Equals(GeckoSmsManager_ACTION_SMS_RECEIVED)) { AutoPtr<IBundle> bundle; pIntent->GetExtras((IBundle**)&bundle); if (bundle == NULL) { return NOERROR; } ArrayOf<ArrayOf<Byte>*>* pdus; bundle->Get(String("pdus"), (IInterface**)&pdus); for (Int32 i = 0; i < pdus->GetLength(); ++i) { AutoPtr<ISmsMessage> msg; CSmsMessage::CreateFromPdu((*pdus[i], (ISmsMessage**)&msg); String smsAddress; msg->GetDisplayOriginatingAddress(&smsAddress); String messageBody; msg->GetDisplayMessageBody(&messageBody); // AutoPtr<ISystem> system; // Elastos::Core::CSystem::AcquireSingleton((ISystem**)&system); // Int64 now; // system->GetCurrentTimeMillis(&now); GeckoAppShell::NotifySmsReceived(smsAddress, messageBody, GetDisplayMessageBody); } return NOERROR; }
ECode Int64Buffer::Put( /* [in] */ const ArrayOf<Int64>& src, /* [in] */ Int32 srcOffset, /* [in] */ Int32 int64Count) { Int32 arrayLength = src.GetLength(); if ((srcOffset | int64Count) < 0 || srcOffset > arrayLength || arrayLength - srcOffset < int64Count) { // throw new ArrayIndexOutOfBoundsException(arrayLength, offset, // count); return E_ARRAY_INDEX_OUT_OF_BOUNDS_EXCEPTION; } Int32 remaining = 0; GetRemaining(&remaining); if (int64Count > remaining) { // throw new BufferOverflowException(); return E_BUFFER_OVER_FLOW_EXCEPTION; } for (Int32 i = srcOffset; i < srcOffset + int64Count; ++i) { Put(src[i]); } return NOERROR; }
Int64 XmlBlock::NativeCreate( /* [in] */ const ArrayOf<Byte>& data, /* [in] */ Int32 offset, /* [in] */ Int32 size) { Int32 bLen = data.GetLength(); if (offset < 0 || offset >= bLen || size < 0 || size > bLen || (offset + size) > bLen) { // doThrow(env, "java/lang/IndexOutOfBoundsException"); assert(0); return 0; } android::ResXMLTree* osb = new android::ResXMLTree(); if (osb) { osb->setTo(data.GetPayload() + offset, size, TRUE); } if (osb == NULL || osb->getError() != android::NO_ERROR) { // doThrow(env, "java/lang/IllegalArgumentException"); assert(0); return 0; } return (Int64)osb; }
ECode Int64Buffer::Put( /* [in] */ const ArrayOf<Int64>& src) { return Put(src, 0, src.GetLength()); }
void UsbHostManager::UsbDeviceAdded( /* [in] */ const String& deviceName, /* [in] */ Int32 vendorID, /* [in] */ Int32 productID, /* [in] */ Int32 deviceClass, /* [in] */ Int32 deviceSubclass, /* [in] */ Int32 deviceProtocol, /* [in] */ const ArrayOf<Int32>& interfaceValues, /* [in] */ const ArrayOf<Int32>& endpointValues) { if (IsBlackListed(deviceName) || IsBlackListed(deviceClass, deviceSubclass, deviceProtocol)) { return; } AutoLock lock(mLock); HashMap< String, AutoPtr<IUsbDevice> >::Iterator it = mDevices.Find(deviceName); if (it != mDevices.End() && it->mSecond != NULL) { Slogger::W(UsbHostManager::TAG, "device already on mDevices list: %s", (const char*)deviceName); return; } Int32 numInterfaces = interfaceValues.GetLength() / 5; AutoPtr< ArrayOf<IParcelable*> > interfaces = ArrayOf<IParcelable*>::Alloc(numInterfaces); // try { // repackage interfaceValues as an array of UsbInterface Int32 intf, endp, ival = 0, eval = 0; for (intf = 0; intf < numInterfaces; intf++) { Int32 interfaceId = interfaceValues[ival++]; Int32 interfaceClass = interfaceValues[ival++]; Int32 interfaceSubclass = interfaceValues[ival++]; Int32 interfaceProtocol = interfaceValues[ival++]; Int32 numEndpoints = interfaceValues[ival++]; AutoPtr<ArrayOf<IParcelable*> > endpoints = ArrayOf<IParcelable*>::Alloc(numEndpoints); for (endp = 0; endp < numEndpoints; endp++) { Int32 address = endpointValues[eval++]; Int32 attributes = endpointValues[eval++]; Int32 maxPacketSize = endpointValues[eval++]; Int32 interval = endpointValues[eval++]; AutoPtr<IUsbEndpoint> tempEndpoint; ECode ec = CUsbEndpoint::New(address, attributes, maxPacketSize, interval, (IUsbEndpoint**)&tempEndpoint); if (FAILED(ec)) { Slogger::E(UsbHostManager::TAG, "error parsing USB descriptors 0x%08x", ec); return; } AutoPtr<IParcelable> tmpParcelable = IParcelable::Probe(tempEndpoint); endpoints->Set(endp, tmpParcelable); } // don't allow if any interfaces are blacklisted if (IsBlackListed(interfaceClass, interfaceSubclass, interfaceProtocol)) { return; } AutoPtr<IUsbInterface> tempInterface; ECode ec = CUsbInterface::New(interfaceId, interfaceClass, interfaceSubclass, interfaceProtocol, *endpoints, (IUsbInterface**)&tempInterface); if (FAILED(ec)) { Slogger::E(UsbHostManager::TAG, "error parsing USB descriptors 0x%08x", ec); return; } AutoPtr<IParcelable> tmpParcelable = IParcelable::Probe(tempInterface); interfaces->Set(intf, tmpParcelable); } // } catch (Exception e) { // // beware of index out of bound exceptions, which might happen if // // a device does not set bNumEndpoints correctly // Slog.e(TAG, "error parsing USB descriptors", e); // return; // } AutoPtr<IUsbDevice> targetDevice; CUsbDevice::New(deviceName, vendorID, productID, deviceClass, deviceSubclass, deviceProtocol, interfaces, (IUsbDevice**)&targetDevice); mDevices[deviceName] = targetDevice; GetCurrentSettings()->DeviceAttached(targetDevice); }
/** * Resolves an android.resource URI to a {@link Resources} and a resource id. * * @hide */ ECode ContentResolver::GetResourceId( /* [in] */ IUri* uri, /* [out] */ IOpenResourceIdResult** result) { VALIDATE_NOT_NULL(result); String authority; FAIL_RETURN(uri->GetAuthority(&authority)); AutoPtr<IResources> r; AutoPtr<ICharSequence> authority2; FAIL_RETURN(CStringWrapper::New(authority, (ICharSequence**)&authority2)); if (TextUtils::IsEmpty(authority2)) { // throw new FileNotFoundException("No authority: " + uri); return E_FILE_NOT_FOUND_EXCEPTION; } else { // try { // TODO: ALEX need getResourcesForApplication // r = mContext.getPackageManager().getResourcesForApplication(authority); return E_NOT_IMPLEMENTED; // } catch (NameNotFoundException ex) { // throw new FileNotFoundException("No package found for authority: " + uri); // } } ArrayOf<String>* path; FAIL_RETURN(uri->GetPathSegments(&path)); if (path == NULL) { // throw new FileNotFoundException("No path: " + uri); return E_FILE_NOT_FOUND_EXCEPTION; } Int32 len = path->GetLength(); Int32 id; if (len == 1) { // try { id = (*path)[0].ToInt32(10); // } catch (NumberFormatException e) { // throw new FileNotFoundException("Single path segment is not a resource ID: " + uri); // } } else if (len == 2) { FAIL_RETURN(r->GetIdentifier((*path)[1], (*path)[0], authority, &id)); } else { // throw new FileNotFoundException("More than two path segments: " + uri); return E_FILE_NOT_FOUND_EXCEPTION; } if (id == 0) { // throw new FileNotFoundException("No resource found for: " + uri); return E_FILE_NOT_FOUND_EXCEPTION; } AutoPtr<IOpenResourceIdResult> res; FAIL_RETURN(COpenResourceIdResult::New((IOpenResourceIdResult**)&res)); res->SetResources(r); res->SetResourceId(id); *result = res; res->AddRef(); return NOERROR; }
void testStringBuffer() { printf("==== Enter testStringBuffer ====\n"); printf("\n === Construct === \n"); StringBuffer sbc(String("Construct from String")); String str = sbc.ToString(); printf(" > Construct:\n%s\n", (const char*)str); printf("\n === Append === \n"); Char32 a = 'A'; StringBuffer sb; ECode ec = sb.ToString(&str); printf(">> Get string from emtpy StringBuffer %s, %08x - %08x\n", str.string(), NOERROR, ec); sb.AppendCStr(">>Start\n"); sb.AppendNULL(); sb.AppendChar('_'); sb.AppendChar(a); sb.AppendChar('_'); sb.AppendBoolean(TRUE); sb.AppendChar('_'); sb.AppendBoolean(FALSE); sb.AppendChar('_'); sb.AppendInt32(32); sb.AppendChar('_'); sb.AppendInt32(-32); sb.AppendChar('_'); sb.AppendInt64(64); sb.AppendChar('_'); sb.AppendInt64(-64); sb.AppendChar('_'); sb.AppendFloat(10.0f); sb.AppendChar('_'); sb.AppendDouble(101010.1010); sb.AppendChar('_'); sb.AppendString(String("String")); sb.AppendCStr("\n<<End"); str = sb.ToString(); printf(" > AppendTest:\n%s\n", (const char*)str); printf("\n === Index ===\n"); Int32 index = 0; String subStr("32"); sb.IndexOf(subStr, &index); printf(" > IndexOf %s is %d\n", (const char*)subStr, index); subStr = String("_NOT_"); sb.IndexOf(subStr, &index); printf(" > IndexOf %s is %d\n", (const char*)subStr, index); subStr = String("32"); sb.LastIndexOf(subStr, &index); printf(" > LastIndexOf %s is %d\n", (const char*)subStr, index); subStr = String("_NOT_"); sb.LastIndexOf(subStr, &index); printf(" > LastIndexOf %s is %d\n", (const char*)subStr, index); printf("\n === Substring ===\n"); Int32 start = 30, end = 32; sb.Substring(start, &subStr); printf(" > Substring from %d is : %s\n", start, (const char*)subStr); sb.SubstringEx(start, end, &subStr); printf(" > Substring from %d to %d is : %s\n", start, end, (const char*)subStr); printf("\n === Get ===\n"); Char32 ch = 0; sb.GetChar(start, &ch); printf(" > GetChar at %d is : %c\n", start, ch); sb.GetLength(&end); printf(" > GetLength is : %d\n", end); sb.GetByteCount(&end); printf(" > GetByteCount is : %d\n", end); sb.GetCapacity(&end); printf(" > GetCapacity is : %d\n", end); printf("\n === Set/Replace/Insert ===\n"); sb.SetChar(13, 'B'); sb.ToString(&str); printf(" > SetCharAt:\n%s\n", (const char*)str); sb.Replace(15, 15 + 4, String("Replace")); sb.ToString(&str); printf(" > Replace:\n%s\n", (const char*)str); sb.InsertString(15, String("Insert_")); sb.ToString(&str); printf(" > InsertString:\n%s\n", (const char*)str); sb.InsertString(0, String("HeadInsert_")); sb.ToString(&str); printf(" > InsertString in head:\n%s\n", (const char*)str); sb.InsertChar(19, '_'); sb.ToString(&str); printf(" > InsertChar:\n%s\n", (const char*)str); sb.InsertBoolean(19, TRUE); sb.ToString(&str); printf(" > InsertBoolean:\n%s\n", (const char*)str); sb.InsertInt32(19, 32); sb.ToString(&str); printf(" > InsertInt32:\n%s\n", (const char*)str); sb.InsertInt64(19, 64); sb.ToString(&str); printf(" > InsertInt64:\n%s\n", (const char*)str); sb.InsertFloat(19, 128.0); sb.ToString(&str); printf(" > InsertFloat:\n%s\n", (const char*)str); sb.InsertDouble(19, 10000.00001); sb.ToString(&str); printf(" > InsertDouble:\n%s\n", (const char*)str); ArrayOf<Char32>* chars = ArrayOf<Char32>::Alloc(10); for (Int32 i = 0; i < chars->GetLength(); ++i) { (*chars)[i] = 'A' + i; } sb.InsertChars(19, *chars); sb.ToString(&str); printf(" > InsertChars:\n%s\n", (const char*)str); sb.InsertCharsEx(19, *chars, 5, 5); sb.ToString(&str); printf(" > InsertCharsEx:\n%s\n", (const char*)str); printf("\n === Delete ===\n"); sb.Delete(19, 24); sb.ToString(&str); printf(" > Delete:\n%s\n", (const char*)str); sb.DeleteChar(1); sb.ToString(&str); printf(" > DeleteChar:\n%s\n", (const char*)str); printf("\n === Reverse ===\n"); sb.Reverse(); sb.ToString(&str); printf(" > Reverse:\n%s\n", (const char*)str); printf("==== Leave testStringBuffer ====\n"); }
ECode CSyncManager::ScheduleSync( /* [in] */IAccount* requestedAccount, /* [in] */String* requestedAuthority, /* [in] */IBundle* extras, /* [in] */Int64 delay, /* [in] */Boolean onlyThoseWithUnkownSyncableState) { Boolean isLoggable = Logger::IsLoggable(CSyncManager::TAG, Logger::VERBOSE); Boolean allowBackgroundData = FALSE; GetConnectivityManager()->GetBackgroundDataSetting(&allowBackgroundData); Boolean backgroundDataUsageAllowed = !mBootCompleted || allowBackgroundData; if (extras == NULL) { CBundle::New((IBundle**)&extras); } Boolean expedited = FALSE; extras->GetBooleanEx(String(ContentResolver_SYNC_EXTRAS_EXPEDITED), FALSE, &expedited); if (expedited) { delay = -1; // this means schedule at the front of the queue } ArrayOf<IAccount*>* accounts; if (requestedAccount != NULL) { // accounts = new Account[]{requestedAccount}; accounts = ArrayOf<IAccount*>::Alloc(1); (*accounts)[0] = requestedAccount; } else { // if the accounts aren't configured yet then we can't support an account-less // sync request accounts = mAccounts; if (accounts->GetLength() == 0) { if (isLoggable) { Logger::V(CSyncManager::TAG, String("scheduleSync: no accounts configured, dropping")); } return NOERROR; } } /*final */ Boolean uploadOnly = FALSE; extras->GetBooleanEx(String(ContentResolver_SYNC_EXTRAS_UPLOAD), FALSE, &uploadOnly); /*final*/ Boolean manualSync= FALSE; extras->GetBooleanEx(String(ContentResolver_SYNC_EXTRAS_MANUAL), FALSE, &manualSync); if (manualSync) { extras->PutBoolean(String(ContentResolver_SYNC_EXTRAS_IGNORE_BACKOFF), TRUE); extras->PutBoolean(String(ContentResolver_SYNC_EXTRAS_IGNORE_SETTINGS), TRUE); } /*final*/ Boolean ignoreSettings; extras->GetBooleanEx(String(ContentResolver_SYNC_EXTRAS_IGNORE_SETTINGS), FALSE, &ignoreSettings); Int32 source = 0; if (uploadOnly) { // source = SyncStorageEngine::SOURCE_LOCAL; } else if (manualSync) { // source = SyncStorageEngine::SOURCE_USER; } else if (requestedAuthority == NULL) { // source = SyncStorageEngine::SOURCE_POLL; } else { // this isn't strictly server, since arbitrary callers can (and do) request // a non-forced two-way sync on a specific url // source = SyncStorageEngine::SOURCE_SERVER; } // Compile a list of authorities that have sync adapters. // For each authority sync each account that matches a sync adapter. // /*final*/ HashSet<String> syncableAuthorities; // = new HashSet<String>(); /* for (RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapter : mSyncAdapters->getAllServices()) { syncableAuthorities.Insert(syncAdapter.type.authority); } // if the url was specified then replace the list of authorities with just this authority // or clear it if this authority isn't syncable if (requestedAuthority != NULL) { Boolean hasSyncAdapter = syncableAuthorities.contains(requestedAuthority); syncableAuthorities.clear(); if (hasSyncAdapter) syncableAuthorities.add(requestedAuthority); } final boolean masterSyncAutomatically = mSyncStorageEngine.getMasterSyncAutomatically(); for (String authority : syncableAuthorities) { for (Account account : accounts) { int isSyncable = mSyncStorageEngine.getIsSyncable(account, authority); if (isSyncable == 0) { continue; } if (onlyThoseWithUnkownSyncableState && isSyncable >= 0) { continue; } final RegisteredServicesCache.ServiceInfo<SyncAdapterType> syncAdapterInfo = mSyncAdapters.getServiceInfo( SyncAdapterType.newKey(authority, account.type)); if (syncAdapterInfo != null) { if (!syncAdapterInfo.type.supportsUploading() && uploadOnly) { continue; } // always allow if the isSyncable state is unknown boolean syncAllowed = (isSyncable < 0) || ignoreSettings || (backgroundDataUsageAllowed && masterSyncAutomatically && mSyncStorageEngine.getSyncAutomatically(account, authority)); if (!syncAllowed) { if (isLoggable) { Log.d(TAG, "scheduleSync: sync of " + account + ", " + authority + " is not allowed, dropping request"); } continue; } if (isLoggable) { Log.v(TAG, "scheduleSync:" + " delay " + delay + ", source " + source + ", account " + account + ", authority " + authority + ", extras " + extras); } scheduleSyncOperation( new SyncOperation(account, source, authority, extras, delay)); } } }*/ return E_NOT_IMPLEMENTED; }