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.PreferenceControllerMixin; 25 import com.android.settingslib.DeviceInfoUtils; 26 import com.android.settingslib.core.AbstractPreferenceController; 27 28 public class FeedbackPreferenceController extends AbstractPreferenceController implements 29 PreferenceControllerMixin { 30 private static final String KEY_DEVICE_FEEDBACK = "device_feedback"; 31 32 private final Fragment mHost; 33 private final Intent intent; 34 FeedbackPreferenceController(Fragment host, Context context)35 public FeedbackPreferenceController(Fragment host, Context context) { 36 super(context); 37 this.mHost = host; 38 intent = new Intent("android.intent.action.BUG_REPORT"); 39 } 40 isAvailable()41 public boolean isAvailable() { 42 return !TextUtils.isEmpty(DeviceInfoUtils.getFeedbackReporterPackage(mContext)); 43 } 44 45 @Override updateState(Preference preference)46 public void updateState(Preference preference) { 47 super.updateState(preference); 48 intent.setPackage(DeviceInfoUtils.getFeedbackReporterPackage(mContext)); 49 preference.setIntent(intent); 50 } 51 getPreferenceKey()52 public String getPreferenceKey() { 53 return KEY_DEVICE_FEEDBACK; 54 } 55 handlePreferenceTreeClick(Preference preference)56 public boolean handlePreferenceTreeClick(Preference preference) { 57 if (!TextUtils.equals(preference.getKey(), KEY_DEVICE_FEEDBACK)) { 58 return false; 59 } 60 if (!this.isAvailable()) { 61 return false; 62 } 63 64 this.mHost.startActivityForResult(intent, 0); 65 return true; 66 } 67 } 68 69