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