• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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.common.actions;
18 
19 import android.content.Intent;
20 import android.media.tv.TvInputInfo;
21 import android.os.Bundle;
22 import android.support.annotation.Nullable;
23 
24 /** Constants and static utilities for the Input Setup Action. */
25 public class InputSetupActionUtils {
26 
27     /**
28      * An intent action to launch setup activity of a TV input.
29      *
30      * <p>The intent should include TV input ID in the value of {@link #EXTRA_INPUT_ID}. Optionally,
31      * given the value of {@link #EXTRA_ACTIVITY_AFTER_COMPLETION}, the activity will be launched
32      * after the setup activity successfully finishes.
33      */
34     public static final String INTENT_ACTION_INPUT_SETUP =
35             "com.android.tv.action.LAUNCH_INPUT_SETUP";
36     /**
37      * A constant of the key to indicate a TV input ID for the intent action {@link
38      * #INTENT_ACTION_INPUT_SETUP}.
39      *
40      * <p>Value type: String
41      */
42     public static final String EXTRA_INPUT_ID = TvInputInfo.EXTRA_INPUT_ID;
43     /**
44      * A constant of the key for intent to launch actual TV input setup activity used with {@link
45      * #INTENT_ACTION_INPUT_SETUP}.
46      *
47      * <p>Value type: Intent (Parcelable)
48      */
49     public static final String EXTRA_SETUP_INTENT = "com.android.tv.extra.SETUP_INTENT";
50     /**
51      * A constant of the key to indicate an Activity launch intent for the intent action {@link
52      * #INTENT_ACTION_INPUT_SETUP}.
53      *
54      * <p>Value type: Intent (Parcelable)
55      */
56     public static final String EXTRA_ACTIVITY_AFTER_COMPLETION =
57             "com.android.tv.intent.extra.ACTIVITY_AFTER_COMPLETION";
58     /**
59      * An intent action to launch setup activity of a TV input.
60      *
61      * <p>The intent should include TV input ID in the value of {@link #EXTRA_INPUT_ID}. Optionally,
62      * given the value of {@link #EXTRA_GOOGLE_ACTIVITY_AFTER_COMPLETION}, the activity will be
63      * launched after the setup activity successfully finishes.
64      *
65      * <p>Value type: Intent (Parcelable)
66      *
67      * @deprecated Use {@link #INTENT_ACTION_INPUT_SETUP} instead
68      */
69     @Deprecated
70     private static final String INTENT_GOOGLE_ACTION_INPUT_SETUP =
71             "com.google.android.tv.action.LAUNCH_INPUT_SETUP";
72     /**
73      * A Google specific constant of the key for intent to launch actual TV input setup activity
74      * used with {@link #INTENT_ACTION_INPUT_SETUP}.
75      *
76      * <p>Value type: Intent (Parcelable)
77      *
78      * @deprecated Use {@link #EXTRA_SETUP_INTENT} instead
79      */
80     @Deprecated
81     private static final String EXTRA_GOOGLE_SETUP_INTENT =
82             "com.google.android.tv.extra.SETUP_INTENT";
83     /**
84      * A Google specific constant of the key to indicate an Activity launch intent for the intent
85      * action {@link #INTENT_ACTION_INPUT_SETUP}.
86      *
87      * <p>Value type: Intent (Parcelable)
88      *
89      * @deprecated Use {@link #EXTRA_ACTIVITY_AFTER_COMPLETION} instead
90      */
91     @Deprecated
92     private static final String EXTRA_GOOGLE_ACTIVITY_AFTER_COMPLETION =
93             "com.google.android.tv.intent.extra.ACTIVITY_AFTER_COMPLETION";
94 
removeSetupIntent(Bundle extras)95     public static void removeSetupIntent(Bundle extras) {
96         extras.remove(EXTRA_SETUP_INTENT);
97         extras.remove(EXTRA_GOOGLE_SETUP_INTENT);
98     }
99 
100     @Nullable
getExtraSetupIntent(Intent intent)101     public static Intent getExtraSetupIntent(Intent intent) {
102         Bundle extras = intent.getExtras();
103         if (extras == null) {
104             return null;
105         }
106         Intent setupIntent = extras.getParcelable(EXTRA_SETUP_INTENT);
107         return setupIntent != null ? setupIntent : extras.getParcelable(EXTRA_GOOGLE_SETUP_INTENT);
108     }
109 
110     @Nullable
getExtraActivityAfter(Intent intent)111     public static Intent getExtraActivityAfter(Intent intent) {
112         Bundle extras = intent.getExtras();
113         if (extras == null) {
114             return null;
115         }
116         Intent setupIntent = extras.getParcelable(EXTRA_ACTIVITY_AFTER_COMPLETION);
117         return setupIntent != null
118                 ? setupIntent
119                 : extras.getParcelable(EXTRA_GOOGLE_ACTIVITY_AFTER_COMPLETION);
120     }
121 
hasInputSetupAction(Intent intent)122     public static boolean hasInputSetupAction(Intent intent) {
123         String action = intent.getAction();
124         return INTENT_ACTION_INPUT_SETUP.equals(action)
125                 || INTENT_GOOGLE_ACTION_INPUT_SETUP.equals(action);
126     }
127 }
128