summaryrefslogtreecommitdiff
path: root/android/media/MockMediaLibraryService2.java
diff options
context:
space:
mode:
authorJustin Klaassen <justinklaassen@google.com>2018-04-03 23:21:57 -0400
committerJustin Klaassen <justinklaassen@google.com>2018-04-03 23:21:57 -0400
commit4d01eeaffaa720e4458a118baa137a11614f00f7 (patch)
tree66751893566986236788e3c796a7cc5e90d05f52 /android/media/MockMediaLibraryService2.java
parenta192cc2a132cb0ee8588e2df755563ec7008c179 (diff)
downloadandroid-28-4d01eeaffaa720e4458a118baa137a11614f00f7.tar.gz
Import Android SDK Platform P [4697573]
/google/data/ro/projects/android/fetch_artifact \ --bid 4697573 \ --target sdk_phone_armv7-win_sdk \ sdk-repo-linux-sources-4697573.zip AndroidVersion.ApiLevel has been modified to appear as 28 Change-Id: If80578c3c657366cc9cf75f8db13d46e2dd4e077
Diffstat (limited to 'android/media/MockMediaLibraryService2.java')
-rw-r--r--android/media/MockMediaLibraryService2.java98
1 files changed, 0 insertions, 98 deletions
diff --git a/android/media/MockMediaLibraryService2.java b/android/media/MockMediaLibraryService2.java
deleted file mode 100644
index 14cf2577..00000000
--- a/android/media/MockMediaLibraryService2.java
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
-* Copyright 2018 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 android.media;
-
-import static junit.framework.Assert.fail;
-
-import android.content.Context;
-import android.media.MediaSession2.CommandGroup;
-import android.media.MediaSession2.ControllerInfo;
-import android.media.TestUtils.SyncHandler;
-import android.os.Bundle;
-import android.os.Process;
-
-import javax.annotation.concurrent.GuardedBy;
-
-/**
- * Mock implementation of {@link MediaLibraryService2} for testing.
- */
-public class MockMediaLibraryService2 extends MediaLibraryService2 {
- // Keep in sync with the AndroidManifest.xml
- public static final String ID = "TestLibrary";
-
- public static final String ROOT_ID = "rootId";
- public static final Bundle EXTRA = new Bundle();
- static {
- EXTRA.putString(ROOT_ID, ROOT_ID);
- }
- @GuardedBy("MockMediaLibraryService2.class")
- private static SessionToken2 sToken;
-
- private MediaLibrarySession mSession;
-
- @Override
- public MediaLibrarySession onCreateSession(String sessionId) {
- final MockPlayer player = new MockPlayer(1);
- final SyncHandler handler = (SyncHandler) TestServiceRegistry.getInstance().getHandler();
- try {
- handler.postAndSync(() -> {
- TestLibrarySessionCallback callback = new TestLibrarySessionCallback();
- mSession = new MediaLibrarySessionBuilder(MockMediaLibraryService2.this,
- player, (runnable) -> handler.post(runnable), callback)
- .setId(sessionId).build();
- });
- } catch (InterruptedException e) {
- fail(e.toString());
- }
- return mSession;
- }
-
- @Override
- public void onDestroy() {
- TestServiceRegistry.getInstance().cleanUp();
- super.onDestroy();
- }
-
- public static SessionToken2 getToken(Context context) {
- synchronized (MockMediaLibraryService2.class) {
- if (sToken == null) {
- sToken = new SessionToken2(SessionToken2.TYPE_LIBRARY_SERVICE,
- context.getPackageName(), ID,
- MockMediaLibraryService2.class.getName(), null);
- }
- return sToken;
- }
- }
-
- private class TestLibrarySessionCallback extends MediaLibrarySessionCallback {
- @Override
- public CommandGroup onConnect(ControllerInfo controller) {
- if (Process.myUid() != controller.getUid()) {
- // It's system app wants to listen changes. Ignore.
- return super.onConnect(controller);
- }
- TestServiceRegistry.getInstance().setServiceInstance(
- MockMediaLibraryService2.this, controller);
- return super.onConnect(controller);
- }
-
- @Override
- public BrowserRoot onGetRoot(ControllerInfo controller, Bundle rootHints) {
- return new BrowserRoot(ROOT_ID, EXTRA);
- }
- }
-} \ No newline at end of file