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 package com.android.settings.support;
17 
18 import android.app.Activity;
19 import android.content.Context;
20 import android.os.Bundle;
21 
22 import com.android.settings.R;
23 import com.android.settings.overlay.FeatureFactory;
24 import com.android.settings.overlay.SupportFeatureProvider;
25 import com.android.settings.search.BaseSearchIndexProvider;
26 import com.android.settingslib.search.Indexable;
27 import com.android.settingslib.search.SearchIndexable;
28 import com.android.settingslib.search.SearchIndexableRaw;
29 
30 import java.util.ArrayList;
31 import java.util.List;
32 
33 /**
34  * Trampoline activity that decides which version of support should be shown to the user.
35  */
36 @SearchIndexable
37 public class SupportDashboardActivity extends Activity implements Indexable {
38 
39     public static final String ACTION_SUPPORT_SETTINGS =
40             "com.android.settings.action.SUPPORT_SETTINGS";
41 
42     @Override
onCreate(Bundle savedInstanceState)43     protected void onCreate(Bundle savedInstanceState) {
44         super.onCreate(savedInstanceState);
45         SupportFeatureProvider supportFeatureProvider = FeatureFactory.getFeatureFactory()
46                 .getSupportFeatureProvider();
47 
48         // try to launch support if we have the feature provider
49         if (supportFeatureProvider != null) {
50             supportFeatureProvider.startSupport(this);
51             finish();
52         }
53     }
54 
55     /**
56      * For Search.
57      */
58     public static final BaseSearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
59             new BaseSearchIndexProvider() {
60                 private static final String SUPPORT_SEARCH_INDEX_KEY = "support_dashboard_activity";
61 
62                 @Override
63                 public List<SearchIndexableRaw> getRawDataToIndex(Context context,
64                         boolean enabled) {
65 
66                     final List<SearchIndexableRaw> result = new ArrayList<>();
67 
68                     // Add the activity title
69                     SearchIndexableRaw data = new SearchIndexableRaw(context);
70                     data.title = context.getString(R.string.page_tab_title_support);
71                     data.screenTitle = context.getString(R.string.page_tab_title_support);
72                     data.summaryOn = context.getString(R.string.support_summary);
73                     data.intentTargetPackage = context.getPackageName();
74                     data.intentTargetClass = SupportDashboardActivity.class.getName();
75                     data.intentAction = ACTION_SUPPORT_SETTINGS;
76                     data.key = SUPPORT_SEARCH_INDEX_KEY;
77                     result.add(data);
78 
79                     return result;
80                 }
81 
82                 @Override
83                 public List<String> getNonIndexableKeys(Context context) {
84                     final List<String> keys = super.getNonIndexableKeys(context);
85                     if (!context.getResources().getBoolean(R.bool.config_support_enabled)) {
86                         keys.add(SUPPORT_SEARCH_INDEX_KEY);
87                     }
88                     return keys;
89                 }
90             };
91 }
92