1 /* 2 * Copyright (C) 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 package com.android.tv.audiotvservice; 17 18 import android.app.Notification; 19 import android.app.Service; 20 import android.content.Intent; 21 import android.media.session.MediaSession; 22 import android.net.Uri; 23 import android.os.IBinder; 24 import android.support.annotation.Nullable; 25 import android.util.Log; 26 import com.android.tv.data.ChannelImpl; 27 import com.android.tv.data.StreamInfo; 28 import com.android.tv.data.api.Channel; 29 import com.android.tv.ui.TunableTvView; 30 import com.android.tv.ui.TunableTvView.OnTuneListener; 31 32 /** Foreground service for audio-only TV inputs. */ 33 public class AudioOnlyTvService extends Service implements OnTuneListener { 34 // TODO(b/110969180): implement this service. 35 private static final String TAG = "AudioOnlyTvService"; 36 private static final int NOTIFICATION_ID = 1; 37 38 @Nullable private String mTvInputId; 39 private TunableTvView mTvView; 40 // TODO(b/110969180): perhaps use MediaSessionWrapper 41 private MediaSession mMediaSession; 42 43 @Nullable 44 @Override onBind(Intent intent)45 public IBinder onBind(Intent intent) { 46 Log.i(TAG, "onBind"); 47 return null; 48 } 49 50 @Override onCreate()51 public void onCreate() { 52 Log.i(TAG, "onCreate"); 53 // TODO(b/110969180): create TvView 54 55 } 56 57 @Override onStartCommand(Intent intent, int flags, int startId)58 public int onStartCommand(Intent intent, int flags, int startId) { 59 Log.i(TAG, "onStartCommand. flags = " + flags + ", startId = " + startId); 60 // TODO(b/110969180): real notification and or media session 61 startForeground(NOTIFICATION_ID, new Notification()); 62 mTvInputId = AudioOnlyTvServiceUtil.getInputIdFromIntent(intent); 63 tune(mTvInputId); 64 return START_STICKY; 65 } 66 tune(String tvInputId)67 private void tune(String tvInputId) { 68 Channel channel = ChannelImpl.createPassthroughChannel(tvInputId); 69 mTvView.tuneTo(channel, null, this); 70 } 71 72 @Override onDestroy()73 public void onDestroy() { 74 Log.i(TAG, "onDestroy"); 75 mTvInputId = null; 76 // TODO(b/110969180): clear TvView 77 } 78 79 // TODO(b/110969180): figure out when to stop ourselves, mediaSession event? 80 81 // TODO(b/110969180): handle OnTuner Listener 82 @Override onTuneFailed(Channel channel)83 public void onTuneFailed(Channel channel) {} 84 85 @Override onUnexpectedStop(Channel channel)86 public void onUnexpectedStop(Channel channel) {} 87 88 @Override onStreamInfoChanged(StreamInfo info, boolean allowAutoSelectionOfTrack)89 public void onStreamInfoChanged(StreamInfo info, boolean allowAutoSelectionOfTrack) {} 90 91 @Override onChannelRetuned(Uri channel)92 public void onChannelRetuned(Uri channel) {} 93 94 @Override onContentBlocked()95 public void onContentBlocked() {} 96 97 @Override onContentAllowed()98 public void onContentAllowed() {} 99 100 @Override onChannelSignalStrength()101 public void onChannelSignalStrength() {} 102 } 103