1 /* 2 * Copyright (C) 2018 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.testing.testdata; 18 19 import android.content.Context; 20 import android.media.tv.TvInputInfo; 21 import com.android.tv.common.util.Clock; 22 import com.android.tv.testing.data.ChannelInfo; 23 import com.android.tv.testing.data.ChannelUtils; 24 import com.android.tv.testing.data.ProgramUtils; 25 import com.android.tv.testing.utils.TestUtils; 26 import java.util.List; 27 28 /** 29 * A set of test data. 30 * 31 * <p>contains: 32 * 33 * <ul> 34 * <li>InputID 35 * <li>Channel List 36 * </ul> 37 * 38 * Call {@link #init(Context)}, to update the TvProvider data base with the given values. 39 */ 40 public abstract class TestData { 41 private List<ChannelInfo> channelList; 42 createChannels(Context context)43 protected abstract List<ChannelInfo> createChannels(Context context); 44 init(Context context, Clock clock, long durationMs)45 public void init(Context context, Clock clock, long durationMs) { 46 channelList = createChannels(context); 47 ChannelUtils.updateChannels(context, getInputId(), channelList); 48 ProgramUtils.updateProgramForAllChannelsOf(context, getInputId(), clock, durationMs); 49 } 50 getTvInputInfo()51 public abstract TvInputInfo getTvInputInfo(); 52 getInputId()53 public final String getInputId() { 54 return getTvInputInfo().getId(); 55 } 56 57 public static final TestData DEFAULT_10_CHANNELS = 58 new TestData() { 59 private TvInputInfo mTvInputInfo = createTvInputInfo(); 60 61 private TvInputInfo createTvInputInfo() { 62 try { 63 return TestUtils.createTvInputInfo( 64 TestUtils.createResolveInfo( 65 "com.android.tv.testing.testdata", 66 "com.android.tv.testing.testdata.Default10Channels"), 67 "com.android.tv.testing.testdata/.Default10Channels", 68 null, 69 TvInputInfo.TYPE_TUNER, 70 true); 71 } catch (Exception e) { 72 throw new RuntimeException(e); 73 } 74 } 75 76 @Override 77 protected List<ChannelInfo> createChannels(Context context) { 78 return ChannelUtils.createChannelInfos(context, 10); 79 } 80 81 @Override 82 public TvInputInfo getTvInputInfo() { 83 return mTvInputInfo; 84 } 85 }; 86 } 87