• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.deviceinfo;
17 
18 import android.app.Fragment;
19 import android.content.Context;
20 import android.content.Intent;
21 import android.support.v7.preference.Preference;
22 import android.text.TextUtils;
23 
24 import com.android.settings.core.PreferenceController;
25 import com.android.settingslib.DeviceInfoUtils;
26 
27 public class FeedbackPreferenceController extends PreferenceController {
28     private static final String KEY_DEVICE_FEEDBACK = "device_feedback";
29 
30     private final Fragment mHost;
31     private final Intent intent;
32 
FeedbackPreferenceController(Fragment host, Context context)33     public FeedbackPreferenceController(Fragment host, Context context) {
34         super(context);
35         this.mHost = host;
36         intent = new Intent("android.intent.action.BUG_REPORT");
37     }
38 
isAvailable()39     public boolean isAvailable() {
40         return !TextUtils.isEmpty(DeviceInfoUtils.getFeedbackReporterPackage(mContext));
41     }
42 
43     @Override
updateState(Preference preference)44     public void updateState(Preference preference) {
45         super.updateState(preference);
46         intent.setPackage(DeviceInfoUtils.getFeedbackReporterPackage(mContext));
47         preference.setIntent(intent);
48     }
49 
getPreferenceKey()50     public String getPreferenceKey() {
51         return KEY_DEVICE_FEEDBACK;
52     }
53 
handlePreferenceTreeClick(Preference preference)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         }
61 
62         this.mHost.startActivityForResult(intent, 0);
63         return true;
64     }
65 }
66 
67