• 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.app;
18 
19 import com.android.tv.TvApplication;
20 import com.android.tv.TvSingletons;
21 import com.android.tv.analytics.Analytics;
22 import com.android.tv.analytics.StubAnalytics;
23 import com.android.tv.analytics.Tracker;
24 import com.android.tv.common.dagger.ApplicationModule;
25 import com.android.tv.common.flags.impl.DefaultBackendKnobsFlags;
26 import com.android.tv.common.flags.impl.DefaultCloudEpgFlags;
27 import com.android.tv.common.flags.impl.DefaultUiFlags;
28 import com.android.tv.common.singletons.HasSingletons;
29 import com.android.tv.modules.TvSingletonsModule;
30 import com.android.tv.perf.PerformanceMonitor;
31 import com.android.tv.tunerinputcontroller.BuiltInTunerManager;
32 
33 import com.google.common.base.Optional;
34 
35 import dagger.android.AndroidInjector;
36 
37 import javax.inject.Inject;
38 
39 /** The top level application for Live TV. */
40 public class LiveTvApplication extends TvApplication implements HasSingletons<TvSingletons> {
41 
42     static {
STARTUP_MEASURE.onAppClassLoaded()43         STARTUP_MEASURE.onAppClassLoaded();
44     }
45 
46     private final DefaultBackendKnobsFlags mBackendKnobsFlags = new DefaultBackendKnobsFlags();
47     private final DefaultCloudEpgFlags mCloudEpgFlags = new DefaultCloudEpgFlags();
48     private final DefaultUiFlags mUiFlags = new DefaultUiFlags();
49 
50     private Analytics mAnalytics;
51     private Tracker mTracker;
52     @Inject PerformanceMonitor mPerformanceMonitor;
53 
54     @Override
applicationInjector()55     protected AndroidInjector<LiveTvApplication> applicationInjector() {
56         return DaggerLiveTvApplicationComponent.builder()
57                 .applicationModule(new ApplicationModule(this))
58                 .tvSingletonsModule(new TvSingletonsModule(this))
59                 .build();
60     }
61 
62     @Override
onCreate()63     public void onCreate() {
64         super.onCreate();
65         STARTUP_MEASURE.onAppCreate(this);
66     }
67 
68     @Override
getPerformanceMonitor()69     public PerformanceMonitor getPerformanceMonitor() {
70         return mPerformanceMonitor;
71     }
72 
73     @Override
getBackendKnobs()74     public DefaultBackendKnobsFlags getBackendKnobs() {
75         return mBackendKnobsFlags;
76     }
77 
78     /** Returns the {@link Analytics}. */
79     @Override
getAnalytics()80     public synchronized Analytics getAnalytics() {
81         if (mAnalytics == null) {
82             mAnalytics = StubAnalytics.getInstance(this);
83         }
84         return mAnalytics;
85     }
86 
87     /** Returns the default tracker. */
88     @Override
getTracker()89     public synchronized Tracker getTracker() {
90         if (mTracker == null) {
91             mTracker = getAnalytics().getDefaultTracker();
92         }
93         return mTracker;
94     }
95 
96     @Override
getCloudEpgFlags()97     public DefaultCloudEpgFlags getCloudEpgFlags() {
98         return mCloudEpgFlags;
99     }
100 
101     @Override
getUiFlags()102     public DefaultUiFlags getUiFlags() {
103         return mUiFlags;
104     }
105 
106     @Override
getBuiltInTunerManager()107     public Optional<BuiltInTunerManager> getBuiltInTunerManager() {
108         return Optional.absent();
109     }
110 
111     @Override
singletons()112     public TvSingletons singletons() {
113         return this;
114     }
115 }
116