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
bf3d81c2
authored
May 30, 2022
by
bachinger
Committed by
Marc Baechinger
May 30, 2022
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
Add missing tests for custom layout notification
PiperOrigin-RevId: 451859199
parent
7af9f020
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
296 additions
and
50 deletions
libraries/test_session_common/src/main/java/androidx/media3/test/session/common/MediaSessionConstants.java
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerCompatCallbackWithMediaSessionCompatTest.java
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerCompatCallbackWithMediaSessionTest.java
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerListenerTest.java
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerListenerWithMediaSessionCompatTest.java
libraries/test_session_current/src/main/java/androidx/media3/session/MediaSessionProviderService.java
libraries/test_session_common/src/main/java/androidx/media3/test/session/common/MediaSessionConstants.java
View file @
bf3d81c2
...
@@ -23,6 +23,7 @@ public class MediaSessionConstants {
...
@@ -23,6 +23,7 @@ public class MediaSessionConstants {
// Test method names
// Test method names
public
static
final
String
TEST_GET_SESSION_ACTIVITY
=
"testGetSessionActivity"
;
public
static
final
String
TEST_GET_SESSION_ACTIVITY
=
"testGetSessionActivity"
;
public
static
final
String
TEST_WITH_CUSTOM_COMMANDS
=
"testWithCustomCommands"
;
public
static
final
String
TEST_CONTROLLER_LISTENER_SESSION_REJECTS
=
"connection_sessionRejects"
;
public
static
final
String
TEST_CONTROLLER_LISTENER_SESSION_REJECTS
=
"connection_sessionRejects"
;
public
static
final
String
TEST_IS_SESSION_COMMAND_AVAILABLE
=
"testIsSessionCommandAvailable"
;
public
static
final
String
TEST_IS_SESSION_COMMAND_AVAILABLE
=
"testIsSessionCommandAvailable"
;
...
...
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerCompatCallbackWithMediaSessionCompatTest.java
0 → 100644
View file @
bf3d81c2
/*
* Copyright 2022 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
androidx
.
media3
.
session
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
CommonConstants
.
DEFAULT_TEST_NAME
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
MILLISECONDS
;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.os.RemoteException
;
import
android.support.v4.media.session.MediaControllerCompat
;
import
android.support.v4.media.session.MediaSessionCompat
;
import
android.support.v4.media.session.PlaybackStateCompat
;
import
androidx.media3.test.session.common.HandlerThreadTestRule
;
import
androidx.media3.test.session.common.MainLooperTestRule
;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.filters.LargeTest
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.CountDownLatch
;
import
org.junit.After
;
import
org.junit.Before
;
import
org.junit.ClassRule
;
import
org.junit.Rule
;
import
org.junit.Test
;
import
org.junit.rules.RuleChain
;
import
org.junit.rules.TestRule
;
import
org.junit.runner.RunWith
;
/**
* Tests for {@link MediaControllerCompat.Callback} with {@link MediaSessionCompat}.
*
* <p>The tests in this class represents the reference specific usages of the legacy API for which
* we need to provide support with the Media3 API.
*
* <p>So these test are actually not tests but rather a reference of how the legacy API is used and
* expected to work.
*/
@RunWith
(
AndroidJUnit4
.
class
)
@LargeTest
public
class
MediaControllerCompatCallbackWithMediaSessionCompatTest
{
private
static
final
int
TIMEOUT_MS
=
1_000
;
@ClassRule
public
static
MainLooperTestRule
mainLooperTestRule
=
new
MainLooperTestRule
();
private
final
HandlerThreadTestRule
threadTestRule
=
new
HandlerThreadTestRule
(
"MediaControllerCompatCallbackWithMediaSessionCompatTest"
);
private
final
MediaControllerTestRule
controllerTestRule
=
new
MediaControllerTestRule
(
threadTestRule
);
@Rule
public
final
TestRule
chain
=
RuleChain
.
outerRule
(
threadTestRule
).
around
(
controllerTestRule
);
private
Context
context
;
private
RemoteMediaSessionCompat
session
;
@Before
public
void
setUp
()
throws
Exception
{
context
=
ApplicationProvider
.
getApplicationContext
();
session
=
new
RemoteMediaSessionCompat
(
DEFAULT_TEST_NAME
,
context
);
}
@After
public
void
cleanUp
()
throws
RemoteException
{
session
.
cleanUp
();
}
/** Custom actions in the legacy session used for instance by Android Auto and Wear OS. */
@Test
public
void
setPlaybackState_withCustomActions_onPlaybackStateCompatChangedCalled
()
throws
Exception
{
MediaSessionCompat
.
Token
sessionToken
=
session
.
getSessionToken
();
Bundle
extras1
=
new
Bundle
();
extras1
.
putString
(
"key"
,
"value-1"
);
PlaybackStateCompat
.
CustomAction
customAction1
=
new
PlaybackStateCompat
.
CustomAction
.
Builder
(
"action1"
,
"actionName1"
,
/* icon= */
1
)
.
setExtras
(
extras1
)
.
build
();
Bundle
extras2
=
new
Bundle
();
extras2
.
putString
(
"key"
,
"value-2"
);
PlaybackStateCompat
.
CustomAction
customAction2
=
new
PlaybackStateCompat
.
CustomAction
.
Builder
(
"action2"
,
"actionName2"
,
/* icon= */
2
)
.
setExtras
(
extras2
)
.
build
();
PlaybackStateCompat
.
Builder
builder
=
new
PlaybackStateCompat
.
Builder
()
.
addCustomAction
(
customAction1
)
.
addCustomAction
(
customAction2
);
List
<
String
>
receivedActions
=
new
ArrayList
<>();
List
<
String
>
receivedDisplayNames
=
new
ArrayList
<>();
List
<
String
>
receivedBundleValues
=
new
ArrayList
<>();
List
<
Integer
>
receivedIconResIds
=
new
ArrayList
<>();
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
1
);
threadTestRule
.
getHandler
()
.
postAndSync
(
()
->
{
MediaControllerCompat
mediaControllerCompat
=
new
MediaControllerCompat
(
context
,
sessionToken
);
mediaControllerCompat
.
registerCallback
(
new
MediaControllerCompat
.
Callback
()
{
@Override
public
void
onPlaybackStateChanged
(
PlaybackStateCompat
state
)
{
List
<
PlaybackStateCompat
.
CustomAction
>
layout
=
state
.
getCustomActions
();
for
(
PlaybackStateCompat
.
CustomAction
action
:
layout
)
{
receivedActions
.
add
(
action
.
getAction
());
receivedDisplayNames
.
add
(
String
.
valueOf
(
action
.
getName
()));
receivedBundleValues
.
add
(
action
.
getExtras
().
getString
(
"key"
));
receivedIconResIds
.
add
(
action
.
getIcon
());
}
countDownLatch
.
countDown
();
}
});
});
session
.
setPlaybackState
(
builder
.
build
());
assertThat
(
countDownLatch
.
await
(
TIMEOUT_MS
,
MILLISECONDS
)).
isTrue
();
assertThat
(
receivedActions
).
containsExactly
(
"action1"
,
"action2"
).
inOrder
();
assertThat
(
receivedDisplayNames
).
containsExactly
(
"actionName1"
,
"actionName2"
).
inOrder
();
assertThat
(
receivedIconResIds
).
containsExactly
(
1
,
2
).
inOrder
();
assertThat
(
receivedBundleValues
).
containsExactly
(
"value-1"
,
"value-2"
).
inOrder
();
}
}
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerCompatCallbackWithMediaSessionTest.java
View file @
bf3d81c2
...
@@ -769,52 +769,54 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
...
@@ -769,52 +769,54 @@ public class MediaControllerCompatCallbackWithMediaSessionTest {
}
}
@Test
@Test
public
void
customLayoutChanged_updatesPlaybackStateCompat
()
throws
Exception
{
public
void
setCustomLayout_onPlaybackStateCompatChangedCalled
()
throws
Exception
{
List
<
CommandButton
>
buttons
=
new
ArrayList
<>();
AtomicReference
<
PlaybackStateCompat
>
playbackStateRef
=
new
AtomicReference
<>();
Bundle
extras1
=
new
Bundle
();
extras1
.
putString
(
"key"
,
"value-1"
);
CommandButton
button1
=
new
CommandButton
.
Builder
()
.
setSessionCommand
(
new
SessionCommand
(
"action1"
,
extras1
))
.
setDisplayName
(
"actionName1"
)
.
setIconResId
(
1
)
.
build
();
Bundle
extras2
=
new
Bundle
();
extras2
.
putString
(
"key"
,
"value-2"
);
CommandButton
button2
=
new
CommandButton
.
Builder
()
.
setSessionCommand
(
new
SessionCommand
(
"action2"
,
extras2
))
.
setDisplayName
(
"actionName2"
)
.
setIconResId
(
2
)
.
build
();
buttons
.
add
(
button1
);
buttons
.
add
(
button2
);
List
<
String
>
receivedActions
=
new
ArrayList
<>();
List
<
String
>
receivedDisplayNames
=
new
ArrayList
<>();
List
<
String
>
receivedBundleValues
=
new
ArrayList
<>();
List
<
Integer
>
receivedIconResIds
=
new
ArrayList
<>();
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
MediaControllerCompat
.
Callback
callback
=
MediaControllerCompat
.
Callback
callback
=
new
MediaControllerCompat
.
Callback
()
{
new
MediaControllerCompat
.
Callback
()
{
@Override
@Override
public
void
onPlaybackStateChanged
(
PlaybackStateCompat
state
)
{
public
void
onPlaybackStateChanged
(
PlaybackStateCompat
state
)
{
playbackStateRef
.
set
(
state
);
List
<
PlaybackStateCompat
.
CustomAction
>
layout
=
state
.
getCustomActions
();
for
(
PlaybackStateCompat
.
CustomAction
action
:
layout
)
{
receivedActions
.
add
(
action
.
getAction
());
receivedDisplayNames
.
add
(
String
.
valueOf
(
action
.
getName
()));
receivedBundleValues
.
add
(
action
.
getExtras
().
getString
(
"key"
));
receivedIconResIds
.
add
(
action
.
getIcon
());
}
latch
.
countDown
();
latch
.
countDown
();
}
}
};
};
controllerCompat
.
registerCallback
(
callback
,
handler
);
controllerCompat
.
registerCallback
(
callback
,
handler
);
List
<
CommandButton
>
customLayout
=
new
ArrayList
<>();
session
.
setCustomLayout
(
buttons
);
Bundle
customCommandBundle1
=
new
Bundle
();
customCommandBundle1
.
putString
(
"customKey1"
,
"customValue1"
);
customLayout
.
add
(
new
CommandButton
.
Builder
()
.
setDisplayName
(
"customCommandName1"
)
.
setIconResId
(
1
)
.
setSessionCommand
(
new
SessionCommand
(
"customCommandAction1"
,
customCommandBundle1
))
.
build
());
Bundle
customCommandBundle2
=
new
Bundle
();
customCommandBundle2
.
putString
(
"customKey2"
,
"customValue2"
);
customLayout
.
add
(
new
CommandButton
.
Builder
()
.
setDisplayName
(
"customCommandName2"
)
.
setIconResId
(
2
)
.
setSessionCommand
(
new
SessionCommand
(
"customCommandAction2"
,
customCommandBundle2
))
.
build
());
session
.
setCustomLayout
(
customLayout
);
assertThat
(
latch
.
await
(
TIMEOUT_MS
,
MILLISECONDS
)).
isTrue
();
assertThat
(
latch
.
await
(
TIMEOUT_MS
,
MILLISECONDS
)).
isTrue
();
List
<
PlaybackStateCompat
.
CustomAction
>
customActions
=
assertThat
(
receivedActions
).
containsExactly
(
"action1"
,
"action2"
).
inOrder
();
playbackStateRef
.
get
().
getCustomActions
();
assertThat
(
receivedDisplayNames
).
containsExactly
(
"actionName1"
,
"actionName2"
).
inOrder
();
assertThat
(
customActions
).
hasSize
(
2
);
assertThat
(
receivedIconResIds
).
containsExactly
(
1
,
2
).
inOrder
();
assertThat
(
customActions
.
get
(
0
).
getAction
()).
isEqualTo
(
"customCommandAction1"
);
assertThat
(
receivedBundleValues
).
containsExactly
(
"value-1"
,
"value-2"
).
inOrder
();
assertThat
(
customActions
.
get
(
0
).
getName
()).
isEqualTo
(
"customCommandName1"
);
assertThat
(
customActions
.
get
(
0
).
getIcon
()).
isEqualTo
(
1
);
assertThat
(
TestUtils
.
equals
(
customActions
.
get
(
0
).
getExtras
(),
customCommandBundle1
)).
isTrue
();
assertThat
(
customActions
.
get
(
1
).
getAction
()).
isEqualTo
(
"customCommandAction2"
);
assertThat
(
customActions
.
get
(
1
).
getName
()).
isEqualTo
(
"customCommandName2"
);
assertThat
(
customActions
.
get
(
1
).
getIcon
()).
isEqualTo
(
2
);
assertThat
(
TestUtils
.
equals
(
customActions
.
get
(
1
).
getExtras
(),
customCommandBundle2
)).
isTrue
();
}
}
@Test
@Test
...
...
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerListenerTest.java
View file @
bf3d81c2
...
@@ -15,7 +15,6 @@
...
@@ -15,7 +15,6 @@
*/
*/
package
androidx
.
media3
.
session
;
package
androidx
.
media3
.
session
;
import
static
androidx
.
media3
.
common
.
Player
.
COMMAND_PLAY_PAUSE
;
import
static
androidx
.
media3
.
common
.
Player
.
COMMAND_SET_REPEAT_MODE
;
import
static
androidx
.
media3
.
common
.
Player
.
COMMAND_SET_REPEAT_MODE
;
import
static
androidx
.
media3
.
common
.
Player
.
EVENT_REPEAT_MODE_CHANGED
;
import
static
androidx
.
media3
.
common
.
Player
.
EVENT_REPEAT_MODE_CHANGED
;
import
static
androidx
.
media3
.
common
.
Player
.
EVENT_SHUFFLE_MODE_ENABLED_CHANGED
;
import
static
androidx
.
media3
.
common
.
Player
.
EVENT_SHUFFLE_MODE_ENABLED_CHANGED
;
...
@@ -30,6 +29,7 @@ import static androidx.media3.test.session.common.CommonConstants.DEFAULT_TEST_N
...
@@ -30,6 +29,7 @@ import static androidx.media3.test.session.common.CommonConstants.DEFAULT_TEST_N
import
static
androidx
.
media3
.
test
.
session
.
common
.
CommonConstants
.
MOCK_MEDIA3_LIBRARY_SERVICE
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
CommonConstants
.
MOCK_MEDIA3_LIBRARY_SERVICE
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
CommonConstants
.
MOCK_MEDIA3_SESSION_SERVICE
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
CommonConstants
.
MOCK_MEDIA3_SESSION_SERVICE
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_CONTROLLER_LISTENER_SESSION_REJECTS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_CONTROLLER_LISTENER_SESSION_REJECTS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_WITH_CUSTOM_COMMANDS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
TestUtils
.
LONG_TIMEOUT_MS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
TestUtils
.
LONG_TIMEOUT_MS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
TestUtils
.
NO_RESPONSE_TIMEOUT_MS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
TestUtils
.
NO_RESPONSE_TIMEOUT_MS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
TestUtils
.
TIMEOUT_MS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
TestUtils
.
TIMEOUT_MS
;
...
@@ -1743,37 +1743,61 @@ public class MediaControllerListenerTest {
...
@@ -1743,37 +1743,61 @@ public class MediaControllerListenerTest {
}
}
@Test
@Test
public
void
onCustomLayoutChang
ed
()
throws
Exception
{
public
void
setCustomLayout_onSetCustomLayoutCall
ed
()
throws
Exception
{
List
<
CommandButton
>
buttons
=
new
ArrayList
<>();
List
<
CommandButton
>
buttons
=
new
ArrayList
<>();
Bundle
extras1
=
new
Bundle
();
CommandButton
button
=
extras1
.
putString
(
"key"
,
"value-1"
);
CommandButton
button1
=
new
CommandButton
.
Builder
()
new
CommandButton
.
Builder
()
.
setPlayerCommand
(
COMMAND_PLAY_PAUSE
)
.
setSessionCommand
(
new
SessionCommand
(
"action1"
,
extras1
))
.
setDisplayName
(
"button"
)
.
setDisplayName
(
"actionName1"
)
.
setIconResId
(
1
)
.
build
();
.
build
();
buttons
.
add
(
button
);
Bundle
extras2
=
new
Bundle
();
extras2
.
putString
(
"key"
,
"value-2"
);
CommandButton
button2
=
new
CommandButton
.
Builder
()
.
setSessionCommand
(
new
SessionCommand
(
"action2"
,
extras2
))
.
setDisplayName
(
"actionName2"
)
.
setIconResId
(
2
)
.
build
();
buttons
.
add
(
button1
);
buttons
.
add
(
button2
);
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
CountDownLatch
latch
=
new
CountDownLatch
(
1
);
List
<
String
>
receivedActions
=
new
ArrayList
<>();
List
<
String
>
receivedDisplayNames
=
new
ArrayList
<>();
List
<
String
>
receivedBundleValues
=
new
ArrayList
<>();
List
<
Integer
>
receivedIconResIds
=
new
ArrayList
<>();
List
<
Integer
>
receivedCommandCodes
=
new
ArrayList
<>();
MediaController
.
Listener
listener
=
MediaController
.
Listener
listener
=
new
MediaController
.
Listener
()
{
new
MediaController
.
Listener
()
{
@Override
@Override
public
ListenableFuture
<
SessionResult
>
onSetCustomLayout
(
public
ListenableFuture
<
SessionResult
>
onSetCustomLayout
(
MediaController
controller
,
List
<
CommandButton
>
layout
)
{
MediaController
controller
,
List
<
CommandButton
>
layout
)
{
assertThat
(
layout
).
hasSize
(
buttons
.
size
());
for
(
CommandButton
button
:
layout
)
{
for
(
int
i
=
0
;
i
<
layout
.
size
();
i
++)
{
receivedActions
.
add
(
button
.
sessionCommand
.
customAction
);
assertThat
(
layout
.
get
(
i
).
playerCommand
).
isEqualTo
(
buttons
.
get
(
i
).
playerCommand
);
receivedDisplayNames
.
add
(
String
.
valueOf
(
button
.
displayName
));
assertThat
(
layout
.
get
(
i
).
displayName
.
toString
())
receivedBundleValues
.
add
(
button
.
sessionCommand
.
customExtras
.
getString
(
"key"
));
.
isEqualTo
(
buttons
.
get
(
i
).
displayName
.
toString
());
receivedCommandCodes
.
add
(
button
.
sessionCommand
.
commandCode
);
receivedIconResIds
.
add
(
button
.
iconResId
);
}
}
latch
.
countDown
();
latch
.
countDown
();
return
Futures
.
immediateFuture
(
new
SessionResult
(
RESULT_SUCCESS
));
return
Futures
.
immediateFuture
(
new
SessionResult
(
RESULT_SUCCESS
));
}
}
};
};
controllerTestRule
.
createController
(
RemoteMediaSession
session
=
createRemoteMediaSession
(
TEST_WITH_CUSTOM_COMMANDS
);
remoteSession
.
getToken
(),
/* connectionHints= */
null
,
listener
);
controllerTestRule
.
createController
(
session
.
getToken
(),
/* connectionHints= */
null
,
listener
);
session
.
setCustomLayout
(
buttons
);
remoteSession
.
setCustomLayout
(
buttons
);
assertThat
(
latch
.
await
(
TIMEOUT_MS
,
MILLISECONDS
)).
isTrue
();
assertThat
(
latch
.
await
(
TIMEOUT_MS
,
MILLISECONDS
)).
isTrue
();
assertThat
(
receivedActions
).
containsExactly
(
"action1"
,
"action2"
).
inOrder
();
assertThat
(
receivedCommandCodes
)
.
containsExactly
(
SessionCommand
.
COMMAND_CODE_CUSTOM
,
SessionCommand
.
COMMAND_CODE_CUSTOM
)
.
inOrder
();
assertThat
(
receivedDisplayNames
).
containsExactly
(
"actionName1"
,
"actionName2"
).
inOrder
();
assertThat
(
receivedIconResIds
).
containsExactly
(
1
,
2
).
inOrder
();
assertThat
(
receivedBundleValues
).
containsExactly
(
"value-1"
,
"value-2"
).
inOrder
();
}
}
@Test
@Test
...
...
libraries/test_session_current/src/androidTest/java/androidx/media3/session/MediaControllerListenerWithMediaSessionCompatTest.java
View file @
bf3d81c2
...
@@ -16,12 +16,14 @@
...
@@ -16,12 +16,14 @@
package
androidx
.
media3
.
session
;
package
androidx
.
media3
.
session
;
import
static
androidx
.
media3
.
common
.
Player
.
EVENT_REPEAT_MODE_CHANGED
;
import
static
androidx
.
media3
.
common
.
Player
.
EVENT_REPEAT_MODE_CHANGED
;
import
static
androidx
.
media3
.
session
.
SessionResult
.
RESULT_SUCCESS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
CommonConstants
.
DEFAULT_TEST_NAME
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
CommonConstants
.
DEFAULT_TEST_NAME
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
TestUtils
.
TIMEOUT_MS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
TestUtils
.
TIMEOUT_MS
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
com
.
google
.
common
.
truth
.
Truth
.
assertThat
;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
MILLISECONDS
;
import
static
java
.
util
.
concurrent
.
TimeUnit
.
MILLISECONDS
;
import
android.content.Context
;
import
android.content.Context
;
import
android.os.Bundle
;
import
android.os.RemoteException
;
import
android.os.RemoteException
;
import
android.support.v4.media.session.MediaSessionCompat
;
import
android.support.v4.media.session.MediaSessionCompat
;
import
android.support.v4.media.session.PlaybackStateCompat
;
import
android.support.v4.media.session.PlaybackStateCompat
;
...
@@ -33,6 +35,10 @@ import androidx.media3.test.session.common.MainLooperTestRule;
...
@@ -33,6 +35,10 @@ import androidx.media3.test.session.common.MainLooperTestRule;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.core.app.ApplicationProvider
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.ext.junit.runners.AndroidJUnit4
;
import
androidx.test.filters.LargeTest
;
import
androidx.test.filters.LargeTest
;
import
com.google.common.util.concurrent.Futures
;
import
com.google.common.util.concurrent.ListenableFuture
;
import
java.util.ArrayList
;
import
java.util.List
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.concurrent.CopyOnWriteArrayList
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.CountDownLatch
;
import
java.util.concurrent.atomic.AtomicReference
;
import
java.util.concurrent.atomic.AtomicReference
;
...
@@ -108,4 +114,58 @@ public class MediaControllerListenerWithMediaSessionCompatTest {
...
@@ -108,4 +114,58 @@ public class MediaControllerListenerWithMediaSessionCompatTest {
assertThat
(
listenerEventCodes
).
containsExactly
(
EVENT_REPEAT_MODE_CHANGED
,
EVENT_ON_EVENTS
);
assertThat
(
listenerEventCodes
).
containsExactly
(
EVENT_REPEAT_MODE_CHANGED
,
EVENT_ON_EVENTS
);
assertThat
(
eventsRef
.
get
()).
isEqualTo
(
testEvents
);
assertThat
(
eventsRef
.
get
()).
isEqualTo
(
testEvents
);
}
}
@Test
public
void
setPlaybackState_withCustomActions_onSetCustomLayoutCalled
()
throws
Exception
{
Bundle
extras1
=
new
Bundle
();
extras1
.
putString
(
"key"
,
"value-1"
);
PlaybackStateCompat
.
CustomAction
customAction1
=
new
PlaybackStateCompat
.
CustomAction
.
Builder
(
"action1"
,
"actionName1"
,
/* icon= */
1
)
.
setExtras
(
extras1
)
.
build
();
Bundle
extras2
=
new
Bundle
();
extras2
.
putString
(
"key"
,
"value-2"
);
PlaybackStateCompat
.
CustomAction
customAction2
=
new
PlaybackStateCompat
.
CustomAction
.
Builder
(
"action2"
,
"actionName2"
,
/* icon= */
2
)
.
setExtras
(
extras2
)
.
build
();
PlaybackStateCompat
.
Builder
builder
=
new
PlaybackStateCompat
.
Builder
()
.
addCustomAction
(
customAction1
)
.
addCustomAction
(
customAction2
);
List
<
String
>
receivedActions
=
new
ArrayList
<>();
List
<
String
>
receivedDisplayNames
=
new
ArrayList
<>();
List
<
String
>
receivedBundleValues
=
new
ArrayList
<>();
List
<
Integer
>
receivedIconResIds
=
new
ArrayList
<>();
List
<
Integer
>
receivedCommandCodes
=
new
ArrayList
<>();
CountDownLatch
countDownLatch
=
new
CountDownLatch
(
1
);
controllerTestRule
.
createController
(
session
.
getSessionToken
(),
new
MediaController
.
Listener
()
{
@Override
public
ListenableFuture
<
SessionResult
>
onSetCustomLayout
(
MediaController
controller
,
List
<
CommandButton
>
layout
)
{
for
(
CommandButton
button
:
layout
)
{
receivedActions
.
add
(
button
.
sessionCommand
.
customAction
);
receivedDisplayNames
.
add
(
String
.
valueOf
(
button
.
displayName
));
receivedBundleValues
.
add
(
button
.
sessionCommand
.
customExtras
.
getString
(
"key"
));
receivedCommandCodes
.
add
(
button
.
sessionCommand
.
commandCode
);
receivedIconResIds
.
add
(
button
.
iconResId
);
}
countDownLatch
.
countDown
();
return
Futures
.
immediateFuture
(
new
SessionResult
(
RESULT_SUCCESS
));
}
});
session
.
setPlaybackState
(
builder
.
build
());
assertThat
(
countDownLatch
.
await
(
TIMEOUT_MS
,
MILLISECONDS
)).
isTrue
();
assertThat
(
receivedActions
).
containsExactly
(
"action1"
,
"action2"
).
inOrder
();
assertThat
(
receivedCommandCodes
)
.
containsExactly
(
SessionCommand
.
COMMAND_CODE_CUSTOM
,
SessionCommand
.
COMMAND_CODE_CUSTOM
)
.
inOrder
();
assertThat
(
receivedDisplayNames
).
containsExactly
(
"actionName1"
,
"actionName2"
).
inOrder
();
assertThat
(
receivedIconResIds
).
containsExactly
(
1
,
2
).
inOrder
();
assertThat
(
receivedBundleValues
).
containsExactly
(
"value-1"
,
"value-2"
).
inOrder
();
}
}
}
libraries/test_session_current/src/main/java/androidx/media3/session/MediaSessionProviderService.java
View file @
bf3d81c2
...
@@ -57,6 +57,7 @@ import static androidx.media3.test.session.common.MediaSessionConstants.KEY_AVAI
...
@@ -57,6 +57,7 @@ import static androidx.media3.test.session.common.MediaSessionConstants.KEY_AVAI
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_CONTROLLER_LISTENER_SESSION_REJECTS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_CONTROLLER_LISTENER_SESSION_REJECTS
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_GET_SESSION_ACTIVITY
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_GET_SESSION_ACTIVITY
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_IS_SESSION_COMMAND_AVAILABLE
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_IS_SESSION_COMMAND_AVAILABLE
;
import
static
androidx
.
media3
.
test
.
session
.
common
.
MediaSessionConstants
.
TEST_WITH_CUSTOM_COMMANDS
;
import
android.app.PendingIntent
;
import
android.app.PendingIntent
;
import
android.app.Service
;
import
android.app.Service
;
...
@@ -177,6 +178,24 @@ public class MediaSessionProviderService extends Service {
...
@@ -177,6 +178,24 @@ public class MediaSessionProviderService extends Service {
builder
.
setSessionActivity
(
pendingIntent
);
builder
.
setSessionActivity
(
pendingIntent
);
break
;
break
;
}
}
case
TEST_WITH_CUSTOM_COMMANDS:
{
SessionCommands
availableSessionCommands
=
new
SessionCommands
.
Builder
()
.
add
(
new
SessionCommand
(
"action1"
,
Bundle
.
EMPTY
))
.
add
(
new
SessionCommand
(
"action2"
,
Bundle
.
EMPTY
))
.
build
();
builder
.
setCallback
(
new
MediaSession
.
Callback
()
{
@Override
public
MediaSession
.
ConnectionResult
onConnect
(
MediaSession
session
,
ControllerInfo
controller
)
{
return
MediaSession
.
ConnectionResult
.
accept
(
availableSessionCommands
,
Player
.
Commands
.
EMPTY
);
}
});
break
;
}
case
TEST_CONTROLLER_LISTENER_SESSION_REJECTS:
case
TEST_CONTROLLER_LISTENER_SESSION_REJECTS:
{
{
builder
.
setCallback
(
builder
.
setCallback
(
...
...
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