1 /* 2 * Copyright (C) 2015 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.ui.sidepanel; 18 19 import android.app.Activity; 20 21 import com.android.tv.MainActivity; 22 import com.android.tv.R; 23 import com.android.tv.common.BuildConfig; 24 import com.android.tv.common.CommonPreferences; 25 import com.android.tv.common.feature.CommonFeatures; 26 import com.android.tv.perf.PerformanceMonitor; 27 28 import com.google.common.base.Optional; 29 import com.google.common.collect.ImmutableList; 30 31 import dagger.android.AndroidInjection; 32 33 import com.android.tv.common.flags.LegacyFlags; 34 35 import javax.inject.Inject; 36 37 /** Options for developers only */ 38 public class DeveloperOptionFragment extends SideFragment { 39 private static final String TRACKER_LABEL = "debug options"; 40 41 @Inject Optional<AdditionalDeveloperItemsFactory> mAdditionalDeveloperItemsFactory; 42 @Inject PerformanceMonitor mPerformanceMonitor; 43 @Inject LegacyFlags mLegacyFlags; 44 45 @Override onAttach(Activity activity)46 public void onAttach(Activity activity) { 47 AndroidInjection.inject(this); 48 super.onAttach(activity); 49 } 50 51 @Override getTitle()52 protected String getTitle() { 53 return getString(R.string.menu_developer_options); 54 } 55 56 @Override getTrackerLabel()57 public String getTrackerLabel() { 58 return TRACKER_LABEL; 59 } 60 61 @Override getItemList()62 protected ImmutableList<Item> getItemList() { 63 ImmutableList.Builder<Item> items = ImmutableList.builder(); 64 if (mAdditionalDeveloperItemsFactory.isPresent()) { 65 items.addAll( 66 mAdditionalDeveloperItemsFactory 67 .get() 68 .getAdditionalDevItems(getMainActivity())); 69 items.add(new DividerItem()); 70 } 71 if (CommonFeatures.DVR.isEnabled(getContext())) { 72 items.add( 73 new ActionItem(getString(R.string.dev_item_dvr_history)) { 74 @Override 75 protected void onSelected() { 76 getMainActivity().getOverlayManager().showDvrHistoryDialog(); 77 } 78 }); 79 } 80 if (BuildConfig.ENG || mLegacyFlags.enableDeveloperFeatures()) { 81 items.add( 82 new ActionItem(getString(R.string.dev_item_watch_history)) { 83 @Override 84 protected void onSelected() { 85 getMainActivity().getOverlayManager().showRecentlyWatchedDialog(); 86 } 87 }); 88 } 89 items.add( 90 new SwitchItem( 91 getString(R.string.dev_item_store_ts_on), 92 getString(R.string.dev_item_store_ts_off), 93 getString(R.string.dev_item_store_ts_description)) { 94 @Override 95 protected void onUpdate() { 96 super.onUpdate(); 97 setChecked(CommonPreferences.getStoreTsStream(getContext())); 98 } 99 100 @Override 101 protected void onSelected() { 102 super.onSelected(); 103 CommonPreferences.setStoreTsStream(getContext(), isChecked()); 104 } 105 }); 106 if (BuildConfig.ENG || mLegacyFlags.enableDeveloperFeatures()) { 107 items.add( 108 new ActionItem(getString(R.string.dev_item_show_performance_monitor_log)) { 109 @Override 110 protected void onSelected() { 111 mPerformanceMonitor.startPerformanceMonitorEventDebugActivity( 112 getContext()); 113 } 114 }); 115 } 116 return items.build(); 117 } 118 119 /** Factory to create additional items. */ 120 public interface AdditionalDeveloperItemsFactory { getAdditionalDevItems(MainActivity mainActivity)121 ImmutableList<Item> getAdditionalDevItems(MainActivity mainActivity); 122 } 123 } 124