1 /* 2 * Copyright 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.common; 18 19 import android.content.Intent; 20 import android.media.tv.TvInputInfo; 21 22 /** 23 * Util class for common use in TV app and inputs. 24 */ 25 public final class TvCommonUtils { TvCommonUtils()26 private TvCommonUtils() { } 27 28 /** 29 * Returns an intent to start the setup activity for the TV input using {@link 30 * TvCommonConstants#INTENT_ACTION_INPUT_SETUP}. 31 */ createSetupIntent(Intent originalSetupIntent, String inputId)32 public static Intent createSetupIntent(Intent originalSetupIntent, String inputId) { 33 if (originalSetupIntent == null) { 34 return null; 35 } 36 Intent setupIntent = new Intent(originalSetupIntent); 37 if (!TvCommonConstants.INTENT_ACTION_INPUT_SETUP.equals(originalSetupIntent.getAction())) { 38 Intent intentContainer = new Intent(TvCommonConstants.INTENT_ACTION_INPUT_SETUP); 39 intentContainer.putExtra(TvCommonConstants.EXTRA_SETUP_INTENT, originalSetupIntent); 40 intentContainer.putExtra(TvCommonConstants.EXTRA_INPUT_ID, inputId); 41 setupIntent = intentContainer; 42 } 43 return setupIntent; 44 } 45 46 /** 47 * Returns an intent to start the setup activity for this TV input using {@link 48 * TvCommonConstants#INTENT_ACTION_INPUT_SETUP}. 49 */ createSetupIntent(TvInputInfo input)50 public static Intent createSetupIntent(TvInputInfo input) { 51 return createSetupIntent(input.createSetupIntent(), input.getId()); 52 } 53 54 /** 55 * Checks if this application is running in tests. 56 * 57 * <p>{@link android.app.ActivityManager#isRunningInTestHarness} doesn't return {@code true} for 58 * the usual devices even the application is running in tests. We need to figure it out by 59 * checking whether the class in tv-tests-common module can be loaded or not. 60 */ isRunningInTest()61 public static boolean isRunningInTest() { 62 try { 63 Class.forName("com.android.tv.testing.Utils"); 64 return true; 65 } catch (ClassNotFoundException e) { 66 return false; 67 } 68 } 69 } 70