blob: ed61a9211f15afddcc602749ca25514d79df385c [file] [log] [blame]
Fan Zhangefb8d622017-02-23 17:50:27 -08001/*
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 */
Fan Zhang69e95c62017-02-23 16:05:30 -080016package com.android.settings.deviceinfo;
17
18import android.app.Fragment;
19import android.content.Context;
20import android.content.Intent;
21import android.support.v7.preference.Preference;
22import android.text.TextUtils;
23
24import com.android.settings.core.PreferenceController;
25import com.android.settingslib.DeviceInfoUtils;
26
27public class FeedbackPreferenceController extends PreferenceController {
28 private static final String KEY_DEVICE_FEEDBACK = "device_feedback";
Fan Zhangefb8d622017-02-23 17:50:27 -080029
Fan Zhang69e95c62017-02-23 16:05:30 -080030 private final Fragment mHost;
Fan Zhangefb8d622017-02-23 17:50:27 -080031 private final Intent intent;
Fan Zhang69e95c62017-02-23 16:05:30 -080032
33 public FeedbackPreferenceController(Fragment host, Context context) {
34 super(context);
35 this.mHost = host;
Fan Zhangefb8d622017-02-23 17:50:27 -080036 intent = new Intent("android.intent.action.BUG_REPORT");
Fan Zhang69e95c62017-02-23 16:05:30 -080037 }
38
39 public boolean isAvailable() {
Fan Zhangefb8d622017-02-23 17:50:27 -080040 return !TextUtils.isEmpty(DeviceInfoUtils.getFeedbackReporterPackage(mContext));
41 }
42
43 @Override
44 public void updateState(Preference preference) {
45 super.updateState(preference);
46 intent.setPackage(DeviceInfoUtils.getFeedbackReporterPackage(mContext));
47 preference.setIntent(intent);
Fan Zhang69e95c62017-02-23 16:05:30 -080048 }
49
50 public String getPreferenceKey() {
51 return KEY_DEVICE_FEEDBACK;
52 }
53
54 public boolean handlePreferenceTreeClick(Preference preference) {
55 if (!TextUtils.equals(preference.getKey(), KEY_DEVICE_FEEDBACK)) {
56 return false;
57 }
58 if (!this.isAvailable()) {
59 return false;
60 }
Fan Zhangefb8d622017-02-23 17:50:27 -080061
Fan Zhang69e95c62017-02-23 16:05:30 -080062 this.mHost.startActivityForResult(intent, 0);
63 return true;
64 }
65}
66