• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 import com.android.tv.Starter;
22 import com.android.tv.TvSingletons;
23 import com.android.tv.data.ChannelDataManager;
24 
25 /** JobService to Fetch EPG data. */
26 public class EpgFetchService extends JobService {
27     private EpgFetcher mEpgFetcher;
28     private ChannelDataManager mChannelDataManager;
29 
30     @Override
onCreate()31     public void onCreate() {
32         super.onCreate();
33         Starter.start(this);
34         TvSingletons tvSingletons = TvSingletons.getSingletons(getApplicationContext());
35         mEpgFetcher = tvSingletons.getEpgFetcher();
36         mChannelDataManager = tvSingletons.getChannelDataManager();
37     }
38 
39     @Override
onStartJob(JobParameters params)40     public boolean onStartJob(JobParameters params) {
41         if (!mChannelDataManager.isDbLoadFinished()) {
42             mChannelDataManager.addListener(
43                     new ChannelDataManager.Listener() {
44                         @Override
45                         public void onLoadFinished() {
46                             mChannelDataManager.removeListener(this);
47                             if (!mEpgFetcher.executeFetchTaskIfPossible(
48                                     EpgFetchService.this, params)) {
49                                 jobFinished(params, false);
50                             }
51                         }
52 
53                         @Override
54                         public void onChannelListUpdated() {}
55 
56                         @Override
57                         public void onChannelBrowsableChanged() {}
58                     });
59             return true;
60         } else {
61             return mEpgFetcher.executeFetchTaskIfPossible(this, params);
62         }
63     }
64 
65     @Override
onStopJob(JobParameters params)66     public boolean onStopJob(JobParameters params) {
67         mEpgFetcher.stopFetchingJob();
68         return false;
69     }
70 }
71