public void run() { for (int i = 0; i < 4; ++i) { showNotification( R.drawable.stat_happy, R.string.status_bar_notifications_happy_message); if (mCondition.block(5 * 1000)) break; showNotification(R.drawable.stat_neutral, R.string.status_bar_notifications_ok_message); if (mCondition.block(5 * 1000)) break; showNotification(R.drawable.stat_sad, R.string.status_bar_notifications_sad_message); if (mCondition.block(5 * 1000)) break; } // Done with our work... stop the service! NotifyingService.this.stopSelf(); }
@SmallTest @Feature({"Cronet"}) public void testInitAndShutdownOnMainThread() throws Exception { final CronetTestActivity activity = launchCronetTestAppAndSkipFactoryInit(); final ConditionVariable block = new ConditionVariable(false); // Post a task to main thread to init and shutdown on the main thread. Runnable blockingTask = new Runnable() { public void run() { // Create new request context, loading the library. final CronetEngine cronetEngine = activity.initCronetEngine(); // Shutdown right after init. cronetEngine.shutdown(); // Verify that context is shutdown. try { cronetEngine.stopNetLog(); fail("Should throw an exception."); } catch (Exception e) { assertEquals("Engine is shut down.", e.getMessage()); } block.open(); } }; new Handler(Looper.getMainLooper()).post(blockingTask); // Wait for shutdown to complete on main thread. block.block(); }
public String getResult() { eventHandled.block(30000); if (result.message == null) { throw new RuntimeException("Timed out waiting for result for JavaScript"); } return result.message; }
@Override public void process(FilterContext context) { if (mLogVerbose) Log.v(TAG, "Processing new frame"); // First, get new frame if available if (mWaitForNewFrame || mFirstFrame) { boolean gotNewFrame; if (mWaitTimeout != 0) { gotNewFrame = mNewFrameAvailable.block(mWaitTimeout); if (!gotNewFrame) { if (!mCloseOnTimeout) { throw new RuntimeException("Timeout waiting for new frame"); } else { if (mLogVerbose) Log.v(TAG, "Timeout waiting for a new frame. Closing."); closeOutputPort("video"); return; } } } else { mNewFrameAvailable.block(); } mNewFrameAvailable.close(); mFirstFrame = false; } mSurfaceTexture.updateTexImage(); mSurfaceTexture.getTransformMatrix(mFrameTransform); Matrix.multiplyMM( mMappedCoords, 0, mFrameTransform, 0, mSourceCoords, 0); mFrameExtractor.setSourceRegion( mMappedCoords[0], mMappedCoords[1], mMappedCoords[4], mMappedCoords[5], mMappedCoords[8], mMappedCoords[9], mMappedCoords[12], mMappedCoords[13]); // Next, render to output Frame output = context.getFrameManager().newFrame(mOutputFormat); mFrameExtractor.process(mMediaFrame, output); output.setTimestamp(mSurfaceTexture.getTimestamp()); pushOutput("video", output); output.release(); }
public synchronized RawTexture get() { if (mCancelled) return null; else if (mResultReady.block(TIMEOUT)) return mTexture; else { mCancelled = true; return null; } }
/** Waits until the camera preview is up running */ public boolean waitForPreviewDone(long timeOutMs) { if (!mPreviewDone.block(timeOutMs)) { // timeout could be expected or unexpected. The caller will decide. Log.w(TAG, "waitForPreviewDone timed out after " + timeOutMs + "ms"); return false; } mPreviewDone.close(); return true; }
@Override public void run() { mRunBlocker.block(); CronetEngine cronetEngine = mActivity.initCronetEngine(); mListener = new TestUrlRequestListener(); UrlRequest.Builder urlRequestBuilder = new UrlRequest.Builder(mUrl, mListener, mListener.getExecutor(), cronetEngine); urlRequestBuilder.build().start(); mListener.blockForDone(); }
// For debugging, it will block the caller for timeout millis. public static void fakeBusy(JobContext jc, int timeout) { final ConditionVariable cv = new ConditionVariable(); jc.setCancelListener( new CancelListener() { public void onCancel() { cv.open(); } }); cv.block(timeout); jc.setCancelListener(null); }
public void run() { while (run_flg) { long when = System.currentTimeMillis(); Notification notification = new Notification(icon, tickerText, when); CharSequence contentTitle = "My notification"; CharSequence contentText = "Hello World! " + i; PendingIntent contentIntent = PendingIntent.getActivity(PushSearvice.this, 0, notificationIntent, 0); notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); mNotificationManager.notify(1, notification); mCondition.block(WAIT_TIME); i++; } }
@SmallTest @Feature({"Cronet"}) public void testNoErrorWhenExceptionDuringStart() throws Exception { TestUrlRequestCallback callback = new TestUrlRequestCallback(); UrlRequest.Builder builder = new UrlRequest.Builder( NativeTestServer.getEchoBodyURL(), callback, callback.getExecutor(), mTestFramework.mCronetEngine); final ConditionVariable first = new ConditionVariable(); final String exceptionMessage = "Bad Length"; builder.addHeader("Content-Type", "useless/string"); builder.setUploadDataProvider( new UploadDataProvider() { @Override public long getLength() throws IOException { first.open(); throw new IOException(exceptionMessage); } @Override public void read(UploadDataSink uploadDataSink, ByteBuffer byteBuffer) throws IOException {} @Override public void rewind(UploadDataSink uploadDataSink) throws IOException {} }, callback.getExecutor()); UrlRequest urlRequest = builder.build(); urlRequest.start(); first.block(); callback.blockForDone(); assertFalse(callback.mOnCanceledCalled); assertEquals(UrlRequestError.LISTENER_EXCEPTION_THROWN, callback.mError.getErrorCode()); assertEquals("Exception received from UploadDataProvider", callback.mError.getMessage()); assertEquals(exceptionMessage, callback.mError.getCause().getMessage()); }
@SmallTest @Feature({"Cronet"}) public void testNoErrorWhenCanceledDuringStart() throws Exception { TestUrlRequestCallback callback = new TestUrlRequestCallback(); UrlRequest.Builder builder = new UrlRequest.Builder( NativeTestServer.getEchoBodyURL(), callback, callback.getExecutor(), mTestFramework.mCronetEngine); final ConditionVariable first = new ConditionVariable(); final ConditionVariable second = new ConditionVariable(); builder.addHeader("Content-Type", "useless/string"); builder.setUploadDataProvider( new UploadDataProvider() { @Override public long getLength() throws IOException { first.open(); second.block(); return 0; } @Override public void read(UploadDataSink uploadDataSink, ByteBuffer byteBuffer) throws IOException {} @Override public void rewind(UploadDataSink uploadDataSink) throws IOException {} }, callback.getExecutor()); UrlRequest urlRequest = builder.build(); urlRequest.start(); first.block(); urlRequest.cancel(); second.open(); callback.blockForDone(); assertTrue(callback.mOnCanceledCalled); }
public void waitUntilOnStatusCalled() { mBlock.block(); mBlock.close(); }
// Method for AsyncTask to block until an Activity is attached protected void blockForActivity() { mActivityCond.block(); }
public void waitUntilPreviewReady() { mPreviewFrameReadyForProcessing.block(); }