1 /*
2  * Copyright (C) 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.settings;
18 
19 import android.app.Activity;
20 import android.content.Context;
21 
22 import androidx.preference.Preference;
23 
24 import com.android.settingslib.core.AbstractPreferenceController;
25 import com.android.tv.settings.system.development.DevelopmentFragment;
26 
27 /**
28  * Add "take a bug report" preference for quick settings in dog-food device.
29  */
30 public class TakeBugReportController extends AbstractPreferenceController {
31     static final String KEY_TAKE_BUG_REPORT = "take_bug_report";
32 
TakeBugReportController(Context context)33     public TakeBugReportController(Context context) {
34         super(context);
35     }
36 
37     @Override
isAvailable()38     public boolean isAvailable() {
39         return android.os.Build.TYPE.equals("userdebug")
40                 && mContext != null
41                 && mContext.getResources() != null
42                 && mContext.getResources().getBoolean(
43                         R.bool.config_quick_settings_show_take_bugreport);
44     }
45 
46     @Override
getPreferenceKey()47     public String getPreferenceKey() {
48         return KEY_TAKE_BUG_REPORT;
49     }
50 
51     @Override
handlePreferenceTreeClick(Preference preference)52     public boolean handlePreferenceTreeClick(Preference preference) {
53         if (KEY_TAKE_BUG_REPORT.equals(preference.getKey())) {
54             DevelopmentFragment.captureBugReport((Activity) mContext);
55             return true;
56         }
57         return super.handlePreferenceTreeClick(preference);
58     }
59 
60     @Override
updateState(Preference preference)61     public void updateState(Preference preference) {
62         super.updateState(preference);
63         if (KEY_TAKE_BUG_REPORT.equals(preference.getKey())) {
64             preference.setTitle(com.android.internal.R.string.bugreport_title);
65             preference.setIcon(R.drawable.ic_bug_report);
66         }
67     }
68 }
69