Replace hidden API startForegroundServiceAsUser

Replace it with getting context as the given user first and
calling startForegroundService, which is a public API.

Also add test for using PendingIntent#getService for
MediaButtonReceiver.

Bug: 161333794
Test: atest CtsMediaTestCases:android.media.cts.\
    MediaSessionTest#testSetMediaButtonReceiver_service
Change-Id: I0fbd2f5aaa011b1514ada6439816f89c4334f0a9
This commit is contained in:
Jin Seok Park
2020-07-26 14:07:48 +09:00
parent b19564f75c
commit 6d6535d30b

View File

@@ -221,8 +221,8 @@ final class MediaButtonReceiverHolder {
context.startActivityAsUser(mediaButtonIntent, userHandle);
break;
case COMPONENT_TYPE_SERVICE:
context.startForegroundServiceAsUser(mediaButtonIntent,
userHandle);
context.createContextAsUser(userHandle, 0).startForegroundService(
mediaButtonIntent);
break;
default:
// Legacy behavior for other cases.