Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
SDK
/
exoplayer
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
d148db57
authored
Dec 08, 2020
by
kimvde
Committed by
Ian Baker
Dec 14, 2020
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Transformer: add a setter for the looper
PiperOrigin-RevId: 346270250
parent
93b3f43e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
2 deletions
robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/RobolectricUtil.java
robolectricutils/src/main/java/com/google/android/exoplayer2/robolectric/RobolectricUtil.java
View file @
d148db57
...
@@ -15,6 +15,8 @@
...
@@ -15,6 +15,8 @@
*/
*/
package
com
.
google
.
android
.
exoplayer2
.
robolectric
;
package
com
.
google
.
android
.
exoplayer2
.
robolectric
;
import
static
org
.
robolectric
.
Shadows
.
shadowOf
;
import
android.os.Looper
;
import
android.os.Looper
;
import
com.google.android.exoplayer2.util.Clock
;
import
com.google.android.exoplayer2.util.Clock
;
import
com.google.android.exoplayer2.util.ConditionVariable
;
import
com.google.android.exoplayer2.util.ConditionVariable
;
...
@@ -69,6 +71,8 @@ public final class RobolectricUtil {
...
@@ -69,6 +71,8 @@ public final class RobolectricUtil {
* Runs tasks of the main Robolectric {@link Looper} until the {@code condition} returns {@code
* Runs tasks of the main Robolectric {@link Looper} until the {@code condition} returns {@code
* true}.
* true}.
*
*
* <p>Must be called on the main test thread.
*
* @param condition The condition.
* @param condition The condition.
* @param timeoutMs The timeout in milliseconds.
* @param timeoutMs The timeout in milliseconds.
* @param clock The {@link Clock} to measure the timeout.
* @param clock The {@link Clock} to measure the timeout.
...
@@ -76,15 +80,47 @@ public final class RobolectricUtil {
...
@@ -76,15 +80,47 @@ public final class RobolectricUtil {
*/
*/
public
static
void
runMainLooperUntil
(
Supplier
<
Boolean
>
condition
,
long
timeoutMs
,
Clock
clock
)
public
static
void
runMainLooperUntil
(
Supplier
<
Boolean
>
condition
,
long
timeoutMs
,
Clock
clock
)
throws
TimeoutException
{
throws
TimeoutException
{
if
(
Looper
.
myLooper
()
!=
Looper
.
getMainLooper
())
{
runLooperUntil
(
Looper
.
getMainLooper
(),
condition
,
timeoutMs
,
clock
);
}
/**
* Runs tasks of the {@code looper} until the {@code condition} returns {@code true}.
*
* <p>Must be called on the thread corresponding to the {@code looper}.
*
* @param looper The {@link Looper}.
* @param condition The condition.
* @throws TimeoutException If the {@link #DEFAULT_TIMEOUT_MS} is exceeded.
*/
public
static
void
runLooperUntil
(
Looper
looper
,
Supplier
<
Boolean
>
condition
)
throws
TimeoutException
{
runLooperUntil
(
looper
,
condition
,
DEFAULT_TIMEOUT_MS
*
1000000
,
Clock
.
DEFAULT
);
}
/**
* Runs tasks of the {@code looper} until the {@code condition} returns {@code true}.
*
* <p>Must be called on the thread corresponding to the {@code looper}.
*
* @param looper The {@link Looper}.
* @param condition The condition.
* @param timeoutMs The timeout in milliseconds.
* @param clock The {@link Clock} to measure the timeout.
* @throws TimeoutException If the {@code timeoutMs timeout} is exceeded.
*/
public
static
void
runLooperUntil
(
Looper
looper
,
Supplier
<
Boolean
>
condition
,
long
timeoutMs
,
Clock
clock
)
throws
TimeoutException
{
if
(
Looper
.
myLooper
()
!=
looper
)
{
throw
new
IllegalStateException
();
throw
new
IllegalStateException
();
}
}
ShadowLooper
shadowLooper
=
shadowOf
(
looper
);
long
timeoutTimeMs
=
clock
.
currentTimeMillis
()
+
timeoutMs
;
long
timeoutTimeMs
=
clock
.
currentTimeMillis
()
+
timeoutMs
;
while
(!
condition
.
get
())
{
while
(!
condition
.
get
())
{
if
(
clock
.
currentTimeMillis
()
>=
timeoutTimeMs
)
{
if
(
clock
.
currentTimeMillis
()
>=
timeoutTimeMs
)
{
throw
new
TimeoutException
();
throw
new
TimeoutException
();
}
}
ShadowLooper
.
runMainLooper
OneTask
();
shadowLooper
.
run
OneTask
();
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment