| Fan Zhang | efb8d62 | 2017-02-23 17:50:27 -0800 | [diff] [blame^] | 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 | */ |
| Fan Zhang | 69e95c6 | 2017-02-23 16:05:30 -0800 | [diff] [blame] | 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"; |
| Fan Zhang | efb8d62 | 2017-02-23 17:50:27 -0800 | [diff] [blame^] | 29 | |
| Fan Zhang | 69e95c6 | 2017-02-23 16:05:30 -0800 | [diff] [blame] | 30 | private final Fragment mHost; |
| Fan Zhang | efb8d62 | 2017-02-23 17:50:27 -0800 | [diff] [blame^] | 31 | private final Intent intent; |
| Fan Zhang | 69e95c6 | 2017-02-23 16:05:30 -0800 | [diff] [blame] | 32 | |
| 33 | public FeedbackPreferenceController(Fragment host, Context context) { |
| 34 | super(context); |
| 35 | this.mHost = host; |
| Fan Zhang | efb8d62 | 2017-02-23 17:50:27 -0800 | [diff] [blame^] | 36 | intent = new Intent("android.intent.action.BUG_REPORT"); |
| Fan Zhang | 69e95c6 | 2017-02-23 16:05:30 -0800 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | public boolean isAvailable() { |
| Fan Zhang | efb8d62 | 2017-02-23 17:50:27 -0800 | [diff] [blame^] | 40 | 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 Zhang | 69e95c6 | 2017-02-23 16:05:30 -0800 | [diff] [blame] | 48 | } |
| 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 Zhang | efb8d62 | 2017-02-23 17:50:27 -0800 | [diff] [blame^] | 61 | |
| Fan Zhang | 69e95c6 | 2017-02-23 16:05:30 -0800 | [diff] [blame] | 62 | this.mHost.startActivityForResult(intent, 0); |
| 63 | return true; |
| 64 | } |
| 65 | } |
| 66 | |