1 /* 2 * Copyright (C) 2024 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.media.bettertogether.cts; 18 19 import android.media.browse.MediaBrowser.MediaItem; 20 import android.os.Bundle; 21 import android.os.ConditionVariable; 22 import android.service.media.MediaBrowserService; 23 24 import androidx.annotation.NonNull; 25 import androidx.annotation.Nullable; 26 27 import java.util.List; 28 import java.util.concurrent.atomic.AtomicReference; 29 30 /** (@link MediaBrowserService} that does not set a session by default. */ 31 public class SimpleMediaBrowserService extends MediaBrowserService { 32 33 public static final AtomicReference<MediaBrowserService> sInstance = new AtomicReference<>(); 34 public static final ConditionVariable sInstanceInitializedCondition = new ConditionVariable(); 35 36 @Override onCreate()37 public void onCreate() { 38 super.onCreate(); 39 sInstance.set(this); 40 sInstanceInitializedCondition.open(); 41 } 42 43 @Override onDestroy()44 public void onDestroy() { 45 sInstanceInitializedCondition.close(); 46 sInstance.set(null); 47 super.onDestroy(); 48 } 49 50 @Nullable 51 @Override onGetRoot( @onNull String clientPackageName, int clientUid, @Nullable Bundle rootHints)52 public BrowserRoot onGetRoot( 53 @NonNull String clientPackageName, int clientUid, @Nullable Bundle rootHints) { 54 return new BrowserRoot("placeholder root id", /* extras= */ null); 55 } 56 57 @Override onLoadChildren(@onNull String parentId, @NonNull Result<List<MediaItem>> result)58 public void onLoadChildren(@NonNull String parentId, @NonNull Result<List<MediaItem>> result) {} 59 } 60