1 /* 2 * Copyright 2018 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 androidx.media.test.service; 18 19 import static androidx.media.test.lib.TestHelperUtil.ACTION_TEST_HELPER; 20 21 import android.app.Service; 22 import android.content.Intent; 23 import android.os.Bundle; 24 import android.os.IBinder; 25 import android.os.Looper; 26 import android.os.RemoteException; 27 import android.support.mediacompat.testlib.ITestHelperForServiceApp; 28 29 import androidx.media.MediaSession2; 30 31 /** 32 * A Service that creates {@link MediaSession2} and calls its methods according to the client app's 33 * requests. 34 */ 35 public class TestHelperService extends Service { 36 37 MediaSession2 mSession2; 38 ServiceBinder mBinder; 39 40 @Override 41 public void onCreate() { 42 super.onCreate(); 43 mBinder = new ServiceBinder(); 44 } 45 46 @Override 47 public IBinder onBind(Intent intent) { 48 if (ACTION_TEST_HELPER.equals(intent.getAction())) { 49 return mBinder; 50 } 51 return null; 52 } 53 54 private class ServiceBinder extends ITestHelperForServiceApp.Stub { 55 @Override 56 public Bundle getSessionToken2(String testName) throws RemoteException { 57 if (Looper.myLooper() == null) { 58 Looper.prepare(); 59 } 60 61 // TODO: Create the right session according to testName, and return its token here. 62 mSession2 = new MediaSession2.Builder(TestHelperService.this) 63 .setPlayer(new MockPlayer(0)) 64 .build(); 65 return mSession2.getToken().toBundle(); 66 } 67 68 @Override 69 public void callMediaSession2Method(int method, Bundle args) throws RemoteException { 70 // TODO: Call appropriate method (mSession2.~~~) 71 } 72 73 // TODO: call(MediaPlayerBase/Agent)Method may be also needed. 74 // If so, do not create mPlayer/mAgent, but get them from mSession.getPlayer()/getAgent(). 75 } 76 } 77