Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
platform_frameworks_base-old
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Farzin Kazemzadeh
platform_frameworks_base-old
Commits
115eead2
Commit
115eead2
authored
5 years ago
by
TreeHugger Robot
Committed by
Android (Google) Code Review
5 years ago
Browse files
Options
Downloads
Plain Diff
Merge "MediaSessionManager: Use Executor instead of Handler"
parents
e185ac2b
95c783e2
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api/system-current.txt
+1
-1
1 addition, 1 deletion
api/system-current.txt
media/java/android/media/session/MediaSessionManager.java
+27
-19
27 additions, 19 deletions
media/java/android/media/session/MediaSessionManager.java
with
28 additions
and
20 deletions
api/system-current.txt
+
1
−
1
View file @
115eead2
...
...
@@ -3693,7 +3693,7 @@ package android.media.audiopolicy {
package android.media.session {
public final class MediaSessionManager {
method @RequiresPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL) public void registerCallback(@NonNull android.media.session.MediaSessionManager.Callback
, @Nullable android.os.Handler
);
method @RequiresPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL) public void registerCallback(@NonNull
java.util.concurrent.Executor, @NonNull
android.media.session.MediaSessionManager.Callback);
method @RequiresPermission(android.Manifest.permission.SET_MEDIA_KEY_LISTENER) public void setOnMediaKeyListener(android.media.session.MediaSessionManager.OnMediaKeyListener, @Nullable android.os.Handler);
method @RequiresPermission(android.Manifest.permission.SET_VOLUME_KEY_LONG_PRESS_LISTENER) public void setOnVolumeKeyLongPressListener(android.media.session.MediaSessionManager.OnVolumeKeyLongPressListener, @Nullable android.os.Handler);
method @RequiresPermission(android.Manifest.permission.MEDIA_CONTENT_CONTROL) public void unregisterCallback(@NonNull android.media.session.MediaSessionManager.Callback);
...
...
This diff is collapsed.
Click to expand it.
media/java/android/media/session/MediaSessionManager.java
+
27
−
19
View file @
115eead2
...
...
@@ -16,6 +16,7 @@
package
android.media.session
;
import
android.annotation.CallbackExecutor
;
import
android.annotation.NonNull
;
import
android.annotation.Nullable
;
import
android.annotation.RequiresPermission
;
...
...
@@ -31,6 +32,7 @@ import android.media.MediaSession2;
import
android.media.Session2Token
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.HandlerExecutor
;
import
android.os.IBinder
;
import
android.os.RemoteException
;
import
android.os.ResultReceiver
;
...
...
@@ -50,6 +52,7 @@ import java.util.HashMap;
import
java.util.List
;
import
java.util.Map
;
import
java.util.Objects
;
import
java.util.concurrent.Executor
;
/**
* Provides support for interacting with {@link MediaSession media sessions}
...
...
@@ -86,7 +89,7 @@ public final class MediaSessionManager {
@GuardedBy
(
"mLock"
)
private
final
CallbackStub
mCbStub
=
new
CallbackStub
();
@GuardedBy
(
"mLock"
)
private
final
Map
<
Callback
,
Handle
r
>
mCallbacks
=
new
HashMap
<>();
private
final
Map
<
Callback
,
Executo
r
>
mCallbacks
=
new
HashMap
<>();
@GuardedBy
(
"mLock"
)
private
MediaSession
.
Token
mCurMediaButtonSession
;
@GuardedBy
(
"mLock"
)
...
...
@@ -765,13 +768,16 @@ public final class MediaSessionManager {
*/
// TODO: Remove this method once Bluetooth app stop calling it.
public
void
setCallback
(
@Nullable
Callback
callback
,
@Nullable
Handler
handler
)
{
if
(
handler
==
null
)
{
handler
=
new
Handler
();
}
synchronized
(
mLock
)
{
if
(
mLegacyCallback
!=
null
)
{
unregisterCallback
(
mLegacyCallback
);
}
mLegacyCallback
=
callback
;
if
(
callback
!=
null
)
{
registerCallback
(
callback
,
handler
);
registerCallback
(
new
HandlerExecutor
(
handler
),
callback
);
}
}
}
...
...
@@ -779,27 +785,29 @@ public final class MediaSessionManager {
/**
* Register a {@link Callback}.
*
* @param executor The executor on which the callback should be invoked
* @param callback A {@link Callback}.
* @param handler The handler on which the callback should be invoked, or {@code null}
* if the callback should be invoked on the calling thread's looper.
* @hide
*/
@SystemApi
@RequiresPermission
(
value
=
android
.
Manifest
.
permission
.
MEDIA_CONTENT_CONTROL
)
public
void
registerCallback
(
@NonNull
Callback
callback
,
@Nullable
Handler
handler
)
{
public
void
registerCallback
(
@NonNull
@CallbackExecutor
Executor
executor
,
@NonNull
Callback
callback
)
{
if
(
executor
==
null
)
{
throw
new
NullPointerException
(
"executor shouldn't be null"
);
}
if
(
callback
==
null
)
{
throw
new
NullPointerException
(
"callback shouldn't be null"
);
}
synchronized
(
mLock
)
{
try
{
if
(
handler
==
null
)
{
handler
=
new
Handler
();
}
mCallbacks
.
put
(
callback
,
handler
);
mCallbacks
.
put
(
callback
,
executor
);
if
(
mCurMediaButtonSession
!=
null
)
{
handler
.
post
(()
->
callback
.
onAddressedPlayerChanged
(
mCurMediaButtonSession
));
executor
.
execute
(
()
->
callback
.
onAddressedPlayerChanged
(
mCurMediaButtonSession
));
}
else
if
(
mCurMediaButtonReceiver
!=
null
)
{
handler
.
post
(()
->
callback
.
onAddressedPlayerChanged
(
mCurMediaButtonReceiver
));
executor
.
execute
(
()
->
callback
.
onAddressedPlayerChanged
(
mCurMediaButtonReceiver
));
}
if
(
mCallbacks
.
size
()
==
1
)
{
...
...
@@ -1147,8 +1155,8 @@ public final class MediaSessionManager {
public
void
onMediaKeyEventDispatchedToMediaSession
(
KeyEvent
event
,
MediaSession
.
Token
sessionToken
)
{
synchronized
(
mLock
)
{
for
(
Map
.
Entry
<
Callback
,
Handle
r
>
e
:
mCallbacks
.
entrySet
())
{
e
.
getValue
().
post
(
for
(
Map
.
Entry
<
Callback
,
Executo
r
>
e
:
mCallbacks
.
entrySet
())
{
e
.
getValue
().
execute
(
()
->
e
.
getKey
().
onMediaKeyEventDispatched
(
event
,
sessionToken
));
}
}
...
...
@@ -1158,8 +1166,8 @@ public final class MediaSessionManager {
public
void
onMediaKeyEventDispatchedToMediaButtonReceiver
(
KeyEvent
event
,
ComponentName
mediaButtonReceiver
)
{
synchronized
(
mLock
)
{
for
(
Map
.
Entry
<
Callback
,
Handle
r
>
e
:
mCallbacks
.
entrySet
())
{
e
.
getValue
().
post
(
for
(
Map
.
Entry
<
Callback
,
Executo
r
>
e
:
mCallbacks
.
entrySet
())
{
e
.
getValue
().
execute
(
()
->
e
.
getKey
().
onMediaKeyEventDispatched
(
event
,
mediaButtonReceiver
));
}
}
...
...
@@ -1170,8 +1178,8 @@ public final class MediaSessionManager {
synchronized
(
mLock
)
{
mCurMediaButtonSession
=
sessionToken
;
mCurMediaButtonReceiver
=
null
;
for
(
Map
.
Entry
<
Callback
,
Handle
r
>
e
:
mCallbacks
.
entrySet
())
{
e
.
getValue
().
post
(()
->
e
.
getKey
().
onAddressedPlayerChanged
(
sessionToken
));
for
(
Map
.
Entry
<
Callback
,
Executo
r
>
e
:
mCallbacks
.
entrySet
())
{
e
.
getValue
().
execute
(()
->
e
.
getKey
().
onAddressedPlayerChanged
(
sessionToken
));
}
}
}
...
...
@@ -1182,8 +1190,8 @@ public final class MediaSessionManager {
synchronized
(
mLock
)
{
mCurMediaButtonSession
=
null
;
mCurMediaButtonReceiver
=
mediaButtonReceiver
;
for
(
Map
.
Entry
<
Callback
,
Handle
r
>
e
:
mCallbacks
.
entrySet
())
{
e
.
getValue
().
post
(()
->
e
.
getKey
().
onAddressedPlayerChanged
(
for
(
Map
.
Entry
<
Callback
,
Executo
r
>
e
:
mCallbacks
.
entrySet
())
{
e
.
getValue
().
execute
(()
->
e
.
getKey
().
onAddressedPlayerChanged
(
mediaButtonReceiver
));
}
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment