Java Code Examples for android.os.ConditionVariable#open()
The following examples show how to use
android.os.ConditionVariable#open() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FacebookActivityTestCase.java From FacebookImageShareIntent with MIT License | 6 votes |
protected void runOnBlockerThread(final Runnable runnable, boolean waitForCompletion) { Runnable runnableToPost = runnable; final ConditionVariable condition = waitForCompletion ? new ConditionVariable(!waitForCompletion) : null; if (waitForCompletion) { runnableToPost = new Runnable() { @Override public void run() { runnable.run(); condition.open(); } }; } TestBlocker blocker = getTestBlocker(); Handler handler = blocker.getHandler(); handler.post(runnableToPost); if (waitForCompletion) { boolean success = condition.block(10000); assertTrue(success); } }
Example 2
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 5 votes |
@Test public void testInvalidUrlGetWithNullHeaders () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_InvalidUrl_Get_No_Headers", invocation.getId()); Request.get("1", invalidUrl, null, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertEquals("Request has changed for some reason", invalidUrl, EVENT_PARAMS[1]); assertEquals("Expected three (3) params in event parameters", 3, EVENT_PARAMS.length); assertEquals("Event ID was incorrect", WebRequestEvent.FAILED, EVENT_ID); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); }
Example 3
Source File: OfflineLicenseHelper.java From Telegram with GNU General Public License v2.0 | 5 votes |
/** * Constructs an instance. Call {@link #release()} when the instance is no longer required. * * @param uuid The UUID of the drm scheme. * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager. * @param callback Performs key and provisioning requests. * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null. * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm, * MediaDrmCallback, HashMap) */ public OfflineLicenseHelper( UUID uuid, ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback, @Nullable HashMap<String, String> optionalKeyRequestParameters) { handlerThread = new HandlerThread("OfflineLicenseHelper"); handlerThread.start(); conditionVariable = new ConditionVariable(); DefaultDrmSessionEventListener eventListener = new DefaultDrmSessionEventListener() { @Override public void onDrmKeysLoaded() { conditionVariable.open(); } @Override public void onDrmSessionManagerError(Exception e) { conditionVariable.open(); } @Override public void onDrmKeysRestored() { conditionVariable.open(); } @Override public void onDrmKeysRemoved() { conditionVariable.open(); } }; drmSessionManager = new DefaultDrmSessionManager<>(uuid, mediaDrm, callback, optionalKeyRequestParameters); drmSessionManager.addListener(new Handler(handlerThread.getLooper()), eventListener); }
Example 4
Source File: SettingsTests.java From FacebookImageShareIntent with MIT License | 5 votes |
@SmallTest @MediumTest @LargeTest public void testSetExecutor() { final ConditionVariable condition = new ConditionVariable(); final Runnable runnable = new Runnable() { @Override public void run() { } }; final Executor executor = new Executor() { @Override public void execute(Runnable command) { assertEquals(runnable, command); command.run(); condition.open(); } }; Executor original = Settings.getExecutor(); try { Settings.setExecutor(executor); Settings.getExecutor().execute(runnable); boolean success = condition.block(5000); assertTrue(success); } finally { Settings.setExecutor(original); } }
Example 5
Source File: OfflineLicenseHelper.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
/** * Constructs an instance. Call {@link #release()} when the instance is no longer required. * * @param uuid The UUID of the drm scheme. * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager. * @param callback Performs key and provisioning requests. * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null. * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm, * MediaDrmCallback, HashMap) */ public OfflineLicenseHelper( UUID uuid, ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback, @Nullable HashMap<String, String> optionalKeyRequestParameters) { handlerThread = new HandlerThread("OfflineLicenseHelper"); handlerThread.start(); conditionVariable = new ConditionVariable(); DefaultDrmSessionEventListener eventListener = new DefaultDrmSessionEventListener() { @Override public void onDrmKeysLoaded() { conditionVariable.open(); } @Override public void onDrmSessionManagerError(Exception e) { conditionVariable.open(); } @Override public void onDrmKeysRestored() { conditionVariable.open(); } @Override public void onDrmKeysRemoved() { conditionVariable.open(); } }; drmSessionManager = new DefaultDrmSessionManager<>(uuid, mediaDrm, callback, optionalKeyRequestParameters); drmSessionManager.addListener(new Handler(handlerThread.getLooper()), eventListener); }
Example 6
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 5 votes |
@SdkSuppress(minSdkVersion = 16) @Ignore @Test public void testValidPostWithInvalidHeader () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; JSONArray headers = new JSONArray("[[\"C,o-n#n#e*c*t*io*n\", \"close\"]]"); WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_Valid_Post_With_Invalid_Header", invocation.getId()); Request.post("1", validUrl, null, headers, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]); assertEquals("Expected three (3) params in event parameters", 3, EVENT_PARAMS.length); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); assertEquals("Event ID was incorrect", WebRequestEvent.FAILED, EVENT_ID); }
Example 7
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 5 votes |
@SdkSuppress(minSdkVersion = 16) @Ignore @Test public void testValidGetWithInvalidHeader () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; JSONArray headers = new JSONArray("[[\"C,o-n#n#e*c*t*io*n\", \"close\"]]"); WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_Valid_Get_With_Invalid_Header", invocation.getId()); Request.get("1", validUrl, headers, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]); assertEquals("Expected three (3) params in event parameters", 3, EVENT_PARAMS.length); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); assertEquals("Event ID was incorrect", WebRequestEvent.FAILED, EVENT_ID); }
Example 8
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 5 votes |
@Test public void testInvalidUrlPostWithNullHeaders () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_InvalidUrl_Post_No_Headers", invocation.getId()); Request.post("1", invalidUrl, null, null, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertEquals("Request has changed for some reason", invalidUrl, EVENT_PARAMS[1]); assertEquals("Expected two (3) params in event parameters", 3, EVENT_PARAMS.length); assertEquals("Event ID was incorrect", WebRequestEvent.FAILED, EVENT_ID); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); }
Example 9
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 5 votes |
@Test public void testValidPostWithNullHeadersAndPostBody () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_Valid_Post_No_Headers_Post_Body", invocation.getId()); Request.post("1", validUrl, "Testing Testing", null, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]); assertEquals("Response code was not OK (200)", 200, EVENT_PARAMS[3]); assertEquals("Event ID was incorrect", WebRequestEvent.COMPLETE, EVENT_ID); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); }
Example 10
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 5 votes |
@Test public void testValidPostWithNullHeaders () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_Valid_Post_No_Headers", invocation.getId()); Request.post("1", validUrl, null, null, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]); assertEquals("Response code was not OK (200)", 200, EVENT_PARAMS[3]); assertEquals("Event ID was incorrect", WebRequestEvent.COMPLETE, EVENT_ID); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); }
Example 11
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 5 votes |
@Test public void testValidGetWithNullHeaders () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_Valid_Get_No_Headers", invocation.getId()); Request.get("1", validUrl, null, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]); assertEquals("Response code was not OK (200)", 200, EVENT_PARAMS[3]); assertEquals("Event ID was incorrect", WebRequestEvent.COMPLETE, EVENT_ID); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); }
Example 12
Source File: OfflineLicenseHelper.java From K-Sonic with MIT License | 5 votes |
/** * Constructs an instance. Call {@link #releaseResources()} when you're done with it. * * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager. * @param callback Performs key and provisioning requests. * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null. * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm, * MediaDrmCallback, HashMap, Handler, EventListener) */ public OfflineLicenseHelper(ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback, HashMap<String, String> optionalKeyRequestParameters) { handlerThread = new HandlerThread("OfflineLicenseHelper"); handlerThread.start(); conditionVariable = new ConditionVariable(); EventListener eventListener = new EventListener() { @Override public void onDrmKeysLoaded() { conditionVariable.open(); } @Override public void onDrmSessionManagerError(Exception e) { conditionVariable.open(); } @Override public void onDrmKeysRestored() { conditionVariable.open(); } @Override public void onDrmKeysRemoved() { conditionVariable.open(); } }; drmSessionManager = new DefaultDrmSessionManager<>(C.WIDEVINE_UUID, mediaDrm, callback, optionalKeyRequestParameters, new Handler(handlerThread.getLooper()), eventListener); }
Example 13
Source File: OfflineLicenseHelper.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Constructs an instance. Call {@link #release()} when the instance is no longer required. * * @param uuid The UUID of the drm scheme. * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager. * @param callback Performs key and provisioning requests. * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null. * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm, * MediaDrmCallback, HashMap, Handler, DefaultDrmSessionEventListener) */ public OfflineLicenseHelper( UUID uuid, ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback, HashMap<String, String> optionalKeyRequestParameters) { handlerThread = new HandlerThread("OfflineLicenseHelper"); handlerThread.start(); conditionVariable = new ConditionVariable(); DefaultDrmSessionEventListener eventListener = new DefaultDrmSessionEventListener() { @Override public void onDrmKeysLoaded() { conditionVariable.open(); } @Override public void onDrmSessionManagerError(Exception e) { conditionVariable.open(); } @Override public void onDrmKeysRestored() { conditionVariable.open(); } @Override public void onDrmKeysRemoved() { conditionVariable.open(); } }; drmSessionManager = new DefaultDrmSessionManager<>(uuid, mediaDrm, callback, optionalKeyRequestParameters); drmSessionManager.addListener(new Handler(handlerThread.getLooper()), eventListener); }
Example 14
Source File: OfflineLicenseHelper.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
/** * Constructs an instance. Call {@link #release()} when the instance is no longer required. * * @param uuid The UUID of the drm scheme. * @param mediaDrm An underlying {@link ExoMediaDrm} for use by the manager. * @param callback Performs key and provisioning requests. * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * to {@link MediaDrm#getKeyRequest(byte[], byte[], String, int, HashMap)}. May be null. * @see DefaultDrmSessionManager#DefaultDrmSessionManager(java.util.UUID, ExoMediaDrm, * MediaDrmCallback, HashMap, Handler, DefaultDrmSessionEventListener) */ public OfflineLicenseHelper( UUID uuid, ExoMediaDrm<T> mediaDrm, MediaDrmCallback callback, HashMap<String, String> optionalKeyRequestParameters) { handlerThread = new HandlerThread("OfflineLicenseHelper"); handlerThread.start(); conditionVariable = new ConditionVariable(); DefaultDrmSessionEventListener eventListener = new DefaultDrmSessionEventListener() { @Override public void onDrmKeysLoaded() { conditionVariable.open(); } @Override public void onDrmSessionManagerError(Exception e) { conditionVariable.open(); } @Override public void onDrmKeysRestored() { conditionVariable.open(); } @Override public void onDrmKeysRemoved() { conditionVariable.open(); } }; drmSessionManager = new DefaultDrmSessionManager<>(uuid, mediaDrm, callback, optionalKeyRequestParameters); drmSessionManager.addListener(new Handler(handlerThread.getLooper()), eventListener); }
Example 15
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 4 votes |
@Test public void testValidPostWithValidHeadersAndPostBody () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_Valid_Post_No_Headers_Post_Body", invocation.getId()); JSONArray headers = new JSONArray("[[\"test-header\", \"test\"]]"); Request.post("1", validUrl, "Testing Testing", headers, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); JSONArray receivedHeaders = (JSONArray)EVENT_PARAMS[4]; boolean testHeaderExists = false; for (int i = 0; i < receivedHeaders.length(); i++) { if (((JSONArray)receivedHeaders.get(i)).get(0).equals("test-header") && ((JSONArray)receivedHeaders.get(i)).get(1).equals("test")) { testHeaderExists = true; } } assertTrue("There should be headers in the connection result", receivedHeaders.length() > 0); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertTrue("Header \"Test-Header\" not found or its content was not \"test\"", testHeaderExists); assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]); assertEquals("Response code was not OK (200)", 200, EVENT_PARAMS[3]); assertEquals("Event ID was incorrect", WebRequestEvent.COMPLETE, EVENT_ID); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); }
Example 16
Source File: OfflineLicenseHelper.java From MediaSDK with Apache License 2.0 | 4 votes |
/** * Constructs an instance. Call {@link #release()} when the instance is no longer required. * * @param uuid The UUID of the drm scheme. * @param mediaDrmProvider A {@link ExoMediaDrm.Provider}. * @param callback Performs key and provisioning requests. * @param optionalKeyRequestParameters An optional map of parameters to pass as the last argument * to {@link MediaDrm#getKeyRequest}. May be null. * @see DefaultDrmSessionManager.Builder */ @SuppressWarnings("unchecked") public OfflineLicenseHelper( UUID uuid, ExoMediaDrm.Provider<T> mediaDrmProvider, MediaDrmCallback callback, @Nullable Map<String, String> optionalKeyRequestParameters) { handlerThread = new HandlerThread("OfflineLicenseHelper"); handlerThread.start(); conditionVariable = new ConditionVariable(); DefaultDrmSessionEventListener eventListener = new DefaultDrmSessionEventListener() { @Override public void onDrmKeysLoaded() { conditionVariable.open(); } @Override public void onDrmSessionManagerError(Exception e) { conditionVariable.open(); } @Override public void onDrmKeysRestored() { conditionVariable.open(); } @Override public void onDrmKeysRemoved() { conditionVariable.open(); } }; if (optionalKeyRequestParameters == null) { optionalKeyRequestParameters = Collections.emptyMap(); } drmSessionManager = (DefaultDrmSessionManager<T>) new DefaultDrmSessionManager.Builder() .setUuidAndExoMediaDrmProvider(uuid, mediaDrmProvider) .setKeyRequestParameters(optionalKeyRequestParameters) .build(callback); drmSessionManager.addListener(new Handler(handlerThread.getLooper()), eventListener); }
Example 17
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 4 votes |
@Test public void testValidGetWithHeader () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; JSONArray headers = new JSONArray("[[\"test-header\", \"test\"]]"); WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_Valid_Get_With_Header", invocation.getId()); Request.get("1", validUrl, headers, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); JSONArray receivedHeaders = (JSONArray)EVENT_PARAMS[4]; boolean testHeaderExists = false; for (int i = 0; i < receivedHeaders.length(); i++) { if (((JSONArray)receivedHeaders.get(i)).get(0).equals("test-header") && ((JSONArray)receivedHeaders.get(i)).get(1).equals("test")) { testHeaderExists = true; } } assertTrue("There should be headers in the connection result", receivedHeaders.length() > 0); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertTrue("Header \"Test-Header\" not found or its content was not \"test\"", testHeaderExists); assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]); assertEquals("Response code was not OK (200)", 200, EVENT_PARAMS[3]); assertEquals("Event ID was incorrect", WebRequestEvent.COMPLETE, EVENT_ID); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); }
Example 18
Source File: RequestTest.java From unity-ads-android with Apache License 2.0 | 4 votes |
@Test public void testValidPostWithHeader () throws Exception { final ConditionVariable cv = new ConditionVariable(); MockWebViewApp webViewApp = new MockWebViewApp() { @Override public boolean sendEvent(Enum eventCategory, Enum eventId, Object... params) { EVENT_CATEGORY = eventCategory; EVENT_ID = eventId; EVENT_PARAMS = params; cv.open(); return true; } }; JSONArray headers = new JSONArray("[[\"test-header\", \"test\"]]"); WebViewApp.setCurrentApp(webViewApp); Invocation invocation = new Invocation(); WebViewCallback callback = new WebViewCallback("Test_Valid_Get_With_Header", invocation.getId()); Request.post("1", validUrl, null, headers, connectTimeout, readTimeout, callback); invocation.sendInvocationCallback(); boolean success = cv.block(30000); assertTrue("ConditionVariable was not opened", success); JSONArray receivedHeaders = (JSONArray)EVENT_PARAMS[4]; boolean testHeaderExists = false; for (int i = 0; i < receivedHeaders.length(); i++) { if (((JSONArray)receivedHeaders.get(i)).get(0).equals("test-header") && ((JSONArray)receivedHeaders.get(i)).get(1).equals("test")) { testHeaderExists = true; } } assertTrue("There should be headers in the connection result", receivedHeaders.length() > 0); assertEquals("Callback status was not OK, successfull callback was expected", CallbackStatus.OK, CALLBACK_STATUS); assertNull("Callback error was not NULL, successfull callback was expected", CALLBACK_ERROR); assertEquals("Callback params list length was expected to be 2 (callback id and request id in params)", 2, CALLBACK_PARAMS.length); assertEquals("Callback first param was expected to be Callback ID", callback.getCallbackId(), CALLBACK_ID); assertTrue("Header \"Test-Header\" not found or its content was not \"test\"", testHeaderExists); assertEquals("Request has changed for some reason", validUrl, EVENT_PARAMS[1]); assertEquals("Response code was not OK (200)", 200, EVENT_PARAMS[3]); assertEquals("Event ID was incorrect", WebRequestEvent.COMPLETE, EVENT_ID); assertEquals("Event Category was incorrect", WebViewEventCategory.REQUEST, EVENT_CATEGORY); }
Example 19
Source File: BroadcastTest.java From unity-ads-android with Apache License 2.0 | 4 votes |
@Test public void testTwoReceivers() throws JSONException { final String jsonAction = "com.unity3d.ads.ACTION_JSON"; final String jsonReceiverName = "jsonReceiver"; final String dataSchemeAction = "com.unity3d.ads.ACTION_DATA_SCHEME"; final String dataSchemeReceiverName = "dataSchemeReceiver"; final String testDataScheme = "test"; final String testDataHost = "example.net"; final String testDataPath = "/path"; final String testStringKey = "testString"; final String testBoolKey = "testBoolean"; final String testLongKey = "testLong"; final String testStringValue = "example"; final boolean testBoolValue = true; final long testLongValue = (long)1234; final ConditionVariable jsonCv = new ConditionVariable(); final ConditionVariable dataSchemeCv = new ConditionVariable(); MockWebViewApp webapp = new MockWebViewApp() { @Override public void broadcastEvent(BroadcastEvent eventId, String name, String action, String data, JSONObject extras) { assertEquals("Broadcast test two receivers: wrong event id", eventId, BroadcastEvent.ACTION); assertTrue("Broadcast test two receivers: receiver name does not match json or data scheme receiver names", name.equals(jsonReceiverName) || name.equals(dataSchemeReceiverName)); if(name.equals(jsonReceiverName)) { assertEquals("Broadcast test two receivers: action does not match", jsonAction, action); assertEquals("Broadcast test two receivers: there should be no data in event", "", data); assertEquals("Broadcast test two receivers: broadcast was sent with three values in extra bundle", 3, extras.length()); try { assertEquals("Broadcast test two receivers: problem with string in bundle extras", testStringValue, extras.getString(testStringKey)); assertEquals("Broadcast test two receivers: problem with boolean in bundle extras", testBoolValue, extras.getBoolean(testBoolKey)); assertEquals("Broadcast test two receivers: problem with long in bundle extras", testLongValue, extras.getLong(testLongKey)); } catch(JSONException e) { fail("Broadcast test two receivers: JSONException: " + e.getMessage()); } jsonCv.open(); } else { assertEquals("Broadcast test two receivers: action does not match", dataSchemeAction, action); assertEquals("Broadcast test two receivers: there should be no bundle extras in this event", 0, extras.length()); Uri testUri = Uri.parse(data); assertEquals("Broadcast test two receivers: data scheme does not match", testDataScheme, testUri.getScheme()); assertEquals("Broadcast test two receivers: data host does not match", testDataHost, testUri.getHost()); assertEquals("Broadcast test two receivers: data path does not match", testDataPath, testUri.getPath()); dataSchemeCv.open(); } } }; WebViewApp.setCurrentApp(webapp); WebViewApp.getCurrentApp().setWebAppLoaded(true); SdkProperties.setInitialized(true); BroadcastMonitor.addBroadcastListener(jsonReceiverName, null, new String[]{jsonAction}); BroadcastMonitor.addBroadcastListener(dataSchemeReceiverName, testDataScheme, new String[]{dataSchemeAction}); Intent jsonIntent = new Intent(); jsonIntent.setAction(jsonAction); jsonIntent.putExtra(testStringKey, testStringValue); jsonIntent.putExtra(testBoolKey, testBoolValue); jsonIntent.putExtra(testLongKey, testLongValue); ClientProperties.getApplicationContext().sendBroadcast(jsonIntent); boolean success = jsonCv.block(30000); assertTrue("Broadcast test two receivers: ", success); Intent dataIntent = new Intent(); dataIntent.setAction(dataSchemeAction); dataIntent.setData(Uri.parse(testDataScheme + "://" + testDataHost + testDataPath)); ClientProperties.getApplicationContext().sendBroadcast(dataIntent); boolean success2 = dataSchemeCv.block(30000); assertTrue("Broadcast test two receivers: ", success2); }