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 com.android.tv.data.epg; 18 19 import android.app.job.JobParameters; 20 import android.app.job.JobService; 21 22 import com.android.tv.Starter; 23 import com.android.tv.data.ChannelDataManager; 24 25 import dagger.android.AndroidInjection; 26 27 import javax.inject.Inject; 28 29 /** JobService to Fetch EPG data. */ 30 public class EpgFetchService extends JobService { 31 @Inject EpgFetcher mEpgFetcher; 32 @Inject ChannelDataManager mChannelDataManager; 33 34 @Override onCreate()35 public void onCreate() { 36 AndroidInjection.inject(this); 37 super.onCreate(); 38 Starter.start(this); 39 } 40 41 @Override onStartJob(JobParameters params)42 public boolean onStartJob(JobParameters params) { 43 if (!mChannelDataManager.isDbLoadFinished()) { 44 mChannelDataManager.addListener( 45 new ChannelDataManager.Listener() { 46 @Override 47 public void onLoadFinished() { 48 mChannelDataManager.removeListener(this); 49 if (!mEpgFetcher.executeFetchTaskIfPossible( 50 EpgFetchService.this, params)) { 51 jobFinished(params, false); 52 } 53 } 54 55 @Override 56 public void onChannelListUpdated() {} 57 58 @Override 59 public void onChannelBrowsableChanged() {} 60 }); 61 return true; 62 } else { 63 return mEpgFetcher.executeFetchTaskIfPossible(this, params); 64 } 65 } 66 67 @Override onStopJob(JobParameters params)68 public boolean onStopJob(JobParameters params) { 69 mEpgFetcher.stopFetchingJob(); 70 return false; 71 } 72 } 73