1/* 2 * Copyright (C) 2016 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 17package com.android.settings.development; 18 19import android.content.Context; 20import android.os.UserManager; 21import android.support.v7.preference.Preference; 22import android.support.v7.preference.PreferenceScreen; 23 24import com.android.settings.core.PreferenceControllerMixin; 25import com.android.settingslib.core.AbstractPreferenceController; 26 27public class BugReportPreferenceController extends AbstractPreferenceController implements 28 PreferenceControllerMixin { 29 30 private static final String KEY_BUGREPORT = "bugreport"; 31 32 private UserManager mUserManager; 33 private Preference mPreference; 34 35 public BugReportPreferenceController(Context context) { 36 super(context); 37 mUserManager = (UserManager) context.getSystemService(Context.USER_SERVICE); 38 } 39 40 @Override 41 public void displayPreference(PreferenceScreen screen) { 42 super.displayPreference(screen); 43 if (isAvailable()) { 44 mPreference = screen.findPreference(KEY_BUGREPORT); 45 } 46 } 47 48 @Override 49 public String getPreferenceKey() { 50 return KEY_BUGREPORT; 51 } 52 53 @Override 54 public boolean isAvailable() { 55 return !mUserManager.hasUserRestriction(UserManager.DISALLOW_DEBUGGING_FEATURES); 56 } 57 58 public void enablePreference(boolean enabled) { 59 if (isAvailable()) { 60 mPreference.setEnabled(enabled); 61 } 62 } 63 64} 65