Home | History | Annotate | Download | only in service
      1 /*
      2  * Copyright (C) 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.annotation.NonNull;
     21 import android.support.annotation.Nullable;
     22 import android.support.v4.media.MediaBrowserCompat;
     23 import android.support.v4.media.MediaBrowserServiceCompat;
     24 import android.support.v4.media.session.MediaSessionCompat;
     25 
     26 import java.util.List;
     27 
     28 /**
     29  * Stub implementation of {@link MediaBrowserServiceCompat}.
     30  * This implementation does not call
     31  * {@link MediaBrowserServiceCompat#setSessionToken(MediaSessionCompat.Token)} in its
     32  * {@link android.app.Service#onCreate}.
     33  */
     34 public class StubMediaBrowserServiceCompatWithDelayedMediaSession extends
     35         MediaBrowserServiceCompat {
     36 
     37     static StubMediaBrowserServiceCompatWithDelayedMediaSession sInstance;
     38     private MediaSessionCompat mSession;
     39 
     40     @Override
     41     public void onCreate() {
     42         super.onCreate();
     43         sInstance = this;
     44         mSession = new MediaSessionCompat(
     45                 this, "StubMediaBrowserServiceCompatWithDelayedMediaSession");
     46     }
     47 
     48     @Nullable
     49     @Override
     50     public BrowserRoot onGetRoot(@NonNull String clientPackageName,
     51             int clientUid, @Nullable Bundle rootHints) {
     52         return new BrowserRoot("StubRootId", null);
     53     }
     54 
     55     @Override
     56     public void onLoadChildren(@NonNull String parentId,
     57             @NonNull Result<List<MediaBrowserCompat.MediaItem>> result) {
     58         result.detach();
     59     }
     60 
     61     public void callSetSessionToken() {
     62         setSessionToken(mSession.getSessionToken());
     63     }
     64 }
     65