• 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 android.content.ComponentName;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.media.tv.TvContract;
23 import com.android.tv.TvApplication;
24 import com.android.tv.analytics.Analytics;
25 import com.android.tv.analytics.StubAnalytics;
26 import com.android.tv.analytics.Tracker;
27 import com.android.tv.common.CommonConstants;
28 import com.android.tv.common.actions.InputSetupActionUtils;
29 import com.android.tv.common.config.DefaultConfigManager;
30 import com.android.tv.common.config.api.RemoteConfig;
31 import com.android.tv.common.experiments.ExperimentLoader;
32 import com.android.tv.common.util.CommonUtils;
33 import com.android.tv.data.epg.EpgReader;
34 import com.android.tv.data.epg.StubEpgReader;
35 import com.android.tv.perf.PerformanceMonitor;
36 import com.android.tv.perf.StubPerformanceMonitor;
37 import com.android.tv.tuner.livetuner.LiveTvTunerTvInputService;
38 import com.android.tv.tuner.setup.LiveTvTunerSetupActivity;
39 import com.android.tv.util.account.AccountHelper;
40 import com.android.tv.util.account.AccountHelperImpl;
41 import javax.inject.Provider;
42 
43 /** The top level application for Live TV. */
44 public class LiveTvApplication extends TvApplication {
45     protected static final String TV_ACTIVITY_CLASS_NAME =
46             CommonConstants.BASE_PACKAGE + ".TvActivity";
47 
48     private final StubPerformanceMonitor performanceMonitor = new StubPerformanceMonitor();
49     private final Provider<EpgReader> mEpgReaderProvider =
50             new Provider<EpgReader>() {
51 
52                 @Override
53                 public EpgReader get() {
54                     return new StubEpgReader(LiveTvApplication.this);
55                 }
56             };
57 
58     private AccountHelper mAccountHelper;
59     private Analytics mAnalytics;
60     private Tracker mTracker;
61     private String mEmbeddedInputId;
62     private RemoteConfig mRemoteConfig;
63     private ExperimentLoader mExperimentLoader;
64 
65     /** Returns the {@link AccountHelperImpl}. */
66     @Override
getAccountHelper()67     public AccountHelper getAccountHelper() {
68         if (mAccountHelper == null) {
69             mAccountHelper = new AccountHelperImpl(getApplicationContext());
70         }
71         return mAccountHelper;
72     }
73 
74     @Override
getPerformanceMonitor()75     public synchronized PerformanceMonitor getPerformanceMonitor() {
76         return performanceMonitor;
77     }
78 
79     @Override
providesEpgReader()80     public Provider<EpgReader> providesEpgReader() {
81         return mEpgReaderProvider;
82     }
83 
84     @Override
getExperimentLoader()85     public ExperimentLoader getExperimentLoader() {
86         mExperimentLoader = new ExperimentLoader();
87         return mExperimentLoader;
88     }
89 
90     /** Returns the {@link Analytics}. */
91     @Override
getAnalytics()92     public synchronized Analytics getAnalytics() {
93         if (mAnalytics == null) {
94             mAnalytics = StubAnalytics.getInstance(this);
95         }
96         return mAnalytics;
97     }
98 
99     /** Returns the default tracker. */
100     @Override
getTracker()101     public synchronized Tracker getTracker() {
102         if (mTracker == null) {
103             mTracker = getAnalytics().getDefaultTracker();
104         }
105         return mTracker;
106     }
107 
108     @Override
getTunerSetupIntent(Context context)109     public Intent getTunerSetupIntent(Context context) {
110         // Make an intent to launch the setup activity of TV tuner input.
111         Intent intent =
112                 CommonUtils.createSetupIntent(
113                         new Intent(context, LiveTvTunerSetupActivity.class), mEmbeddedInputId);
114         intent.putExtra(InputSetupActionUtils.EXTRA_INPUT_ID, mEmbeddedInputId);
115         Intent tvActivityIntent = new Intent();
116         tvActivityIntent.setComponent(new ComponentName(context, TV_ACTIVITY_CLASS_NAME));
117         intent.putExtra(InputSetupActionUtils.EXTRA_ACTIVITY_AFTER_COMPLETION, tvActivityIntent);
118         return intent;
119     }
120 
121     @Override
getEmbeddedTunerInputId()122     public synchronized String getEmbeddedTunerInputId() {
123         if (mEmbeddedInputId == null) {
124             mEmbeddedInputId =
125                     TvContract.buildInputId(
126                             new ComponentName(this, LiveTvTunerTvInputService.class));
127         }
128         return mEmbeddedInputId;
129     }
130 
131     @Override
getRemoteConfig()132     public RemoteConfig getRemoteConfig() {
133         if (mRemoteConfig == null) {
134             // No need to synchronize this, it does not hurt to create two and throw one away.
135             mRemoteConfig = DefaultConfigManager.createInstance(this).getRemoteConfig();
136         }
137         return mRemoteConfig;
138     }
139 }
140