1 /*
2  * Copyright (C) 2019 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.settings.help;
18 
19 import android.content.pm.ResolveInfo;
20 import android.os.Bundle;
21 
22 import androidx.annotation.Keep;
23 import androidx.preference.Preference;
24 
25 import com.android.internal.logging.nano.MetricsProto;
26 import com.android.tv.settings.MainFragment;
27 import com.android.tv.settings.R;
28 import com.android.tv.settings.SettingsPreferenceFragment;
29 import com.android.tv.settings.overlay.FeatureFactory;
30 
31 /**
32  * The "Help & feedback" screen in TV settings.
33  */
34 @Keep
35 public class HelpFragment extends SettingsPreferenceFragment {
36 
37     private static final String KEY_HELP = "help_center";
38 
39     @Override
onCreatePreferences(Bundle savedInstanceState, String rootKey)40     public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
41         setPreferencesFromResource(R.xml.help_and_feedback, null);
42 
43         final Preference helpPref = findPreference(KEY_HELP);
44         if (helpPref != null) {
45             final ResolveInfo info = MainFragment.systemIntentIsHandled(getActivity(),
46                     helpPref.getIntent());
47             helpPref.setVisible(info != null);
48         }
49     }
50 
51     @Override
onPreferenceTreeClick(Preference preference)52     public boolean onPreferenceTreeClick(Preference preference) {
53         switch (preference.getKey()) {
54             case KEY_HELP:
55                 FeatureFactory.getFactory(getActivity()).getSupportFeatureProvider().startSupport(
56                         getActivity());
57                 return true;
58             default:
59                 return super.onPreferenceTreeClick(preference);
60         }
61     }
62 
63     @Override
getMetricsCategory()64     public int getMetricsCategory() {
65         return MetricsProto.MetricsEvent.ACTION_SETTING_HELP_AND_FEEDBACK;
66     }
67 }
68