Home | History | Annotate | Download | only in util
      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.util;
     18 
     19 import android.content.Context;
     20 import android.content.Intent;
     21 import com.android.tv.InputSessionManager;
     22 import com.android.tv.MainActivityWrapper;
     23 import com.android.tv.TvApplication;
     24 import com.android.tv.TvSingletons;
     25 import com.android.tv.analytics.Analytics;
     26 import com.android.tv.analytics.Tracker;
     27 import com.android.tv.common.config.api.RemoteConfig;
     28 import com.android.tv.common.experiments.ExperimentLoader;
     29 import com.android.tv.common.recording.RecordingStorageStatusManager;
     30 import com.android.tv.common.util.Clock;
     31 import com.android.tv.data.ChannelDataManager;
     32 import com.android.tv.data.PreviewDataManager;
     33 import com.android.tv.data.ProgramDataManager;
     34 import com.android.tv.data.epg.EpgFetcher;
     35 import com.android.tv.data.epg.EpgReader;
     36 import com.android.tv.dvr.DvrDataManager;
     37 import com.android.tv.dvr.DvrManager;
     38 import com.android.tv.dvr.DvrScheduleManager;
     39 import com.android.tv.dvr.DvrWatchedPositionManager;
     40 import com.android.tv.dvr.recorder.RecordingScheduler;
     41 import com.android.tv.perf.PerformanceMonitor;
     42 import com.android.tv.testing.FakeClock;
     43 import com.android.tv.tuner.TunerInputController;
     44 import java.util.concurrent.Executor;
     45 import javax.inject.Provider;
     46 
     47 /** Mock {@link TvSingletons} class. */
     48 public class MockTvSingletons implements TvSingletons {
     49     public final FakeClock fakeClock = FakeClock.createWithCurrentTime();
     50 
     51     private final TvApplication mApp;
     52     private PerformanceMonitor mPerformanceMonitor;
     53 
     54     public MockTvSingletons(Context context) {
     55         mApp = (TvApplication) context.getApplicationContext();
     56     }
     57 
     58     @Override
     59     public Analytics getAnalytics() {
     60         return mApp.getAnalytics();
     61     }
     62 
     63     @Override
     64     public void handleInputCountChanged() {}
     65 
     66     @Override
     67     public ChannelDataManager getChannelDataManager() {
     68         return mApp.getChannelDataManager();
     69     }
     70 
     71     @Override
     72     public boolean isChannelDataManagerLoadFinished() {
     73         return mApp.isChannelDataManagerLoadFinished();
     74     }
     75 
     76     @Override
     77     public ProgramDataManager getProgramDataManager() {
     78         return mApp.getProgramDataManager();
     79     }
     80 
     81     @Override
     82     public boolean isProgramDataManagerCurrentProgramsLoadFinished() {
     83         return mApp.isProgramDataManagerCurrentProgramsLoadFinished();
     84     }
     85 
     86     @Override
     87     public PreviewDataManager getPreviewDataManager() {
     88         return mApp.getPreviewDataManager();
     89     }
     90 
     91     @Override
     92     public DvrDataManager getDvrDataManager() {
     93         return mApp.getDvrDataManager();
     94     }
     95 
     96     @Override
     97     public Clock getClock() {
     98         return fakeClock;
     99     }
    100 
    101     @Override
    102     public RecordingStorageStatusManager getRecordingStorageStatusManager() {
    103         return mApp.getRecordingStorageStatusManager();
    104     }
    105 
    106     @Override
    107     public DvrScheduleManager getDvrScheduleManager() {
    108         return mApp.getDvrScheduleManager();
    109     }
    110 
    111     @Override
    112     public DvrManager getDvrManager() {
    113         return mApp.getDvrManager();
    114     }
    115 
    116     @Override
    117     public RecordingScheduler getRecordingScheduler() {
    118         return mApp.getRecordingScheduler();
    119     }
    120 
    121     @Override
    122     public DvrWatchedPositionManager getDvrWatchedPositionManager() {
    123         return mApp.getDvrWatchedPositionManager();
    124     }
    125 
    126     @Override
    127     public InputSessionManager getInputSessionManager() {
    128         return mApp.getInputSessionManager();
    129     }
    130 
    131     @Override
    132     public Tracker getTracker() {
    133         return mApp.getTracker();
    134     }
    135 
    136     @Override
    137     public TvInputManagerHelper getTvInputManagerHelper() {
    138         return mApp.getTvInputManagerHelper();
    139     }
    140 
    141     @Override
    142     public Provider<EpgReader> providesEpgReader() {
    143         return mApp.providesEpgReader();
    144     }
    145 
    146     @Override
    147     public EpgFetcher getEpgFetcher() {
    148         return mApp.getEpgFetcher();
    149     }
    150 
    151     @Override
    152     public SetupUtils getSetupUtils() {
    153         return mApp.getSetupUtils();
    154     }
    155 
    156     @Override
    157     public TunerInputController getTunerInputController() {
    158         return mApp.getTunerInputController();
    159     }
    160 
    161     @Override
    162     public ExperimentLoader getExperimentLoader() {
    163         return mApp.getExperimentLoader();
    164     }
    165 
    166     @Override
    167     public MainActivityWrapper getMainActivityWrapper() {
    168         return mApp.getMainActivityWrapper();
    169     }
    170 
    171     @Override
    172     public com.android.tv.util.account.AccountHelper getAccountHelper() {
    173         return mApp.getAccountHelper();
    174     }
    175 
    176     @Override
    177     public RemoteConfig getRemoteConfig() {
    178         return mApp.getRemoteConfig();
    179     }
    180 
    181     @Override
    182     public Intent getTunerSetupIntent(Context context) {
    183         return mApp.getTunerSetupIntent(context);
    184     }
    185 
    186     @Override
    187     public boolean isRunningInMainProcess() {
    188         return mApp.isRunningInMainProcess();
    189     }
    190 
    191     @Override
    192     public PerformanceMonitor getPerformanceMonitor() {
    193         return mPerformanceMonitor != null ? mPerformanceMonitor : mApp.getPerformanceMonitor();
    194     }
    195 
    196     public void setPerformanceMonitor(PerformanceMonitor performanceMonitor) {
    197         mPerformanceMonitor = performanceMonitor;
    198     }
    199 
    200     @Override
    201     public String getEmbeddedTunerInputId() {
    202         return "com.android.tv/.tuner.tvinput.LiveTvTunerTvInputService";
    203     }
    204 
    205     @Override
    206     public Executor getDbExecutor() {
    207         return mApp.getDbExecutor();
    208     }
    209 }
    210