微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android.os.ConditionVariable的实例源码

项目:airgram    文件AudioTrack.java   
/**
 * Creates an audio track using the specified audio capabilities and stream type.
 *
 * @param audioCapabilities The current audio playback capabilities.
 * @param streamType The type of audio stream for the underlying {@link android.media.AudioTrack}.
 */
public AudioTrack(AudioCapabilities audioCapabilities,int streamType) {
  this.audioCapabilities = audioCapabilities;
  this.streamType = streamType;
  releasingConditionVariable = new ConditionVariable(true);
  if (Util.SDK_INT >= 18) {
    try {
      getLatencyMethod =
          android.media.AudioTrack.class.getmethod("getLatency",(Class<?>[]) null);
    } catch (NoSuchMethodException e) {
      // There's no guarantee this method exists. Do nothing.
    }
  }
  if (Util.SDK_INT >= 23) {
    audioTrackUtil = new AudioTrackUtilV23();
  } else if (Util.SDK_INT >= 19) {
    audioTrackUtil = new AudioTrackUtilV19();
  } else {
    audioTrackUtil = new AudioTrackUtil();
  }
  playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
  volume = 1.0f;
  startMediaTimeState = START_NOT_SET;
}
项目:airgram    文件SimpleCache.java   
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 */
public SimpleCache(File cacheDir,Cacheevictor evictor) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.cachedSpans = new HashMap<>();
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
      }
    }
  }.start();
  conditionVariable.block();
}
项目:chromium-net-for-android    文件cronetUrlRequestContextTest.java   
@SmallTest
@Feature({"cronet"})
public void testinitTwoenginesSimultaneously() throws Exception {
    final cronetTestFramework testFramework = startcronetTestFrameworkAndSkipLibraryInit();

    // Threads will block on runBlocker to ensure simultaneous execution.
    ConditionVariable runBlocker = new ConditionVariable(false);
    RequestThread thread1 = new RequestThread(testFramework,mUrl,runBlocker);
    RequestThread thread2 = new RequestThread(testFramework,mUrl404,runBlocker);

    thread1.start();
    thread2.start();
    runBlocker.open();
    thread1.join();
    thread2.join();
    assertEquals(200,thread1.mCallback.mResponseInfo.getHttpStatusCode());
    assertEquals(404,thread2.mCallback.mResponseInfo.getHttpStatusCode());
}
项目:chromium-net-for-android    文件cronetUrlRequestContextTest.java   
@SmallTest
@Feature({"cronet"})
public void testinitTwoenginesInSequence() throws Exception {
    final cronetTestFramework testFramework = startcronetTestFrameworkAndSkipLibraryInit();

    ConditionVariable runBlocker = new ConditionVariable(true);
    RequestThread thread1 = new RequestThread(testFramework,runBlocker);

    thread1.start();
    thread1.join();
    thread2.start();
    thread2.join();
    assertEquals(200,thread2.mCallback.mResponseInfo.getHttpStatusCode());
}
项目:chromium-net-for-android    文件cronetUrlRequestContextTest.java   
@SmallTest
@Feature({"cronet"})
public void testThreadedStartup() throws Exception {
    final ConditionVariable otherThreadDone = new ConditionVariable();
    final ConditionVariable uiThreadDone = new ConditionVariable();
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        public void run() {
            final cronetEngine.Builder builder =
                    new cronetEngine.Builder(getContext()).setLibraryName("cronet_tests");
            new Thread() {
                public void run() {
                    cronetEngine cronetEngine = builder.build();
                    otherThreadDone.open();
                    cronetEngine.shutdown();
                }
            }.start();
            otherThreadDone.block();
            builder.build().shutdown();
            uiThreadDone.open();
        }
    });
    assertTrue(uiThreadDone.block(1000));
}
项目:PlusGram    文件AudioTrack.java   
/**
 * Creates an audio track using the specified audio capabilities and stream type.
 *
 * @param audioCapabilities The current audio playback capabilities.
 * @param streamType The type of audio stream for the underlying {@link android.media.AudioTrack}.
 */
public AudioTrack(AudioCapabilities audioCapabilities,(Class<?>[]) null);
    } catch (NoSuchMethodException e) {
      // There's no guarantee this method exists. Do nothing.
    }
  }
  if (Util.SDK_INT >= 23) {
    audioTrackUtil = new AudioTrackUtilV23();
  } else if (Util.SDK_INT >= 19) {
    audioTrackUtil = new AudioTrackUtilV19();
  } else {
    audioTrackUtil = new AudioTrackUtil();
  }
  playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
  volume = 1.0f;
  startMediaTimeState = START_NOT_SET;
}
项目:PlusGram    文件SimpleCache.java   
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 */
public SimpleCache(File cacheDir,Cacheevictor evictor) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.cachedSpans = new HashMap<>();
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
      }
    }
  }.start();
  conditionVariable.block();
}
项目:Exoplayer2Radio    文件SimpleCache.java   
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 * @param evictor The evictor to be used.
 * @param secretKey If not null,cache keys will be stored encrypted on filesystem using AES/CBC.
 *     The key must be 16 bytes long.
 */
public SimpleCache(File cacheDir,Cacheevictor evictor,byte[] secretKey) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.index = new CachedContentIndex(cacheDir,secretKey);
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        try {
          initialize();
        } catch (CacheException e) {
          initializationException = e;
        }
        SimpleCache.this.evictor.onCacheInitialized();
      }
    }
  }.start();
  conditionVariable.block();
}
项目:android_packages_apps_tv    文件ScanFragment.java   
public ChannelScanTask(int channelMapId) {
    mActivity = getActivity();
    mChannelMapId = channelMapId;
    if (FAKE_MODE) {
        mScanTsstreamer = new FakeTsstreamer(this);
    } else {
        TunerHal hal = TunerHal.createInstance(mActivity.getApplicationContext());
        if (hal == null) {
            throw new RuntimeException("Failed to open a DVB device");
        }
        mScanTsstreamer = new TunerTsstreamer(hal,this);
    }
    mFileTsstreamer = SCAN_LOCAL_STREAMS ? new FileTsstreamer(this) : null;
    mConditionStopped = new ConditionVariable();
    mChannelDataManager.setChannelScanListener(this,new Handler());
}
项目:android_packages_apps_tv    文件SimpleSampleBuffer.java   
@Override
public void writeSample(int index,SampleHolder sample,ConditionVariable conditionVariable) throws IOException {
    sample.data.position(0).limit(sample.size);
    SampleHolder sampletoQueue = mSamplePool.acquireSample(sample.size);
    sampletoQueue.size = sample.size;
    sampletoQueue.clearData();
    sampletoQueue.data.put(sample.data);
    sampletoQueue.timeUs = sample.timeUs;
    sampletoQueue.flags = sample.flags;

    synchronized (this) {
        if (mPlayingSampleQueues[index] != null) {
            mPlayingSampleQueues[index].queueSample(sampletoQueue);
        }
    }
}
项目:PlatePicks-Android    文件S3WholeBucketIterator.java   
/**
 * Constructs this iterator.
 * @param s3Client the S3 client.
 * @param bucketName the S3 bucket name.
 * @param s3ContentPrefix the portion of the s3 object prefix that should be omitted from the relative path
 *                        of the S3ContentSummary objects this iterator returns.
 * @param prefix the s3 object prefix; may be null.
 * @param delimiter the s3 object delimiter; may be null.
 * @param includeDirectories whether to include directories (common prefixes)
 * @param errorHandler an error handler.
 */
public S3WholeBucketIterator(final AmazonS3 s3Client,final String bucketName,final String s3ContentPrefix,final String prefix,final String delimiter,final boolean includeDirectories,final S3ListErrorHandler errorHandler) {
    this.s3Client = s3Client;
    this.bucketName = bucketName;
    this.errorHandler = errorHandler;
    this.s3ContentPrefix = s3ContentPrefix;
    this.prefix = prefix;
    this.delimiter = delimiter;
    this.includeDirectories = includeDirectories;
    summaries = new ConcurrentLinkedQueue<>();
    summaryCount = new AtomicInteger();
    summaryCount.set(0);
    waitingForObjects = new ConditionVariable();
    waitingForReader = new ConditionVariable(true);
    areListingObjects = true;

    // Start the background thread to begin listing objects.
    listingThread = new Thread(this);
    listingThread.start();
}
项目:miku    文件AudioTrack.java   
public AudioTrack() {
  releasingConditionVariable = new ConditionVariable(true);
  if (Util.SDK_INT >= 18) {
    try {
      getLatencyMethod =
          android.media.AudioTrack.class.getmethod("getLatency",(Class<?>[]) null);
    } catch (NoSuchMethodException e) {
      // There's no guarantee this method exists. Do nothing.
    }
  }
  if (Util.SDK_INT >= 19) {
    audioTrackUtil = new AudioTrackUtilV19();
  } else {
    audioTrackUtil = new AudioTrackUtil();
  }
  playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
  volume = 1.0f;
  startMediaTimeState = START_NOT_SET;
}
项目:miku    文件SimpleCache.java   
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 */
public SimpleCache(File cacheDir,Cacheevictor evictor) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.cachedSpans = new HashMap<>();
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread() {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
      }
    }
  }.start();
  conditionVariable.block();
}
项目:K-Sonic    文件SimpleCache.java   
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 * @param evictor The evictor to be used.
 * @param secretKey If not null,secretKey);
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        try {
          initialize();
        } catch (CacheException e) {
          initializationException = e;
        }
        SimpleCache.this.evictor.onCacheInitialized();
      }
    }
  }.start();
  conditionVariable.block();
}
项目:ExoPlayer-Demo    文件AudioTrack.java   
/**
 * Creates an audio track using the specified audio capabilities and stream type.
 *
 * @param audioCapabilities The current audio playback capabilities.
 * @param streamType The type of audio stream for the underlying {@link android.media.AudioTrack}.
 */
public AudioTrack(AudioCapabilities audioCapabilities,(Class<?>[]) null);
    } catch (NoSuchMethodException e) {
      // There's no guarantee this method exists. Do nothing.
    }
  }
  if (Util.SDK_INT >= 23) {
    audioTrackUtil = new AudioTrackUtilV23();
  } else if (Util.SDK_INT >= 19) {
    audioTrackUtil = new AudioTrackUtilV19();
  } else {
    audioTrackUtil = new AudioTrackUtil();
  }
  playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
  volume = 1.0f;
  startMediaTimeState = START_NOT_SET;
}
项目:ExoPlayer-Demo    文件SimpleCache.java   
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 */
public SimpleCache(File cacheDir,Cacheevictor evictor) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.cachedSpans = new HashMap<>();
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
      }
    }
  }.start();
  conditionVariable.block();
}
项目:unity-ads-android    文件InitializeThread.java   
@Override
public InitializeState execute() {
    DeviceLog.error("Unity Ads init: network error,waiting for connection events");

    _conditionVariable = new ConditionVariable();
    ConnectivityMonitor.addListener(this);

    if (_conditionVariable.block(10000L * 60L)) {
        ConnectivityMonitor.removeListener(this);
        return _erroredState;
    }
    else {
        ConnectivityMonitor.removeListener(this);
        return new InitializeStateError("network error",new Exception("No connected events within the timeout!"));
    }
}
项目:unity-ads-android    文件ClientPropertiesTest.java   
@Test
public void testSetActivity () throws InterruptedException {
    final ConditionVariable cv = new ConditionVariable();

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            MockActivity act = new MockActivity();
            ClientProperties.setActivity(act);
            cv.open();
        }
    });

    boolean success = cv.block(10000);
    assertTrue("ConditionVariable was not opened!",success);
    assertNotNull("Activity should not be null after setting it",ClientProperties.getActivity());
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testSetConfiguration () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppLoaded(true);
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean success = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",success);

    final Configuration conf = new Configuration(TestUtilities.getTestServerAddress());
    WebViewApp.getCurrentApp().setConfiguration(conf);

    assertNotNull("Current WebApp configuration should not be null",WebViewApp.getCurrentApp().getConfiguration());
    assertEquals("Local configuration and current WebApp configuration should be the same object",conf,WebViewApp.getCurrentApp().getConfiguration());
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testSetWebAppLoaded () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean success = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",success);
    assertFalse("WebApp should not be loaded. It was just created",WebViewApp.getCurrentApp().isWebAppLoaded());
    WebViewApp.getCurrentApp().setWebAppLoaded(true);
    assertTrue("WebApp should Now be \"loaded\". We set the status to true",WebViewApp.getCurrentApp().isWebAppLoaded());
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testSendEventShouldFail () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",cvsuccess);
    boolean success = WebViewApp.getCurrentApp().sendEvent(MockEventCategory.TEST_CATEGORY_1,MockEvent.TEST_EVENT_1);
    assertFalse("sendEvent -method should've returned false",success);
    assertFalse("WebView invokeJavascript should've not been invoked but was (webviewapp is not loaded so no call should have occured)",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_INVOKED);
    assertNull("The invoked JavaScript string should be null (webviewapp is not loaded so no call should have occured)",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testSendEventShouldSucceed () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();

    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppLoaded(true);
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",MockEvent.TEST_EVENT_1);
    assertTrue("sendEvent should have succeeded",success);
    assertTrue("WebView invokeJavascript should've been invoked but was not",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_INVOKED);
    assertNotNull("The invoked JavaScript string should not be null",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testSendEventWithParamsShouldSucceed () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppLoaded(true);
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",MockEvent.TEST_EVENT_1,"Test",12345,true);
    assertTrue("sendEvent should have succeeded",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testInvokeMethodShouldFailWebAppNotLoaded () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppLoaded(false);
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",cvsuccess);
    Method m = getClass().getmethod("testNativeCallbackMethod");
    boolean success = WebViewApp.getCurrentApp().invokeMethod("TestClass","testMethod",m);
    assertFalse("invokeMethod -method should've returned false",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testInvokeMethodShouldSucceedMethodNull () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppLoaded(true);
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",cvsuccess);
    Method m = null;
    boolean success = WebViewApp.getCurrentApp().invokeMethod("TestClass",m);
    assertTrue("invokeMethod -method should've returned true",success);
    assertTrue("WebView invokeJavascript should've succeeded but didn't",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_INVOKED);
    assertNotNull("The invoked JavaScript string should not be null.",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testInvokeMethodShouldSucceed () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppLoaded(true);
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testInvokeMethodWithParamsShouldSucceed () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppLoaded(true);
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",m,true);
    assertTrue("invokeMethod -method should've returned true",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testInvokeCallbackShouldFailWebAppNotLoaded () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",cvsuccess);
    Invocation invocation = new Invocation();
    invocation.setInvocationResponse(CallbackStatus.OK,null,true);
    boolean success = WebViewApp.getCurrentApp().invokeCallback(invocation);
    assertFalse("invokeCallback -method should've returned false (webapp not loaded)",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testInvokeCallbackShouldSucceed () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppLoaded(true);
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",true);
    boolean success = WebViewApp.getCurrentApp().invokeCallback(invocation);
    assertTrue("invokeCallback -method should've returned true",((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件WebViewAppTest.java   
@Test
public void testInvokeCallbackWithErrorShouldSucceed () throws Exception {
    WebViewApp.setCurrentApp(null);
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            WebViewApp.setCurrentApp(new WebViewApp());
            WebViewApp.getCurrentApp().setWebView(new MockWebView(InstrumentationRegistry.getContext()));
            WebViewApp.getCurrentApp().setWebAppLoaded(true);
            WebViewApp.getCurrentApp().setWebAppInitialized(true);
            cv.open();
        }
    });

    boolean cvsuccess = cv.block(10000);
    assertTrue("ConditionVariable was not opened successfully",Mockerror.TEST_ERROR_1,((MockWebView) WebViewApp.getCurrentApp().getWebView()).JS_CALL);
}
项目:unity-ads-android    文件VideoViewTest.java   
@Test
@RequiresDevice
public void testConstruct () throws Exception {
    final ConditionVariable cv = new ConditionVariable();
    Handler handler = new Handler(Looper.getMainLooper());
    handler.post(new Runnable() {
        @Override
        public void run() {
            VideoPlayerView vp = new VideoPlayerView(getInstrumentation().getTargetContext());
            assertNotNull("VideoPlayerView should not be null after constructing",vp);
            cv.open();
        }
    });

    boolean success = cv.block(30000);
    assertTrue("Condition variable was not opened properly: VideoPlayer was not created",success);
}
项目:videoPickPlayer    文件AudioTrack.java   
/**
 * @param audioCapabilities The current audio capabilities.
 * @param streamType The type of audio stream for the underlying {@link android.media.AudioTrack}.
 */
public AudioTrack(AudioCapabilities audioCapabilities,(Class<?>[]) null);
    } catch (NoSuchMethodException e) {
      // There's no guarantee this method exists. Do nothing.
    }
  }
  if (Util.SDK_INT >= 23) {
    audioTrackUtil = new AudioTrackUtilV23();
  } else if (Util.SDK_INT >= 19) {
    audioTrackUtil = new AudioTrackUtilV19();
  } else {
    audioTrackUtil = new AudioTrackUtil();
  }
  playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
  volume = 1.0f;
  startMediaTimeState = START_NOT_SET;
}
项目:videoPickPlayer    文件SimpleCache.java   
/**
 * Constructs the cache. The cache will delete any unrecognized files from the directory. Hence
 * the directory cannot be used to store other files.
 *
 * @param cacheDir A dedicated cache directory.
 */
public SimpleCache(File cacheDir,Cacheevictor evictor) {
  this.cacheDir = cacheDir;
  this.evictor = evictor;
  this.lockedSpans = new HashMap<>();
  this.cachedSpans = new HashMap<>();
  this.listeners = new HashMap<>();
  // Start cache initialization.
  final ConditionVariable conditionVariable = new ConditionVariable();
  new Thread("SimpleCache.initialize()") {
    @Override
    public void run() {
      synchronized (SimpleCache.this) {
        conditionVariable.open();
        initialize();
      }
    }
  }.start();
  conditionVariable.block();
}
项目:chromium-net-for-android    文件cronetUrlRequestTest.java   
@SmallTest
@Feature({"cronet"})
@OnlyRunNativecronet // No destroyed callback for tests
public void testExecutorShutdown() {
    TestUrlRequestCallback callback = new TestUrlRequestCallback();

    callback.setAutoAdvance(false);
    UrlRequest.Builder builder = new UrlRequest.Builder(NativeTestServer.getEchoBodyURL(),callback,callback.getExecutor(),mTestFramework.mcronetEngine);
    cronetUrlRequest urlRequest = (cronetUrlRequest) builder.build();
    urlRequest.start();
    callback.waitForNextStep();
    assertFalse(callback.isDone());
    assertFalse(urlRequest.isDone());

    final ConditionVariable requestDestroyed = new ConditionVariable(false);
    urlRequest.setonDestroyedCallbackForTesting(new Runnable() {
        @Override
        public void run() {
            requestDestroyed.open();
        }
    });

    // Shutdown the executor,so posting the task will throw an exception.
    callback.shutdownExecutor();
    ByteBuffer readBuffer = ByteBuffer.allocateDirect(5);
    urlRequest.read(readBuffer);
    // Callback will never be called again because executor is shutdown,// but request will be destroyed from network thread.
    requestDestroyed.block();

    assertFalse(callback.isDone());
    assertTrue(urlRequest.isDone());
}
项目:chromium-net-for-android    文件cronetUrlRequestTest.java   
@SmallTest
@Feature({"cronet"})
@OnlyRunNativecronet // No adapter to destroy in pure java
// Regression test for crbug.com/564946.
public void testDestroyUploadDataStreamAdapterOnSucceededCallback() throws Exception {
    TestUrlRequestCallback callback = new QuitOnSuccessCallback();
    UrlRequest.Builder builder = new UrlRequest.Builder(NativeTestServer.getEchoBodyURL(),mTestFramework.mcronetEngine);

    TestUploadDataProvider dataProvider = new TestUploadDataProvider(
            TestUploadDataProvider.SuccessCallbackMode.SYNC,callback.getExecutor());
    builder.setUploadDataProvider(dataProvider,callback.getExecutor());
    builder.addHeader("Content-Type","useless/string");
    cronetUrlRequest request = (cronetUrlRequest) builder.build();
    final ConditionVariable uploadDataStreamAdapterDestroyed = new ConditionVariable();
    request.setonDestroyedUploadCallbackForTesting(new Runnable() {
        @Override
        public void run() {
            uploadDataStreamAdapterDestroyed.open();
        }
    });

    request.start();
    uploadDataStreamAdapterDestroyed.block();

    assertEquals(200,callback.mResponseInfo.getHttpStatusCode());
    assertEquals("",callback.mResponseAsstring);
}
项目:chromium-net-for-android    文件cronetUrlRequestContextTest.java   
@SmallTest
@Feature({"cronet"})
public void testinitAndShutdownOnMainThread() throws Exception {
    final cronetTestFramework testFramework = startcronetTestFrameworkAndSkipLibraryInit();
    final ConditionVariable block = new ConditionVariable(false);

    // Post a task to main thread to init and shutdown on the main thread.
    Runnable blockingTask = new Runnable() {
        @Override
        public void run() {
            // Create new request context,loading the library.
            final cronetEngine cronetEngine = testFramework.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();
}
项目:chromium-net-for-android    文件TestBidirectionalStreamCallback.java   
/**
 * Returns {@code false} if the callback should continue to advance the
 * stream.
 */
private boolean maybeThrowCancelOrPause(
        final BidirectionalStream stream,ConditionVariable stepBlock) {
    if (mResponseStep != mFailureStep || mFailureType == FailureType.NONE) {
        if (!mAutoAdvance) {
            stepBlock.open();
            return true;
        }
        return false;
    }

    if (mFailureType == FailureType.THROW_SYNC) {
        throw new IllegalStateException("Callback Exception.");
    }
    Runnable task = new Runnable() {
        public void run() {
            stream.cancel();
        }
    };
    if (mFailureType == FailureType.CANCEL_ASYNC
            || mFailureType == FailureType.CANCEL_ASYNC_WITHOUT_PAUSE) {
        getExecutor().execute(task);
    } else {
        task.run();
    }
    return mFailureType != FailureType.CANCEL_ASYNC_WITHOUT_PAUSE;
}
项目:chromium-net-for-android    文件BidirectionalStreamTest.java   
@SmallTest
@Feature({"cronet"})
@OnlyRunNativecronet
public void testExecutorShutdownBeforeStreamIsDone() {
    // Test that stream is destroyed even if executor is shut down and rejects posting tasks.
    TestBidirectionalStreamCallback callback = new TestBidirectionalStreamCallback();
    callback.setAutoAdvance(false);
    BidirectionalStream.Builder builder =
            new BidirectionalStream.Builder(Http2TestServer.getEchoMethodUrl(),mTestFramework.mcronetEngine);
    cronetBidirectionalStream stream =
            (cronetBidirectionalStream) builder.setHttpMethod("GET").build();
    stream.start();
    callback.waitForNextReadStep();
    assertFalse(callback.isDone());
    assertFalse(stream.isDone());

    final ConditionVariable streamDestroyed = new ConditionVariable(false);
    stream.setonDestroyedCallbackForTesting(new Runnable() {
        @Override
        public void run() {
            streamDestroyed.open();
        }
    });

    // Shut down the executor,so posting the task will throw an exception.
    callback.shutdownExecutor();
    ByteBuffer readBuffer = ByteBuffer.allocateDirect(5);
    stream.read(readBuffer);
    // Callback will never be called again because executor is shut down,// but stream will be destroyed from network thread.
    streamDestroyed.block();

    assertFalse(callback.isDone());
    assertTrue(stream.isDone());
}
项目:medialibrary    文件galleryUtils.java   
public static void fakeBusy(ThreadPool.JobContext jc,int timeout) {
    final ConditionVariable cv = new ConditionVariable();
    jc.setCancelListener(new ThreadPool.CancelListener() {
        @Override
        public void onCancel() {
            cv.open();
        }
    });
    cv.block(timeout);
    jc.setCancelListener(null);
}
项目:VirtualHook    文件VClientImpl.java   
public void bindApplication(final String packageName,final String processName) {
    if (Looper.getMainLooper() == Looper.myLooper()) {
        bindApplicationNoCheck(packageName,processName,new ConditionVariable());
    } else {
        final ConditionVariable lock = new ConditionVariable();
        VirtualRuntime.getUIHandler().post(new Runnable() {
            @Override
            public void run() {
                bindApplicationNoCheck(packageName,lock);
                lock.open();
            }
        });
        lock.block();
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。