1 /* 2 * Copyright 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.support.mediacompat.service; 18 19 import android.os.Bundle; 20 import android.support.v4.media.MediaBrowserCompat; 21 import android.support.v4.media.session.MediaSessionCompat; 22 23 import androidx.annotation.NonNull; 24 import androidx.annotation.Nullable; 25 import androidx.media.MediaBrowserServiceCompat; 26 27 import java.util.List; 28 29 /** 30 * Stub implementation of {@link MediaBrowserServiceCompat}. 31 * This implementation does not call 32 * {@link MediaBrowserServiceCompat#setSessionToken(MediaSessionCompat.Token)} in its 33 * {@link android.app.Service#onCreate}. 34 */ 35 public class StubMediaBrowserServiceCompatWithDelayedMediaSession extends 36 MediaBrowserServiceCompat { 37 38 static StubMediaBrowserServiceCompatWithDelayedMediaSession sInstance; 39 private MediaSessionCompat mSession; 40 41 @Override 42 public void onCreate() { 43 super.onCreate(); 44 sInstance = this; 45 mSession = new MediaSessionCompat( 46 this, "StubMediaBrowserServiceCompatWithDelayedMediaSession"); 47 } 48 49 @Nullable 50 @Override 51 public BrowserRoot onGetRoot(@NonNull String clientPackageName, 52 int clientUid, @Nullable Bundle rootHints) { 53 return new BrowserRoot("StubRootId", null); 54 } 55 56 @Override 57 public void onLoadChildren(@NonNull String parentId, 58 @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) { 59 result.detach(); 60 } 61 62 public void callSetSessionToken() { 63 setSessionToken(mSession.getSessionToken()); 64 } 65 } 66